SEC-246: Enable late binding on DaoAuthenticationProvider.userDetailsService field.
This commit is contained in:
parent
d541c8e257
commit
f4156a22bd
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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.AuthenticationException;
|
||||||
import org.acegisecurity.AuthenticationServiceException;
|
import org.acegisecurity.AuthenticationServiceException;
|
||||||
import org.acegisecurity.BadCredentialsException;
|
import org.acegisecurity.BadCredentialsException;
|
||||||
|
|
||||||
import org.acegisecurity.providers.AuthenticationProvider;
|
import org.acegisecurity.providers.AuthenticationProvider;
|
||||||
import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
|
import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
|
||||||
import org.acegisecurity.providers.encoding.PasswordEncoder;
|
import org.acegisecurity.providers.encoding.PasswordEncoder;
|
||||||
import org.acegisecurity.providers.encoding.PlaintextPasswordEncoder;
|
import org.acegisecurity.providers.encoding.PlaintextPasswordEncoder;
|
||||||
|
|
||||||
import org.acegisecurity.userdetails.UserDetails;
|
import org.acegisecurity.userdetails.UserDetails;
|
||||||
import org.acegisecurity.userdetails.UserDetailsService;
|
import org.acegisecurity.userdetails.UserDetailsService;
|
||||||
|
|
||||||
import org.springframework.dao.DataAccessException;
|
import org.springframework.dao.DataAccessException;
|
||||||
|
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
|
|
||||||
|
@ -39,9 +43,9 @@ public class DaoAuthenticationProvider
|
||||||
extends AbstractUserDetailsAuthenticationProvider {
|
extends AbstractUserDetailsAuthenticationProvider {
|
||||||
//~ Instance fields ========================================================
|
//~ Instance fields ========================================================
|
||||||
|
|
||||||
private UserDetailsService userDetailsService;
|
|
||||||
private PasswordEncoder passwordEncoder = new PlaintextPasswordEncoder();
|
private PasswordEncoder passwordEncoder = new PlaintextPasswordEncoder();
|
||||||
private SaltSource saltSource;
|
private SaltSource saltSource;
|
||||||
|
private UserDetailsService userDetailsService;
|
||||||
|
|
||||||
//~ Methods ================================================================
|
//~ Methods ================================================================
|
||||||
|
|
||||||
|
@ -67,10 +71,6 @@ public class DaoAuthenticationProvider
|
||||||
"An Authentication DAO must be set");
|
"An Authentication DAO must be set");
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserDetailsService getUserDetailsService() {
|
|
||||||
return userDetailsService;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PasswordEncoder getPasswordEncoder() {
|
public PasswordEncoder getPasswordEncoder() {
|
||||||
return passwordEncoder;
|
return passwordEncoder;
|
||||||
}
|
}
|
||||||
|
@ -79,34 +79,35 @@ public class DaoAuthenticationProvider
|
||||||
return saltSource;
|
return saltSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public UserDetailsService getUserDetailsService() {
|
||||||
|
return userDetailsService;
|
||||||
|
}
|
||||||
|
|
||||||
protected final UserDetails retrieveUser(String username,
|
protected final UserDetails retrieveUser(String username,
|
||||||
UsernamePasswordAuthenticationToken authentication)
|
UsernamePasswordAuthenticationToken authentication)
|
||||||
throws AuthenticationException {
|
throws AuthenticationException {
|
||||||
UserDetails loadedUser;
|
UserDetails loadedUser;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
loadedUser = this.userDetailsService.loadUserByUsername(username);
|
loadedUser = this.getUserDetailsService()
|
||||||
|
.loadUserByUsername(username);
|
||||||
} catch (DataAccessException repositoryProblem) {
|
} catch (DataAccessException repositoryProblem) {
|
||||||
throw new AuthenticationServiceException(
|
throw new AuthenticationServiceException(repositoryProblem
|
||||||
repositoryProblem.getMessage(), repositoryProblem );
|
.getMessage(), repositoryProblem);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (loadedUser == null) {
|
if (loadedUser == null) {
|
||||||
throw new AuthenticationServiceException(
|
throw new AuthenticationServiceException(
|
||||||
"AuthenticationDao returned null, which is an interface contract violation");
|
"AuthenticationDao returned null, which is an interface contract violation");
|
||||||
}
|
}
|
||||||
|
|
||||||
return loadedUser;
|
return loadedUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUserDetailsService(UserDetailsService authenticationDao) {
|
|
||||||
this.userDetailsService = authenticationDao;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the PasswordEncoder instance to be used to encode and validate
|
* Sets the PasswordEncoder instance to be used to encode and validate
|
||||||
* passwords. If not set, {@link PlaintextPasswordEncoder} will be
|
* passwords. If not set, {@link PlaintextPasswordEncoder} will be used by
|
||||||
* used by default.
|
* default.
|
||||||
*
|
*
|
||||||
* @param passwordEncoder The passwordEncoder to use
|
* @param passwordEncoder The passwordEncoder to use
|
||||||
*/
|
*/
|
||||||
|
@ -115,10 +116,9 @@ public class DaoAuthenticationProvider
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The source of salts to use when decoding passwords.
|
* The source of salts to use when decoding passwords. <code>null</code> is
|
||||||
* <code>null</code> is a valid value, meaning the
|
* a valid value, meaning the <code>DaoAuthenticationProvider</code> will
|
||||||
* <code>DaoAuthenticationProvider</code> will present
|
* present <code>null</code> to the relevant <code>PasswordEncoder</code>.
|
||||||
* <code>null</code> to the relevant <code>PasswordEncoder</code>.
|
|
||||||
*
|
*
|
||||||
* @param saltSource to use when attempting to decode passwords via the
|
* @param saltSource to use when attempting to decode passwords via the
|
||||||
* <code>PasswordEncoder</code>
|
* <code>PasswordEncoder</code>
|
||||||
|
@ -126,4 +126,8 @@ public class DaoAuthenticationProvider
|
||||||
public void setSaltSource(SaltSource saltSource) {
|
public void setSaltSource(SaltSource saltSource) {
|
||||||
this.saltSource = saltSource;
|
this.saltSource = saltSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setUserDetailsService(UserDetailsService authenticationDao) {
|
||||||
|
this.userDetailsService = authenticationDao;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue