SEC-1012: Added more generics and warning suppression
This commit is contained in:
+4
-17
@@ -29,22 +29,9 @@ import org.springframework.security.providers.rememberme.RememberMeAuthenticatio
|
||||
* @version $Id$
|
||||
*/
|
||||
public class AuthenticationTrustResolverImplTests extends TestCase {
|
||||
//~ Constructors ===================================================================================================
|
||||
|
||||
public AuthenticationTrustResolverImplTests() {
|
||||
super();
|
||||
}
|
||||
|
||||
public AuthenticationTrustResolverImplTests(String arg0) {
|
||||
super(arg0);
|
||||
}
|
||||
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
public static void main(String[] args) {
|
||||
junit.textui.TestRunner.run(AuthenticationTrustResolverImplTests.class);
|
||||
}
|
||||
|
||||
public void testCorrectOperationIsAnonymous() {
|
||||
AuthenticationTrustResolverImpl trustResolver = new AuthenticationTrustResolverImpl();
|
||||
assertTrue(trustResolver.isAnonymous(
|
||||
@@ -69,11 +56,11 @@ public class AuthenticationTrustResolverImplTests extends TestCase {
|
||||
AuthenticationTrustResolverImpl trustResolver = new AuthenticationTrustResolverImpl();
|
||||
|
||||
assertEquals(AnonymousAuthenticationToken.class, trustResolver.getAnonymousClass());
|
||||
trustResolver.setAnonymousClass(String.class);
|
||||
assertEquals(String.class, trustResolver.getAnonymousClass());
|
||||
trustResolver.setAnonymousClass(TestingAuthenticationToken.class);
|
||||
assertEquals(TestingAuthenticationToken.class, trustResolver.getAnonymousClass());
|
||||
|
||||
assertEquals(RememberMeAuthenticationToken.class, trustResolver.getRememberMeClass());
|
||||
trustResolver.setRememberMeClass(String.class);
|
||||
assertEquals(String.class, trustResolver.getRememberMeClass());
|
||||
trustResolver.setRememberMeClass(TestingAuthenticationToken.class);
|
||||
assertEquals(TestingAuthenticationToken.class, trustResolver.getRememberMeClass());
|
||||
}
|
||||
}
|
||||
|
||||
+2
-10
@@ -35,16 +35,8 @@ import org.springframework.security.util.SimpleMethodInvocation;
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public class AfterInvocationProviderManagerTests extends TestCase {
|
||||
//~ Constructors ===================================================================================================
|
||||
|
||||
public AfterInvocationProviderManagerTests() {
|
||||
super();
|
||||
}
|
||||
|
||||
public AfterInvocationProviderManagerTests(String arg0) {
|
||||
super(arg0);
|
||||
}
|
||||
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
@@ -167,7 +159,7 @@ public class AfterInvocationProviderManagerTests extends TestCase {
|
||||
return returnedObject;
|
||||
}
|
||||
|
||||
public boolean supports(Class clazz) {
|
||||
public boolean supports(Class<? extends Object> clazz) {
|
||||
return secureObject.isAssignableFrom(clazz);
|
||||
}
|
||||
|
||||
|
||||
@@ -51,10 +51,10 @@ public interface BusinessService {
|
||||
|
||||
public int someOther(int input);
|
||||
|
||||
public List methodReturningAList(List someList);
|
||||
public List<Object> methodReturningAList(List<Object> someList);
|
||||
|
||||
public Object[] methodReturningAnArray(Object[] someArray);
|
||||
|
||||
public List methodReturningAList(String userName, String extraParam);
|
||||
public List<Object> methodReturningAList(String userName, String extraParam);
|
||||
|
||||
}
|
||||
|
||||
@@ -37,12 +37,12 @@ public class BusinessServiceImpl<E extends Entity> implements BusinessService {
|
||||
return input;
|
||||
}
|
||||
|
||||
public List methodReturningAList(List someList) {
|
||||
public List<Object> methodReturningAList(List<Object> someList) {
|
||||
return someList;
|
||||
}
|
||||
|
||||
public List methodReturningAList(String userName, String arg2) {
|
||||
return new ArrayList();
|
||||
public List<Object> methodReturningAList(String userName, String arg2) {
|
||||
return new ArrayList<Object>();
|
||||
}
|
||||
|
||||
public Object[] methodReturningAnArray(Object[] someArray) {
|
||||
|
||||
+3
-3
@@ -30,12 +30,12 @@ public class ExpressionProtectedBusinessServiceImpl implements BusinessService {
|
||||
|
||||
@PreFilter(filterTarget="someList", value="filterObject == authentication.name or filterObject == 'sam'")
|
||||
@PostFilter("filterObject == 'bob'")
|
||||
public List methodReturningAList(List someList) {
|
||||
public List<Object> methodReturningAList(List<Object> someList) {
|
||||
return someList;
|
||||
}
|
||||
|
||||
public List methodReturningAList(String userName, String arg2) {
|
||||
return new ArrayList();
|
||||
public List<Object> methodReturningAList(String userName, String arg2) {
|
||||
return new ArrayList<Object>();
|
||||
}
|
||||
|
||||
@PostFilter("filterObject == 'bob'")
|
||||
|
||||
+2
-2
@@ -38,11 +38,11 @@ public class Jsr250BusinessServiceImpl implements BusinessService {
|
||||
return input;
|
||||
}
|
||||
|
||||
public List methodReturningAList(List someList) {
|
||||
public List<Object> methodReturningAList(List<Object> someList) {
|
||||
return someList;
|
||||
}
|
||||
|
||||
public List methodReturningAList(String userName, String arg2) {
|
||||
public List<Object> methodReturningAList(String userName, String arg2) {
|
||||
return new ArrayList();
|
||||
}
|
||||
|
||||
|
||||
+22
-6
@@ -1,7 +1,7 @@
|
||||
package org.springframework.security.config;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.security.config.ConfigTestUtils.*;
|
||||
import static org.springframework.security.config.ConfigTestUtils.AUTH_PROVIDER_XML;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -11,16 +11,19 @@ import org.junit.Test;
|
||||
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
|
||||
import org.springframework.context.support.AbstractXmlApplicationContext;
|
||||
import org.springframework.security.AccessDeniedException;
|
||||
import org.springframework.security.Authentication;
|
||||
import org.springframework.security.AuthenticationCredentialsNotFoundException;
|
||||
import org.springframework.security.GrantedAuthority;
|
||||
import org.springframework.security.GrantedAuthorityImpl;
|
||||
import org.springframework.security.afterinvocation.AfterInvocationProviderManager;
|
||||
import org.springframework.security.annotation.BusinessService;
|
||||
import org.springframework.security.context.SecurityContextHolder;
|
||||
import org.springframework.security.expression.support.MethodExpressionAfterInvocationProvider;
|
||||
import org.springframework.security.expression.support.MethodExpressionVoter;
|
||||
import org.springframework.security.providers.TestingAuthenticationToken;
|
||||
import org.springframework.security.providers.UsernamePasswordAuthenticationToken;
|
||||
import org.springframework.security.userdetails.UserDetailsService;
|
||||
import org.springframework.security.util.AuthorityUtils;
|
||||
import org.springframework.security.util.FieldUtils;
|
||||
import org.springframework.security.util.InMemoryXmlApplicationContext;
|
||||
import org.springframework.security.vote.AffirmativeBased;
|
||||
|
||||
/**
|
||||
* @author Ben Alex
|
||||
@@ -107,7 +110,7 @@ public class GlobalMethodSecurityBeanDefinitionParserTests {
|
||||
|
||||
UserDetailsService service = (UserDetailsService) appContext.getBean("myUserService");
|
||||
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken("Test", "Password",
|
||||
new GrantedAuthority[] {new GrantedAuthorityImpl("ROLE_SOMEOTHERROLE")});
|
||||
AuthorityUtils.createAuthorityList("ROLE_SOMEOTHERROLE"));
|
||||
SecurityContextHolder.getContext().setAuthentication(token);
|
||||
|
||||
service.loadUserByUsername("notused");
|
||||
@@ -180,12 +183,25 @@ public class GlobalMethodSecurityBeanDefinitionParserTests {
|
||||
);
|
||||
|
||||
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken("Test", "Password",
|
||||
new GrantedAuthority[] {new GrantedAuthorityImpl("ROLE_SOMEOTHERROLE")});
|
||||
AuthorityUtils.createAuthorityList("ROLE_SOMEOTHERROLE"));
|
||||
SecurityContextHolder.getContext().setAuthentication(token);
|
||||
target = (BusinessService) appContext.getBean("businessService");
|
||||
target.someUserMethod1();
|
||||
}
|
||||
|
||||
// Expression configuration tests
|
||||
|
||||
@Test
|
||||
public void expressionVoterAndAfterInvocationProviderUseSameExpressionHandlerInstance() throws Exception {
|
||||
setContext("<global-method-security expression-annotations='enabled'/>" + AUTH_PROVIDER_XML);
|
||||
AffirmativeBased adm = (AffirmativeBased) appContext.getBean(GlobalMethodSecurityBeanDefinitionParser.ACCESS_MANAGER_ID);
|
||||
List voters = (List) FieldUtils.getFieldValue(adm, "decisionVoters");
|
||||
MethodExpressionVoter mev = (MethodExpressionVoter) voters.get(0);
|
||||
AfterInvocationProviderManager pm = (AfterInvocationProviderManager) appContext.getBean(BeanIds.AFTER_INVOCATION_MANAGER);
|
||||
MethodExpressionAfterInvocationProvider aip = (MethodExpressionAfterInvocationProvider) pm.getProviders().get(0);
|
||||
assertTrue(FieldUtils.getFieldValue(mev, "expressionHandler") == FieldUtils.getFieldValue(aip, "expressionHandler"));
|
||||
}
|
||||
|
||||
@Test(expected=AccessDeniedException.class)
|
||||
public void accessIsDeniedForHasRoleExpression() {
|
||||
setContext(
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ public class MockAfterInvocationProvider implements AfterInvocationProvider {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean supports(Class clazz) {
|
||||
public boolean supports(Class<? extends Object> clazz) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
+1
-18
@@ -9,34 +9,17 @@ import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.security.ConfigAttribute;
|
||||
import org.springframework.security.annotation.ExpressionProtectedBusinessServiceImpl;
|
||||
import org.springframework.security.providers.TestingAuthenticationToken;
|
||||
import org.springframework.security.util.SimpleMethodInvocation;
|
||||
import org.springframework.security.vote.AccessDecisionVoter;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class MethodExpressionVoterTests {
|
||||
private TestingAuthenticationToken joe = new TestingAuthenticationToken("joe", "joespass", "blah");
|
||||
private MethodInvocation miListArg;
|
||||
private MethodInvocation miArrayArg;
|
||||
private List listArg;
|
||||
private Object[] arrayArg;
|
||||
private MethodExpressionVoter am = new MethodExpressionVoter();
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
Method m = ExpressionProtectedBusinessServiceImpl.class.getMethod("methodReturningAList",
|
||||
String.class, String.class);
|
||||
m = ExpressionProtectedBusinessServiceImpl.class.getMethod("methodReturningAList", List.class);
|
||||
listArg = new ArrayList(Arrays.asList("joe", "bob", "sam"));
|
||||
miListArg = new SimpleMethodInvocation(new Object(), m, new Object[] {listArg});
|
||||
m = ExpressionProtectedBusinessServiceImpl.class.getMethod("methodReturningAnArray", Object[].class);
|
||||
arrayArg = new Object[] {"joe", "bob", "sam"};
|
||||
miArrayArg = new SimpleMethodInvocation(new Object(), m, new Object[] {arrayArg});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasRoleExpressionAllowsUserWithRole() throws Exception {
|
||||
MethodInvocation mi = new SimpleMethodInvocation(new TargetImpl(), methodTakingAnArray());
|
||||
|
||||
+2
-2
@@ -90,7 +90,7 @@ public class AbstractSecurityInterceptorTests extends TestCase {
|
||||
private class MockSecurityInterceptorReturnsNull extends AbstractSecurityInterceptor {
|
||||
private ObjectDefinitionSource objectDefinitionSource;
|
||||
|
||||
public Class getSecureObjectClass() {
|
||||
public Class<? extends Object> getSecureObjectClass() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ public class AbstractSecurityInterceptorTests extends TestCase {
|
||||
private class MockSecurityInterceptorWhichOnlySupportsStrings extends AbstractSecurityInterceptor {
|
||||
private ObjectDefinitionSource objectDefinitionSource;
|
||||
|
||||
public Class getSecureObjectClass() {
|
||||
public Class<? extends Object> getSecureObjectClass() {
|
||||
return String.class;
|
||||
}
|
||||
|
||||
|
||||
+23
-22
@@ -15,25 +15,26 @@
|
||||
|
||||
package org.springframework.security.providers;
|
||||
|
||||
import org.springframework.security.Authentication;
|
||||
import org.springframework.security.AuthenticationException;
|
||||
import org.springframework.security.AuthenticationServiceException;
|
||||
import org.springframework.security.GrantedAuthority;
|
||||
import org.springframework.security.GrantedAuthorityImpl;
|
||||
import org.springframework.security.MockApplicationEventPublisher;
|
||||
import org.springframework.security.AccountStatusException;
|
||||
import org.springframework.security.concurrent.ConcurrentSessionControllerImpl;
|
||||
import org.springframework.security.concurrent.NullConcurrentSessionController;
|
||||
import org.springframework.security.concurrent.ConcurrentLoginException;
|
||||
import org.springframework.security.util.AuthorityUtils;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
import org.springframework.security.AccountStatusException;
|
||||
import org.springframework.security.Authentication;
|
||||
import org.springframework.security.AuthenticationException;
|
||||
import org.springframework.security.AuthenticationServiceException;
|
||||
import org.springframework.security.GrantedAuthority;
|
||||
import org.springframework.security.MockApplicationEventPublisher;
|
||||
import org.springframework.security.concurrent.ConcurrentLoginException;
|
||||
import org.springframework.security.concurrent.ConcurrentSessionControllerImpl;
|
||||
import org.springframework.security.concurrent.NullConcurrentSessionController;
|
||||
import org.springframework.security.util.AuthorityUtils;
|
||||
|
||||
/**
|
||||
* Tests {@link ProviderManager}.
|
||||
@@ -48,7 +49,7 @@ public class ProviderManagerTests {
|
||||
@Test(expected=ProviderNotFoundException.class)
|
||||
public void authenticationFailsWithUnsupportedToken() throws Exception {
|
||||
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken("Test", "Password",
|
||||
new GrantedAuthority[] {new GrantedAuthorityImpl("ROLE_ONE"), new GrantedAuthorityImpl("ROLE_TWO")});
|
||||
AuthorityUtils.createAuthorityList("ROLE_ONE", "ROLE_TWO"));
|
||||
|
||||
ProviderManager mgr = makeProviderManager();
|
||||
mgr.setApplicationEventPublisher(new MockApplicationEventPublisher(true));
|
||||
@@ -108,7 +109,7 @@ public class ProviderManagerTests {
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void startupFailsIfProviderListDoesNotContainProviders() throws Exception {
|
||||
List providers = new Vector();
|
||||
List<Object> providers = new ArrayList<Object>();
|
||||
providers.add("THIS_IS_NOT_A_PROVIDER");
|
||||
|
||||
ProviderManager mgr = new ProviderManager();
|
||||
@@ -143,7 +144,7 @@ public class ProviderManagerTests {
|
||||
return authentication;
|
||||
}
|
||||
|
||||
public boolean supports(Class authentication) {
|
||||
public boolean supports(Class<? extends Object> authentication) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
@@ -196,7 +197,7 @@ public class ProviderManagerTests {
|
||||
|
||||
private ProviderManager makeProviderManager() throws Exception {
|
||||
MockProvider provider1 = new MockProvider();
|
||||
List providers = new Vector();
|
||||
List<AuthenticationProvider> providers = new ArrayList<AuthenticationProvider>();
|
||||
providers.add(provider1);
|
||||
|
||||
ProviderManager mgr = new ProviderManager();
|
||||
@@ -210,7 +211,7 @@ public class ProviderManagerTests {
|
||||
private ProviderManager makeProviderManagerWithMockProviderWhichReturnsNullInList() {
|
||||
MockProviderWhichReturnsNull provider1 = new MockProviderWhichReturnsNull();
|
||||
MockProvider provider2 = new MockProvider();
|
||||
List providers = new Vector();
|
||||
List<Object> providers = new ArrayList<Object>();
|
||||
providers.add(provider1);
|
||||
providers.add(provider2);
|
||||
|
||||
@@ -231,7 +232,7 @@ public class ProviderManagerTests {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean supports(Class authentication) {
|
||||
public boolean supports(Class<? extends Object> authentication) {
|
||||
if (TestingAuthenticationToken.class.isAssignableFrom(authentication)) {
|
||||
return true;
|
||||
} else {
|
||||
@@ -249,7 +250,7 @@ public class ProviderManagerTests {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean supports(Class authentication) {
|
||||
public boolean supports(Class<? extends Object> authentication) {
|
||||
if (TestingAuthenticationToken.class.isAssignableFrom(authentication)) {
|
||||
return true;
|
||||
} else {
|
||||
@@ -263,7 +264,7 @@ public class ProviderManagerTests {
|
||||
throw new AccountStatusException("xxx") {};
|
||||
}
|
||||
|
||||
public boolean supports(Class authentication) {
|
||||
public boolean supports(Class<? extends Object> authentication) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -273,7 +274,7 @@ public class ProviderManagerTests {
|
||||
throw new ConcurrentLoginException("xxx") {};
|
||||
}
|
||||
|
||||
public boolean supports(Class authentication) {
|
||||
public boolean supports(Class<? extends Object> authentication) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
+1
@@ -41,6 +41,7 @@ import javax.servlet.ServletException;
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public class ChannelDecisionManagerImplTests extends TestCase {
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
|
||||
+40
-54
@@ -15,43 +15,39 @@
|
||||
|
||||
package org.springframework.security.ui.basicauth;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.springframework.security.matcher.AuthenticationMatcher.anAuthenticationWithUsernameAndPassword;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.Filter;
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.jmock.Expectations;
|
||||
import org.jmock.Mockery;
|
||||
import org.jmock.integration.junit4.JUnit4Mockery;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.security.MockAuthenticationEntryPoint;
|
||||
import org.springframework.security.MockAuthenticationManager;
|
||||
import org.springframework.security.MockFilterConfig;
|
||||
import org.springframework.security.MockApplicationEventPublisher;
|
||||
|
||||
import org.springframework.security.context.SecurityContextHolder;
|
||||
|
||||
import org.springframework.security.providers.ProviderManager;
|
||||
import org.springframework.security.providers.dao.DaoAuthenticationProvider;
|
||||
|
||||
import org.springframework.security.userdetails.UserDetails;
|
||||
import org.springframework.security.userdetails.memory.InMemoryDaoImpl;
|
||||
import org.springframework.security.userdetails.memory.UserMap;
|
||||
import org.springframework.security.userdetails.memory.UserMapEditor;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
import org.springframework.mock.web.MockHttpSession;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import javax.servlet.Filter;
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
import org.springframework.security.Authentication;
|
||||
import org.springframework.security.AuthenticationManager;
|
||||
import org.springframework.security.BadCredentialsException;
|
||||
import org.springframework.security.MockAuthenticationEntryPoint;
|
||||
import org.springframework.security.MockAuthenticationManager;
|
||||
import org.springframework.security.MockFilterConfig;
|
||||
import org.springframework.security.context.SecurityContextHolder;
|
||||
import org.springframework.security.providers.TestingAuthenticationToken;
|
||||
|
||||
|
||||
/**
|
||||
@@ -64,6 +60,7 @@ public class BasicProcessingFilterTests {
|
||||
//~ Instance fields ================================================================================================
|
||||
|
||||
private BasicProcessingFilter filter;
|
||||
private Mockery jmock = new JUnit4Mockery();
|
||||
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
@@ -89,19 +86,14 @@ public class BasicProcessingFilterTests {
|
||||
public void setUp() throws Exception {
|
||||
SecurityContextHolder.clearContext();
|
||||
|
||||
// Create User Details Service, provider and authentication manager
|
||||
InMemoryDaoImpl dao = new InMemoryDaoImpl();
|
||||
UserMapEditor editor = new UserMapEditor();
|
||||
editor.setAsText("rod=koala,ROLE_ONE,ROLE_TWO,enabled\r\n");
|
||||
dao.setUserMap((UserMap) editor.getValue());
|
||||
|
||||
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
|
||||
provider.setUserDetailsService(dao);
|
||||
|
||||
ProviderManager manager = new ProviderManager();
|
||||
manager.setProviders(Arrays.asList(new Object[] {provider}));
|
||||
manager.setApplicationEventPublisher(new MockApplicationEventPublisher());
|
||||
manager.afterPropertiesSet();
|
||||
final AuthenticationManager manager = jmock.mock(AuthenticationManager.class);
|
||||
final Authentication rod = new TestingAuthenticationToken("rod", "koala", "ROLE_1");
|
||||
jmock.checking(new Expectations() {{
|
||||
allowing(manager).authenticate(with(anAuthenticationWithUsernameAndPassword("rod", "koala")));
|
||||
will(returnValue(rod));
|
||||
allowing(manager).authenticate(with(any(Authentication.class)));
|
||||
will(throwException(new BadCredentialsException("")));
|
||||
}});
|
||||
|
||||
filter = new BasicProcessingFilter();
|
||||
filter.setAuthenticationManager(manager);
|
||||
@@ -164,8 +156,8 @@ public class BasicProcessingFilterTests {
|
||||
executeFilterInContainerSimulator(filter, request, true);
|
||||
|
||||
assertNotNull(SecurityContextHolder.getContext().getAuthentication());
|
||||
assertEquals("rod",
|
||||
((UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUsername());
|
||||
assertEquals("rod", SecurityContextHolder.getContext().getAuthentication().getName());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -193,16 +185,11 @@ public class BasicProcessingFilterTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testStartupDetectsMissingAuthenticationManager() throws Exception {
|
||||
try {
|
||||
BasicProcessingFilter filter = new BasicProcessingFilter();
|
||||
filter.setAuthenticationEntryPoint(new MockAuthenticationEntryPoint("x"));
|
||||
filter.afterPropertiesSet();
|
||||
fail("Should have thrown IllegalArgumentException");
|
||||
} catch (IllegalArgumentException expected) {
|
||||
assertEquals("An AuthenticationManager is required", expected.getMessage());
|
||||
}
|
||||
BasicProcessingFilter filter = new BasicProcessingFilter();
|
||||
filter.setAuthenticationEntryPoint(new MockAuthenticationEntryPoint("x"));
|
||||
filter.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -218,8 +205,7 @@ public class BasicProcessingFilterTests {
|
||||
executeFilterInContainerSimulator(filter, request, true);
|
||||
|
||||
assertNotNull(SecurityContextHolder.getContext().getAuthentication());
|
||||
assertEquals("rod",
|
||||
((UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUsername());
|
||||
assertEquals("rod", SecurityContextHolder.getContext().getAuthentication().getName());
|
||||
|
||||
// NOW PERFORM FAILED AUTHENTICATION
|
||||
// Setup our HTTP request
|
||||
@@ -249,7 +235,7 @@ public class BasicProcessingFilterTests {
|
||||
assertTrue(filter.isIgnoreFailure());
|
||||
|
||||
// Test - the filter chain will be invoked, as we've set ignoreFailure = true
|
||||
MockHttpServletResponse response = executeFilterInContainerSimulator(filter, request, true);
|
||||
executeFilterInContainerSimulator(filter, request, true);
|
||||
|
||||
assertNull(SecurityContextHolder.getContext().getAuthentication());
|
||||
}
|
||||
|
||||
+2
-18
@@ -32,27 +32,11 @@ import java.util.Vector;
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public class AbstractAccessDecisionManagerTests extends TestCase {
|
||||
//~ Constructors ===================================================================================================
|
||||
|
||||
public AbstractAccessDecisionManagerTests() {
|
||||
super();
|
||||
}
|
||||
|
||||
public AbstractAccessDecisionManagerTests(String arg0) {
|
||||
super(arg0);
|
||||
}
|
||||
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
public static void main(String[] args) {
|
||||
junit.textui.TestRunner.run(AbstractAccessDecisionManagerTests.class);
|
||||
}
|
||||
|
||||
public final void setUp() throws Exception {
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
public void testAllowIfAccessDecisionManagerDefaults()
|
||||
throws Exception {
|
||||
MockDecisionManagerImpl mock = new MockDecisionManagerImpl();
|
||||
@@ -168,7 +152,7 @@ public class AbstractAccessDecisionManagerTests extends TestCase {
|
||||
}
|
||||
|
||||
private class MockStringOnlyVoter implements AccessDecisionVoter {
|
||||
public boolean supports(Class clazz) {
|
||||
public boolean supports(Class<? extends Object> clazz) {
|
||||
if (String.class.isAssignableFrom(clazz)) {
|
||||
return true;
|
||||
} else {
|
||||
|
||||
@@ -41,7 +41,7 @@ public class AffirmativeBasedTests {
|
||||
RoleVoter roleVoter = new RoleVoter();
|
||||
DenyVoter denyForSureVoter = new DenyVoter();
|
||||
DenyAgainVoter denyAgainForSureVoter = new DenyAgainVoter();
|
||||
List voters = new ArrayList();
|
||||
List<AccessDecisionVoter> voters = new ArrayList<AccessDecisionVoter>();
|
||||
voters.add(roleVoter);
|
||||
voters.add(denyForSureVoter);
|
||||
voters.add(denyAgainForSureVoter);
|
||||
|
||||
@@ -47,7 +47,7 @@ public class DenyAgainVoter implements AccessDecisionVoter {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean supports(Class clazz) {
|
||||
public boolean supports(Class<? extends Object> clazz) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ public class DenyVoter implements AccessDecisionVoter {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean supports(Class clazz) {
|
||||
public boolean supports(Class<? extends Object> clazz) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user