Use the CAs login module to connect to a database to verify user legitimacy

Source: Internet
Author: User
Tags cas ticket

Use CAS Login Module Connecting application database verifying user legitimacy

For more information on how to configure the CAS login module to integrate into the development WEB application See here:

http://blog.csdn.net/jia20003/article/details/49683827

Based on the CAS server 3.5.0 version configuration implementation.

Here we mainly describe how to take advantage of existing user data tables user_table in the username with the Password Two fields to enable the user to CAS Module Login time Query our application database Basicweb in the user_table table. Verify the user name and password, and actually implement the user's legality check.

the approximate steps need to be configured as follows to first open CAS server of the War package Then in Web-inf found in the directory Deployerconfigcontext.xml This file opens to find:

<bean class= "Org.jasig.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler"/ >

替换为:

<bean id= "Searchmodesearchdatabaseauthenticationhandler"  class= " Org.jasig.cas.adaptors.jdbc.SearchModeSearchDatabaseAuthenticationHandler "  abstract=" false "lazy-init=" Default "autowire=" Default ">  <property  name=" Tableusers ">   <value>user_table</ value>  </property>  <property name= "Fielduser" >   <value>username</value>  </property>  <property name= "Fieldpassword" >   <value>password</value>  </property>  <property name= "DataSource" ref= "DataSource"/></bean> <bean class= " Org.jasig.cas.adaptors.jdbc.QueryDatabaseAuthenticationHandler ">  <property name=" DataSource "ref=" DataSource "/>  <property name=" SQL "value=" select password from user_table where lower (username) = lower (?) "/ ></bean>

which user_table to be Basicweb tables in the database

username with the Password is its two field name

and then in the outermost Beans Add in Tags DataSource The relevant configuration is as follows:

<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://localhost:3306/basicweb</value></property>  <property name= "username" ><value>root</value></property>  <property name= "password "><value>password123</value></property>  </bean>  

Save later overwriteWarin the original configuration file. Finally, we need to openWarinWeb-infdirectory underLibCatalog toMySQL JDBCConnection SupportJarwith the download goodCas-server-3.5.0-rc1\modules\cas-server-support-jdbc-3.5.0-rc1.jarare added toLibdirectory to go, and then saveWar, redeploy toTomcat\webappsdirectory.

The test finds that the post submits the form without data, and the workaround is to add the following configuration in Web. xml:

<filter><filter-name>cas Validation filter</filter-name><filter-class> Org.jasig.cas.client.validation.cas20proxyreceivingticketvalidationfilter</filter-class><init-param ><param-name>casserverurlprefix</param-name><param-value>http://localhost:8080/cas</ param-value></init-param><init-param><param-name>servername</param-name>< param-value>http://localhost:8080</param-value></init-param><!--Agent--><init-param> <param-name>acceptanyproxy</param-name><param-value>true</param-value></init-param ><!--configured to False, otherwise the parameter passed by the agent is not received--><init-param><param-name>redirectaftervalidation</ Param-name><param-value>false</param-value></init-param></filter>
The reason is that if you do not add it, it will validate ticket and find that the URL we submitted does notticket is not considered legal, re-created the new ticket, resulting in the loss of form data



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Use the CAs login module to connect to a database to verify user legitimacy

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.