CAS database query authentication (XML configuration)

Source: Internet
Author: User
Tags cas

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.