Removing $Id$ markers and stripping trailing whitespace from the codebase.
This commit is contained in:
@@ -19,7 +19,6 @@ package org.springframework.security;
|
||||
* Represents the interface of a secured object.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public interface ITargetObject {
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
@@ -25,7 +25,6 @@ import org.springframework.security.core.AuthenticationException;
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @author Wesley Hall
|
||||
* @version $Id$
|
||||
*/
|
||||
public class MockAuthenticationManager extends AbstractAuthenticationManager {
|
||||
//~ Instance fields ================================================================================================
|
||||
|
||||
@@ -27,7 +27,6 @@ import java.lang.reflect.Method;
|
||||
* A mock AspectJ <code>JoinPoint</code>.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public class MockJoinPoint implements JoinPoint {
|
||||
|
||||
@@ -24,7 +24,6 @@ package org.springframework.security;
|
||||
* its parent class or classes).</p>
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class OtherTargetObject extends TargetObject implements ITargetObject {
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
@@ -24,7 +24,6 @@ import javax.sql.DataSource;
|
||||
* Singleton which provides a populated database connection for all JDBC-related unit tests.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class PopulatedDatabase {
|
||||
//~ Static fields/initializers =====================================================================================
|
||||
|
||||
@@ -23,7 +23,6 @@ import org.springframework.security.core.context.SecurityContextHolder;
|
||||
* Represents a secured object.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class TargetObject implements ITargetObject {
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
@@ -9,14 +9,13 @@ import org.springframework.beans.factory.DisposableBean;
|
||||
* shuts down the database when the application context it is defined in is closed.
|
||||
*
|
||||
* @author Luke Taylor
|
||||
* @version $Id$
|
||||
*/
|
||||
public class TestDataSource extends DriverManagerDataSource implements DisposableBean {
|
||||
String name;
|
||||
|
||||
public TestDataSource(String databaseName) {
|
||||
name = databaseName;
|
||||
System.out.println("Creating database: " + name);
|
||||
System.out.println("Creating database: " + name);
|
||||
setDriverClassName("org.hsqldb.jdbcDriver");
|
||||
setUrl("jdbc:hsqldb:mem:" + databaseName);
|
||||
setUsername("sa");
|
||||
|
||||
@@ -26,7 +26,6 @@ import org.springframework.security.util.SimpleMethodInvocation;
|
||||
* Tests {@link AuthenticationCredentialsNotFoundEvent}.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class AuthenticationCredentialsNotFoundEventTests {
|
||||
|
||||
|
||||
@@ -27,7 +27,6 @@ import org.springframework.security.util.SimpleMethodInvocation;
|
||||
* Tests {@link AuthorizationFailureEvent}.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class AuthorizationFailureEventTests {
|
||||
|
||||
|
||||
@@ -26,7 +26,6 @@ import org.springframework.security.util.SimpleMethodInvocation;
|
||||
* Tests {@link AuthorizedEvent}.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class AuthorizedEventTests {
|
||||
|
||||
|
||||
@@ -26,7 +26,6 @@ import org.springframework.security.access.SecurityConfig;
|
||||
* Tests {@link SecurityConfig}.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class SecurityConfigTests {
|
||||
|
||||
@@ -37,7 +36,7 @@ public class SecurityConfigTests {
|
||||
SecurityConfig config = new SecurityConfig("TEST");
|
||||
Assert.assertEquals("TEST".hashCode(), config.hashCode());
|
||||
}
|
||||
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testCannotConstructWithNullAttribute() {
|
||||
new SecurityConfig(null); // SEC-727
|
||||
@@ -84,7 +83,7 @@ public class SecurityConfigTests {
|
||||
SecurityConfig config = new SecurityConfig("TEST");
|
||||
Assert.assertEquals("TEST", config.toString());
|
||||
}
|
||||
|
||||
|
||||
//~ Inner Classes ==================================================================================================
|
||||
|
||||
private class MockConfigAttribute implements ConfigAttribute {
|
||||
|
||||
@@ -24,7 +24,6 @@ import org.springframework.security.access.annotation.Secured;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
|
||||
/**
|
||||
* @version $Id$
|
||||
*/
|
||||
@Secured({"ROLE_USER"})
|
||||
@PermitAll
|
||||
|
||||
@@ -10,7 +10,6 @@ import javax.annotation.security.PermitAll;
|
||||
/**
|
||||
*
|
||||
* @author Luke Taylor
|
||||
* @version $Id$
|
||||
*/
|
||||
@PermitAll
|
||||
public class Jsr250BusinessServiceImpl implements BusinessService {
|
||||
|
||||
@@ -15,7 +15,6 @@ import org.springframework.security.access.ConfigAttribute;
|
||||
/**
|
||||
* @author Luke Taylor
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class Jsr250MethodDefinitionSourceTests {
|
||||
Jsr250MethodSecurityMetadataSource mds = new Jsr250MethodSecurityMetadataSource();
|
||||
|
||||
@@ -36,7 +36,6 @@ import org.springframework.security.access.method.MethodSecurityMetadataSourceEd
|
||||
* Extra tests to demonstrate generics behaviour with <code>MapBasedMethodDefinitionSource</code>.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class MethodDefinitionSourceEditorTigerTests {
|
||||
|
||||
@@ -32,7 +32,6 @@ import org.springframework.util.StringUtils;
|
||||
* @author Mark St.Godard
|
||||
* @author Joe Scalise
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class SecuredAnnotationSecurityMetadataDefinitionSourceTests extends TestCase {
|
||||
//~ Instance fields ================================================================================================
|
||||
|
||||
@@ -22,7 +22,6 @@ import org.springframework.util.Assert;
|
||||
* An entity used in our generics testing.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class Entity {
|
||||
//~ Instance fields ================================================================================================
|
||||
|
||||
@@ -19,7 +19,6 @@ package org.springframework.security.access.annotation.test;
|
||||
* An extended version of <code>Entity</code>.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class Organisation extends Entity {
|
||||
//~ Instance fields ================================================================================================
|
||||
|
||||
@@ -18,8 +18,6 @@ package org.springframework.security.access.annotation.test;
|
||||
/**
|
||||
* DOCUMENT ME!
|
||||
*
|
||||
* @author $author$
|
||||
* @version $Revision: 1496 $
|
||||
*/
|
||||
public interface OrganisationService extends Service<Organisation> {
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
@@ -19,7 +19,6 @@ package org.springframework.security.access.annotation.test;
|
||||
* An extended version of <code>Entity</code>.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class Person extends Entity {
|
||||
//~ Instance fields ================================================================================================
|
||||
|
||||
@@ -18,8 +18,6 @@ package org.springframework.security.access.annotation.test;
|
||||
/**
|
||||
* DOCUMENT ME!
|
||||
*
|
||||
* @author $author$
|
||||
* @version $Revision: 1496 $
|
||||
*/
|
||||
public class PersonServiceImpl extends ServiceImpl<Person> implements PersonService {
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
@@ -22,7 +22,6 @@ import java.util.Collection;
|
||||
* An interface that uses Java 5 generics.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public interface Service<E extends Entity> {
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
@@ -13,7 +13,6 @@ import org.springframework.security.core.authority.AuthorityUtils;
|
||||
/**
|
||||
*
|
||||
* @author Luke Taylor
|
||||
* @version $Id$
|
||||
* @since 3.0
|
||||
*/
|
||||
public class SecurityExpressionRootTests {
|
||||
|
||||
@@ -18,7 +18,6 @@ import org.springframework.security.core.Authentication;
|
||||
* Tests for {@link MethodSecurityExpressionRoot}
|
||||
*
|
||||
* @author Luke Taylor
|
||||
* @version $Id$
|
||||
*/
|
||||
public class MethodSecurityExpressionRootTests {
|
||||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
|
||||
@@ -17,7 +17,6 @@ import org.springframework.security.access.prepost.PrePostAnnotationSecurityMeta
|
||||
/**
|
||||
*
|
||||
* @author Luke Taylor
|
||||
* @version $Id$
|
||||
* @since 3.0
|
||||
*/
|
||||
public class PrePostAnnotationSecurityMetadataSourceTests {
|
||||
|
||||
@@ -110,7 +110,7 @@ public class RoleHierarchyImplTests extends TestCase {
|
||||
fail("A cycle in role hierarchy was incorrectly detected!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// SEC-863
|
||||
public void testSimpleRoleHierarchyWithCustomGrantedAuthorityImplementation() {
|
||||
|
||||
|
||||
@@ -1,78 +1,78 @@
|
||||
package org.springframework.security.access.hierarchicalroles;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.jmock.Expectations;
|
||||
import org.jmock.Mockery;
|
||||
import org.jmock.integration.junit4.JMock;
|
||||
import org.jmock.integration.junit4.JUnit4Mockery;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.dao.EmptyResultDataAccessException;
|
||||
import org.springframework.security.access.hierarchicalroles.RoleHierarchyImpl;
|
||||
import org.springframework.security.access.hierarchicalroles.UserDetailsServiceWrapper;
|
||||
import org.springframework.security.core.authority.AuthorityUtils;
|
||||
import org.springframework.security.core.userdetails.User;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||
|
||||
@RunWith(JMock.class)
|
||||
@SuppressWarnings("deprecation")
|
||||
public class UserDetailsServiceWrapperTests {
|
||||
|
||||
private UserDetailsService wrappedUserDetailsService = null;
|
||||
private UserDetailsServiceWrapper userDetailsServiceWrapper = null;
|
||||
private Mockery jmockContext = new JUnit4Mockery();
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
RoleHierarchyImpl roleHierarchy = new RoleHierarchyImpl();
|
||||
roleHierarchy.setHierarchy("ROLE_A > ROLE_B");
|
||||
final UserDetails user = new User("EXISTING_USER", "PASSWORD", true, true, true, true,
|
||||
AuthorityUtils.createAuthorityList("ROLE_A"));
|
||||
final UserDetailsService wrappedUserDetailsService = jmockContext.mock(UserDetailsService.class);
|
||||
|
||||
jmockContext.checking( new Expectations() {{
|
||||
allowing(wrappedUserDetailsService).loadUserByUsername("EXISTING_USER"); will(returnValue(user));
|
||||
allowing(wrappedUserDetailsService).loadUserByUsername("USERNAME_NOT_FOUND_EXCEPTION"); will(throwException(new UsernameNotFoundException("USERNAME_NOT_FOUND_EXCEPTION")));
|
||||
allowing(wrappedUserDetailsService).loadUserByUsername("DATA_ACCESS_EXCEPTION"); will(throwException(new EmptyResultDataAccessException(1234)));
|
||||
}});
|
||||
this.wrappedUserDetailsService = wrappedUserDetailsService;
|
||||
userDetailsServiceWrapper = new UserDetailsServiceWrapper();
|
||||
userDetailsServiceWrapper.setRoleHierarchy(roleHierarchy);
|
||||
userDetailsServiceWrapper.setUserDetailsService(wrappedUserDetailsService);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadUserByUsername() {
|
||||
UserDetails expectedUserDetails = new User("EXISTING_USER", "PASSWORD", true, true, true, true,
|
||||
AuthorityUtils.createAuthorityList("ROLE_A", "ROLE_B"));
|
||||
UserDetails userDetails = userDetailsServiceWrapper.loadUserByUsername("EXISTING_USER");
|
||||
assertEquals(expectedUserDetails.getPassword(), userDetails.getPassword());
|
||||
assertEquals(expectedUserDetails.getUsername(), userDetails.getUsername());
|
||||
assertEquals(expectedUserDetails.isAccountNonExpired(), userDetails.isAccountNonExpired());
|
||||
assertEquals(expectedUserDetails.isAccountNonLocked(), userDetails.isAccountNonLocked());
|
||||
assertEquals(expectedUserDetails.isCredentialsNonExpired(), expectedUserDetails.isCredentialsNonExpired());
|
||||
assertEquals(expectedUserDetails.isEnabled(), userDetails.isEnabled());
|
||||
assertTrue(HierarchicalRolesTestHelper.containTheSameGrantedAuthorities(expectedUserDetails.getAuthorities(), userDetails.getAuthorities()));
|
||||
|
||||
try {
|
||||
userDetails = userDetailsServiceWrapper.loadUserByUsername("USERNAME_NOT_FOUND_EXCEPTION");
|
||||
fail("testLoadUserByUsername() - UsernameNotFoundException did not bubble up!");
|
||||
} catch (UsernameNotFoundException e) {}
|
||||
|
||||
try {
|
||||
userDetails = userDetailsServiceWrapper.loadUserByUsername("DATA_ACCESS_EXCEPTION");
|
||||
fail("testLoadUserByUsername() - DataAccessException did not bubble up!");
|
||||
} catch (DataAccessException e) {}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetWrappedUserDetailsService() {
|
||||
assertTrue(userDetailsServiceWrapper.getWrappedUserDetailsService() == wrappedUserDetailsService);
|
||||
}
|
||||
|
||||
}
|
||||
package org.springframework.security.access.hierarchicalroles;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.jmock.Expectations;
|
||||
import org.jmock.Mockery;
|
||||
import org.jmock.integration.junit4.JMock;
|
||||
import org.jmock.integration.junit4.JUnit4Mockery;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.dao.EmptyResultDataAccessException;
|
||||
import org.springframework.security.access.hierarchicalroles.RoleHierarchyImpl;
|
||||
import org.springframework.security.access.hierarchicalroles.UserDetailsServiceWrapper;
|
||||
import org.springframework.security.core.authority.AuthorityUtils;
|
||||
import org.springframework.security.core.userdetails.User;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||
|
||||
@RunWith(JMock.class)
|
||||
@SuppressWarnings("deprecation")
|
||||
public class UserDetailsServiceWrapperTests {
|
||||
|
||||
private UserDetailsService wrappedUserDetailsService = null;
|
||||
private UserDetailsServiceWrapper userDetailsServiceWrapper = null;
|
||||
private Mockery jmockContext = new JUnit4Mockery();
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
RoleHierarchyImpl roleHierarchy = new RoleHierarchyImpl();
|
||||
roleHierarchy.setHierarchy("ROLE_A > ROLE_B");
|
||||
final UserDetails user = new User("EXISTING_USER", "PASSWORD", true, true, true, true,
|
||||
AuthorityUtils.createAuthorityList("ROLE_A"));
|
||||
final UserDetailsService wrappedUserDetailsService = jmockContext.mock(UserDetailsService.class);
|
||||
|
||||
jmockContext.checking( new Expectations() {{
|
||||
allowing(wrappedUserDetailsService).loadUserByUsername("EXISTING_USER"); will(returnValue(user));
|
||||
allowing(wrappedUserDetailsService).loadUserByUsername("USERNAME_NOT_FOUND_EXCEPTION"); will(throwException(new UsernameNotFoundException("USERNAME_NOT_FOUND_EXCEPTION")));
|
||||
allowing(wrappedUserDetailsService).loadUserByUsername("DATA_ACCESS_EXCEPTION"); will(throwException(new EmptyResultDataAccessException(1234)));
|
||||
}});
|
||||
this.wrappedUserDetailsService = wrappedUserDetailsService;
|
||||
userDetailsServiceWrapper = new UserDetailsServiceWrapper();
|
||||
userDetailsServiceWrapper.setRoleHierarchy(roleHierarchy);
|
||||
userDetailsServiceWrapper.setUserDetailsService(wrappedUserDetailsService);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadUserByUsername() {
|
||||
UserDetails expectedUserDetails = new User("EXISTING_USER", "PASSWORD", true, true, true, true,
|
||||
AuthorityUtils.createAuthorityList("ROLE_A", "ROLE_B"));
|
||||
UserDetails userDetails = userDetailsServiceWrapper.loadUserByUsername("EXISTING_USER");
|
||||
assertEquals(expectedUserDetails.getPassword(), userDetails.getPassword());
|
||||
assertEquals(expectedUserDetails.getUsername(), userDetails.getUsername());
|
||||
assertEquals(expectedUserDetails.isAccountNonExpired(), userDetails.isAccountNonExpired());
|
||||
assertEquals(expectedUserDetails.isAccountNonLocked(), userDetails.isAccountNonLocked());
|
||||
assertEquals(expectedUserDetails.isCredentialsNonExpired(), expectedUserDetails.isCredentialsNonExpired());
|
||||
assertEquals(expectedUserDetails.isEnabled(), userDetails.isEnabled());
|
||||
assertTrue(HierarchicalRolesTestHelper.containTheSameGrantedAuthorities(expectedUserDetails.getAuthorities(), userDetails.getAuthorities()));
|
||||
|
||||
try {
|
||||
userDetails = userDetailsServiceWrapper.loadUserByUsername("USERNAME_NOT_FOUND_EXCEPTION");
|
||||
fail("testLoadUserByUsername() - UsernameNotFoundException did not bubble up!");
|
||||
} catch (UsernameNotFoundException e) {}
|
||||
|
||||
try {
|
||||
userDetails = userDetailsServiceWrapper.loadUserByUsername("DATA_ACCESS_EXCEPTION");
|
||||
fail("testLoadUserByUsername() - DataAccessException did not bubble up!");
|
||||
} catch (DataAccessException e) {}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetWrappedUserDetailsService() {
|
||||
assertTrue(userDetailsServiceWrapper.getWrappedUserDetailsService() == wrappedUserDetailsService);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,86 +1,86 @@
|
||||
package org.springframework.security.access.hierarchicalroles;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.security.access.hierarchicalroles.RoleHierarchyImpl;
|
||||
import org.springframework.security.access.hierarchicalroles.UserDetailsWrapper;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.authority.AuthorityUtils;
|
||||
import org.springframework.security.core.userdetails.User;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
|
||||
/**
|
||||
* Tests for {@link UserDetailsWrapper}.
|
||||
*
|
||||
* @author Michael Mayr
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class UserDetailsWrapperTests extends TestCase {
|
||||
|
||||
private List<GrantedAuthority> authorities = null;
|
||||
private UserDetails userDetails1 = null;
|
||||
private UserDetails userDetails2 = null;
|
||||
private UserDetailsWrapper userDetailsWrapper1 = null;
|
||||
private UserDetailsWrapper userDetailsWrapper2 = null;
|
||||
|
||||
public UserDetailsWrapperTests() {
|
||||
}
|
||||
|
||||
public UserDetailsWrapperTests(String testCaseName) {
|
||||
super(testCaseName);
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
RoleHierarchyImpl roleHierarchy = new RoleHierarchyImpl();
|
||||
roleHierarchy.setHierarchy("ROLE_A > ROLE_B");
|
||||
authorities = AuthorityUtils.createAuthorityList("ROLE_A");
|
||||
userDetails1 = new User("TestUser1", "TestPassword1", true, true, true, true, authorities);
|
||||
userDetails2 = new User("TestUser2", "TestPassword2", false, false, false, false, authorities);
|
||||
userDetailsWrapper1 = new UserDetailsWrapper(userDetails1, roleHierarchy);
|
||||
userDetailsWrapper2 = new UserDetailsWrapper(userDetails2, roleHierarchy);
|
||||
}
|
||||
|
||||
public void testIsAccountNonExpired() {
|
||||
assertEquals(userDetails1.isAccountNonExpired(), userDetailsWrapper1.isAccountNonExpired());
|
||||
assertEquals(userDetails2.isAccountNonExpired(), userDetailsWrapper2.isAccountNonExpired());
|
||||
}
|
||||
|
||||
public void testIsAccountNonLocked() {
|
||||
assertEquals(userDetails1.isAccountNonLocked(), userDetailsWrapper1.isAccountNonLocked());
|
||||
assertEquals(userDetails2.isAccountNonLocked(), userDetailsWrapper2.isAccountNonLocked());
|
||||
}
|
||||
|
||||
public void testGetAuthorities() {
|
||||
List<GrantedAuthority> expectedAuthorities = AuthorityUtils.createAuthorityList("ROLE_A", "ROLE_B");
|
||||
assertTrue(HierarchicalRolesTestHelper.containTheSameGrantedAuthorities(userDetailsWrapper1.getAuthorities(), expectedAuthorities));
|
||||
assertTrue(HierarchicalRolesTestHelper.containTheSameGrantedAuthorities(userDetailsWrapper2.getAuthorities(), expectedAuthorities));
|
||||
}
|
||||
|
||||
public void testIsCredentialsNonExpired() {
|
||||
assertEquals(userDetails1.isCredentialsNonExpired(), userDetailsWrapper1.isCredentialsNonExpired());
|
||||
assertEquals(userDetails2.isCredentialsNonExpired(), userDetailsWrapper2.isCredentialsNonExpired());
|
||||
}
|
||||
|
||||
public void testIsEnabled() {
|
||||
assertEquals(userDetails1.isEnabled(), userDetailsWrapper1.isEnabled());
|
||||
assertEquals(userDetails2.isEnabled(), userDetailsWrapper2.isEnabled());
|
||||
}
|
||||
|
||||
public void testGetPassword() {
|
||||
assertEquals(userDetails1.getPassword(), userDetailsWrapper1.getPassword());
|
||||
assertEquals(userDetails2.getPassword(), userDetailsWrapper2.getPassword());
|
||||
}
|
||||
|
||||
public void testGetUsername() {
|
||||
assertEquals(userDetails1.getUsername(), userDetailsWrapper1.getUsername());
|
||||
assertEquals(userDetails2.getUsername(), userDetailsWrapper2.getUsername());
|
||||
}
|
||||
|
||||
public void testGetUnwrappedUserDetails() {
|
||||
assertTrue(userDetailsWrapper1.getUnwrappedUserDetails() == userDetails1);
|
||||
assertTrue(userDetailsWrapper2.getUnwrappedUserDetails() == userDetails2);
|
||||
}
|
||||
|
||||
}
|
||||
package org.springframework.security.access.hierarchicalroles;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.security.access.hierarchicalroles.RoleHierarchyImpl;
|
||||
import org.springframework.security.access.hierarchicalroles.UserDetailsWrapper;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.authority.AuthorityUtils;
|
||||
import org.springframework.security.core.userdetails.User;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
|
||||
/**
|
||||
* Tests for {@link UserDetailsWrapper}.
|
||||
*
|
||||
* @author Michael Mayr
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class UserDetailsWrapperTests extends TestCase {
|
||||
|
||||
private List<GrantedAuthority> authorities = null;
|
||||
private UserDetails userDetails1 = null;
|
||||
private UserDetails userDetails2 = null;
|
||||
private UserDetailsWrapper userDetailsWrapper1 = null;
|
||||
private UserDetailsWrapper userDetailsWrapper2 = null;
|
||||
|
||||
public UserDetailsWrapperTests() {
|
||||
}
|
||||
|
||||
public UserDetailsWrapperTests(String testCaseName) {
|
||||
super(testCaseName);
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
RoleHierarchyImpl roleHierarchy = new RoleHierarchyImpl();
|
||||
roleHierarchy.setHierarchy("ROLE_A > ROLE_B");
|
||||
authorities = AuthorityUtils.createAuthorityList("ROLE_A");
|
||||
userDetails1 = new User("TestUser1", "TestPassword1", true, true, true, true, authorities);
|
||||
userDetails2 = new User("TestUser2", "TestPassword2", false, false, false, false, authorities);
|
||||
userDetailsWrapper1 = new UserDetailsWrapper(userDetails1, roleHierarchy);
|
||||
userDetailsWrapper2 = new UserDetailsWrapper(userDetails2, roleHierarchy);
|
||||
}
|
||||
|
||||
public void testIsAccountNonExpired() {
|
||||
assertEquals(userDetails1.isAccountNonExpired(), userDetailsWrapper1.isAccountNonExpired());
|
||||
assertEquals(userDetails2.isAccountNonExpired(), userDetailsWrapper2.isAccountNonExpired());
|
||||
}
|
||||
|
||||
public void testIsAccountNonLocked() {
|
||||
assertEquals(userDetails1.isAccountNonLocked(), userDetailsWrapper1.isAccountNonLocked());
|
||||
assertEquals(userDetails2.isAccountNonLocked(), userDetailsWrapper2.isAccountNonLocked());
|
||||
}
|
||||
|
||||
public void testGetAuthorities() {
|
||||
List<GrantedAuthority> expectedAuthorities = AuthorityUtils.createAuthorityList("ROLE_A", "ROLE_B");
|
||||
assertTrue(HierarchicalRolesTestHelper.containTheSameGrantedAuthorities(userDetailsWrapper1.getAuthorities(), expectedAuthorities));
|
||||
assertTrue(HierarchicalRolesTestHelper.containTheSameGrantedAuthorities(userDetailsWrapper2.getAuthorities(), expectedAuthorities));
|
||||
}
|
||||
|
||||
public void testIsCredentialsNonExpired() {
|
||||
assertEquals(userDetails1.isCredentialsNonExpired(), userDetailsWrapper1.isCredentialsNonExpired());
|
||||
assertEquals(userDetails2.isCredentialsNonExpired(), userDetailsWrapper2.isCredentialsNonExpired());
|
||||
}
|
||||
|
||||
public void testIsEnabled() {
|
||||
assertEquals(userDetails1.isEnabled(), userDetailsWrapper1.isEnabled());
|
||||
assertEquals(userDetails2.isEnabled(), userDetailsWrapper2.isEnabled());
|
||||
}
|
||||
|
||||
public void testGetPassword() {
|
||||
assertEquals(userDetails1.getPassword(), userDetailsWrapper1.getPassword());
|
||||
assertEquals(userDetails2.getPassword(), userDetailsWrapper2.getPassword());
|
||||
}
|
||||
|
||||
public void testGetUsername() {
|
||||
assertEquals(userDetails1.getUsername(), userDetailsWrapper1.getUsername());
|
||||
assertEquals(userDetails2.getUsername(), userDetailsWrapper2.getUsername());
|
||||
}
|
||||
|
||||
public void testGetUnwrappedUserDetails() {
|
||||
assertTrue(userDetailsWrapper1.getUnwrappedUserDetails() == userDetails1);
|
||||
assertTrue(userDetailsWrapper2.getUnwrappedUserDetails() == userDetails2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -32,7 +32,6 @@ import org.springframework.security.util.SimpleMethodInvocation;
|
||||
* <code>MethodSecurityInterceptorTests</code> class.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class AbstractSecurityInterceptorTests {
|
||||
private Mockery jmock = new JUnit4Mockery();
|
||||
|
||||
@@ -35,7 +35,6 @@ import org.springframework.security.util.SimpleMethodInvocation;
|
||||
* Tests {@link AfterInvocationProviderManager}.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public class AfterInvocationProviderManagerTests extends TestCase {
|
||||
|
||||
@@ -33,7 +33,6 @@ import org.springframework.security.util.SimpleMethodInvocation;
|
||||
* Tests {@link InterceptorStatusToken}.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class InterceptorStatusTokenTests {
|
||||
|
||||
|
||||
@@ -25,7 +25,6 @@ import org.springframework.security.access.intercept.NullRunAsManager;
|
||||
* Tests {@link NullRunAsManager}.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class NullRunAsManagerTests extends TestCase {
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
@@ -29,7 +29,6 @@ import org.springframework.security.core.authority.AuthorityUtils;
|
||||
* Tests {@link RunAsManagerImpl}.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class RunAsManagerImplTests extends TestCase {
|
||||
public void testAlwaysSupportsClass() {
|
||||
|
||||
@@ -28,7 +28,6 @@ import org.springframework.security.core.authority.GrantedAuthorityImpl;
|
||||
* Tests {@link RunAsUserToken}.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class RunAsUserTokenTests extends TestCase {
|
||||
//~ Constructors ===================================================================================================
|
||||
|
||||
@@ -50,7 +50,6 @@ import org.springframework.security.core.context.SecurityContextHolder;
|
||||
* Tests {@link MethodSecurityInterceptor}.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public class MethodSecurityInterceptorTests {
|
||||
|
||||
@@ -29,7 +29,6 @@ import org.springframework.security.access.method.MethodSecurityMetadataSourceEd
|
||||
* Tests {@link MethodSecurityMetadataSourceAdvisor}.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class MethodSecurityMetadataSourceAdvisorTests extends TestCase {
|
||||
|
||||
@@ -42,7 +42,6 @@ import org.springframework.security.core.context.SecurityContextHolder;
|
||||
* Tests {@link AspectJSecurityInterceptor}.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class AspectJSecurityInterceptorTests {
|
||||
private Mockery jmock = new JUnit4Mockery();
|
||||
|
||||
@@ -45,7 +45,6 @@ import org.springframework.security.util.MethodInvocationUtils;
|
||||
* Tests {@link org.springframework.security.access.intercept.MethodInvocationPrivilegeEvaluator}.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class MethodInvocationPrivilegeEvaluatorTests {
|
||||
private Mockery jmock = new JUnit4Mockery();
|
||||
|
||||
@@ -37,7 +37,6 @@ import org.springframework.security.access.method.MethodSecurityMetadataSourceEd
|
||||
* Tests {@link MethodSecurityMetadataSourceEditor} and its associated {@link MapBasedMethodSecurityMetadataSource}.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public class MethodSecurityMetadataSourceEditorTests extends TestCase {
|
||||
|
||||
@@ -29,7 +29,6 @@ import org.springframework.security.access.method.MethodSecurityMetadataSource;
|
||||
|
||||
/**
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class MockMethodSecurityMetadataSource implements MethodSecurityMetadataSource {
|
||||
//~ Instance fields ================================================================================================
|
||||
|
||||
@@ -34,7 +34,6 @@ import java.util.Vector;
|
||||
* Tests {@link AbstractAccessDecisionManager}.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public class AbstractAccessDecisionManagerTests extends TestCase {
|
||||
|
||||
@@ -18,7 +18,6 @@ import org.springframework.security.util.MethodInvocationUtils;
|
||||
/**
|
||||
*
|
||||
* @author Luke Taylor
|
||||
* @version $Id$
|
||||
*/
|
||||
public class AbstractAclVoterTests {
|
||||
private AbstractAclVoter voter = new AbstractAclVoter() {
|
||||
|
||||
@@ -36,7 +36,6 @@ import org.springframework.security.core.Authentication;
|
||||
* Tests {@link AffirmativeBased}.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class AffirmativeBasedTests {
|
||||
private final List<ConfigAttribute> attrs = new ArrayList<ConfigAttribute>();
|
||||
|
||||
@@ -34,7 +34,6 @@ import org.springframework.security.core.authority.AuthorityUtils;
|
||||
* Tests {@link AuthenticatedVoter}.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class AuthenticatedVoterTests extends TestCase {
|
||||
|
||||
|
||||
@@ -36,7 +36,6 @@ import org.springframework.security.core.authority.GrantedAuthorityImpl;
|
||||
* Tests {@link ConsensusBased}.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class ConsensusBasedTests {
|
||||
|
||||
|
||||
@@ -31,7 +31,6 @@ import java.util.Iterator;
|
||||
* All comparisons are case sensitive.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class DenyAgainVoter implements AccessDecisionVoter {
|
||||
// ~ Methods
|
||||
|
||||
@@ -29,7 +29,6 @@ import java.util.Iterator;
|
||||
* <p>All comparisons are case sensitive.</p>
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class DenyVoter implements AccessDecisionVoter {
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
@@ -32,7 +32,6 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* @author Greg Turnquist
|
||||
* @version $Id$
|
||||
*/
|
||||
@ContextConfiguration(locations={"/org/springframework/security/vote/labelBasedSecurityApplicationContext.xml"})
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
|
||||
@@ -11,7 +11,6 @@ import org.springframework.security.core.Authentication;
|
||||
/**
|
||||
*
|
||||
* @author Luke Taylor
|
||||
* @version $Id$
|
||||
*/
|
||||
public class RoleVoterTests {
|
||||
@Test
|
||||
|
||||
@@ -24,7 +24,6 @@ import java.io.Serializable;
|
||||
* For label unit tests.
|
||||
*
|
||||
* @author Greg Turnquist
|
||||
* @version $Id$
|
||||
*/
|
||||
public class SampleBlockOfData implements Serializable, LabeledData {
|
||||
//~ Static fields/initializers =====================================================================================
|
||||
|
||||
@@ -20,7 +20,6 @@ import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Greg Turnquist
|
||||
* @version $Id$
|
||||
*/
|
||||
public interface SampleService {
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
@@ -22,7 +22,6 @@ import java.util.Vector;
|
||||
* For label unit tests.
|
||||
*
|
||||
* @author Greg Turnquist
|
||||
* @version $Id$
|
||||
*/
|
||||
public class SampleServiceImpl implements SampleService {
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
@@ -19,7 +19,6 @@ package org.springframework.security.access.vote;
|
||||
* Simple domain object, used by {@link BasicAclEntryVoterTests}.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class SomeDomainObject {
|
||||
//~ Instance fields ================================================================================================
|
||||
|
||||
@@ -20,7 +20,6 @@ package org.springframework.security.access.vote;
|
||||
* <code>SomeDomainObject</code>.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class SomeDomainObjectManager {
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
@@ -33,7 +33,6 @@ import org.springframework.security.authentication.TestingAuthenticationToken;
|
||||
* Tests {@link UnanimousBased}.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class UnanimousBasedTests extends TestCase {
|
||||
|
||||
|
||||
@@ -30,7 +30,6 @@ import org.springframework.security.core.authority.GrantedAuthorityImpl;
|
||||
* Tests {@link AbstractAuthenticationToken}.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class AbstractAuthenticationTokenTests {
|
||||
//~ Instance fields ================================================================================================
|
||||
|
||||
@@ -10,7 +10,6 @@ import org.springframework.security.authentication.TestingAuthenticationToken;
|
||||
/**
|
||||
*
|
||||
* @author Luke Taylor
|
||||
* @version $Id$
|
||||
*/
|
||||
public class AuthenticationDetailsSourceImplTests {
|
||||
|
||||
|
||||
@@ -28,7 +28,6 @@ import org.springframework.security.core.authority.AuthorityUtils;
|
||||
* Tests {@link org.springframework.security.authentication.AuthenticationTrustResolverImpl}.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class AuthenticationTrustResolverImplTests extends TestCase {
|
||||
|
||||
|
||||
@@ -34,7 +34,6 @@ import org.springframework.security.core.authority.AuthorityUtils;
|
||||
* Tests {@link ProviderManager}.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public class ProviderManagerTests {
|
||||
|
||||
@@ -26,7 +26,6 @@ import org.springframework.security.core.authority.AuthorityUtils;
|
||||
* Tests {@link TestingAuthenticationProvider}.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class TestingAuthenticationProviderTests extends TestCase {
|
||||
|
||||
|
||||
@@ -28,7 +28,6 @@ import org.springframework.security.core.authority.AuthorityUtils;
|
||||
* Tests {@link UsernamePasswordAuthenticationToken}.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class UsernamePasswordAuthenticationTokenTests {
|
||||
|
||||
|
||||
@@ -32,7 +32,6 @@ import org.springframework.security.core.authority.GrantedAuthorityImpl;
|
||||
* Tests {@link AnonymousAuthenticationProvider}.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class AnonymousAuthenticationProviderTests extends TestCase {
|
||||
|
||||
|
||||
@@ -29,7 +29,6 @@ import org.springframework.security.core.authority.AuthorityUtils;
|
||||
* Tests {@link AnonymousAuthenticationToken}.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class AnonymousAuthenticationTokenTests extends TestCase {
|
||||
|
||||
|
||||
@@ -45,7 +45,6 @@ import org.springframework.security.core.userdetails.cache.NullUserCache;
|
||||
* Tests {@link DaoAuthenticationProvider}.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class DaoAuthenticationProviderTests extends TestCase {
|
||||
private static final List<GrantedAuthority> ROLES_12 = AuthorityUtils.createAuthorityList("ROLE_ONE", "ROLE_TWO");
|
||||
|
||||
@@ -28,7 +28,6 @@ import org.springframework.security.core.userdetails.UserDetails;
|
||||
* Tests {@link ReflectionSaltSource}.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class ReflectionSaltSourceTests {
|
||||
private UserDetails user = new User("scott", "wombat", true, true, true, true,
|
||||
|
||||
@@ -24,7 +24,6 @@ import junit.framework.TestCase;
|
||||
* Tests {@link SystemWideSaltSource}.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class SystemWideSaltSourceTests extends TestCase {
|
||||
//~ Constructors ===================================================================================================
|
||||
|
||||
@@ -25,7 +25,6 @@ import org.springframework.security.authentication.encoding.BasePasswordEncoder;
|
||||
* <p>TestCase for BasePasswordEncoder.</p>
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class BasePasswordEncoderTests extends TestCase {
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
@@ -1,73 +1,73 @@
|
||||
/* Copyright 2004, 2005, 2006, 2007 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.authentication.encoding;
|
||||
|
||||
import org.springframework.security.authentication.encoding.Md4PasswordEncoder;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class Md4PasswordEncoderTests extends TestCase {
|
||||
|
||||
public void testEncodeUnsaltedPassword() {
|
||||
Md4PasswordEncoder md4 = new Md4PasswordEncoder();
|
||||
md4.setEncodeHashAsBase64(true);
|
||||
String encodedPassword = md4.encodePassword("ww_uni123", null);
|
||||
assertEquals("8zobtq72iAt0W6KNqavGwg==", encodedPassword);
|
||||
}
|
||||
|
||||
public void testEncodeSaltedPassword() {
|
||||
Md4PasswordEncoder md4 = new Md4PasswordEncoder();
|
||||
md4.setEncodeHashAsBase64(true);
|
||||
String encodedPassword = md4.encodePassword("ww_uni123", "Alan K Stewart");
|
||||
assertEquals("ZplT6P5Kv6Rlu6W4FIoYNA==", encodedPassword);
|
||||
}
|
||||
|
||||
public void testEncodeNullPassword() {
|
||||
Md4PasswordEncoder md4 = new Md4PasswordEncoder();
|
||||
md4.setEncodeHashAsBase64(true);
|
||||
String encodedPassword = md4.encodePassword(null, null);
|
||||
assertEquals("MdbP4NFq6TG3PFnX4MCJwA==", encodedPassword);
|
||||
}
|
||||
|
||||
public void testEncodeEmptyPassword() {
|
||||
Md4PasswordEncoder md4 = new Md4PasswordEncoder();
|
||||
md4.setEncodeHashAsBase64(true);
|
||||
String encodedPassword = md4.encodePassword("", null);
|
||||
assertEquals("MdbP4NFq6TG3PFnX4MCJwA==", encodedPassword);
|
||||
}
|
||||
|
||||
public void testNonAsciiPasswordHasCorrectHash() {
|
||||
Md4PasswordEncoder md4 = new Md4PasswordEncoder();
|
||||
String encodedPassword = md4.encodePassword("\u4F60\u597d", null);
|
||||
assertEquals("a7f1196539fd1f85f754ffd185b16e6e", encodedPassword);
|
||||
}
|
||||
|
||||
public void testIsHexPasswordValid() {
|
||||
Md4PasswordEncoder md4 = new Md4PasswordEncoder();
|
||||
assertTrue(md4.isPasswordValid("31d6cfe0d16ae931b73c59d7e0c089c0", "", null));
|
||||
}
|
||||
|
||||
public void testIsPasswordValid() {
|
||||
Md4PasswordEncoder md4 = new Md4PasswordEncoder();
|
||||
md4.setEncodeHashAsBase64(true);
|
||||
assertTrue(md4.isPasswordValid("8zobtq72iAt0W6KNqavGwg==", "ww_uni123", null));
|
||||
}
|
||||
|
||||
public void testIsSaltedPasswordValid() {
|
||||
Md4PasswordEncoder md4 = new Md4PasswordEncoder();
|
||||
md4.setEncodeHashAsBase64(true);
|
||||
assertTrue(md4.isPasswordValid("ZplT6P5Kv6Rlu6W4FIoYNA==", "ww_uni123", "Alan K Stewart"));
|
||||
}
|
||||
}
|
||||
/* Copyright 2004, 2005, 2006, 2007 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.authentication.encoding;
|
||||
|
||||
import org.springframework.security.authentication.encoding.Md4PasswordEncoder;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class Md4PasswordEncoderTests extends TestCase {
|
||||
|
||||
public void testEncodeUnsaltedPassword() {
|
||||
Md4PasswordEncoder md4 = new Md4PasswordEncoder();
|
||||
md4.setEncodeHashAsBase64(true);
|
||||
String encodedPassword = md4.encodePassword("ww_uni123", null);
|
||||
assertEquals("8zobtq72iAt0W6KNqavGwg==", encodedPassword);
|
||||
}
|
||||
|
||||
public void testEncodeSaltedPassword() {
|
||||
Md4PasswordEncoder md4 = new Md4PasswordEncoder();
|
||||
md4.setEncodeHashAsBase64(true);
|
||||
String encodedPassword = md4.encodePassword("ww_uni123", "Alan K Stewart");
|
||||
assertEquals("ZplT6P5Kv6Rlu6W4FIoYNA==", encodedPassword);
|
||||
}
|
||||
|
||||
public void testEncodeNullPassword() {
|
||||
Md4PasswordEncoder md4 = new Md4PasswordEncoder();
|
||||
md4.setEncodeHashAsBase64(true);
|
||||
String encodedPassword = md4.encodePassword(null, null);
|
||||
assertEquals("MdbP4NFq6TG3PFnX4MCJwA==", encodedPassword);
|
||||
}
|
||||
|
||||
public void testEncodeEmptyPassword() {
|
||||
Md4PasswordEncoder md4 = new Md4PasswordEncoder();
|
||||
md4.setEncodeHashAsBase64(true);
|
||||
String encodedPassword = md4.encodePassword("", null);
|
||||
assertEquals("MdbP4NFq6TG3PFnX4MCJwA==", encodedPassword);
|
||||
}
|
||||
|
||||
public void testNonAsciiPasswordHasCorrectHash() {
|
||||
Md4PasswordEncoder md4 = new Md4PasswordEncoder();
|
||||
String encodedPassword = md4.encodePassword("\u4F60\u597d", null);
|
||||
assertEquals("a7f1196539fd1f85f754ffd185b16e6e", encodedPassword);
|
||||
}
|
||||
|
||||
public void testIsHexPasswordValid() {
|
||||
Md4PasswordEncoder md4 = new Md4PasswordEncoder();
|
||||
assertTrue(md4.isPasswordValid("31d6cfe0d16ae931b73c59d7e0c089c0", "", null));
|
||||
}
|
||||
|
||||
public void testIsPasswordValid() {
|
||||
Md4PasswordEncoder md4 = new Md4PasswordEncoder();
|
||||
md4.setEncodeHashAsBase64(true);
|
||||
assertTrue(md4.isPasswordValid("8zobtq72iAt0W6KNqavGwg==", "ww_uni123", null));
|
||||
}
|
||||
|
||||
public void testIsSaltedPasswordValid() {
|
||||
Md4PasswordEncoder md4 = new Md4PasswordEncoder();
|
||||
md4.setEncodeHashAsBase64(true);
|
||||
assertTrue(md4.isPasswordValid("ZplT6P5Kv6Rlu6W4FIoYNA==", "ww_uni123", "Alan K Stewart"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,6 @@ import junit.framework.TestCase;
|
||||
* @author colin sampaleanu
|
||||
* @author Ben Alex
|
||||
* @author Ray Krueger
|
||||
* @version $Id$
|
||||
*/
|
||||
public class Md5PasswordEncoderTests extends TestCase {
|
||||
//~ Methods ========================================================================================================
|
||||
@@ -42,12 +41,12 @@ public class Md5PasswordEncoderTests extends TestCase {
|
||||
assertEquals("a68aafd90299d0b137de28fb4bb68573", encoded);
|
||||
assertEquals("MD5", pe.getAlgorithm());
|
||||
}
|
||||
|
||||
|
||||
public void testNonAsciiPasswordHasCorrectHash() {
|
||||
Md5PasswordEncoder md5 = new Md5PasswordEncoder();
|
||||
String encodedPassword = md5.encodePassword("\u4F60\u597d", null);
|
||||
assertEquals("7eca689f0d3389d9dea66ae112e5cfd7", encodedPassword);
|
||||
}
|
||||
assertEquals("7eca689f0d3389d9dea66ae112e5cfd7", encodedPassword);
|
||||
}
|
||||
|
||||
public void testBase64() throws Exception {
|
||||
Md5PasswordEncoder pe = new Md5PasswordEncoder();
|
||||
|
||||
@@ -25,7 +25,6 @@ import junit.framework.TestCase;
|
||||
*
|
||||
* @author colin sampaleanu
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class PlaintextPasswordEncoderTests extends TestCase {
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
@@ -26,7 +26,6 @@ import junit.framework.TestCase;
|
||||
* @author colin sampaleanu
|
||||
* @author Ben Alex
|
||||
* @author Ray Krueger
|
||||
* @version $Id$
|
||||
*/
|
||||
public class ShaPasswordEncoderTests extends TestCase {
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
@@ -32,7 +32,6 @@ import org.springframework.security.core.AuthenticationException;
|
||||
* Tests {@link AbstractAuthenticationEvent} and its subclasses.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class AuthenticationEventTests extends TestCase {
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
@@ -29,7 +29,6 @@ import org.springframework.security.core.Authentication;
|
||||
* Tests {@link LoggerListener}.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class LoggerListenerTests extends TestCase {
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
@@ -50,7 +50,6 @@ import org.springframework.security.core.session.SessionDestroyedEvent;
|
||||
* Tests for the JaasAuthenticationProvider
|
||||
*
|
||||
* @author Ray Krueger
|
||||
* @version $Id$
|
||||
*/
|
||||
public class JaasAuthenticationProviderTests {
|
||||
//~ Instance fields ================================================================================================
|
||||
|
||||
@@ -23,7 +23,6 @@ import org.springframework.security.authentication.jaas.event.JaasAuthentication
|
||||
|
||||
/**
|
||||
* @author Ray Krueger
|
||||
* @version $Id$
|
||||
*/
|
||||
public class JaasEventCheck implements ApplicationListener<JaasAuthenticationEvent> {
|
||||
//~ Instance fields ================================================================================================
|
||||
|
||||
@@ -26,7 +26,6 @@ import org.springframework.security.authentication.jaas.AuthorityGranter;
|
||||
/**
|
||||
*
|
||||
* @author Ray Krueger
|
||||
* @version $Id$
|
||||
*/
|
||||
public class TestAuthorityGranter implements AuthorityGranter {
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
@@ -29,7 +29,6 @@ import javax.security.auth.callback.UnsupportedCallbackException;
|
||||
* TestCallbackHandler
|
||||
*
|
||||
* @author Ray Krueger
|
||||
* @version $Id$
|
||||
*/
|
||||
public class TestCallbackHandler implements JaasAuthenticationCallbackHandler {
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
@@ -27,7 +27,6 @@ import javax.security.auth.spi.LoginModule;
|
||||
|
||||
/**
|
||||
* @author Ray Krueger
|
||||
* @version $Id$
|
||||
*/
|
||||
public class TestLoginModule implements LoginModule {
|
||||
//~ Instance fields ================================================================================================
|
||||
|
||||
@@ -26,7 +26,6 @@ import org.springframework.security.authentication.rcp.RemoteAuthenticationManag
|
||||
* Tests {@link RemoteAuthenticationManagerImpl}.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class RemoteAuthenticationManagerImplTests extends TestCase {
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
@@ -29,7 +29,6 @@ import org.springframework.security.core.authority.AuthorityUtils;
|
||||
* Tests {@link RemoteAuthenticationProvider}.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class RemoteAuthenticationProviderTests extends TestCase {
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
@@ -29,7 +29,6 @@ import org.springframework.security.core.authority.AuthorityUtils;
|
||||
* Tests {@link RememberMeAuthenticationProvider}.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class RememberMeAuthenticationProviderTests extends TestCase {
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
@@ -29,7 +29,6 @@ import org.springframework.security.core.authority.AuthorityUtils;
|
||||
* Tests {@link RememberMeAuthenticationToken}.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class RememberMeAuthenticationTokenTests extends TestCase {
|
||||
private static final List<GrantedAuthority> ROLES_12 = AuthorityUtils.createAuthorityList("ROLE_ONE", "ROLE_TWO");
|
||||
|
||||
@@ -11,7 +11,6 @@ import org.springframework.security.core.authority.AuthorityUtils;
|
||||
|
||||
/**
|
||||
* @author Luke Taylor
|
||||
* @version $Id$
|
||||
*/
|
||||
public class AuthorityUtilsTests {
|
||||
|
||||
|
||||
@@ -26,7 +26,6 @@ import org.springframework.security.core.authority.GrantedAuthorityImpl;
|
||||
* Tests {@link GrantedAuthorityImpl}.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class GrantedAuthorityImplTests {
|
||||
|
||||
|
||||
@@ -1,210 +1,210 @@
|
||||
package org.springframework.security.core.authority.mapping;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.authority.GrantedAuthorityImpl;
|
||||
import org.springframework.security.core.authority.mapping.Attributes2GrantedAuthoritiesMapper;
|
||||
import org.springframework.security.core.authority.mapping.MapBasedAttributes2GrantedAuthoritiesMapper;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Ruud Senden
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public class MapBasedAttributes2GrantedAuthoritiesMapperTest {
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testAfterPropertiesSetNoMap() throws Exception {
|
||||
MapBasedAttributes2GrantedAuthoritiesMapper mapper = new MapBasedAttributes2GrantedAuthoritiesMapper();
|
||||
mapper.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testAfterPropertiesSetEmptyMap() throws Exception {
|
||||
MapBasedAttributes2GrantedAuthoritiesMapper mapper = new MapBasedAttributes2GrantedAuthoritiesMapper();
|
||||
mapper.setAttributes2grantedAuthoritiesMap(new HashMap());
|
||||
mapper.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testAfterPropertiesSetInvalidKeyTypeMap() throws Exception {
|
||||
MapBasedAttributes2GrantedAuthoritiesMapper mapper = new MapBasedAttributes2GrantedAuthoritiesMapper();
|
||||
HashMap m = new HashMap();
|
||||
m.put(new Object(),"ga1");
|
||||
mapper.setAttributes2grantedAuthoritiesMap(m);
|
||||
mapper.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testAfterPropertiesSetInvalidValueTypeMap1() throws Exception {
|
||||
MapBasedAttributes2GrantedAuthoritiesMapper mapper = new MapBasedAttributes2GrantedAuthoritiesMapper();
|
||||
HashMap m = new HashMap();
|
||||
m.put("role1",new Object());
|
||||
mapper.setAttributes2grantedAuthoritiesMap(m);
|
||||
mapper.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testAfterPropertiesSetInvalidValueTypeMap2() throws Exception {
|
||||
MapBasedAttributes2GrantedAuthoritiesMapper mapper = new MapBasedAttributes2GrantedAuthoritiesMapper();
|
||||
HashMap m = new HashMap();
|
||||
m.put("role1",new Object[]{new String[]{"ga1","ga2"}, new Object()});
|
||||
mapper.setAttributes2grantedAuthoritiesMap(m);
|
||||
mapper.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAfterPropertiesSetValidMap() throws Exception {
|
||||
MapBasedAttributes2GrantedAuthoritiesMapper mapper = new MapBasedAttributes2GrantedAuthoritiesMapper();
|
||||
HashMap m = getValidAttributes2GrantedAuthoritiesMap();
|
||||
mapper.setAttributes2grantedAuthoritiesMap(m);
|
||||
mapper.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapping1() throws Exception {
|
||||
String[] roles = { "role1" };
|
||||
String[] expectedGas = { "ga1" };
|
||||
Attributes2GrantedAuthoritiesMapper mapper = getDefaultMapper();
|
||||
testGetGrantedAuthorities(mapper, roles, expectedGas);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapping2() throws Exception {
|
||||
String[] roles = { "role2" };
|
||||
String[] expectedGas = { "ga2" };
|
||||
Attributes2GrantedAuthoritiesMapper mapper = getDefaultMapper();
|
||||
testGetGrantedAuthorities(mapper, roles, expectedGas);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapping3() throws Exception {
|
||||
String[] roles = { "role3" };
|
||||
String[] expectedGas = { "ga3", "ga4" };
|
||||
Attributes2GrantedAuthoritiesMapper mapper = getDefaultMapper();
|
||||
testGetGrantedAuthorities(mapper, roles, expectedGas);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapping4() throws Exception {
|
||||
String[] roles = { "role4" };
|
||||
String[] expectedGas = { "ga5", "ga6" };
|
||||
Attributes2GrantedAuthoritiesMapper mapper = getDefaultMapper();
|
||||
testGetGrantedAuthorities(mapper, roles, expectedGas);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapping5() throws Exception {
|
||||
String[] roles = { "role5" };
|
||||
String[] expectedGas = { "ga7", "ga8", "ga9" };
|
||||
Attributes2GrantedAuthoritiesMapper mapper = getDefaultMapper();
|
||||
testGetGrantedAuthorities(mapper, roles, expectedGas);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapping6() throws Exception {
|
||||
String[] roles = { "role6" };
|
||||
String[] expectedGas = { "ga10", "ga11", "ga12" };
|
||||
Attributes2GrantedAuthoritiesMapper mapper = getDefaultMapper();
|
||||
testGetGrantedAuthorities(mapper, roles, expectedGas);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapping7() throws Exception {
|
||||
String[] roles = { "role7" };
|
||||
String[] expectedGas = { "ga13", "ga14" };
|
||||
Attributes2GrantedAuthoritiesMapper mapper = getDefaultMapper();
|
||||
testGetGrantedAuthorities(mapper, roles, expectedGas);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapping8() throws Exception {
|
||||
String[] roles = { "role8" };
|
||||
String[] expectedGas = { "ga13", "ga14" };
|
||||
Attributes2GrantedAuthoritiesMapper mapper = getDefaultMapper();
|
||||
testGetGrantedAuthorities(mapper, roles, expectedGas);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapping9() throws Exception {
|
||||
String[] roles = { "role9" };
|
||||
String[] expectedGas = {};
|
||||
Attributes2GrantedAuthoritiesMapper mapper = getDefaultMapper();
|
||||
testGetGrantedAuthorities(mapper, roles, expectedGas);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapping10() throws Exception {
|
||||
String[] roles = { "role10" };
|
||||
String[] expectedGas = {};
|
||||
Attributes2GrantedAuthoritiesMapper mapper = getDefaultMapper();
|
||||
testGetGrantedAuthorities(mapper, roles, expectedGas);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapping11() throws Exception {
|
||||
String[] roles = { "role11" };
|
||||
String[] expectedGas = {};
|
||||
Attributes2GrantedAuthoritiesMapper mapper = getDefaultMapper();
|
||||
testGetGrantedAuthorities(mapper, roles, expectedGas);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonExistingMapping() throws Exception {
|
||||
String[] roles = { "nonExisting" };
|
||||
String[] expectedGas = {};
|
||||
Attributes2GrantedAuthoritiesMapper mapper = getDefaultMapper();
|
||||
testGetGrantedAuthorities(mapper, roles, expectedGas);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMappingCombination() throws Exception {
|
||||
String[] roles = { "role1", "role2", "role3", "role4", "role5", "role6", "role7", "role8", "role9", "role10", "role11" };
|
||||
String[] expectedGas = { "ga1", "ga2", "ga3", "ga4", "ga5", "ga6", "ga7", "ga8", "ga9", "ga10", "ga11", "ga12", "ga13", "ga14"};
|
||||
Attributes2GrantedAuthoritiesMapper mapper = getDefaultMapper();
|
||||
testGetGrantedAuthorities(mapper, roles, expectedGas);
|
||||
}
|
||||
|
||||
private HashMap getValidAttributes2GrantedAuthoritiesMap() {
|
||||
HashMap m = new HashMap();
|
||||
m.put("role1","ga1");
|
||||
m.put("role2",new GrantedAuthorityImpl("ga2"));
|
||||
m.put("role3",Arrays.asList(new Object[]{"ga3",new GrantedAuthorityImpl("ga4")}));
|
||||
m.put("role4","ga5,ga6");
|
||||
m.put("role5",Arrays.asList(new Object[]{"ga7","ga8",new Object[]{new GrantedAuthorityImpl("ga9")}}));
|
||||
m.put("role6",new Object[]{"ga10","ga11",new Object[]{new GrantedAuthorityImpl("ga12")}});
|
||||
m.put("role7",new String[]{"ga13","ga14"});
|
||||
m.put("role8",new String[]{"ga13","ga14",null});
|
||||
m.put("role9",null);
|
||||
m.put("role10",new Object[]{});
|
||||
m.put("role11",Arrays.asList(new Object[]{null}));
|
||||
return m;
|
||||
}
|
||||
|
||||
private MapBasedAttributes2GrantedAuthoritiesMapper getDefaultMapper() throws Exception {
|
||||
MapBasedAttributes2GrantedAuthoritiesMapper mapper = new MapBasedAttributes2GrantedAuthoritiesMapper();
|
||||
mapper.setAttributes2grantedAuthoritiesMap(getValidAttributes2GrantedAuthoritiesMap());
|
||||
mapper.afterPropertiesSet();
|
||||
return mapper;
|
||||
}
|
||||
|
||||
private void testGetGrantedAuthorities(Attributes2GrantedAuthoritiesMapper mapper, String[] roles, String[] expectedGas) {
|
||||
List<GrantedAuthority> result = mapper.getGrantedAuthorities(Arrays.asList(roles));
|
||||
Collection resultColl = new ArrayList(result.size());
|
||||
for (int i = 0; i < result.size(); i++) {
|
||||
resultColl.add(result.get(i).getAuthority());
|
||||
}
|
||||
Collection expectedColl = Arrays.asList(expectedGas);
|
||||
assertTrue("Role collections should match; result: " + resultColl + ", expected: " + expectedColl, expectedColl
|
||||
.containsAll(resultColl)
|
||||
&& resultColl.containsAll(expectedColl));
|
||||
}
|
||||
}
|
||||
package org.springframework.security.core.authority.mapping;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.authority.GrantedAuthorityImpl;
|
||||
import org.springframework.security.core.authority.mapping.Attributes2GrantedAuthoritiesMapper;
|
||||
import org.springframework.security.core.authority.mapping.MapBasedAttributes2GrantedAuthoritiesMapper;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Ruud Senden
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public class MapBasedAttributes2GrantedAuthoritiesMapperTest {
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testAfterPropertiesSetNoMap() throws Exception {
|
||||
MapBasedAttributes2GrantedAuthoritiesMapper mapper = new MapBasedAttributes2GrantedAuthoritiesMapper();
|
||||
mapper.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testAfterPropertiesSetEmptyMap() throws Exception {
|
||||
MapBasedAttributes2GrantedAuthoritiesMapper mapper = new MapBasedAttributes2GrantedAuthoritiesMapper();
|
||||
mapper.setAttributes2grantedAuthoritiesMap(new HashMap());
|
||||
mapper.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testAfterPropertiesSetInvalidKeyTypeMap() throws Exception {
|
||||
MapBasedAttributes2GrantedAuthoritiesMapper mapper = new MapBasedAttributes2GrantedAuthoritiesMapper();
|
||||
HashMap m = new HashMap();
|
||||
m.put(new Object(),"ga1");
|
||||
mapper.setAttributes2grantedAuthoritiesMap(m);
|
||||
mapper.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testAfterPropertiesSetInvalidValueTypeMap1() throws Exception {
|
||||
MapBasedAttributes2GrantedAuthoritiesMapper mapper = new MapBasedAttributes2GrantedAuthoritiesMapper();
|
||||
HashMap m = new HashMap();
|
||||
m.put("role1",new Object());
|
||||
mapper.setAttributes2grantedAuthoritiesMap(m);
|
||||
mapper.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testAfterPropertiesSetInvalidValueTypeMap2() throws Exception {
|
||||
MapBasedAttributes2GrantedAuthoritiesMapper mapper = new MapBasedAttributes2GrantedAuthoritiesMapper();
|
||||
HashMap m = new HashMap();
|
||||
m.put("role1",new Object[]{new String[]{"ga1","ga2"}, new Object()});
|
||||
mapper.setAttributes2grantedAuthoritiesMap(m);
|
||||
mapper.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAfterPropertiesSetValidMap() throws Exception {
|
||||
MapBasedAttributes2GrantedAuthoritiesMapper mapper = new MapBasedAttributes2GrantedAuthoritiesMapper();
|
||||
HashMap m = getValidAttributes2GrantedAuthoritiesMap();
|
||||
mapper.setAttributes2grantedAuthoritiesMap(m);
|
||||
mapper.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapping1() throws Exception {
|
||||
String[] roles = { "role1" };
|
||||
String[] expectedGas = { "ga1" };
|
||||
Attributes2GrantedAuthoritiesMapper mapper = getDefaultMapper();
|
||||
testGetGrantedAuthorities(mapper, roles, expectedGas);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapping2() throws Exception {
|
||||
String[] roles = { "role2" };
|
||||
String[] expectedGas = { "ga2" };
|
||||
Attributes2GrantedAuthoritiesMapper mapper = getDefaultMapper();
|
||||
testGetGrantedAuthorities(mapper, roles, expectedGas);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapping3() throws Exception {
|
||||
String[] roles = { "role3" };
|
||||
String[] expectedGas = { "ga3", "ga4" };
|
||||
Attributes2GrantedAuthoritiesMapper mapper = getDefaultMapper();
|
||||
testGetGrantedAuthorities(mapper, roles, expectedGas);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapping4() throws Exception {
|
||||
String[] roles = { "role4" };
|
||||
String[] expectedGas = { "ga5", "ga6" };
|
||||
Attributes2GrantedAuthoritiesMapper mapper = getDefaultMapper();
|
||||
testGetGrantedAuthorities(mapper, roles, expectedGas);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapping5() throws Exception {
|
||||
String[] roles = { "role5" };
|
||||
String[] expectedGas = { "ga7", "ga8", "ga9" };
|
||||
Attributes2GrantedAuthoritiesMapper mapper = getDefaultMapper();
|
||||
testGetGrantedAuthorities(mapper, roles, expectedGas);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapping6() throws Exception {
|
||||
String[] roles = { "role6" };
|
||||
String[] expectedGas = { "ga10", "ga11", "ga12" };
|
||||
Attributes2GrantedAuthoritiesMapper mapper = getDefaultMapper();
|
||||
testGetGrantedAuthorities(mapper, roles, expectedGas);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapping7() throws Exception {
|
||||
String[] roles = { "role7" };
|
||||
String[] expectedGas = { "ga13", "ga14" };
|
||||
Attributes2GrantedAuthoritiesMapper mapper = getDefaultMapper();
|
||||
testGetGrantedAuthorities(mapper, roles, expectedGas);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapping8() throws Exception {
|
||||
String[] roles = { "role8" };
|
||||
String[] expectedGas = { "ga13", "ga14" };
|
||||
Attributes2GrantedAuthoritiesMapper mapper = getDefaultMapper();
|
||||
testGetGrantedAuthorities(mapper, roles, expectedGas);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapping9() throws Exception {
|
||||
String[] roles = { "role9" };
|
||||
String[] expectedGas = {};
|
||||
Attributes2GrantedAuthoritiesMapper mapper = getDefaultMapper();
|
||||
testGetGrantedAuthorities(mapper, roles, expectedGas);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapping10() throws Exception {
|
||||
String[] roles = { "role10" };
|
||||
String[] expectedGas = {};
|
||||
Attributes2GrantedAuthoritiesMapper mapper = getDefaultMapper();
|
||||
testGetGrantedAuthorities(mapper, roles, expectedGas);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapping11() throws Exception {
|
||||
String[] roles = { "role11" };
|
||||
String[] expectedGas = {};
|
||||
Attributes2GrantedAuthoritiesMapper mapper = getDefaultMapper();
|
||||
testGetGrantedAuthorities(mapper, roles, expectedGas);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonExistingMapping() throws Exception {
|
||||
String[] roles = { "nonExisting" };
|
||||
String[] expectedGas = {};
|
||||
Attributes2GrantedAuthoritiesMapper mapper = getDefaultMapper();
|
||||
testGetGrantedAuthorities(mapper, roles, expectedGas);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMappingCombination() throws Exception {
|
||||
String[] roles = { "role1", "role2", "role3", "role4", "role5", "role6", "role7", "role8", "role9", "role10", "role11" };
|
||||
String[] expectedGas = { "ga1", "ga2", "ga3", "ga4", "ga5", "ga6", "ga7", "ga8", "ga9", "ga10", "ga11", "ga12", "ga13", "ga14"};
|
||||
Attributes2GrantedAuthoritiesMapper mapper = getDefaultMapper();
|
||||
testGetGrantedAuthorities(mapper, roles, expectedGas);
|
||||
}
|
||||
|
||||
private HashMap getValidAttributes2GrantedAuthoritiesMap() {
|
||||
HashMap m = new HashMap();
|
||||
m.put("role1","ga1");
|
||||
m.put("role2",new GrantedAuthorityImpl("ga2"));
|
||||
m.put("role3",Arrays.asList(new Object[]{"ga3",new GrantedAuthorityImpl("ga4")}));
|
||||
m.put("role4","ga5,ga6");
|
||||
m.put("role5",Arrays.asList(new Object[]{"ga7","ga8",new Object[]{new GrantedAuthorityImpl("ga9")}}));
|
||||
m.put("role6",new Object[]{"ga10","ga11",new Object[]{new GrantedAuthorityImpl("ga12")}});
|
||||
m.put("role7",new String[]{"ga13","ga14"});
|
||||
m.put("role8",new String[]{"ga13","ga14",null});
|
||||
m.put("role9",null);
|
||||
m.put("role10",new Object[]{});
|
||||
m.put("role11",Arrays.asList(new Object[]{null}));
|
||||
return m;
|
||||
}
|
||||
|
||||
private MapBasedAttributes2GrantedAuthoritiesMapper getDefaultMapper() throws Exception {
|
||||
MapBasedAttributes2GrantedAuthoritiesMapper mapper = new MapBasedAttributes2GrantedAuthoritiesMapper();
|
||||
mapper.setAttributes2grantedAuthoritiesMap(getValidAttributes2GrantedAuthoritiesMap());
|
||||
mapper.afterPropertiesSet();
|
||||
return mapper;
|
||||
}
|
||||
|
||||
private void testGetGrantedAuthorities(Attributes2GrantedAuthoritiesMapper mapper, String[] roles, String[] expectedGas) {
|
||||
List<GrantedAuthority> result = mapper.getGrantedAuthorities(Arrays.asList(roles));
|
||||
Collection resultColl = new ArrayList(result.size());
|
||||
for (int i = 0; i < result.size(); i++) {
|
||||
resultColl.add(result.get(i).getAuthority());
|
||||
}
|
||||
Collection expectedColl = Arrays.asList(expectedGas);
|
||||
assertTrue("Role collections should match; result: " + resultColl + ", expected: " + expectedColl, expectedColl
|
||||
.containsAll(resultColl)
|
||||
&& resultColl.containsAll(expectedColl));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,123 +1,123 @@
|
||||
package org.springframework.security.core.authority.mapping;
|
||||
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.authority.mapping.SimpleAttributes2GrantedAuthoritiesMapper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author TSARDD
|
||||
* @since 18-okt-2007
|
||||
*/
|
||||
public class SimpleRoles2GrantedAuthoritiesMapperTests extends TestCase {
|
||||
|
||||
public final void testAfterPropertiesSetConvertToUpperAndLowerCase() {
|
||||
SimpleAttributes2GrantedAuthoritiesMapper mapper = new SimpleAttributes2GrantedAuthoritiesMapper();
|
||||
mapper.setConvertAttributeToLowerCase(true);
|
||||
mapper.setConvertAttributeToUpperCase(true);
|
||||
try {
|
||||
mapper.afterPropertiesSet();
|
||||
fail("Expected exception not thrown");
|
||||
} catch (IllegalArgumentException expected) {
|
||||
} catch (Exception unexpected) {
|
||||
fail("Unexpected exception: " + unexpected);
|
||||
}
|
||||
}
|
||||
|
||||
public final void testAfterPropertiesSet() {
|
||||
SimpleAttributes2GrantedAuthoritiesMapper mapper = new SimpleAttributes2GrantedAuthoritiesMapper();
|
||||
try {
|
||||
mapper.afterPropertiesSet();
|
||||
} catch (Exception unexpected) {
|
||||
fail("Unexpected exception: " + unexpected);
|
||||
}
|
||||
}
|
||||
|
||||
public final void testGetGrantedAuthoritiesNoConversion() {
|
||||
String[] roles = { "Role1", "Role2" };
|
||||
String[] expectedGas = { "Role1", "Role2" };
|
||||
SimpleAttributes2GrantedAuthoritiesMapper mapper = getDefaultMapper();
|
||||
testGetGrantedAuthorities(mapper, roles, expectedGas);
|
||||
}
|
||||
|
||||
public final void testGetGrantedAuthoritiesToUpperCase() {
|
||||
String[] roles = { "Role1", "Role2" };
|
||||
String[] expectedGas = { "ROLE1", "ROLE2" };
|
||||
SimpleAttributes2GrantedAuthoritiesMapper mapper = getDefaultMapper();
|
||||
mapper.setConvertAttributeToUpperCase(true);
|
||||
testGetGrantedAuthorities(mapper, roles, expectedGas);
|
||||
}
|
||||
|
||||
public final void testGetGrantedAuthoritiesToLowerCase() {
|
||||
String[] roles = { "Role1", "Role2" };
|
||||
String[] expectedGas = { "role1", "role2" };
|
||||
SimpleAttributes2GrantedAuthoritiesMapper mapper = getDefaultMapper();
|
||||
mapper.setConvertAttributeToLowerCase(true);
|
||||
testGetGrantedAuthorities(mapper, roles, expectedGas);
|
||||
}
|
||||
|
||||
public final void testGetGrantedAuthoritiesAddPrefixIfAlreadyExisting() {
|
||||
String[] roles = { "Role1", "Role2", "ROLE_Role3" };
|
||||
String[] expectedGas = { "ROLE_Role1", "ROLE_Role2", "ROLE_ROLE_Role3" };
|
||||
SimpleAttributes2GrantedAuthoritiesMapper mapper = getDefaultMapper();
|
||||
mapper.setAddPrefixIfAlreadyExisting(true);
|
||||
mapper.setAttributePrefix("ROLE_");
|
||||
testGetGrantedAuthorities(mapper, roles, expectedGas);
|
||||
}
|
||||
|
||||
public final void testGetGrantedAuthoritiesDontAddPrefixIfAlreadyExisting1() {
|
||||
String[] roles = { "Role1", "Role2", "ROLE_Role3" };
|
||||
String[] expectedGas = { "ROLE_Role1", "ROLE_Role2", "ROLE_Role3" };
|
||||
SimpleAttributes2GrantedAuthoritiesMapper mapper = getDefaultMapper();
|
||||
mapper.setAddPrefixIfAlreadyExisting(false);
|
||||
mapper.setAttributePrefix("ROLE_");
|
||||
testGetGrantedAuthorities(mapper, roles, expectedGas);
|
||||
}
|
||||
|
||||
public final void testGetGrantedAuthoritiesDontAddPrefixIfAlreadyExisting2() {
|
||||
String[] roles = { "Role1", "Role2", "role_Role3" };
|
||||
String[] expectedGas = { "ROLE_Role1", "ROLE_Role2", "ROLE_role_Role3" };
|
||||
SimpleAttributes2GrantedAuthoritiesMapper mapper = getDefaultMapper();
|
||||
mapper.setAddPrefixIfAlreadyExisting(false);
|
||||
mapper.setAttributePrefix("ROLE_");
|
||||
testGetGrantedAuthorities(mapper, roles, expectedGas);
|
||||
}
|
||||
|
||||
public final void testGetGrantedAuthoritiesCombination1() {
|
||||
String[] roles = { "Role1", "Role2", "role_Role3" };
|
||||
String[] expectedGas = { "ROLE_ROLE1", "ROLE_ROLE2", "ROLE_ROLE3" };
|
||||
SimpleAttributes2GrantedAuthoritiesMapper mapper = getDefaultMapper();
|
||||
mapper.setAddPrefixIfAlreadyExisting(false);
|
||||
mapper.setConvertAttributeToUpperCase(true);
|
||||
mapper.setAttributePrefix("ROLE_");
|
||||
testGetGrantedAuthorities(mapper, roles, expectedGas);
|
||||
}
|
||||
|
||||
private void testGetGrantedAuthorities(SimpleAttributes2GrantedAuthoritiesMapper mapper, String[] roles, String[] expectedGas) {
|
||||
List<GrantedAuthority> result = mapper.getGrantedAuthorities(Arrays.asList(roles));
|
||||
Collection<String> resultColl = new ArrayList<String>(result.size());
|
||||
for (int i = 0; i < result.size(); i++) {
|
||||
resultColl.add(result.get(i).getAuthority());
|
||||
}
|
||||
Collection<String> expectedColl = Arrays.asList(expectedGas);
|
||||
assertTrue("Role collections do not match; result: " + resultColl + ", expected: " + expectedColl, expectedColl
|
||||
.containsAll(resultColl)
|
||||
&& resultColl.containsAll(expectedColl));
|
||||
}
|
||||
|
||||
private SimpleAttributes2GrantedAuthoritiesMapper getDefaultMapper() {
|
||||
SimpleAttributes2GrantedAuthoritiesMapper mapper = new SimpleAttributes2GrantedAuthoritiesMapper();
|
||||
mapper.setAttributePrefix("");
|
||||
mapper.setConvertAttributeToLowerCase(false);
|
||||
mapper.setConvertAttributeToUpperCase(false);
|
||||
mapper.setAddPrefixIfAlreadyExisting(false);
|
||||
return mapper;
|
||||
}
|
||||
|
||||
}
|
||||
package org.springframework.security.core.authority.mapping;
|
||||
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.authority.mapping.SimpleAttributes2GrantedAuthoritiesMapper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author TSARDD
|
||||
* @since 18-okt-2007
|
||||
*/
|
||||
public class SimpleRoles2GrantedAuthoritiesMapperTests extends TestCase {
|
||||
|
||||
public final void testAfterPropertiesSetConvertToUpperAndLowerCase() {
|
||||
SimpleAttributes2GrantedAuthoritiesMapper mapper = new SimpleAttributes2GrantedAuthoritiesMapper();
|
||||
mapper.setConvertAttributeToLowerCase(true);
|
||||
mapper.setConvertAttributeToUpperCase(true);
|
||||
try {
|
||||
mapper.afterPropertiesSet();
|
||||
fail("Expected exception not thrown");
|
||||
} catch (IllegalArgumentException expected) {
|
||||
} catch (Exception unexpected) {
|
||||
fail("Unexpected exception: " + unexpected);
|
||||
}
|
||||
}
|
||||
|
||||
public final void testAfterPropertiesSet() {
|
||||
SimpleAttributes2GrantedAuthoritiesMapper mapper = new SimpleAttributes2GrantedAuthoritiesMapper();
|
||||
try {
|
||||
mapper.afterPropertiesSet();
|
||||
} catch (Exception unexpected) {
|
||||
fail("Unexpected exception: " + unexpected);
|
||||
}
|
||||
}
|
||||
|
||||
public final void testGetGrantedAuthoritiesNoConversion() {
|
||||
String[] roles = { "Role1", "Role2" };
|
||||
String[] expectedGas = { "Role1", "Role2" };
|
||||
SimpleAttributes2GrantedAuthoritiesMapper mapper = getDefaultMapper();
|
||||
testGetGrantedAuthorities(mapper, roles, expectedGas);
|
||||
}
|
||||
|
||||
public final void testGetGrantedAuthoritiesToUpperCase() {
|
||||
String[] roles = { "Role1", "Role2" };
|
||||
String[] expectedGas = { "ROLE1", "ROLE2" };
|
||||
SimpleAttributes2GrantedAuthoritiesMapper mapper = getDefaultMapper();
|
||||
mapper.setConvertAttributeToUpperCase(true);
|
||||
testGetGrantedAuthorities(mapper, roles, expectedGas);
|
||||
}
|
||||
|
||||
public final void testGetGrantedAuthoritiesToLowerCase() {
|
||||
String[] roles = { "Role1", "Role2" };
|
||||
String[] expectedGas = { "role1", "role2" };
|
||||
SimpleAttributes2GrantedAuthoritiesMapper mapper = getDefaultMapper();
|
||||
mapper.setConvertAttributeToLowerCase(true);
|
||||
testGetGrantedAuthorities(mapper, roles, expectedGas);
|
||||
}
|
||||
|
||||
public final void testGetGrantedAuthoritiesAddPrefixIfAlreadyExisting() {
|
||||
String[] roles = { "Role1", "Role2", "ROLE_Role3" };
|
||||
String[] expectedGas = { "ROLE_Role1", "ROLE_Role2", "ROLE_ROLE_Role3" };
|
||||
SimpleAttributes2GrantedAuthoritiesMapper mapper = getDefaultMapper();
|
||||
mapper.setAddPrefixIfAlreadyExisting(true);
|
||||
mapper.setAttributePrefix("ROLE_");
|
||||
testGetGrantedAuthorities(mapper, roles, expectedGas);
|
||||
}
|
||||
|
||||
public final void testGetGrantedAuthoritiesDontAddPrefixIfAlreadyExisting1() {
|
||||
String[] roles = { "Role1", "Role2", "ROLE_Role3" };
|
||||
String[] expectedGas = { "ROLE_Role1", "ROLE_Role2", "ROLE_Role3" };
|
||||
SimpleAttributes2GrantedAuthoritiesMapper mapper = getDefaultMapper();
|
||||
mapper.setAddPrefixIfAlreadyExisting(false);
|
||||
mapper.setAttributePrefix("ROLE_");
|
||||
testGetGrantedAuthorities(mapper, roles, expectedGas);
|
||||
}
|
||||
|
||||
public final void testGetGrantedAuthoritiesDontAddPrefixIfAlreadyExisting2() {
|
||||
String[] roles = { "Role1", "Role2", "role_Role3" };
|
||||
String[] expectedGas = { "ROLE_Role1", "ROLE_Role2", "ROLE_role_Role3" };
|
||||
SimpleAttributes2GrantedAuthoritiesMapper mapper = getDefaultMapper();
|
||||
mapper.setAddPrefixIfAlreadyExisting(false);
|
||||
mapper.setAttributePrefix("ROLE_");
|
||||
testGetGrantedAuthorities(mapper, roles, expectedGas);
|
||||
}
|
||||
|
||||
public final void testGetGrantedAuthoritiesCombination1() {
|
||||
String[] roles = { "Role1", "Role2", "role_Role3" };
|
||||
String[] expectedGas = { "ROLE_ROLE1", "ROLE_ROLE2", "ROLE_ROLE3" };
|
||||
SimpleAttributes2GrantedAuthoritiesMapper mapper = getDefaultMapper();
|
||||
mapper.setAddPrefixIfAlreadyExisting(false);
|
||||
mapper.setConvertAttributeToUpperCase(true);
|
||||
mapper.setAttributePrefix("ROLE_");
|
||||
testGetGrantedAuthorities(mapper, roles, expectedGas);
|
||||
}
|
||||
|
||||
private void testGetGrantedAuthorities(SimpleAttributes2GrantedAuthoritiesMapper mapper, String[] roles, String[] expectedGas) {
|
||||
List<GrantedAuthority> result = mapper.getGrantedAuthorities(Arrays.asList(roles));
|
||||
Collection<String> resultColl = new ArrayList<String>(result.size());
|
||||
for (int i = 0; i < result.size(); i++) {
|
||||
resultColl.add(result.get(i).getAuthority());
|
||||
}
|
||||
Collection<String> expectedColl = Arrays.asList(expectedGas);
|
||||
assertTrue("Role collections do not match; result: " + resultColl + ", expected: " + expectedColl, expectedColl
|
||||
.containsAll(resultColl)
|
||||
&& resultColl.containsAll(expectedColl));
|
||||
}
|
||||
|
||||
private SimpleAttributes2GrantedAuthoritiesMapper getDefaultMapper() {
|
||||
SimpleAttributes2GrantedAuthoritiesMapper mapper = new SimpleAttributes2GrantedAuthoritiesMapper();
|
||||
mapper.setAttributePrefix("");
|
||||
mapper.setConvertAttributeToLowerCase(false);
|
||||
mapper.setConvertAttributeToUpperCase(false);
|
||||
mapper.setAddPrefixIfAlreadyExisting(false);
|
||||
return mapper;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ import org.springframework.security.core.context.SecurityContextImpl;
|
||||
* Tests {@link SecurityContextHolder}.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class SecurityContextHolderTests extends TestCase {
|
||||
|
||||
|
||||
@@ -27,7 +27,6 @@ import org.springframework.security.core.context.SecurityContextImpl;
|
||||
* Tests {@link SecurityContextImpl}.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class SecurityContextImplTests extends TestCase {
|
||||
//~ Constructors ===================================================================================================
|
||||
|
||||
@@ -26,7 +26,6 @@ import org.springframework.security.core.session.SessionInformation;
|
||||
* Tests {@link SessionInformation}.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class SessionInformationTests extends TestCase {
|
||||
//~ Methods ========================================================================================================
|
||||
|
||||
@@ -31,7 +31,6 @@ import org.springframework.security.core.session.SessionRegistryImpl;
|
||||
* Tests {@link SessionRegistryImpl}.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class SessionRegistryImplTests {
|
||||
private SessionRegistryImpl sessionRegistry;
|
||||
|
||||
@@ -9,7 +9,7 @@ import org.springframework.security.core.token.DefaultToken;
|
||||
|
||||
/**
|
||||
* Tests {@link DefaultToken}.
|
||||
*
|
||||
*
|
||||
* @author Ben Alex
|
||||
*
|
||||
*/
|
||||
@@ -19,12 +19,12 @@ public class DefaultTokenTests {
|
||||
String key = "key";
|
||||
long created = new Date().getTime();
|
||||
String extendedInformation = "extended";
|
||||
|
||||
|
||||
DefaultToken t1 = new DefaultToken(key, created, extendedInformation);
|
||||
DefaultToken t2 = new DefaultToken(key, created, extendedInformation);
|
||||
Assert.assertEquals(t1, t2);
|
||||
}
|
||||
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testRejectsNullExtendedInformation() {
|
||||
String key = "key";
|
||||
@@ -36,7 +36,7 @@ public class DefaultTokenTests {
|
||||
public void testEqualityWithDifferentExtendedInformation3() {
|
||||
String key = "key";
|
||||
long created = new Date().getTime();
|
||||
|
||||
|
||||
DefaultToken t1 = new DefaultToken(key, created, "length1");
|
||||
DefaultToken t2 = new DefaultToken(key, created, "longerLength2");
|
||||
Assert.assertFalse(t1.equals(t2));
|
||||
|
||||
@@ -15,7 +15,7 @@ import org.springframework.security.core.token.Token;
|
||||
|
||||
/**
|
||||
* Tests {@link KeyBasedPersistenceTokenService}.
|
||||
*
|
||||
*
|
||||
* @author Ben Alex
|
||||
*
|
||||
*/
|
||||
@@ -35,7 +35,7 @@ public class KeyBasedPersistenceTokenServiceTests {
|
||||
}
|
||||
return service;
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testOperationWithSimpleExtendedInformation() {
|
||||
KeyBasedPersistenceTokenService service = getService();
|
||||
@@ -61,7 +61,7 @@ public class KeyBasedPersistenceTokenServiceTests {
|
||||
Token result = service.verifyToken(token.getKey());
|
||||
Assert.assertEquals(token, result);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testOperationWithNoExtendedInformation() {
|
||||
KeyBasedPersistenceTokenService service = getService();
|
||||
@@ -69,14 +69,14 @@ public class KeyBasedPersistenceTokenServiceTests {
|
||||
Token result = service.verifyToken(token.getKey());
|
||||
Assert.assertEquals(token, result);
|
||||
}
|
||||
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testOperationWithMissingKey() {
|
||||
KeyBasedPersistenceTokenService service = getService();
|
||||
Token token = new DefaultToken("", new Date().getTime(), "");
|
||||
service.verifyToken(token.getKey());
|
||||
}
|
||||
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testOperationWithTamperedKey() {
|
||||
KeyBasedPersistenceTokenService service = getService();
|
||||
|
||||
@@ -17,7 +17,6 @@ import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||
* valid, locked, disabled, credentialsExpired, expired. All passwords are "".
|
||||
*
|
||||
* @author Luke Taylor
|
||||
* @version $Id$
|
||||
*/
|
||||
public class MockUserDetailsService implements UserDetailsService {
|
||||
private Map<String, User> users = new HashMap<String, User>();
|
||||
|
||||
@@ -1,51 +1,51 @@
|
||||
package org.springframework.security.core.userdetails;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.security.authentication.TestingAuthenticationToken;
|
||||
import org.springframework.security.core.authority.AuthorityUtils;
|
||||
import org.springframework.security.core.userdetails.User;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.security.core.userdetails.UserDetailsByNameServiceWrapper;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author TSARDD
|
||||
* @since 18-okt-2007
|
||||
*/
|
||||
public class UserDetailsByNameServiceWrapperTests extends TestCase {
|
||||
|
||||
public final void testAfterPropertiesSet() {
|
||||
UserDetailsByNameServiceWrapper svc = new UserDetailsByNameServiceWrapper();
|
||||
try {
|
||||
svc.afterPropertiesSet();
|
||||
fail("AfterPropertiesSet didn't throw expected exception");
|
||||
} catch (IllegalArgumentException expected) {
|
||||
} catch (Exception unexpected) {
|
||||
fail("AfterPropertiesSet throws unexpected exception");
|
||||
}
|
||||
}
|
||||
|
||||
public final void testGetUserDetails() throws Exception {
|
||||
UserDetailsByNameServiceWrapper svc = new UserDetailsByNameServiceWrapper();
|
||||
final User user = new User("dummy", "dummy", true, true, true, true, AuthorityUtils.NO_AUTHORITIES);
|
||||
svc.setUserDetailsService(new UserDetailsService() {
|
||||
public UserDetails loadUserByUsername(String name) throws UsernameNotFoundException, DataAccessException {
|
||||
if (user != null && user.getUsername().equals(name)) {
|
||||
return user;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
});
|
||||
svc.afterPropertiesSet();
|
||||
UserDetails result1 = svc.loadUserDetails(new TestingAuthenticationToken("dummy", "dummy"));
|
||||
assertEquals("Result doesn't match original user", user, result1);
|
||||
UserDetails result2 = svc.loadUserDetails(new TestingAuthenticationToken("dummy2", "dummy"));
|
||||
assertNull("Result should have been null", result2);
|
||||
}
|
||||
|
||||
}
|
||||
package org.springframework.security.core.userdetails;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.security.authentication.TestingAuthenticationToken;
|
||||
import org.springframework.security.core.authority.AuthorityUtils;
|
||||
import org.springframework.security.core.userdetails.User;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.security.core.userdetails.UserDetailsByNameServiceWrapper;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author TSARDD
|
||||
* @since 18-okt-2007
|
||||
*/
|
||||
public class UserDetailsByNameServiceWrapperTests extends TestCase {
|
||||
|
||||
public final void testAfterPropertiesSet() {
|
||||
UserDetailsByNameServiceWrapper svc = new UserDetailsByNameServiceWrapper();
|
||||
try {
|
||||
svc.afterPropertiesSet();
|
||||
fail("AfterPropertiesSet didn't throw expected exception");
|
||||
} catch (IllegalArgumentException expected) {
|
||||
} catch (Exception unexpected) {
|
||||
fail("AfterPropertiesSet throws unexpected exception");
|
||||
}
|
||||
}
|
||||
|
||||
public final void testGetUserDetails() throws Exception {
|
||||
UserDetailsByNameServiceWrapper svc = new UserDetailsByNameServiceWrapper();
|
||||
final User user = new User("dummy", "dummy", true, true, true, true, AuthorityUtils.NO_AUTHORITIES);
|
||||
svc.setUserDetailsService(new UserDetailsService() {
|
||||
public UserDetails loadUserByUsername(String name) throws UsernameNotFoundException, DataAccessException {
|
||||
if (user != null && user.getUsername().equals(name)) {
|
||||
return user;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
});
|
||||
svc.afterPropertiesSet();
|
||||
UserDetails result1 = svc.loadUserDetails(new TestingAuthenticationToken("dummy", "dummy"));
|
||||
assertEquals("Result doesn't match original user", user, result1);
|
||||
UserDetails result2 = svc.loadUserDetails(new TestingAuthenticationToken("dummy2", "dummy"));
|
||||
assertNull("Result should have been null", result2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -31,7 +31,6 @@ import org.springframework.security.core.authority.GrantedAuthorityImpl;
|
||||
* Tests {@link User}.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class UserTests {
|
||||
private static final List<GrantedAuthority> ROLE_12 = AuthorityUtils.createAuthorityList("ROLE_ONE","ROLE_TWO");
|
||||
|
||||
@@ -32,7 +32,6 @@ import org.springframework.security.core.userdetails.cache.EhCacheBasedUserCache
|
||||
* Tests {@link EhCacheBasedUserCache}.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class EhCacheBasedUserCacheTests {
|
||||
private static CacheManager cacheManager;
|
||||
|
||||
@@ -26,7 +26,6 @@ import org.springframework.security.core.userdetails.cache.NullUserCache;
|
||||
* Tests {@link NullUserCache}.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class NullUserCacheTests extends TestCase {
|
||||
|
||||
|
||||
@@ -27,7 +27,6 @@ import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||
* Tests {@link JdbcDaoImpl}.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class JdbcDaoImplTests extends TestCase {
|
||||
|
||||
|
||||
@@ -29,7 +29,6 @@ import java.util.Properties;
|
||||
* Tests {@link InMemoryDaoImpl}.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class InMemoryDaoTests extends TestCase {
|
||||
//~ Constructors ===================================================================================================
|
||||
|
||||
@@ -25,7 +25,6 @@ import org.springframework.security.core.userdetails.memory.UserAttributeEditor;
|
||||
* Tests {@link UserAttributeEditor} and associated {@link UserAttribute}.
|
||||
*
|
||||
* @author Ben Alex
|
||||
* @version $Id$
|
||||
*/
|
||||
public class UserAttributeEditorTests extends TestCase {
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user