mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-03-06 21:39:25 +00:00
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:
parent
57150a6717
commit
977bc2b164
@ -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 <tt>null</tt>)
|
||||
* @throws SQLException
|
||||
* @throws DataAccessException
|
||||
*/
|
||||
public Set<Long> extractData(ResultSet rs) throws SQLException, DataAccessException {
|
||||
public Set<Long> extractData(ResultSet rs) throws SQLException {
|
||||
Set<Long> parentIdsToLookup = new HashSet<Long>(); // Set of parent_id Longs
|
||||
|
||||
while (rs.next()) {
|
||||
|
@ -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"
|
||||
|
@ -24,10 +24,6 @@
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>servlet-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-tx</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
|
@ -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 <A HREF="http://ehcache.sourceforge.net">EHCACHE</a>.
|
||||
* Caches tickets using a Spring IoC defined <a href="http://ehcache.sourceforge.net">EHCACHE</a>.
|
||||
*
|
||||
* @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);
|
||||
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();
|
||||
|
||||
} 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() {
|
||||
|
@ -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"
|
||||
}
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
@ -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 <tt>UserDetailsService</tt> in a way that its <tt>loadUserByUsername()</tt>
|
||||
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -15,13 +15,9 @@
|
||||
|
||||
package org.springframework.security.authentication.encoding;
|
||||
|
||||
import org.springframework.dao.DataAccessException;
|
||||
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Interface for performing authentication operations on a password.
|
||||
* </p>
|
||||
*
|
||||
* @author colin sampaleanu
|
||||
*/
|
||||
@ -48,11 +44,8 @@ public interface PasswordEncoder {
|
||||
* <code>null</code> value is legal.
|
||||
*
|
||||
* @return encoded password
|
||||
*
|
||||
* @throws DataAccessException DOCUMENT ME!
|
||||
*/
|
||||
String encodePassword(String rawPass, Object salt)
|
||||
throws DataAccessException;
|
||||
String encodePassword(String rawPass, Object salt);
|
||||
|
||||
/**
|
||||
* <p>Validates a specified "raw" password against an encoded password.</p>
|
||||
@ -67,9 +60,6 @@ public interface PasswordEncoder {
|
||||
* <code>null</code> 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);
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
|
@ -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 <code>null</code>)
|
||||
*
|
||||
* @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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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<UserDetails> users = loadUsersByUsername(username);
|
||||
|
||||
if (users.size() == 0) {
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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 {
|
||||
|
@ -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<GrantedAuthority> authorities = getUserAuthorities(dn, username);
|
||||
|
||||
|
@ -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'
|
||||
|
Loading…
x
Reference in New Issue
Block a user