zoukankan      html  css  js  c++  java
  • SSO之CAS配置二——数据库和LDAP

    对于CAS Server的cas.war中默认的认证Handler是SimpleTestUsernamePasswordAuthenticationHandler,该方式只要输入的用户名和密码相同就能通过验证,因此需要更改设置,常见的有数据库,xml文件,ldap方式。下面讲述数据库和ldap两种方式。

      在CAS Server中webapp下的cas中配置文件deployerConfigContext.xml,把上述的简单认证注释掉,在其下面加入数据库handler,如下:

    <bean class="org.jasig.cas.adaptors.jdbc.QueryDatabaseAuthenticationHandler">

                          <property name="dataSource" ref="dataSource"></property>
                          <property name="sql" value="select password from t_admin_user where login_name=?"></property>
                            <!-- <property name="passwordEncoder" ref="MD5PasswordEncoder"></property> -->

            </bean> 

    上述配置还是用到了dataSource和passwordEncoder,因此需要加入以下配置,位置只要在<beans>下就行:

    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">

        <property name="driverClassName"><value>com.mysql.jdbc.Driver</value></property>
        <property name="url"><value>jdbc:mysql://173.39.160.72/ireg?useUnicode=true&amp;characterEncoding=UTF-8&amp;autoReconnect=true</value></property>
        <property name="username"><value>root</value></property>
        <property name="password"><value>root</value></property>
    </bean>

      <bean id="MD5PasswordEncoder" class="org.jasig.cas.authentication.handler.DefaultPasswordEncoder">
         <constructor-arg index="0">
             <value>MD5</value>
         </constructor-arg>

    </bean> 

    其中ireg是存储用户表t_admin_user的数据库,如果数据库中的密码没有采取MD5散列的话,就不要加入passwordEncoder属性了,就像我上面的配置。

      然后再CAS Server中的webapp下cas的库加入,数据库连接驱动和包支持,mysql-connector-java-5.1.18-bin.jar和cas-server-support-jdbc-3.5.1.jar。

     对于我的程序来说,访问测试web应用http://cas.client:8080/CasClient/index.jsp 然后输入数据库中的密码就可以正常查看了。

      对于LDAP来讲,同样是改变deployerConfigContext.xml,加入LDAP的handler,如下:

    <bean class="org.jasig.cas.adaptors.ldap.BindLdapAuthenticationHandler">    

             <property name="filter" value="uid=%u" />    
             <!-- 基节点 -->  
             <property name="searchBase" value="ou=system" />    
             <property  name="contextSource" ref="contextSource" />    

         </bean>   

    还要在其他位置加入contextSource的配置:

    <bean id="contextSource" class="org.springframework.ldap.core.support.LdapContextSource">       

        <property name="anonymousReadOnly" value="false" />  
        <property name="password" value="secret" />  
        <property name="pooled" value="true" />  
        <property name="urls">  
            <list>  
                value>ldap://dsx.xxxxx.com/</value>   
            </list>  
        </property>  
        <!-- 如果是老版本,这里应该用的是userName,而不是userDn -->   
        <property name="userDn" value="uid=admin,ou=system" />  
        <property name="baseEnvironmentProperties">  
            <map>  
              <entry>    
                <!--none 端口 389-->      
                <!--ssl 端口 636-->                       
                <key><value>java.naming.security.protocol</value></key>    
                <value>none</value>    
              </entry>    
              <entry>                       
                <key><value>java.naming.security.authentication</value></key>         
                <value>simple</value>  
              </entry>  
            </map>  
        </property>  

    </bean>  

      然后在cas 库中加入cas-server-support-ldap-3.5.1.jar ,spring-ldap的jar文件,应该就可以了,因为这个例子没有测试,所以先写在这儿,测试后如果有错误会更改!

     

  • 相关阅读:
    页面转表格并且下载
    关于表格导入
    C/C++作用域运算符::
    设计模式之观察者模式_C++
    C# 传不定参数
    C语言中的位域的使用
    C++/python求哈希值(SHA256)
    C++中纯虚函数
    类模板/函数模板实现父类指针指向子类对象(虚函数实现多态)
    Windows Socket 接口简介
  • 原文地址:https://www.cnblogs.com/kingcucumber/p/2826748.html
Copyright © 2011-2022 走看看