This article source code download:http://download.csdn.net/detail/jadyer/8940967
/** * @see------------------------------------------------------------------------------------------------------- -----------------* @see Introduce some other configuration items from Cas.properties in the CAS-4.0.3 server * @see 1. cas.securitycontext.status.allowedsubnet=127.0.0.1 * @see access to the server statistics page: http://sso.jadyer.com:8080/cas-server-web/ Status * @see access to the server statistics page: http://sso.jadyer.com:8080/cas-server-web/statistics * @see 2.HOST.NAME=S3 * @see UNIQUEIDG The host.name is used as the ticket suffix in the various uniqueticketidgenerator generated tgt/st, such as the Enerators.xml in the ticket @see Host.name is typically used in a clustered environment, The value must be unique for each node, so that the various ticket generated by the entire cluster environment are necessarily unique * @see There is no need to modify it in a standalone environment * @see 3.cas.logout.followserviceredirects=true * @ See if client logout is allowed to redirect to the resource specified by the service parameter * @see 4.tgt.maxtimetoliveinseconds=28800 * @see Specify the maximum effective time for the session, which is timed out from generation to specified time , the default 28800s, that is, 8 hours * @see 5.tgt.timetokillinseconds=7200 * @see Specify the time-out period of user action, that is, how long the user expires after the operation, the default 7200s, that is, 2 hours * @see by my pro-test: TGT . Timetokillinseconds also note the time-out period for the client Web. XML configuration * @see that only the client configuration time-out is not greater than tgt.timetokillinseconds when the server-side settings are visibleEffect * @see 6.st.timetokillinseconds=10 * @see Specify the time of service ticket, default 10s * @see This is also the reason why debug often fails during the CAS application certification process, because when tracking se Rvice ticket has been valid for 10 seconds. * @see 7.slo.callbacks.disabled=false * @see Whether to disable the single point of logout * @see----------------------------------- -------------------------------------------------------------------------------------* @create 2015-7-28 PM 7 : 49:24 * @author Xuan Yu Here is a description of the modifications required to enable the RememberMe feature
/** * @see CAS server rememberme * @see--------------------------------------------------------------------------------- ---------------------------------------* @see about RememberMe, can refer to the official documents, the URL is as follows (the following two URLs describe the RememberMe implementation is the same, but the second one has other description) * @see http://jasig.github.io/cas/development/installation/Configuring-LongTerm-Authentication.html * @see/http Jasig.github.io/cas/4.0.x/installation/configuring-authentication-components.html#long-term-authentication * @ See RememberMe is usually said to remember the password function, you can let the user log in successfully, close the browser and then reopen the browser to access the app without having to log in again * @see RememberMe with the above session timeout configuration tgt.timetokillinseconds is different, the session timeout is for a session, RememberMe is broader * @see In addition, this article CAS-4.0.3 server source modification, is in my following three blog based on the revision, and eventually I will be on the CSDN to provide the overall source download * @see http://blog.csdn.net/jadyer/article/details/ 46875393 * @see http://blog.csdn.net/jadyer/article/details/46914661 * @see http://blog.csdn.net/jadyer/article/ details/46916169 * @see Specific steps to modify are as follows * @see new configuration item in 1.cas.properties remembermeduration=1209600 * @see 2. New RememberMe expiration policy configuration in Ticketexpirationpolicies.xml * @see 3.ticNew property entry in Ketgrantingticketcookiegenerator.xml p:remembermemaxage= "${remembermeduration:1209600}" * @see 4. Deployerconfigcontext.xml * Add RememberMe field in 5.casloginview.jsp form * @see 6.login-webflow.xml increase the configuration of the Receive Form rememberme field @see * @see 7.usernamepasswordcaptchacredential.java Integrated remembermeusernamepasswordcredential allows you to receive the form's rememberme field * @see- --------------------------------------------------------------------------------------------------------------- --------* @create 2015-7-28 PM 7:58:08 * @author Xuan Yu Here are the changes to Ticketexpirationpolicies.xml
<?xml version= "1.0" encoding= "UTF-8"?><!--Licensed to Jasig under one or more contributor license Agreemen Ts. See the NOTICE file distributed with this work for additional information regarding copyright ownership. Jasig licenses this file to you under the Apache License, Version 2.0 (the "License"); You are not a use of this file except in compliance with the License. Obtain a copy of the License at the following location:http://www.apache.org/licenses/license-2.0 Unle SS required by applicable law or agreed to in writing, software distributed under the License are distributed on an " As is ' BASIS, without warranties or CONDITIONS of any KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.--><beans XM lns= "Http://www.springframework.org/schema/beans" xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns: P= "Http://www.springframework.org/schema/p "xmlns:c=" http://www.springframework.org/schema/c "xmlns:util=" http://www.springframework.org/ Schema/util "xsi:schemalocation=" Http://www.springframework.org/schema/beans http://www.sp Ringframework.org/schema/beans/spring-beans.xsd Http://www.springframework.org/schema/util Http://www.springframework.org/schema/util/spring-util.xsd "> <description> assignm ENT of expiration policies for the different tickets generated by CAS including ticket Granting Ticket (TGT), servi CE ticket (ST), Proxy granting Ticket (PGT), and proxy ticket (PT). These expiration policies determine how long the ticket they is assigned to can is used and even how often they CA n be used before becoming expired/invalid. </description> <!--expiration policies--<util:constant id= "SECONDS" static-field= "Java.util.concu Rrent. Timeunit.seconds "/> <bean id= "Serviceticketexpirationpolicy" class= " Org.jasig.cas.ticket.support.MultiTimeUseOrTimeoutExpirationPolicy "c:numberofuses=" 1 "c:timetokill=" ${st.timeto KILLINSECONDS:10} "c:timeunit-ref=" SECONDS "/> <!--Ticketgrantingticketexpirationpolicy:default as of 3.5--> ; <!--provides both idle and hard timeouts, for instance 2 hour sliding windows with an 8 hour max lifetime-< ;! --<bean id= "Grantingticketexpirationpolicy" class= " Org.jasig.cas.ticket.support.TicketGrantingTicketExpirationPolicy "p:maxtimetoliveinseconds=" ${ tgt.maxtimetoliveinseconds:28800} "p:timetokillinseconds=" ${tgt.timetokillinseconds:7200} "/>--><!-- The following is the RememberMe required configuration--><!--here to first the original <bean id= "Grantingticketexpirationpolicy" > commented out, as shown above--><!-- The comment is because the 117th line of Applicationcontext.xml uses <bean id= "Grantingticketexpirationpolicy" >--><!-- And what we need to implement RememberMe is Remembermedelegatingexpirationpolicy, not the default ticketgrantIngticketexpirationpolicy--><!--See the configuration below for a glance--><!--| The following policy applies to standard CAS SSO sessions.| Default 2h (7200s) sliding expiration with default 8h (28800s) maximum Lifetime.--><bean id= "Standardsessiontgtexpi Rationpolicy "class=" Org.jasig.cas.ticket.support.TicketGrantingTicketExpirationPolicy "p:maxtimetoliveinseconds = "${tgt.maxtimetoliveinseconds:28800}" p:timetokillinseconds= "${tgt.timetokillinseconds:7200}"/><!--| The following policy applies to long term CAS SSO sessions.| Default duration is weeks (1209600s).--><bean id= "Longtermsessiontgtexpirationpolicy" class= " Org.jasig.cas.ticket.support.TimeoutExpirationPolicy "c:timetokillinmilliseconds=" #{${remembermeduration : 1209600} * "/><bean id=" Grantingticketexpirationpolicy "class=" Org.jasig.cas.ticket.support.RememberMeDelegatingExpirationPolicy "p:sessionexpirationpolicy-ref=" Standardsessiontgtexpirationpolicy "p:remembermeexpirationpolicy-ref=" longtermsessIontgtexpirationpolicy "/></beans>
Here are the changes to Ticketgrantingticketcookiegenerator.xml
<?xml version= "1.0" encoding= "UTF-8"? ><beans xmlns= "/http Www.springframework.org/schema/beans "xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance "xmlns:p=" Http://ww w.springframework.org/schema/p "xsi:schemalocation=" Http://www.springframework.org/schema/beans/http Www.springframework.org/schema/beans/spring-beans.xsd "><description>defines The cookie that stores the Ticketgrantingticket. You are likely should never modify these (especially the "secure" property). Can change the name if you want to make it harder for people to guess.</description><!--add rememberme for P:rem Embermemaxage Property Configuration--><bean id= "Ticketgrantingticketcookiegenerator" class= " Org.jasig.cas.web.support.CookieRetrievingCookieGenerator "p:cookiesecure=" false "p:cookiemaxage="-1 "p: Remembermemaxage= "${remembermeduration:1209600}" P:cookiename= "CASTGC" p:cookiepath= "/cas"/></beans>
here is the section Deployerconfigcontext.xml modified
<bean id= "AuthenticationManager" class= "Org.jasig.cas.authentication.PolicyBasedAuthenticationManager" > <constructor-arg><map><entry key-ref= "Proxyauthenticationhandler" value-ref= " Proxyprincipalresolver "/><entry key-ref=" Primaryauthenticationhandler "value-ref=" PrimaryPrincipalResolver "/></map></constructor-arg><property name=" Authenticationpolicy "><bean class=" Org.jasig.cas.authentication.AnyAuthenticationPolicy "/></property><!--to the additional properties required for RememberMe <property name= "authenticationmetadatapopulators" ><list><bean class= " Org.jasig.cas.authentication.SuccessfulHandlerMetaDataPopulator "/><bean class=" Org.jasig.cas.authentication.principal.RememberMeAuthenticationMetaDataPopulator "/></list></ Property></bean>
here is the section Login-webflow.xml modified
<view-state id= "Viewloginform" view= "Casloginview" model= "credential" > <binder> <binding property= "username"/> <binding property= "password"/> <!--foreground form Add Verification Code field CAPTCHA- < Binding property= "Captcha"/> <!--foreground form add rememberme field-- <binding property= "RememberMe"/> </binder> <on-entry> <set name= "viewscope.commandname" value= "' Credential '"/> </on-entry><transition on= "Submit" bind= "true" validate= "true" to= "Validatecaptcha" > < Evaluate expression= "Authenticationviacaptchaformaction.dobind (Flowrequestcontext, flowscope.credential)"/> </transition></view-state>
here's Usernamepasswordcaptchacredential.java .
Package Com.msxf.sso.model;import org.jasig.cas.authentication.remembermeusernamepasswordcredential;/** * Custom entity class to receive login verification code * @create 2015-7-14 PM 4:28:33 * @author Jade
here's//web-inf//view//jsp//msxf//ui//casloginview.jsp .
<%@ page pageencoding= "UTF-8"%><%@ taglib prefix= "C" uri= "Http://java.sun.com/jsp/jstl/core"%><%@ Taglib prefix= "form" uri= "Http://www.springframework.org/tags/form"%><c:set var= "CTX" value= "${ PageContext.request.contextPath} "scope=" Session "/><! DOCTYPE html>Finally, the added remembermeduration configuration in the Cas.properties
# Long Term authentication session length in seconds# service end RememberMe, default is 1209600s, that is, two weeks remembermeduration=1209600
To verify the success of the RememberMe function is: With the success of the client single sign-on, switch off the browser, and then open the browser to access the client, if you do not log in to access success Instructions RememberMe success!! Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
"Test water CAS-4.0.3" No. 09 Section _cas service End RememberMe