the previous blog introduction CAS of the Demo , login interface user name, password and not through database query authentication. This blog, will show how to use the XML configuration, CAS Login database query authentication.
the required database SSO _cas, tables in the library: Tb_user , the fields in the table: Id , username , Password ;
database query authentication (via XML configuration)
1 , modify CAs server-side configuration
Tomcat under Webapps/cas/web_inf/deployerconfigcontext.xml The following changes are made to the file:
<beanclass= "Org.jasig.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler"/ >
Modified to:
<beanclass= "Org.jasig.cas.adaptors.jdbc.QueryDatabaseAuthenticationHandler" >
<propertyname= "DataSource" ref= "DataSource" ></property>
<propertyname= "SQL" value= "select password from Tb_user whereusername=?" ></property>
</property>
</bean>
Add DataSource Bean definition of:
<beanid= "DataSource"
class= "Org.springframework.jdbc.datasource.DriverManagerDataSource" >
<propertyname= "Driverclassname" value= "Com.mysql.jdbc.Driver"/>
<propertyname= "url" value= "Jdbc:mysql://localhost/sso_cas"/>
<propertyname= "username" value= "root"/>
<propertyname= "Password" value= "root"/>
</bean>
Attention
1,querydatabaseauthenticationhandler is a Cas-server-support-jdbc One of the query interfaces provided is by configuring a SQL The statement identifies the password and matches the given password;
2,sql Statement : Select password from Tb_user whereusername=? based on user name User name query table tb_user password password field,CAS Matches the password entered by the user, if the match is passed;
Note: Multiple databases can be configured
If you need to configure multiple databases, you can configure multiple Querydatabaseauthenticationhandler and multiple DataSource
if a_user auser b_user There is a user buser cas a_user If the username and password are correct, then pass if a_user cas b_user , the user name password is correct even if passed, at this time is not correct, even if the login verification failed.
Add the related Jar Package
need to be Web of the project Lib Add two packages below: Cas-server-support-jdbc-x.x.x.jar and the Mysql-connector-java-x.x.x-bin.jar(Specific version number is subject to availability)
when configured as follows, enter CAS login page, user name password needs to be authenticated by querying the database, enter the user name Admin , Password 123 to log on successfully, if you enter a user name Admin , Password Admin is not able to log on successfully.
CAS database query authentication (XML configuration)