SEC-1433: Reduce the number of direct dependencies on DataAccessException from spring-tx.
It is still required as a compile-time dependency by classes which use Spring's JDBC support, but it doesn't really have to be used in many interfaces and classes which are not necessarily backed by JDBC implementations.
This commit is contained in:
@@ -9,10 +9,6 @@ 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;
|
||||
@@ -38,7 +34,6 @@ public class UserDetailsServiceWrapperTests {
|
||||
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();
|
||||
@@ -63,16 +58,10 @@ public class UserDetailsServiceWrapperTests {
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.dao.DataRetrievalFailureException;
|
||||
import org.springframework.security.authentication.AccountExpiredException;
|
||||
import org.springframework.security.authentication.AuthenticationServiceException;
|
||||
@@ -437,15 +436,13 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
||||
//~ Inner Classes ==================================================================================================
|
||||
|
||||
private class MockAuthenticationDaoReturnsNull implements UserDetailsService {
|
||||
public UserDetails loadUserByUsername(String username)
|
||||
throws UsernameNotFoundException, DataAccessException {
|
||||
public UserDetails loadUserByUsername(String username) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private class MockAuthenticationDaoSimulateBackendError implements UserDetailsService {
|
||||
public UserDetails loadUserByUsername(String username)
|
||||
throws UsernameNotFoundException, DataAccessException {
|
||||
public UserDetails loadUserByUsername(String username) {
|
||||
throw new DataRetrievalFailureException("This mock simulator is designed to fail");
|
||||
}
|
||||
}
|
||||
@@ -453,8 +450,7 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
||||
private class MockAuthenticationDaoUserrod implements UserDetailsService {
|
||||
private String password = "koala";
|
||||
|
||||
public UserDetails loadUserByUsername(String username)
|
||||
throws UsernameNotFoundException, DataAccessException {
|
||||
public UserDetails loadUserByUsername(String username) {
|
||||
if ("rod".equals(username)) {
|
||||
return new User("rod", password, true, true, true, true, ROLES_12);
|
||||
} else {
|
||||
@@ -468,8 +464,7 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
||||
}
|
||||
|
||||
private class MockAuthenticationDaoUserrodWithSalt implements UserDetailsService {
|
||||
public UserDetails loadUserByUsername(String username)
|
||||
throws UsernameNotFoundException, DataAccessException {
|
||||
public UserDetails loadUserByUsername(String username) {
|
||||
if ("rod".equals(username)) {
|
||||
return new User("rod", "koala{SYSTEM_SALT_VALUE}", true, true, true, true, ROLES_12);
|
||||
} else {
|
||||
@@ -479,8 +474,7 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
||||
}
|
||||
|
||||
private class MockAuthenticationDaoUserPeter implements UserDetailsService {
|
||||
public UserDetails loadUserByUsername(String username)
|
||||
throws UsernameNotFoundException, DataAccessException {
|
||||
public UserDetails loadUserByUsername(String username) {
|
||||
if ("peter".equals(username)) {
|
||||
return new User("peter", "opal", false, true, true, true, ROLES_12);
|
||||
} else {
|
||||
@@ -490,8 +484,7 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
||||
}
|
||||
|
||||
private class MockAuthenticationDaoUserPeterAccountExpired implements UserDetailsService {
|
||||
public UserDetails loadUserByUsername(String username)
|
||||
throws UsernameNotFoundException, DataAccessException {
|
||||
public UserDetails loadUserByUsername(String username) {
|
||||
if ("peter".equals(username)) {
|
||||
return new User("peter", "opal", true, false, true, true, ROLES_12);
|
||||
} else {
|
||||
@@ -501,8 +494,7 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
||||
}
|
||||
|
||||
private class MockAuthenticationDaoUserPeterAccountLocked implements UserDetailsService {
|
||||
public UserDetails loadUserByUsername(String username)
|
||||
throws UsernameNotFoundException, DataAccessException {
|
||||
public UserDetails loadUserByUsername(String username) {
|
||||
if ("peter".equals(username)) {
|
||||
return new User("peter", "opal", true, true, true, false, ROLES_12);
|
||||
} else {
|
||||
@@ -512,8 +504,7 @@ public class DaoAuthenticationProviderTests extends TestCase {
|
||||
}
|
||||
|
||||
private class MockAuthenticationDaoUserPeterCredentialsExpired implements UserDetailsService {
|
||||
public UserDetails loadUserByUsername(String username)
|
||||
throws UsernameNotFoundException, DataAccessException {
|
||||
public UserDetails loadUserByUsername(String username) {
|
||||
if ("peter".equals(username)) {
|
||||
return new User("peter", "opal", true, true, false, true, ROLES_12);
|
||||
} else {
|
||||
|
||||
@@ -17,9 +17,6 @@ package org.springframework.security.authentication.encoding;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.security.authentication.encoding.BasePasswordEncoder;
|
||||
|
||||
|
||||
/**
|
||||
* <p>TestCase for BasePasswordEncoder.</p>
|
||||
@@ -126,13 +123,11 @@ public class BasePasswordEncoderTests extends TestCase {
|
||||
//~ Inner Classes ==================================================================================================
|
||||
|
||||
private class MockPasswordEncoder extends BasePasswordEncoder {
|
||||
public String encodePassword(String rawPass, Object salt)
|
||||
throws DataAccessException {
|
||||
public String encodePassword(String rawPass, Object salt) {
|
||||
throw new UnsupportedOperationException("mock method not implemented");
|
||||
}
|
||||
|
||||
public boolean isPasswordValid(String encPass, String rawPass, Object salt)
|
||||
throws DataAccessException {
|
||||
public boolean isPasswordValid(String encPass, String rawPass, Object salt) {
|
||||
throw new UnsupportedOperationException("mock method not implemented");
|
||||
}
|
||||
|
||||
|
||||
@@ -4,13 +4,8 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.dao.DataAccessException;
|
||||
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;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||
|
||||
/**
|
||||
* A test UserDetailsService containing a set of standard usernames corresponding to their account status:
|
||||
@@ -30,7 +25,7 @@ public class MockUserDetailsService implements UserDetailsService {
|
||||
users.put("expired", new User("expired", "",true,false,true,true,auths));
|
||||
}
|
||||
|
||||
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException {
|
||||
public UserDetails loadUserByUsername(String username) {
|
||||
if (users.get(username) == null) {
|
||||
throw new UsernameNotFoundException("User not found: " + username);
|
||||
}
|
||||
|
||||
@@ -2,14 +2,8 @@ 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;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -33,7 +27,7 @@ public class UserDetailsByNameServiceWrapperTests extends TestCase {
|
||||
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 {
|
||||
public UserDetails loadUserByUsername(String name) {
|
||||
if (user != null && user.getUsername().equals(name)) {
|
||||
return user;
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user