From 977bc2b164718a36360dcc6bf649938c7d7499b0 Mon Sep 17 00:00:00 2001 From: Luke Taylor Date: Fri, 26 Mar 2010 18:05:28 +0000 Subject: [PATCH] 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. --- .../acls/jdbc/BasicLookupStrategy.java | 4 +- cas/cas.gradle | 1 - cas/pom.xml | 4 -- .../EhCacheBasedTicketCache.java | 25 +++----- config/config.gradle | 6 +- .../PostProcessedMockUserDetailsService.java | 5 +- .../UserDetailsServiceWrapper.java | 4 +- .../dao/DaoAuthenticationProvider.java | 7 ++- .../encoding/PasswordEncoder.java | 14 +---- .../UserDetailsByNameServiceWrapper.java | 6 +- .../core/userdetails/UserDetailsService.java | 6 +- .../cache/EhCacheBasedUserCache.java | 21 ++----- .../core/userdetails/jdbc/JdbcDaoImpl.java | 3 +- .../userdetails/memory/InMemoryDaoImpl.java | 5 +- .../remoting/dns/DnsLookupException.java | 6 +- .../UserDetailsServiceWrapperTests.java | 11 ---- .../dao/DaoAuthenticationProviderTests.java | 25 +++----- .../encoding/BasePasswordEncoderTests.java | 9 +-- .../userdetails/MockUserDetailsService.java | 7 +-- .../UserDetailsByNameServiceWrapperTests.java | 8 +-- .../userdetails/LdapUserDetailsManager.java | 59 +++++++++---------- openid/openid.gradle | 1 - 22 files changed, 70 insertions(+), 167 deletions(-) diff --git a/acl/src/main/java/org/springframework/security/acls/jdbc/BasicLookupStrategy.java b/acl/src/main/java/org/springframework/security/acls/jdbc/BasicLookupStrategy.java index 2f3af20204..1e43244eb6 100644 --- a/acl/src/main/java/org/springframework/security/acls/jdbc/BasicLookupStrategy.java +++ b/acl/src/main/java/org/springframework/security/acls/jdbc/BasicLookupStrategy.java @@ -29,7 +29,6 @@ import java.util.Set; import javax.sql.DataSource; -import org.springframework.dao.DataAccessException; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.PreparedStatementSetter; import org.springframework.jdbc.core.ResultSetExtractor; @@ -495,9 +494,8 @@ public final class BasicLookupStrategy implements LookupStrategy { * @param rs The {@link ResultSet} to be processed * @return a list of parent IDs remaining to be looked up (may be empty, but never null) * @throws SQLException - * @throws DataAccessException */ - public Set extractData(ResultSet rs) throws SQLException, DataAccessException { + public Set extractData(ResultSet rs) throws SQLException { Set parentIdsToLookup = new HashSet(); // Set of parent_id Longs while (rs.next()) { diff --git a/cas/cas.gradle b/cas/cas.gradle index 7b4945de3e..1f51ff69f5 100644 --- a/cas/cas.gradle +++ b/cas/cas.gradle @@ -4,7 +4,6 @@ dependencies { project(':spring-security-web'), "org.springframework:spring-context:$springVersion", "org.springframework:spring-beans:$springVersion", - "org.springframework:spring-tx:$springVersion", "org.springframework:spring-web:$springVersion", "org.jasig.cas:cas-client-core:3.1.9", "net.sf.ehcache:ehcache:$ehcacheVersion" diff --git a/cas/pom.xml b/cas/pom.xml index 4361da39bb..d7d203cfe0 100644 --- a/cas/pom.xml +++ b/cas/pom.xml @@ -24,10 +24,6 @@ javax.servlet servlet-api - - org.springframework - spring-tx - org.springframework spring-test diff --git a/cas/src/main/java/org/springframework/security/cas/authentication/EhCacheBasedTicketCache.java b/cas/src/main/java/org/springframework/security/cas/authentication/EhCacheBasedTicketCache.java index abbc5c79a0..0d9cee19e2 100644 --- a/cas/src/main/java/org/springframework/security/cas/authentication/EhCacheBasedTicketCache.java +++ b/cas/src/main/java/org/springframework/security/cas/authentication/EhCacheBasedTicketCache.java @@ -15,23 +15,17 @@ package org.springframework.security.cas.authentication; -import net.sf.ehcache.CacheException; -import net.sf.ehcache.Element; import net.sf.ehcache.Ehcache; - +import net.sf.ehcache.Element; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; - import org.springframework.beans.factory.InitializingBean; - -import org.springframework.dao.DataRetrievalFailureException; - import org.springframework.util.Assert; /** - * Caches tickets using a Spring IoC defined EHCACHE. + * Caches tickets using a Spring IoC defined EHCACHE. * * @author Ben Alex */ @@ -51,18 +45,13 @@ public class EhCacheBasedTicketCache implements StatelessTicketCache, Initializi } public CasAuthenticationToken getByTicketId(final String serviceTicket) { - try { - final Element element = cache.get(serviceTicket); - - if (logger.isDebugEnabled()) { - logger.debug("Cache hit: " + (element != null) + "; service ticket: " + serviceTicket); - } - - return element == null ? null : (CasAuthenticationToken) element.getValue(); + final Element element = cache.get(serviceTicket); - } catch (CacheException cacheException) { - throw new DataRetrievalFailureException("Cache failure: " + cacheException.getMessage()); + if (logger.isDebugEnabled()) { + logger.debug("Cache hit: " + (element != null) + "; service ticket: " + serviceTicket); } + + return element == null ? null : (CasAuthenticationToken) element.getValue(); } public Ehcache getCache() { diff --git a/config/config.gradle b/config/config.gradle index a24a092a58..f4c34de019 100644 --- a/config/config.gradle +++ b/config/config.gradle @@ -9,8 +9,7 @@ dependencies { "org.springframework:spring-aop:$springVersion", "org.springframework:spring-context:$springVersion", "org.springframework:spring-web:$springVersion", - "org.springframework:spring-beans:$springVersion", - "org.springframework:spring-tx:$springVersion" + "org.springframework:spring-beans:$springVersion" provided "javax.servlet:servlet-api:2.5" @@ -20,7 +19,8 @@ dependencies { 'javax.annotation:jsr250-api:1.0', 'aopalliance:aopalliance:1.0', "org.springframework.ldap:spring-ldap-core:$springLdapVersion", - "org.springframework:spring-jdbc:$springVersion" + "org.springframework:spring-jdbc:$springVersion", + "org.springframework:spring-tx:$springVersion" testRuntime "hsqldb:hsqldb:$hsqlVersion" } diff --git a/config/src/test/java/org/springframework/security/config/PostProcessedMockUserDetailsService.java b/config/src/test/java/org/springframework/security/config/PostProcessedMockUserDetailsService.java index da45fc4684..d600291aca 100644 --- a/config/src/test/java/org/springframework/security/config/PostProcessedMockUserDetailsService.java +++ b/config/src/test/java/org/springframework/security/config/PostProcessedMockUserDetailsService.java @@ -1,9 +1,7 @@ package org.springframework.security.config; -import org.springframework.dao.DataAccessException; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetailsService; -import org.springframework.security.core.userdetails.UsernameNotFoundException; public class PostProcessedMockUserDetailsService implements UserDetailsService { private String postProcessorWasHere; @@ -20,8 +18,7 @@ public class PostProcessedMockUserDetailsService implements UserDetailsService { this.postProcessorWasHere = postProcessorWasHere; } - public UserDetails loadUserByUsername(String username) - throws UsernameNotFoundException, DataAccessException { + public UserDetails loadUserByUsername(String username) { throw new UnsupportedOperationException("Not for actual use"); } } diff --git a/core/src/main/java/org/springframework/security/access/hierarchicalroles/UserDetailsServiceWrapper.java b/core/src/main/java/org/springframework/security/access/hierarchicalroles/UserDetailsServiceWrapper.java index d6afdddb19..01aef30e30 100755 --- a/core/src/main/java/org/springframework/security/access/hierarchicalroles/UserDetailsServiceWrapper.java +++ b/core/src/main/java/org/springframework/security/access/hierarchicalroles/UserDetailsServiceWrapper.java @@ -16,8 +16,6 @@ package org.springframework.security.access.hierarchicalroles; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetailsService; -import org.springframework.security.core.userdetails.UsernameNotFoundException; -import org.springframework.dao.DataAccessException; /** * This class wraps Spring Security's UserDetailsService in a way that its loadUserByUsername() @@ -42,7 +40,7 @@ public class UserDetailsServiceWrapper implements UserDetailsService { this.userDetailsService = userDetailsService; } - public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException { + public UserDetails loadUserByUsername(String username) { UserDetails userDetails = userDetailsService.loadUserByUsername(username); // wrapped UserDetailsService might throw UsernameNotFoundException or DataAccessException which will then bubble up return new UserDetailsWrapper(userDetails, roleHierarchy); diff --git a/core/src/main/java/org/springframework/security/authentication/dao/DaoAuthenticationProvider.java b/core/src/main/java/org/springframework/security/authentication/dao/DaoAuthenticationProvider.java index c713d77e8f..35d1131729 100644 --- a/core/src/main/java/org/springframework/security/authentication/dao/DaoAuthenticationProvider.java +++ b/core/src/main/java/org/springframework/security/authentication/dao/DaoAuthenticationProvider.java @@ -24,7 +24,7 @@ import org.springframework.security.authentication.encoding.PlaintextPasswordEnc import org.springframework.security.core.AuthenticationException; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetailsService; -import org.springframework.dao.DataAccessException; +import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.util.Assert; /** @@ -80,8 +80,9 @@ public class DaoAuthenticationProvider extends AbstractUserDetailsAuthentication try { loadedUser = this.getUserDetailsService().loadUserByUsername(username); - } - catch (DataAccessException repositoryProblem) { + } catch (UsernameNotFoundException notFound) { + throw notFound; + } catch (Exception repositoryProblem) { throw new AuthenticationServiceException(repositoryProblem.getMessage(), repositoryProblem); } diff --git a/core/src/main/java/org/springframework/security/authentication/encoding/PasswordEncoder.java b/core/src/main/java/org/springframework/security/authentication/encoding/PasswordEncoder.java index 54f1069d9b..9f51da8264 100644 --- a/core/src/main/java/org/springframework/security/authentication/encoding/PasswordEncoder.java +++ b/core/src/main/java/org/springframework/security/authentication/encoding/PasswordEncoder.java @@ -15,13 +15,9 @@ package org.springframework.security.authentication.encoding; -import org.springframework.dao.DataAccessException; - /** - *

* Interface for performing authentication operations on a password. - *

* * @author colin sampaleanu */ @@ -48,11 +44,8 @@ public interface PasswordEncoder { * null value is legal. * * @return encoded password - * - * @throws DataAccessException DOCUMENT ME! */ - String encodePassword(String rawPass, Object salt) - throws DataAccessException; + String encodePassword(String rawPass, Object salt); /** *

Validates a specified "raw" password against an encoded password.

@@ -67,9 +60,6 @@ public interface PasswordEncoder { * null value is legal. * * @return true if the password is valid , false otherwise - * - * @throws DataAccessException DOCUMENT ME! */ - boolean isPasswordValid(String encPass, String rawPass, Object salt) - throws DataAccessException; + boolean isPasswordValid(String encPass, String rawPass, Object salt); } diff --git a/core/src/main/java/org/springframework/security/core/userdetails/UserDetailsByNameServiceWrapper.java b/core/src/main/java/org/springframework/security/core/userdetails/UserDetailsByNameServiceWrapper.java index 44118df738..73b32014cf 100755 --- a/core/src/main/java/org/springframework/security/core/userdetails/UserDetailsByNameServiceWrapper.java +++ b/core/src/main/java/org/springframework/security/core/userdetails/UserDetailsByNameServiceWrapper.java @@ -1,8 +1,7 @@ package org.springframework.security.core.userdetails; -import org.springframework.security.core.Authentication; import org.springframework.beans.factory.InitializingBean; -import org.springframework.dao.DataAccessException; +import org.springframework.security.core.Authentication; import org.springframework.util.Assert; /** @@ -48,8 +47,7 @@ public class UserDetailsByNameServiceWrapper implements AuthenticationUserDetail * Get the UserDetails object from the wrapped UserDetailsService * implementation */ - public UserDetails loadUserDetails(Authentication authentication) throws UsernameNotFoundException, - DataAccessException { + public UserDetails loadUserDetails(Authentication authentication) throws UsernameNotFoundException { return this.userDetailsService.loadUserByUsername(authentication.getName()); } diff --git a/core/src/main/java/org/springframework/security/core/userdetails/UserDetailsService.java b/core/src/main/java/org/springframework/security/core/userdetails/UserDetailsService.java index b16c1c5595..bdab2b878e 100644 --- a/core/src/main/java/org/springframework/security/core/userdetails/UserDetailsService.java +++ b/core/src/main/java/org/springframework/security/core/userdetails/UserDetailsService.java @@ -15,8 +15,6 @@ package org.springframework.security.core.userdetails; -import org.springframework.dao.DataAccessException; - /** * Core interface which loads user-specific data. @@ -46,8 +44,6 @@ public interface UserDetailsService { * @return a fully populated user record (never null) * * @throws UsernameNotFoundException if the user could not be found or the user has no GrantedAuthority - * @throws DataAccessException if user could not be found for a repository-specific reason */ - UserDetails loadUserByUsername(String username) - throws UsernameNotFoundException, DataAccessException; + UserDetails loadUserByUsername(String username) throws UsernameNotFoundException; } diff --git a/core/src/main/java/org/springframework/security/core/userdetails/cache/EhCacheBasedUserCache.java b/core/src/main/java/org/springframework/security/core/userdetails/cache/EhCacheBasedUserCache.java index 7c729abc56..9b760350bf 100644 --- a/core/src/main/java/org/springframework/security/core/userdetails/cache/EhCacheBasedUserCache.java +++ b/core/src/main/java/org/springframework/security/core/userdetails/cache/EhCacheBasedUserCache.java @@ -15,21 +15,14 @@ package org.springframework.security.core.userdetails.cache; -import net.sf.ehcache.CacheException; -import net.sf.ehcache.Element; import net.sf.ehcache.Ehcache; - - -import org.springframework.security.core.userdetails.UserCache; -import org.springframework.security.core.userdetails.UserDetails; +import net.sf.ehcache.Element; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; - import org.springframework.beans.factory.InitializingBean; - -import org.springframework.dao.DataRetrievalFailureException; - +import org.springframework.security.core.userdetails.UserCache; +import org.springframework.security.core.userdetails.UserDetails; import org.springframework.util.Assert; @@ -59,13 +52,7 @@ public class EhCacheBasedUserCache implements UserCache, InitializingBean { } public UserDetails getUserFromCache(String username) { - Element element = null; - - try { - element = cache.get(username); - } catch (CacheException cacheException) { - throw new DataRetrievalFailureException("Cache failure: " + cacheException.getMessage()); - } + Element element = cache.get(username); if (logger.isDebugEnabled()) { logger.debug("Cache hit: " + (element != null) + "; username: " + username); diff --git a/core/src/main/java/org/springframework/security/core/userdetails/jdbc/JdbcDaoImpl.java b/core/src/main/java/org/springframework/security/core/userdetails/jdbc/JdbcDaoImpl.java index 032c5990d2..86e99c0d59 100644 --- a/core/src/main/java/org/springframework/security/core/userdetails/jdbc/JdbcDaoImpl.java +++ b/core/src/main/java/org/springframework/security/core/userdetails/jdbc/JdbcDaoImpl.java @@ -24,7 +24,6 @@ import java.util.Set; import org.springframework.context.ApplicationContextException; import org.springframework.context.support.MessageSourceAccessor; -import org.springframework.dao.DataAccessException; import org.springframework.jdbc.core.RowMapper; import org.springframework.jdbc.core.support.JdbcDaoSupport; import org.springframework.security.core.GrantedAuthority; @@ -148,7 +147,7 @@ public class JdbcDaoImpl extends JdbcDaoSupport implements UserDetailsService { Assert.isTrue(enableAuthorities || enableGroups, "Use of either authorities or groups must be enabled"); } - public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException { + public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { List users = loadUsersByUsername(username); if (users.size() == 0) { diff --git a/core/src/main/java/org/springframework/security/core/userdetails/memory/InMemoryDaoImpl.java b/core/src/main/java/org/springframework/security/core/userdetails/memory/InMemoryDaoImpl.java index 194ad1acfd..1230714401 100644 --- a/core/src/main/java/org/springframework/security/core/userdetails/memory/InMemoryDaoImpl.java +++ b/core/src/main/java/org/springframework/security/core/userdetails/memory/InMemoryDaoImpl.java @@ -21,8 +21,6 @@ import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.beans.factory.InitializingBean; -import org.springframework.dao.DataAccessException; - import org.springframework.util.Assert; import java.util.Properties; @@ -49,8 +47,7 @@ public class InMemoryDaoImpl implements UserDetailsService, InitializingBean { return userMap; } - public UserDetails loadUserByUsername(String username) - throws UsernameNotFoundException, DataAccessException { + public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { return userMap.getUser(username); } diff --git a/core/src/main/java/org/springframework/security/remoting/dns/DnsLookupException.java b/core/src/main/java/org/springframework/security/remoting/dns/DnsLookupException.java index f70f11aef0..127239d237 100644 --- a/core/src/main/java/org/springframework/security/remoting/dns/DnsLookupException.java +++ b/core/src/main/java/org/springframework/security/remoting/dns/DnsLookupException.java @@ -16,17 +16,13 @@ package org.springframework.security.remoting.dns; -import org.springframework.dao.DataAccessException; - /** * This will be thrown for unknown DNS errors. * * @author Mike Wiesner * @since 3.0 */ -public class DnsLookupException extends DataAccessException { - - private static final long serialVersionUID = -7538424279394361310L; +public class DnsLookupException extends RuntimeException { public DnsLookupException(String msg, Throwable cause) { super(msg, cause); diff --git a/core/src/test/java/org/springframework/security/access/hierarchicalroles/UserDetailsServiceWrapperTests.java b/core/src/test/java/org/springframework/security/access/hierarchicalroles/UserDetailsServiceWrapperTests.java index 4791ebc311..a0bb26cf6e 100755 --- a/core/src/test/java/org/springframework/security/access/hierarchicalroles/UserDetailsServiceWrapperTests.java +++ b/core/src/test/java/org/springframework/security/access/hierarchicalroles/UserDetailsServiceWrapperTests.java @@ -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); } - } diff --git a/core/src/test/java/org/springframework/security/authentication/dao/DaoAuthenticationProviderTests.java b/core/src/test/java/org/springframework/security/authentication/dao/DaoAuthenticationProviderTests.java index 4d1b9365ac..a1181501ad 100644 --- a/core/src/test/java/org/springframework/security/authentication/dao/DaoAuthenticationProviderTests.java +++ b/core/src/test/java/org/springframework/security/authentication/dao/DaoAuthenticationProviderTests.java @@ -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 { diff --git a/core/src/test/java/org/springframework/security/authentication/encoding/BasePasswordEncoderTests.java b/core/src/test/java/org/springframework/security/authentication/encoding/BasePasswordEncoderTests.java index a1148a88e8..df22e5c8a6 100644 --- a/core/src/test/java/org/springframework/security/authentication/encoding/BasePasswordEncoderTests.java +++ b/core/src/test/java/org/springframework/security/authentication/encoding/BasePasswordEncoderTests.java @@ -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; - /** *

TestCase for BasePasswordEncoder.

@@ -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"); } diff --git a/core/src/test/java/org/springframework/security/core/userdetails/MockUserDetailsService.java b/core/src/test/java/org/springframework/security/core/userdetails/MockUserDetailsService.java index 3cacf102b3..b2c512ac00 100644 --- a/core/src/test/java/org/springframework/security/core/userdetails/MockUserDetailsService.java +++ b/core/src/test/java/org/springframework/security/core/userdetails/MockUserDetailsService.java @@ -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); } diff --git a/core/src/test/java/org/springframework/security/core/userdetails/UserDetailsByNameServiceWrapperTests.java b/core/src/test/java/org/springframework/security/core/userdetails/UserDetailsByNameServiceWrapperTests.java index 8f0f7b072c..ad02fdbbf8 100755 --- a/core/src/test/java/org/springframework/security/core/userdetails/UserDetailsByNameServiceWrapperTests.java +++ b/core/src/test/java/org/springframework/security/core/userdetails/UserDetailsByNameServiceWrapperTests.java @@ -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 { diff --git a/ldap/src/main/java/org/springframework/security/ldap/userdetails/LdapUserDetailsManager.java b/ldap/src/main/java/org/springframework/security/ldap/userdetails/LdapUserDetailsManager.java index 8e22d971cc..9ff0c0bced 100644 --- a/ldap/src/main/java/org/springframework/security/ldap/userdetails/LdapUserDetailsManager.java +++ b/ldap/src/main/java/org/springframework/security/ldap/userdetails/LdapUserDetailsManager.java @@ -14,30 +14,11 @@ */ package org.springframework.security.ldap.userdetails; -import org.springframework.security.authentication.BadCredentialsException; -import org.springframework.security.core.Authentication; -import org.springframework.security.core.GrantedAuthority; -import org.springframework.security.core.authority.GrantedAuthorityImpl; -import org.springframework.security.core.context.SecurityContextHolder; -import org.springframework.security.core.userdetails.UserDetails; -import org.springframework.security.core.userdetails.UsernameNotFoundException; -import org.springframework.security.ldap.LdapUsernameToDnMapper; -import org.springframework.security.ldap.LdapUtils; -import org.springframework.security.ldap.DefaultLdapUsernameToDnMapper; -import org.springframework.security.provisioning.UserDetailsManager; -import org.springframework.dao.DataAccessException; -import org.springframework.ldap.core.AttributesMapper; -import org.springframework.ldap.core.AttributesMapperCallbackHandler; -import org.springframework.ldap.core.ContextExecutor; -import org.springframework.ldap.core.ContextSource; -import org.springframework.ldap.core.DirContextAdapter; -import org.springframework.ldap.core.DistinguishedName; -import org.springframework.ldap.core.LdapTemplate; -import org.springframework.ldap.core.SearchExecutor; -import org.springframework.util.Assert; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; +import java.util.Arrays; +import java.util.Collection; +import java.util.LinkedList; +import java.util.List; +import java.util.ListIterator; import javax.naming.Context; import javax.naming.NameNotFoundException; @@ -51,11 +32,29 @@ import javax.naming.directory.ModificationItem; import javax.naming.directory.SearchControls; import javax.naming.directory.SearchResult; import javax.naming.ldap.LdapContext; -import java.util.Arrays; -import java.util.Collection; -import java.util.LinkedList; -import java.util.List; -import java.util.ListIterator; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.ldap.core.AttributesMapper; +import org.springframework.ldap.core.AttributesMapperCallbackHandler; +import org.springframework.ldap.core.ContextExecutor; +import org.springframework.ldap.core.ContextSource; +import org.springframework.ldap.core.DirContextAdapter; +import org.springframework.ldap.core.DistinguishedName; +import org.springframework.ldap.core.LdapTemplate; +import org.springframework.ldap.core.SearchExecutor; +import org.springframework.security.authentication.BadCredentialsException; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.authority.GrantedAuthorityImpl; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.core.userdetails.UsernameNotFoundException; +import org.springframework.security.ldap.DefaultLdapUsernameToDnMapper; +import org.springframework.security.ldap.LdapUsernameToDnMapper; +import org.springframework.security.ldap.LdapUtils; +import org.springframework.security.provisioning.UserDetailsManager; +import org.springframework.util.Assert; /** * An Ldap implementation of UserDetailsManager. @@ -123,7 +122,7 @@ public class LdapUserDetailsManager implements UserDetailsManager { template = new LdapTemplate(contextSource); } - public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException { + public UserDetails loadUserByUsername(String username) { DistinguishedName dn = usernameMapper.buildDn(username); List authorities = getUserAuthorities(dn, username); diff --git a/openid/openid.gradle b/openid/openid.gradle index 814d480259..6a01b39729 100644 --- a/openid/openid.gradle +++ b/openid/openid.gradle @@ -7,7 +7,6 @@ dependencies { "org.springframework:spring-aop:$springVersion", "org.springframework:spring-context:$springVersion", "org.springframework:spring-beans:$springVersion", - "org.springframework:spring-tx:$springVersion", "org.springframework:spring-web:$springVersion" provided 'javax.servlet:servlet-api:2.5'