mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-05-31 01:02:14 +00:00
SEC-417: Fix. Remove hard-coded messages from JdbcDaoImpl to allow internationalized versions for "user not found" etc.
This commit is contained in:
parent
8a35f7da75
commit
c7354c125a
@ -17,6 +17,7 @@ package org.acegisecurity.userdetails.jdbc;
|
|||||||
|
|
||||||
import org.acegisecurity.GrantedAuthority;
|
import org.acegisecurity.GrantedAuthority;
|
||||||
import org.acegisecurity.GrantedAuthorityImpl;
|
import org.acegisecurity.GrantedAuthorityImpl;
|
||||||
|
import org.acegisecurity.AcegiMessageSource;
|
||||||
|
|
||||||
import org.acegisecurity.userdetails.User;
|
import org.acegisecurity.userdetails.User;
|
||||||
import org.acegisecurity.userdetails.UserDetails;
|
import org.acegisecurity.userdetails.UserDetails;
|
||||||
@ -24,6 +25,7 @@ import org.acegisecurity.userdetails.UserDetailsService;
|
|||||||
import org.acegisecurity.userdetails.UsernameNotFoundException;
|
import org.acegisecurity.userdetails.UsernameNotFoundException;
|
||||||
|
|
||||||
import org.springframework.context.ApplicationContextException;
|
import org.springframework.context.ApplicationContextException;
|
||||||
|
import org.springframework.context.support.MessageSourceAccessor;
|
||||||
|
|
||||||
import org.springframework.dao.DataAccessException;
|
import org.springframework.dao.DataAccessException;
|
||||||
|
|
||||||
@ -65,6 +67,7 @@ public class JdbcDaoImpl extends JdbcDaoSupport implements UserDetailsService {
|
|||||||
|
|
||||||
//~ Instance fields ================================================================================================
|
//~ Instance fields ================================================================================================
|
||||||
|
|
||||||
|
protected MessageSourceAccessor messages = AcegiMessageSource.getAccessor();
|
||||||
protected MappingSqlQuery authoritiesByUsernameMapping;
|
protected MappingSqlQuery authoritiesByUsernameMapping;
|
||||||
protected MappingSqlQuery usersByUsernameMapping;
|
protected MappingSqlQuery usersByUsernameMapping;
|
||||||
private String authoritiesByUsernameQuery;
|
private String authoritiesByUsernameQuery;
|
||||||
@ -124,7 +127,8 @@ public class JdbcDaoImpl extends JdbcDaoSupport implements UserDetailsService {
|
|||||||
List users = usersByUsernameMapping.execute(username);
|
List users = usersByUsernameMapping.execute(username);
|
||||||
|
|
||||||
if (users.size() == 0) {
|
if (users.size() == 0) {
|
||||||
throw new UsernameNotFoundException("User not found");
|
throw new UsernameNotFoundException(
|
||||||
|
messages.getMessage("JdbcDaoImpl.notFound", new Object[]{username}, "Username {0} not found"));
|
||||||
}
|
}
|
||||||
|
|
||||||
UserDetails user = (UserDetails) users.get(0); // contains no GrantedAuthority[]
|
UserDetails user = (UserDetails) users.get(0); // contains no GrantedAuthority[]
|
||||||
@ -134,7 +138,9 @@ public class JdbcDaoImpl extends JdbcDaoSupport implements UserDetailsService {
|
|||||||
addCustomAuthorities(user.getUsername(), dbAuths);
|
addCustomAuthorities(user.getUsername(), dbAuths);
|
||||||
|
|
||||||
if (dbAuths.size() == 0) {
|
if (dbAuths.size() == 0) {
|
||||||
throw new UsernameNotFoundException("User has no GrantedAuthority");
|
throw new UsernameNotFoundException(
|
||||||
|
messages.getMessage("JdbcDaoImpl.noAuthority",
|
||||||
|
new Object[] {username}, "User {0} has no GrantedAuthority"));
|
||||||
}
|
}
|
||||||
|
|
||||||
GrantedAuthority[] arrayAuths = (GrantedAuthority[]) dbAuths.toArray(new GrantedAuthority[dbAuths.size()]);
|
GrantedAuthority[] arrayAuths = (GrantedAuthority[]) dbAuths.toArray(new GrantedAuthority[dbAuths.size()]);
|
||||||
|
@ -29,6 +29,8 @@ DigestProcessingFilter.nonceNotNumeric=Nonce token should have yielded a numeric
|
|||||||
DigestProcessingFilter.nonceCompromised=Nonce token compromised {0}
|
DigestProcessingFilter.nonceCompromised=Nonce token compromised {0}
|
||||||
DigestProcessingFilter.usernameNotFound=Username {0} not found
|
DigestProcessingFilter.usernameNotFound=Username {0} not found
|
||||||
DigestProcessingFilter.incorrectResponse=Incorrect response
|
DigestProcessingFilter.incorrectResponse=Incorrect response
|
||||||
|
JdbcDaoImpl.notFound=User {0} not found
|
||||||
|
JdbcDaoImpl.noAuthority=User {0} has no GrantedAuthority
|
||||||
SwitchUserProcessingFilter.noCurrentUser=No current user associated with this request
|
SwitchUserProcessingFilter.noCurrentUser=No current user associated with this request
|
||||||
SwitchUserProcessingFilter.noOriginalAuthentication=Could not find original Authentication object
|
SwitchUserProcessingFilter.noOriginalAuthentication=Could not find original Authentication object
|
||||||
SwitchUserProcessingFilter.usernameNotFound=Username {0} not found
|
SwitchUserProcessingFilter.usernameNotFound=Username {0} not found
|
||||||
|
@ -33,6 +33,8 @@ DigestProcessingFilter.nonceNotNumeric = Le jeton nonce aurait d
|
|||||||
DigestProcessingFilter.nonceCompromised = Le jeton nonce est compromis {0}
|
DigestProcessingFilter.nonceCompromised = Le jeton nonce est compromis {0}
|
||||||
DigestProcessingFilter.usernameNotFound = Le nom d'utilisateur {0} n'a pas été trouvé
|
DigestProcessingFilter.usernameNotFound = Le nom d'utilisateur {0} n'a pas été trouvé
|
||||||
DigestProcessingFilter.incorrectResponse = Réponse incorrecte
|
DigestProcessingFilter.incorrectResponse = Réponse incorrecte
|
||||||
|
JdbcDaoImpl.notFound=Le nom d'utilisateur {0} n'a pas été trouvé
|
||||||
|
JdbcDaoImpl.noAuthority=Le compte utilisateur {0} n'a pas de permissions
|
||||||
SwitchUserProcessingFilter.noCurrentUser = Aucun utilisateur n'est associé à la requête en cours
|
SwitchUserProcessingFilter.noCurrentUser = Aucun utilisateur n'est associé à la requête en cours
|
||||||
SwitchUserProcessingFilter.noOriginalAuthentication = L'objet Authentication original n'a pas été trouvé
|
SwitchUserProcessingFilter.noOriginalAuthentication = L'objet Authentication original n'a pas été trouvé
|
||||||
SwitchUserProcessingFilter.usernameNotFound = Le nom d'utilisateur {0} n'a pas été trouvé
|
SwitchUserProcessingFilter.usernameNotFound = Le nom d'utilisateur {0} n'a pas été trouvé
|
||||||
|
@ -40,7 +40,6 @@ public class JdbcDaoTests extends TestCase {
|
|||||||
//~ Constructors ===================================================================================================
|
//~ Constructors ===================================================================================================
|
||||||
|
|
||||||
public JdbcDaoTests() {
|
public JdbcDaoTests() {
|
||||||
super();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public JdbcDaoTests(String arg0) {
|
public JdbcDaoTests(String arg0) {
|
||||||
@ -49,10 +48,6 @@ public class JdbcDaoTests extends TestCase {
|
|||||||
|
|
||||||
//~ Methods ========================================================================================================
|
//~ Methods ========================================================================================================
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
junit.textui.TestRunner.run(JdbcDaoTests.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
private JdbcDaoImpl makePopulatedJdbcDao() throws Exception {
|
private JdbcDaoImpl makePopulatedJdbcDao() throws Exception {
|
||||||
JdbcDaoImpl dao = new JdbcDaoImpl();
|
JdbcDaoImpl dao = new JdbcDaoImpl();
|
||||||
dao.setDataSource(PopulatedDatabase.getDataSource());
|
dao.setDataSource(PopulatedDatabase.getDataSource());
|
||||||
@ -71,10 +66,6 @@ public class JdbcDaoTests extends TestCase {
|
|||||||
return dao;
|
return dao;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void setUp() throws Exception {
|
|
||||||
super.setUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testCheckDaoAccessUserSuccess() throws Exception {
|
public void testCheckDaoAccessUserSuccess() throws Exception {
|
||||||
JdbcDaoImpl dao = makePopulatedJdbcDao();
|
JdbcDaoImpl dao = makePopulatedJdbcDao();
|
||||||
UserDetails user = dao.loadUserByUsername("marissa");
|
UserDetails user = dao.loadUserByUsername("marissa");
|
||||||
@ -121,7 +112,7 @@ public class JdbcDaoTests extends TestCase {
|
|||||||
dao.loadUserByUsername("cooper");
|
dao.loadUserByUsername("cooper");
|
||||||
fail("Should have thrown UsernameNotFoundException");
|
fail("Should have thrown UsernameNotFoundException");
|
||||||
} catch (UsernameNotFoundException expected) {
|
} catch (UsernameNotFoundException expected) {
|
||||||
assertEquals("User has no GrantedAuthority", expected.getMessage());
|
assertEquals("User cooper has no GrantedAuthority", expected.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user