SEC-2781: Remove deprecations
This commit is contained in:
-91
@@ -1,91 +0,0 @@
|
||||
/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
|
||||
*
|
||||
* Licensed 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
|
||||
*
|
||||
* 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.springframework.security.taglibs.authz;
|
||||
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.*;
|
||||
import org.springframework.security.authentication.TestingAuthenticationToken;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
|
||||
import javax.servlet.jsp.JspException;
|
||||
import javax.servlet.jsp.tagext.Tag;
|
||||
|
||||
|
||||
/**
|
||||
* @author Francois Beausoleil
|
||||
*/
|
||||
public class AuthorizeTagAttributeTests {
|
||||
//~ Instance fields ================================================================================================
|
||||
|
||||
private final JspAuthorizeTag authorizeTag = new JspAuthorizeTag();
|
||||
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken("abc", "123", "ROLE_SUPERVISOR", "ROLE_RESTRICTED"));
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
SecurityContextHolder.clearContext();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAssertsIfAllGrantedSecond() throws JspException {
|
||||
authorizeTag.setIfAllGranted("ROLE_SUPERVISOR,ROLE_SUPERTELLER");
|
||||
authorizeTag.setIfAnyGranted("ROLE_RESTRICTED");
|
||||
assertEquals("prevents request - principal is missing ROLE_SUPERTELLER", Tag.SKIP_BODY,
|
||||
authorizeTag.doStartTag());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAssertsIfAnyGrantedLast() throws JspException {
|
||||
authorizeTag.setIfAnyGranted("ROLE_BANKER");
|
||||
assertEquals("prevents request - principal is missing ROLE_BANKER", Tag.SKIP_BODY, authorizeTag.doStartTag());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAssertsIfNotGrantedFirst() throws JspException {
|
||||
authorizeTag.setIfNotGranted("ROLE_RESTRICTED");
|
||||
authorizeTag.setIfAllGranted("ROLE_SUPERVISOR,ROLE_RESTRICTED");
|
||||
authorizeTag.setIfAnyGranted("ROLE_SUPERVISOR");
|
||||
assertEquals("prevents request - principal has ROLE_RESTRICTED", Tag.SKIP_BODY, authorizeTag.doStartTag());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAssertsIfNotGrantedIgnoresWhitespaceInAttribute()
|
||||
throws JspException {
|
||||
authorizeTag.setIfAnyGranted("\tROLE_SUPERVISOR \t, \r\n\t ROLE_TELLER ");
|
||||
assertEquals("allows request - principal has ROLE_SUPERVISOR", Tag.EVAL_BODY_INCLUDE, authorizeTag.doStartTag());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIfAllGrantedIgnoresWhitespaceInAttribute() throws JspException {
|
||||
authorizeTag.setIfAllGranted("\nROLE_SUPERVISOR\t,ROLE_RESTRICTED\t\n\r ");
|
||||
assertEquals("allows request - principal has ROLE_RESTRICTED " + "and ROLE_SUPERVISOR", Tag.EVAL_BODY_INCLUDE,
|
||||
authorizeTag.doStartTag());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIfNotGrantedIgnoresWhitespaceInAttribute() throws JspException {
|
||||
authorizeTag.setIfNotGranted(" \t ROLE_TELLER \r");
|
||||
assertEquals("allows request - principal does not have ROLE_TELLER", Tag.EVAL_BODY_INCLUDE,
|
||||
authorizeTag.doStartTag());
|
||||
}
|
||||
}
|
||||
-131
@@ -1,131 +0,0 @@
|
||||
/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
|
||||
*
|
||||
* Licensed 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
|
||||
*
|
||||
* 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.springframework.security.taglibs.authz;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.*;
|
||||
import org.springframework.security.authentication.TestingAuthenticationToken;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.authority.GrantedAuthorityImpl;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
|
||||
import javax.servlet.jsp.JspException;
|
||||
import javax.servlet.jsp.tagext.Tag;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francois Beausoleil
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class AuthorizeTagCustomGrantedAuthorityTests {
|
||||
//~ Instance fields ================================================================================================
|
||||
|
||||
private final JspAuthorizeTag authorizeTag = new JspAuthorizeTag();
|
||||
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken("abc", "123", "ROLE_TELLER"));
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
SecurityContextHolder.clearContext();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllowsRequestWhenCustomAuthorityPresentsCorrectRole() throws JspException {
|
||||
authorizeTag.setIfAnyGranted("ROLE_TELLER");
|
||||
assertEquals("authorized - ROLE_TELLER in both sets", Tag.EVAL_BODY_INCLUDE, authorizeTag.doStartTag());
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("serial")
|
||||
public void testRejectsRequestWhenCustomAuthorityReturnsNull() throws JspException {
|
||||
authorizeTag.setIfAnyGranted("ROLE_TELLER");
|
||||
List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
|
||||
authorities.add(new GrantedAuthority() {
|
||||
public String getAuthority() {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken("abc", "123", authorities));
|
||||
|
||||
try {
|
||||
authorizeTag.doStartTag();
|
||||
fail("Failed to reject GrantedAuthority with NULL getAuthority()");
|
||||
} catch (IllegalArgumentException expected) {
|
||||
assertTrue("expected", true);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("serial")
|
||||
public void testAuthorizeCustomGrantedAuthority() throws JspException {
|
||||
authorizeTag.setIfAnyGranted(null);
|
||||
authorizeTag.setIfNotGranted(null);
|
||||
authorizeTag.setIfAllGranted("ROLE_TEST");
|
||||
List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
|
||||
authorities.add(new GrantedAuthority() {
|
||||
public String getAuthority() {
|
||||
return "ROLE_TEST";
|
||||
}
|
||||
});
|
||||
SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken("abc", "123", authorities));
|
||||
assertEquals("Expected to be authorized", Tag.EVAL_BODY_INCLUDE, authorizeTag.doStartTag());
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("serial")
|
||||
public void testAuthorizeExtendsGrantedAuthorityImpl() throws JspException {
|
||||
authorizeTag.setIfAnyGranted(null);
|
||||
authorizeTag.setIfNotGranted(null);
|
||||
authorizeTag.setIfAllGranted("ROLE_TEST");
|
||||
List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
|
||||
authorities.add(new GrantedAuthorityImpl("ROLE_TEST") {});
|
||||
SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken("abc", "123", authorities));
|
||||
assertEquals("Expected to be authorized", Tag.EVAL_BODY_INCLUDE, authorizeTag.doStartTag());
|
||||
}
|
||||
|
||||
// SEC-1900
|
||||
@Test
|
||||
public void testAuthorizeUsingGrantedAuthorityImpl() throws JspException {
|
||||
authorizeTag.setIfAnyGranted(null);
|
||||
authorizeTag.setIfNotGranted(null);
|
||||
authorizeTag.setIfAllGranted("ROLE_TEST");
|
||||
List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
|
||||
authorities.add(new GrantedAuthorityImpl("ROLE_TEST"));
|
||||
SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken("abc", "123", authorities));
|
||||
assertEquals("Expected to be authorized", Tag.EVAL_BODY_INCLUDE, authorizeTag.doStartTag());
|
||||
}
|
||||
|
||||
// SEC-1900
|
||||
@Test
|
||||
public void testNotAuthorizeUsingGrantedAuthorityImpl() throws JspException {
|
||||
authorizeTag.setIfAnyGranted(null);
|
||||
authorizeTag.setIfNotGranted(null);
|
||||
authorizeTag.setIfAllGranted("ROLE_ADMIN");
|
||||
List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
|
||||
authorities.add(new GrantedAuthorityImpl("ROLE_TEST"));
|
||||
SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken("abc", "123", authorities));
|
||||
assertEquals("Expected to not be authorized", Tag.SKIP_BODY, authorizeTag.doStartTag());
|
||||
}
|
||||
}
|
||||
-71
@@ -145,77 +145,6 @@ public class AuthorizeTagTests {
|
||||
assertEquals(Tag.SKIP_BODY, authorizeTag.doStartTag());
|
||||
}
|
||||
|
||||
// Legacy attribute tests
|
||||
|
||||
@Test
|
||||
public void testAlwaysReturnsUnauthorizedIfNoUserFound() throws JspException {
|
||||
SecurityContextHolder.clearContext();
|
||||
authorizeTag.setIfAllGranted("ROLE_TELLER");
|
||||
assertEquals(Tag.SKIP_BODY, authorizeTag.doStartTag());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultsToNotOutputtingBodyWhenNoRequiredAuthorities() throws JspException {
|
||||
assertEquals(null, authorizeTag.getIfAllGranted());
|
||||
assertEquals(null, authorizeTag.getIfAnyGranted());
|
||||
assertEquals(null, authorizeTag.getIfNotGranted());
|
||||
|
||||
assertEquals(Tag.SKIP_BODY, authorizeTag.doStartTag());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultsToNotOutputtingBodyWhenNoAuthoritiesProvided() throws JspException {
|
||||
authorizeTag.setIfAllGranted("");
|
||||
authorizeTag.setIfAnyGranted("");
|
||||
authorizeTag.setIfNotGranted("");
|
||||
|
||||
assertEquals(Tag.SKIP_BODY, authorizeTag.doStartTag());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOutputsBodyIfOneRolePresent() throws JspException {
|
||||
authorizeTag.setIfAnyGranted("ROLE_TELLER");
|
||||
assertEquals(Tag.EVAL_BODY_INCLUDE, authorizeTag.doStartTag());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOutputsBodyWhenAllGranted() throws JspException {
|
||||
authorizeTag.setIfAllGranted("ROLE SUPERVISOR, \nROLE_TELLER");
|
||||
assertEquals(Tag.EVAL_BODY_INCLUDE, authorizeTag.doStartTag());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOutputsBodyWhenNotGrantedSatisfied() throws JspException {
|
||||
authorizeTag.setIfNotGranted("ROLE_BANKER");
|
||||
assertEquals(Tag.EVAL_BODY_INCLUDE, authorizeTag.doStartTag());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPreventsBodyOutputIfNoSecurityContext() throws JspException {
|
||||
SecurityContextHolder.getContext().setAuthentication(null);
|
||||
authorizeTag.setIfAnyGranted("ROLE_BANKER");
|
||||
|
||||
assertEquals(Tag.SKIP_BODY, authorizeTag.doStartTag());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSkipsBodyIfNoAnyRolePresent() throws JspException {
|
||||
authorizeTag.setIfAnyGranted("ROLE_BANKER");
|
||||
assertEquals(Tag.SKIP_BODY, authorizeTag.doStartTag());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSkipsBodyWhenMissingAnAllGranted() throws JspException {
|
||||
authorizeTag.setIfAllGranted("ROLE SUPERVISOR, ROLE_TELLER,\n\rROLE_BANKER");
|
||||
assertEquals(Tag.SKIP_BODY, authorizeTag.doStartTag());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSkipsBodyWhenNotGrantedUnsatisfied() throws JspException {
|
||||
authorizeTag.setIfNotGranted("ROLE_TELLER");
|
||||
assertEquals("prevents request - principal has ROLE_TELLER", Tag.SKIP_BODY, authorizeTag.doStartTag());
|
||||
}
|
||||
|
||||
public static class MockWebInvocationPrivilegeEvaluator implements WebInvocationPrivilegeEvaluator {
|
||||
|
||||
public boolean isAllowed(String uri, Authentication authentication) {
|
||||
|
||||
-81
@@ -1,81 +0,0 @@
|
||||
/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
|
||||
*
|
||||
* Licensed 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
|
||||
*
|
||||
* 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.springframework.security.taglibs.velocity;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.springframework.security.authentication.TestingAuthenticationToken;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
|
||||
import javax.servlet.jsp.JspException;
|
||||
|
||||
|
||||
public class AuthzImplAttributeTests extends TestCase {
|
||||
//~ Instance fields ================================================================================================
|
||||
|
||||
private final Authz authz = new AuthzImpl();
|
||||
private TestingAuthenticationToken currentUser;
|
||||
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
SecurityContextHolder.getContext().setAuthentication(
|
||||
new TestingAuthenticationToken("abc", "123", "ROLE_SUPERVISOR","ROLE_RESTRICTED"));
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
SecurityContextHolder.clearContext();
|
||||
}
|
||||
|
||||
public void testAssertsIfAllGrantedSecond() {
|
||||
boolean r1 = authz.allGranted("ROLE_SUPERVISOR,ROLE_SUPERTELLER");
|
||||
boolean r2 = authz.anyGranted("ROLE_RESTRICTED");
|
||||
|
||||
//prevents request - principal is missing ROLE_SUPERTELLE
|
||||
assertFalse(r1 && r2);
|
||||
}
|
||||
|
||||
public void testAssertsIfAnyGrantedLast() {
|
||||
boolean r2 = authz.anyGranted("ROLE_BANKER");
|
||||
|
||||
// prevents request - principal is missing ROLE_BANKER
|
||||
assertFalse(r2);
|
||||
}
|
||||
|
||||
public void testAssertsIfNotGrantedFirst() {
|
||||
boolean r1 = authz.allGranted("ROLE_SUPERVISOR,ROLE_RESTRICTED");
|
||||
boolean r2 = authz.noneGranted("ROLE_RESTRICTED");
|
||||
boolean r3 = authz.anyGranted("ROLE_SUPERVISOR");
|
||||
|
||||
//prevents request - principal has ROLE_RESTRICTED
|
||||
assertFalse(r1 && r2 && r3);
|
||||
}
|
||||
|
||||
public void testAssertsIfNotGrantedIgnoresWhitespaceInAttribute() {
|
||||
//allows request - principal has ROLE_SUPERVISOR
|
||||
assertTrue(authz.anyGranted("\tROLE_SUPERVISOR \t, \r\n\t ROLE_TELLER "));
|
||||
}
|
||||
|
||||
public void testIfAllGrantedIgnoresWhitespaceInAttribute() {
|
||||
//allows request - principal has ROLE_RESTRICTED and ROLE_SUPERVISOR
|
||||
assertTrue(authz.allGranted("\nROLE_SUPERVISOR\t,ROLE_RESTRICTED\t\n\r "));
|
||||
}
|
||||
|
||||
public void testIfNotGrantedIgnoresWhitespaceInAttribute()
|
||||
throws JspException {
|
||||
//prevents request - principal does not have ROLE_TELLER
|
||||
assertFalse(authz.allGranted(" \t ROLE_TELLER \r"));
|
||||
}
|
||||
}
|
||||
-88
@@ -1,88 +0,0 @@
|
||||
/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
|
||||
*
|
||||
* Licensed 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
|
||||
*
|
||||
* 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.springframework.security.taglibs.velocity;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.springframework.security.authentication.TestingAuthenticationToken;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
|
||||
public class AuthzImplAuthorizeTagTests extends TestCase {
|
||||
//~ Instance fields ================================================================================================
|
||||
|
||||
private Authz authz = new AuthzImpl();
|
||||
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
SecurityContextHolder.getContext().setAuthentication(
|
||||
new TestingAuthenticationToken("abc", "123", "ROLE_SUPERVISOR", "ROLE_TELLER"));
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
SecurityContextHolder.clearContext();
|
||||
}
|
||||
|
||||
public void testAlwaysReturnsUnauthorizedIfNoUserFound() {
|
||||
SecurityContextHolder.getContext().setAuthentication(null);
|
||||
|
||||
//prevents request - no principal in Context
|
||||
assertFalse(authz.allGranted("ROLE_TELLER"));
|
||||
}
|
||||
|
||||
public void testDefaultsToNotOutputtingBodyWhenNoRequiredAuthorities() {
|
||||
//prevents body output - no authorities granted
|
||||
assertFalse(authz.allGranted(""));
|
||||
assertFalse(authz.anyGranted(""));
|
||||
assertFalse(authz.noneGranted(""));
|
||||
}
|
||||
|
||||
public void testOutputsBodyIfOneRolePresent() {
|
||||
//authorized - ROLE_TELLER in both sets
|
||||
assertTrue(authz.anyGranted("ROLE_TELLER"));
|
||||
}
|
||||
|
||||
public void testOutputsBodyWhenAllGranted() {
|
||||
// allows request - all required roles granted on principal
|
||||
assertTrue(authz.allGranted("ROLE_SUPERVISOR,ROLE_TELLER"));
|
||||
}
|
||||
|
||||
public void testOutputsBodyWhenNotGrantedSatisfied() {
|
||||
// allows request - principal doesn't have ROLE_BANKER
|
||||
assertTrue(authz.noneGranted("ROLE_BANKER"));
|
||||
}
|
||||
|
||||
public void testPreventsBodyOutputIfNoSecureContext() {
|
||||
SecurityContextHolder.getContext().setAuthentication(null);
|
||||
|
||||
// prevents output - no context defined
|
||||
assertFalse(authz.anyGranted("ROLE_BANKER"));
|
||||
}
|
||||
|
||||
public void testSkipsBodyIfNoAnyRolePresent() {
|
||||
// unauthorized - ROLE_BANKER not in granted authorities
|
||||
assertFalse(authz.anyGranted("ROLE_BANKER"));
|
||||
}
|
||||
|
||||
public void testSkipsBodyWhenMissingAnAllGranted() {
|
||||
// prevents request - missing ROLE_BANKER on principal
|
||||
assertFalse(authz.allGranted("ROLE_SUPERVISOR,ROLE_TELLER,ROLE_BANKER"));
|
||||
}
|
||||
|
||||
public void testSkipsBodyWhenNotGrantedUnsatisfied() {
|
||||
// prevents request - principal has ROLE_TELLER
|
||||
assertFalse(authz.noneGranted("ROLE_TELLER"));
|
||||
}
|
||||
}
|
||||
-63
@@ -1,63 +0,0 @@
|
||||
/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
|
||||
*
|
||||
* Licensed 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
|
||||
*
|
||||
* 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.springframework.security.taglibs.velocity;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.security.authentication.TestingAuthenticationToken;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.authority.AuthorityUtils;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.security.core.userdetails.User;
|
||||
|
||||
|
||||
public class AuthzImplTests extends TestCase {
|
||||
//~ Instance fields ================================================================================================
|
||||
|
||||
private Authz authz = new AuthzImpl();
|
||||
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
public void testOperationWhenPrincipalIsAString() {
|
||||
Authentication auth = new TestingAuthenticationToken("rodAsString", "koala", AuthorityUtils.NO_AUTHORITIES );
|
||||
SecurityContextHolder.getContext().setAuthentication(auth);
|
||||
|
||||
assertEquals("rodAsString", authz.getPrincipal());
|
||||
}
|
||||
|
||||
public void testOperationWhenPrincipalIsAUserDetailsInstance() {
|
||||
Authentication auth = new TestingAuthenticationToken(new User("rodUserDetails", "koala", true, true, true,
|
||||
true, AuthorityUtils.NO_AUTHORITIES), "koala", AuthorityUtils.NO_AUTHORITIES);
|
||||
SecurityContextHolder.getContext().setAuthentication(auth);
|
||||
|
||||
assertEquals("rodUserDetails", authz.getPrincipal());
|
||||
}
|
||||
|
||||
public void testOperationWhenPrincipalIsNull() {
|
||||
Authentication auth = new TestingAuthenticationToken(null, "koala", AuthorityUtils.NO_AUTHORITIES );
|
||||
SecurityContextHolder.getContext().setAuthentication(auth);
|
||||
|
||||
assertNull(authz.getPrincipal());
|
||||
}
|
||||
|
||||
public void testOperationWhenSecurityContextIsNull() {
|
||||
SecurityContextHolder.getContext().setAuthentication(null);
|
||||
|
||||
assertEquals(null, authz.getPrincipal());
|
||||
|
||||
SecurityContextHolder.getContext().setAuthentication(null);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user