|
@@ -1,4 +1,4 @@
|
|
|
-/* Copyright 2004, 2005 Acegi Technology Pty Limited
|
|
|
+/* Copyright 2004, 2005, 2006 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.
|
|
@@ -18,13 +18,17 @@ package org.acegisecurity.providers.dao;
|
|
|
import org.acegisecurity.AuthenticationException;
|
|
|
import org.acegisecurity.AuthenticationServiceException;
|
|
|
import org.acegisecurity.BadCredentialsException;
|
|
|
+
|
|
|
import org.acegisecurity.providers.AuthenticationProvider;
|
|
|
import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
|
|
|
import org.acegisecurity.providers.encoding.PasswordEncoder;
|
|
|
import org.acegisecurity.providers.encoding.PlaintextPasswordEncoder;
|
|
|
+
|
|
|
import org.acegisecurity.userdetails.UserDetails;
|
|
|
import org.acegisecurity.userdetails.UserDetailsService;
|
|
|
+
|
|
|
import org.springframework.dao.DataAccessException;
|
|
|
+
|
|
|
import org.springframework.util.Assert;
|
|
|
|
|
|
|
|
@@ -39,9 +43,9 @@ public class DaoAuthenticationProvider
|
|
|
extends AbstractUserDetailsAuthenticationProvider {
|
|
|
//~ Instance fields ========================================================
|
|
|
|
|
|
- private UserDetailsService userDetailsService;
|
|
|
private PasswordEncoder passwordEncoder = new PlaintextPasswordEncoder();
|
|
|
private SaltSource saltSource;
|
|
|
+ private UserDetailsService userDetailsService;
|
|
|
|
|
|
//~ Methods ================================================================
|
|
|
|
|
@@ -67,10 +71,6 @@ public class DaoAuthenticationProvider
|
|
|
"An Authentication DAO must be set");
|
|
|
}
|
|
|
|
|
|
- public UserDetailsService getUserDetailsService() {
|
|
|
- return userDetailsService;
|
|
|
- }
|
|
|
-
|
|
|
public PasswordEncoder getPasswordEncoder() {
|
|
|
return passwordEncoder;
|
|
|
}
|
|
@@ -79,34 +79,35 @@ public class DaoAuthenticationProvider
|
|
|
return saltSource;
|
|
|
}
|
|
|
|
|
|
+ public UserDetailsService getUserDetailsService() {
|
|
|
+ return userDetailsService;
|
|
|
+ }
|
|
|
+
|
|
|
protected final UserDetails retrieveUser(String username,
|
|
|
- UsernamePasswordAuthenticationToken authentication)
|
|
|
+ UsernamePasswordAuthenticationToken authentication)
|
|
|
throws AuthenticationException {
|
|
|
UserDetails loadedUser;
|
|
|
|
|
|
try {
|
|
|
- loadedUser = this.userDetailsService.loadUserByUsername(username);
|
|
|
+ loadedUser = this.getUserDetailsService()
|
|
|
+ .loadUserByUsername(username);
|
|
|
} catch (DataAccessException repositoryProblem) {
|
|
|
- throw new AuthenticationServiceException(
|
|
|
- repositoryProblem.getMessage(), repositoryProblem );
|
|
|
+ throw new AuthenticationServiceException(repositoryProblem
|
|
|
+ .getMessage(), repositoryProblem);
|
|
|
}
|
|
|
|
|
|
if (loadedUser == null) {
|
|
|
throw new AuthenticationServiceException(
|
|
|
- "AuthenticationDao returned null, which is an interface contract violation");
|
|
|
+ "AuthenticationDao returned null, which is an interface contract violation");
|
|
|
}
|
|
|
|
|
|
return loadedUser;
|
|
|
}
|
|
|
|
|
|
- public void setUserDetailsService(UserDetailsService authenticationDao) {
|
|
|
- this.userDetailsService = authenticationDao;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* Sets the PasswordEncoder instance to be used to encode and validate
|
|
|
- * passwords. If not set, {@link PlaintextPasswordEncoder} will be
|
|
|
- * used by default.
|
|
|
+ * passwords. If not set, {@link PlaintextPasswordEncoder} will be used by
|
|
|
+ * default.
|
|
|
*
|
|
|
* @param passwordEncoder The passwordEncoder to use
|
|
|
*/
|
|
@@ -115,10 +116,9 @@ public class DaoAuthenticationProvider
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * The source of salts to use when decoding passwords.
|
|
|
- * <code>null</code> is a valid value, meaning the
|
|
|
- * <code>DaoAuthenticationProvider</code> will present
|
|
|
- * <code>null</code> to the relevant <code>PasswordEncoder</code>.
|
|
|
+ * The source of salts to use when decoding passwords. <code>null</code> is
|
|
|
+ * a valid value, meaning the <code>DaoAuthenticationProvider</code> will
|
|
|
+ * present <code>null</code> to the relevant <code>PasswordEncoder</code>.
|
|
|
*
|
|
|
* @param saltSource to use when attempting to decode passwords via the
|
|
|
* <code>PasswordEncoder</code>
|
|
@@ -126,4 +126,8 @@ public class DaoAuthenticationProvider
|
|
|
public void setSaltSource(SaltSource saltSource) {
|
|
|
this.saltSource = saltSource;
|
|
|
}
|
|
|
+
|
|
|
+ public void setUserDetailsService(UserDetailsService authenticationDao) {
|
|
|
+ this.userDetailsService = authenticationDao;
|
|
|
+ }
|
|
|
}
|