日期:2014-05-16  浏览次数:20583 次

cas通过jdbc方式认证用户

?

?

<!-- [if !mso]> <style> v\:* {behavior:url(#default#VML);} o\:* {behavior:url(#default#VML);} p\:* {behavior:url(#default#VML);} .shape {behavior:url(#default#VML);} v\:textbox {display:none;} </style> <![endif]--><!-- [if !ppt]--><!-- [endif]-->

cas-server 端默认的账号验证方式为用户名与密码相同即可,若需改为连接数据库形式则需
? 1) 修改 cas/WEB-INF/deployerConfigContext.xml
? ? 添加 DataSource

<bean id="dataSource"class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName"><value>……</value</property>
        <property name=“url”><value>……</value></property>
        <property name="username"><value>……</value></property>
        <property name="password"><value>……</value></property>
</bean> 
?
? 2) 替换 AuthenticationHandler
? ? 注释掉下面的bean
   <bean class="org.jasig.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler" /> 
?
然后在同一位置添加bean:
<!-- 用sql形式验证  -->
<bean class="org.jasig.cas.adaptors.jdbc.QueryDatabaseAuthenticationHandler">
?<property name="sql" value="select password from t_user where username=?" />
?<property name="dataSource" ref="dataSource" />
<property name=“passwordEncoder” ref=“mypasswordEncoder”/>
?</bean>
?
<!-- [if !mso]> <style> v\:* {behavior:url(#default#VML);} o\:* {behavior:url(#default#VML);} p\:* {behavior:url(#default#VML);} .shape {behavior:url(#default#VML);} v\:textbox {display:none;} </style> <![endif]--><!-- [if !ppt]--><!-- [endif]-->
?
3.在最外层添加密码的蝙蝠方式bean:
<bean id="mypasswordEncoder"   class="org.jasig.cas.authentication.handler.DefaultPasswordEncoder">
       <constructor-arg value="MD5"/>
</bean> 
?
<!-- [if !mso]> <style> v\:* {behavior:url(#default#VML);} o\:* {behavior:url(#default#VML);} p\:* {behavior:url(#default#VML);} .shape {behavior:url(#default#VML);} v\:textbox {display:none;} </style> <![endif]--><!-- [if !ppt]--><!-- [endif]-->
?
?