Skip to content
Browse files

Default expiration policy config uses seconds time unit for both TGT …

…and ST expiration policies
  • Loading branch information...
1 parent 11709f8 commit a08f601e71b0abf98f5cda666144bce09c957638 @dima767 committed Mar 8, 2012
View
6 ...ore/src/main/java/org/jasig/cas/ticket/support/MultiTimeUseOrTimeoutExpirationPolicy.java
@@ -9,6 +9,8 @@
import org.jasig.cas.ticket.TicketState;
import org.springframework.util.Assert;
+import java.util.concurrent.TimeUnit;
+
/**
* ExpirationPolicy that is based on certain number of uses of a ticket or a
* certain time period for a ticket to exist.
@@ -38,6 +40,10 @@ public MultiTimeUseOrTimeoutExpirationPolicy(final int numberOfUses,
}
+ public MultiTimeUseOrTimeoutExpirationPolicy(int numberOfUses, long timeToKill, TimeUnit timeUnit) {
+ this(numberOfUses, timeUnit.toMillis(timeToKill));
+ }
+
public boolean isExpired(final TicketState ticketState) {
return (ticketState == null)
|| (ticketState.getCountOfUses() >= this.numberOfUses)
View
10 ...rc/test/java/org/jasig/cas/ticket/support/MultiTimeUseOrTimeoutExpirationPolicyTests.java
@@ -12,14 +12,18 @@
import junit.framework.TestCase;
+import java.util.concurrent.TimeUnit;
+
/**
* @author Scott Battaglia
* @version $Revision$ $Date$
* @since 3.0
*/
public class MultiTimeUseOrTimeoutExpirationPolicyTests extends TestCase {
- private static final long TIMEOUT = 5000;
+ private static final long TIMEOUT_SECONDS = 5L;
+
+ private static final long TIMEOUT_MILLISECONDS = 5000L;
private static final int NUMBER_OF_USES = 5;
@@ -31,7 +35,7 @@
protected void setUp() throws Exception {
this.expirationPolicy = new MultiTimeUseOrTimeoutExpirationPolicy(
- NUMBER_OF_USES, TIMEOUT);
+ NUMBER_OF_USES, TIMEOUT_SECONDS, TimeUnit.SECONDS);
this.ticket = new TicketGrantingTicketImpl("test", TestUtils
.getAuthentication(), this.expirationPolicy);
@@ -49,7 +53,7 @@ public void testTicketIsNotExpired() {
public void testTicketIsExpiredByTime() {
try {
- Thread.sleep(TIMEOUT + TIMEOUT_BUFFER);
+ Thread.sleep(TIMEOUT_MILLISECONDS + TIMEOUT_BUFFER);
assertTrue(this.ticket.isExpired());
} catch (InterruptedException e) {
fail(e.getMessage());
View
61 cas-server-webapp/src/main/webapp/WEB-INF/spring-configuration/ticketExpirationPolicies.xml
@@ -2,37 +2,40 @@
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
- xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
- <description>
- Assignment of expiration policies for the different tickets generated by CAS including ticket granting ticket (TGT), service ticket (ST), proxy granting ticket (PGT), and proxy ticket (PT).
- These expiration policies determine how long the ticket they are assigned to can be used and even how often they can be used before becoming expired / invalid.
- </description>
+ 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.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/util
+ http://www.springframework.org/schema/util/spring-util.xsd">
+ <description>
+ Assignment of expiration policies for the different tickets generated by CAS including ticket granting ticket
+ (TGT), service ticket (ST), proxy granting ticket (PGT), and proxy ticket (PT).
+ These expiration policies determine how long the ticket they are assigned to can be used and even how often they
+ can be used before becoming expired / invalid.
+ </description>
+
+ <!-- Expiration policies -->
+ <util:constant id="SECONDS" static-field="java.util.concurrent.TimeUnit.SECONDS"/>
+ <bean id="serviceTicketExpirationPolicy" class="org.jasig.cas.ticket.support.MultiTimeUseOrTimeoutExpirationPolicy"
+ c:numberOfUses="1" c:timeToKill="10" c:timeUnit-ref="SECONDS"/>
+
+ <!-- Alternative is to use the constructor that takes time in miliseconds
+ <bean id="serviceTicketExpirationPolicy" class="org.jasig.cas.ticket.support.MultiTimeUseOrTimeoutExpirationPolicy"
+ c:numberOfUses="1" c:timeToKillInMilliSeconds="10000"/> -->
+
- <!-- Expiration policies -->
- <bean id="serviceTicketExpirationPolicy" class="org.jasig.cas.ticket.support.MultiTimeUseOrTimeoutExpirationPolicy">
- <!-- This argument is the number of times that a ticket can be used before its considered expired. -->
- <constructor-arg
- index="0"
- value="1" />
-
- <!-- This argument is the time a ticket can exist before its considered expired. -->
- <constructor-arg
- index="1"
- value="10000" />
- </bean>
-
<!-- TicketGrantingTicketExpirationPolicy: Default as of 3.5 -->
<!-- Provides both idle and hard timeouts, for instance 2 hour sliding window with an 8 hour max lifetime -->
- <bean id="grantingTicketExpirationPolicy" class="org.jasig.cas.ticket.support.TicketGrantingTicketExpirationPolicy"
- p:maxTimeToLiveInMilliSeconds="28800000"
- p:timeToKillInMilliSeconds="7200000" />
-
- <!-- Simple Timeout Expiration Policy -->
- <!-- <bean id="grantingTicketExpirationPolicy" class="org.jasig.cas.ticket.support.TimeoutExpirationPolicy">
- This argument is the time a ticket can exist before its considered expired.
- <constructor-arg
- index="0"
- value="7200000" />
- </bean> -->
+ <bean id="grantingTicketExpirationPolicy" class="org.jasig.cas.ticket.support.TicketGrantingTicketExpirationPolicy"
+ p:maxTimeToLiveInSeconds="28800"
+ p:timeToKillInSeconds="7200"/>
+
+ <!-- Simple Timeout Expiration Policy -->
+ <!-- <bean id="grantingTicketExpirationPolicy" class="org.jasig.cas.ticket.support.TimeoutExpirationPolicy">
+ This argument is the time a ticket can exist before its considered expired.
+ <constructor-arg
+ index="0"
+ value="7200000" />
+ </bean> -->
</beans>

0 comments on commit a08f601

Please sign in to comment.
Something went wrong with that request. Please try again.