Automatic login after "Go" CAS Registration

Source: Internet
Author: User

This article transferred from:

1.The introduction of CAS no longer, I would like to involve the SSO students should all understand the framework, we currently use the CAS Server version of, the CAs Client version is 3.1.10.
CAs Project official: Http://
This document describes the process of CAS client-to-server-based smal validation that does not include CAS clients and servers.

2.For logging on to its main processing flow:
after successful registration, call the relevant module of CAS login processing--Authentication user name password--Generate TGT----build TG---add ST&TGT to related Register class, add TG T to Cookie, redirect to Cas/login URL, complete

3.CAS Login Processing main Module (class):
A. Credentials is used to store user login authentication information interface.
Its default implementation class: Org.jasig.cas.authentication.principal.UsernamePasswordCredentials
B. Centralauthenticationservice is used to generate the authentication service class for the ST (service Ticket) and TGT (Ticketgrantingticket).
Its default implementation class: Org.jasig.cas.CentralAuthenticationServiceImpl
C. cookieretrievingcookiegenerator is used to add a TGT to a cookie and to manage cookies.

4.Specific implementation code:

/*** User Register process and automatic login. * @paramuserForm the user information object. * @paramrequest the HttpServletRequest object *@paramresponse the HttpServletResponse object *@returnGet result View*/  protectedModelandview handleuserregisterinternal (Userinfovo userForm, httpservletrequest request, HttpServletResponse Response) {Modelandview Signinview=NewModelandview (Register_view); Final BooleanIsUnique =Userservice.checkuserunique (Userform.getloginname ()); Final Booleanisregistered = IsUnique? RegisterUser (UserForm, request, Response):false; if(isregistered) {Bindticketgrantingticket (Userform.getloginname (), Userform.getloginpassword (), request, Res          Ponse);      Signinview.setviewname (Getsigninview (request)); }      returnSigninview; }  
/*** Invoke Generate validate tickets and add the TGT to cookie. * @paramloginName the user login name. * @paramloginpassword the user login password. * @paramrequest the HttpServletRequest object. * @paramresponse the HttpServletResponse object. */  protected voidBindticketgrantingticket (String loginName, String loginpassword, HttpServletRequest request, HttpServletResponse Response) {Try{usernamepasswordcredentials Credentials=Newusernamepasswordcredentials ();          Credentials.setusername (LoginName);          Credentials.setpassword (Loginpassword); String Ticketgrantingticket=Centralauthenticationservice.createticketgrantingticket (credentials);      Ticketgrantingticketcookiegenerator.addcookie (Request, response, ticketgrantingticket); } Catch(Ticketexception te) {logger.error ("Validate the login name" + loginName + "failure, can ' t bind the tgt!", TE); } Catch(Exception e) {logger.error ("Bindticketgrantingticket has exception.", E); }  }  
/**   * Get the SignIn view URL.   @param request the HttpServletRequest object.   @return redirect URL   */  protected String Getsigninview (httpservletrequest request) {      = Servletrequestutils.getstringparameter ( Request, "service", "" ")      ; return ("Redirect:login" + (Service.length () > 0?) "? service=" + Service: "));  }

cas-servlet.xml related code:

class= "Com.xxxxx.sso.web.RegisterController"       p:userservice-ref= "UserService"      P: Validator-ref= "Registervalidator"      p:centralauthenticationservice-ref= " Centralauthenticationservice "      p:ticketgrantingticketcookiegenerator-ref=" Ticketgrantingticketcookiegenerator "/>  

Note: About Centralauthenticationservice and Ticketgrantingticketcookiegenerator have been declared in spring-configuration/ Applicationcontext.xml and Ticketgrantingticketcookiegenerator.xml.

Automatic login after "Go" CAS Registration

Related Article

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: 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.