CAS Single Sign-on modify authentication mode Jeesite

Source: Internet
Author: User
Tags cas

This article draws on the single sign-on CAS series section No. 04.

First of all we want to import CAs into MyEclipse, the specific method (self-created project, gradle), I used the first method, after the creation of a Web project, the compiled files copied to the project, the directory must be correct Oh,

As shown in figure:

1, CSA's default login user password configuration in deployerconfigcontext.xml, so go to deployerconfigcontext.xml inside find

You can find <bean id= "Primaryauthenticationhandler" class= "Org.jasig ... Acceptusersauthenticationhandler ">

We found in Acceptusersauthenticationhandler.java that the CAs are reading the configured user passwords to the global map<string, string>

2, and Acceptusersauthenticationhandler.java is achieved through the inheritance of Abstractusernamepasswordauthenticationhandler.java certification

So create Com.jadyer.sso.authentication.UserAuthenticationHandler extends Abstractusernamepasswordauthenticationhandler

Then rewrite the authenticateusernamepasswordinternal () method, in the inside to get to the front page input user password, and then to the database commander to check on the line.

3. Next Create \web-inf\spring-configuration\applicationcontext-datasource.xml

It will be loaded automatically at startup (as set in Web. xml)

Then configure the database connection pool, the user name password of the connection pool, etc. can be configured in \web-inf\cas.properties

Add <context:component-scan base-package= "Com.jadyer.sso"/> at the same time, making it possible to apply spring annotations to custom classes

4. Create a new Userdaojdbc.java class that uses Springjdbctemplate to access the database

Because you want to connect to the database, you also add the Druid jar package and the Mysql-connector-java jar package to the Lib directory

5, finally remember deployerconfigcontext.xml inside put this section bean configuration to comment out <bean id= "Primaryauthenticationhandler" >

and declare it as a bean using @component (value= "Primaryauthenticationhandler") in the custom Userauthenticationhandler.java

Note that the name should be Primaryauthenticationhandler, because the other configuration of deployerconfigcontext.xml references the Primaryauthenticationhandler

Or you're going to find a location that references Primaryauthenticationhandler. Modify to a new bean


Here's how to do it specifically:

1, authentication class Userauthenticationhandler.java

[HTML]  View Plain  copy package authentication;   import  java.security.generalsecurityexception;   import javax.annotation.resource;   Import  javax.security.auth.login.FailedLoginException;   import  org.jasig.cas.authentication.handlerresult;   import  org.jasig.cas.authentication.preventedexception;   import  org.jasig.cas.authentication.usernamepasswordcredential;   import  org.jasig.cas.authentication.handler.support.abstractusernamepasswordauthenticationhandler;   Import  org.jasig.cas.authentication.principal.SimplePrincipal;   import  org.springframework.stereotype.component;     /**    *  Custom User Login Authentication class      */   @Component (value= "Primaryauthenticationhandler")    public class  Userauthenticationhandler extends abstractusernamepasswordauthenticationhandler {        @Resource        private  userdaojdbc userdaojdbc;           @Override         protected handlerresult authenticateusernamepasswordinternal (UsernamePasswordCredential  transformedcredential)  throws GeneralSecurityException, PreventedException {  The           //usernamepasswordcredential parameter contains user information entered in the foreground page            String username =  Transformedcredential.getusername ();           String  Password = transformedcredential.getpassword ();            //Authentication user name and password are correct            if ( Userdaojdbc.verifyaccount (Username, password)) {   &NBSp;           return createhandlerresult ( Transformedcredential, new simpleprincipal (username),  null);            }           throw new  failedloginexception ();       }  }  

2, the Password check class Userdaojdbc.java, in order to conform to Jeesite in the authentication method, will jeesite the decryption method to bring over

[HTML]  View Plain  copy package authentication;   import javax.annotation.resource;    import javax.sql.datasource;   import  org.springframework.dao.emptyresultdataaccessexception;   import  org.springframework.jdbc.core.jdbctemplate;   import org.springframework.stereotype.repository;          @Repository    public class userdaojdbc {        private static final String SQL_VERIFY_ACCOUNT =  " Select count (*)  from sys_user  where login_name=?  and del_flag=0 ";       private static final string sql_verify_password  =  "Select password from sys_user  where login_name=?  and  del_flag=0 ";       private JdbcTemplate jdbctemplate;       public static final int hash_interations  = 1024;        @Resource   

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.