diff --git a/cas-client-core/src/main/java/org/jasig/cas/client/authentication/DefaultGatewayResolverImpl.java b/cas-client-core/src/main/java/org/jasig/cas/client/authentication/DefaultGatewayResolverImpl.java index d0d2475..ca4c0c8 100644 --- a/cas-client-core/src/main/java/org/jasig/cas/client/authentication/DefaultGatewayResolverImpl.java +++ b/cas-client-core/src/main/java/org/jasig/cas/client/authentication/DefaultGatewayResolverImpl.java @@ -33,7 +33,6 @@ public final class DefaultGatewayResolverImpl implements GatewayResolver { } final boolean result = session.getAttribute(CONST_CAS_GATEWAY) != null; - session.removeAttribute(CONST_CAS_GATEWAY); return result; } diff --git a/cas-client-core/src/test/java/org/jasig/cas/client/authentication/AuthenticationFilterTests.java b/cas-client-core/src/test/java/org/jasig/cas/client/authentication/AuthenticationFilterTests.java index 48479a5..742a5cf 100644 --- a/cas-client-core/src/test/java/org/jasig/cas/client/authentication/AuthenticationFilterTests.java +++ b/cas-client-core/src/test/java/org/jasig/cas/client/authentication/AuthenticationFilterTests.java @@ -177,8 +177,13 @@ public final class AuthenticationFilterTests { final MockHttpServletResponse response2 = new MockHttpServletResponse(); this.filter.doFilter(request, response2, filterChain); - assertNull(session.getAttribute(DefaultGatewayResolverImpl.CONST_CAS_GATEWAY)); + assertNotNull(session.getAttribute(DefaultGatewayResolverImpl.CONST_CAS_GATEWAY)); assertNull(response2.getRedirectedUrl()); + + final MockHttpServletResponse response3 = new MockHttpServletResponse(); + this.filter.doFilter(request, response3, filterChain); + assertNotNull(session.getAttribute(DefaultGatewayResolverImpl.CONST_CAS_GATEWAY)); + assertNull(response3.getRedirectedUrl()); } @Test diff --git a/cas-client-core/src/test/java/org/jasig/cas/client/authentication/DefaultGatewayResolverImplTests.java b/cas-client-core/src/test/java/org/jasig/cas/client/authentication/DefaultGatewayResolverImplTests.java new file mode 100644 index 0000000..f8e75e6 --- /dev/null +++ b/cas-client-core/src/test/java/org/jasig/cas/client/authentication/DefaultGatewayResolverImplTests.java @@ -0,0 +1,72 @@ +/* + * Licensed to Jasig under one or more contributor license + * agreements. 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 may not use this file + * except in compliance with the License. You may obtain a + * copy of the License at the following location: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is 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. + */ +package org.jasig.cas.client.authentication; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import org.junit.Before; +import org.junit.Test; +import org.springframework.mock.web.MockHttpServletRequest; +import org.springframework.mock.web.MockHttpServletResponse; +import org.springframework.mock.web.MockHttpSession; + +public class DefaultGatewayResolverImplTests { + + private DefaultGatewayResolverImpl resolver; + + @Before + public void setUp() throws Exception { + this.resolver = new DefaultGatewayResolverImpl(); + } + + @Test + public void testReentrancy() throws Exception { + final MockHttpServletRequest request1 = new MockHttpServletRequest(); + assertFalse(this.resolver.hasGatewayedAlready(request1, "foo")); + assertFalse(this.resolver.hasGatewayedAlready(request1, "foo")); + assertEquals("foo", this.resolver.storeGatewayInformation(request1, "foo")); + assertEquals("foo", this.resolver.storeGatewayInformation(request1, "foo")); + assertTrue(this.resolver.hasGatewayedAlready(request1, "foo")); + assertTrue(this.resolver.hasGatewayedAlready(request1, "foo")); + } + + @Test + public void testSessionConcurrency() throws Exception { + final MockHttpSession session = new MockHttpSession(); + final MockHttpServletRequest request1 = new MockHttpServletRequest(); + final MockHttpServletRequest request2 = new MockHttpServletRequest(); + request1.setSession(session); + request2.setSession(session); + + assertFalse(this.resolver.hasGatewayedAlready(request1, "abc")); + assertFalse(this.resolver.hasGatewayedAlready(request2, "def")); + + assertEquals("abc", this.resolver.storeGatewayInformation(request1, "abc")); + + assertTrue(this.resolver.hasGatewayedAlready(request2, "def")); + assertTrue(this.resolver.hasGatewayedAlready(request1, "abc")); + + assertEquals("def", this.resolver.storeGatewayInformation(request2, "def")); + + assertTrue(this.resolver.hasGatewayedAlready(request1, "abc")); + assertTrue(this.resolver.hasGatewayedAlready(request2, "def")); + + } +}