This article transferred from: http://denger.iteye.com/blog/805743
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 3.4.2.1, the CAs Client version is 3.1.10.
CAs Project official: Http://www.jasig.org/cas
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