loadGroupAuthorities(String username) {
- return groupAuthoritiesByUsernameMapping.execute(username);
+ return getJdbcTemplate().query(groupAuthoritiesByUsernameQuery, new String[] {username}, new RowMapper() {
+ public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
+ String roleName = getRolePrefix() + rs.getString(3);
+ GrantedAuthorityImpl authority = new GrantedAuthorityImpl(roleName);
+
+ return authority;
+ }
+ });
}
/**
@@ -247,12 +251,12 @@ public class JdbcDaoImpl extends JdbcDaoSupport implements UserDetailsService {
}
/**
- * Allows the default query string used to retrieve authorities based on username to be overriden, if
+ * Allows the default query string used to retrieve authorities based on username to be overridden, if
* default table or column names need to be changed. The default query is {@link
* #DEF_AUTHORITIES_BY_USERNAME_QUERY}; when modifying this query, ensure that all returned columns are mapped
* back to the same column names as in the default query.
*
- * @param queryString The query string to set
+ * @param queryString The SQL query string to set
*/
public void setAuthoritiesByUsernameQuery(String queryString) {
authoritiesByUsernameQuery = queryString;
@@ -263,12 +267,12 @@ public class JdbcDaoImpl extends JdbcDaoSupport implements UserDetailsService {
}
/**
- * Allows the default query string used to retrieve group authorities based on username to be overriden, if
+ * Allows the default query string used to retrieve group authorities based on username to be overridden, if
* default table or column names need to be changed. The default query is {@link
* #DEF_GROUP_AUTHORITIES_BY_USERNAME_QUERY}; when modifying this query, ensure that all returned columns are mapped
* back to the same column names as in the default query.
*
- * @param queryString The query string to set
+ * @param queryString The SQL query string to set
*/
public void setGroupAuthoritiesByUsernameQuery(String queryString) {
groupAuthoritiesByUsernameQuery = queryString;
@@ -309,12 +313,14 @@ public class JdbcDaoImpl extends JdbcDaoSupport implements UserDetailsService {
}
/**
- * Allows the default query string used to retrieve users based on username to be overriden, if default
+ * Allows the default query string used to retrieve users based on username to be overridden, if default
* table or column names need to be changed. The default query is {@link #DEF_USERS_BY_USERNAME_QUERY}; when
* modifying this query, ensure that all returned columns are mapped back to the same column names as in the
- * default query. If the 'enabled' column does not exist in the source db, a permanent true value for this column
- * may be returned by using a query similar to
- * "SELECT username,password,'true' as enabled FROM users WHERE username = ?"
+ * default query. If the 'enabled' column does not exist in the source database, a permanent true value for this
+ * column may be returned by using a query similar to
+ *
+ * "select username,password,'true' as enabled from users where username = ?"
+ *
*
* @param usersByUsernameQueryString The query string to set
*/
@@ -344,59 +350,4 @@ public class JdbcDaoImpl extends JdbcDaoSupport implements UserDetailsService {
public void setEnableGroups(boolean enableGroups) {
this.enableGroups = enableGroups;
}
-
- //~ Inner Classes ==================================================================================================
-
- /**
- * Query object to look up a user's authorities.
- */
- private class AuthoritiesByUsernameMapping extends MappingSqlQuery {
- protected AuthoritiesByUsernameMapping(DataSource ds) {
- super(ds, authoritiesByUsernameQuery);
- declareParameter(new SqlParameter(Types.VARCHAR));
- compile();
- }
-
- protected Object mapRow(ResultSet rs, int rownum) throws SQLException {
- String roleName = rolePrefix + rs.getString(2);
- GrantedAuthorityImpl authority = new GrantedAuthorityImpl(roleName);
-
- return authority;
- }
- }
-
- private class GroupAuthoritiesByUsernameMapping extends MappingSqlQuery {
- protected GroupAuthoritiesByUsernameMapping(DataSource ds) {
- super(ds, groupAuthoritiesByUsernameQuery);
- declareParameter(new SqlParameter(Types.VARCHAR));
- compile();
- }
-
- protected Object mapRow(ResultSet rs, int rownum) throws SQLException {
- String roleName = rolePrefix + rs.getString(3);
- GrantedAuthorityImpl authority = new GrantedAuthorityImpl(roleName);
-
- return authority;
- }
- }
-
- /**
- * Query object to look up a user.
- */
- private class UsersByUsernameMapping extends MappingSqlQuery {
- protected UsersByUsernameMapping(DataSource ds) {
- super(ds, usersByUsernameQuery);
- declareParameter(new SqlParameter(Types.VARCHAR));
- compile();
- }
-
- protected Object mapRow(ResultSet rs, int rownum) throws SQLException {
- String username = rs.getString(1);
- String password = rs.getString(2);
- boolean enabled = rs.getBoolean(3);
- UserDetails user = new User(username, password, enabled, true, true, true, AuthorityUtils.NO_AUTHORITIES);
-
- return user;
- }
- }
}
diff --git a/core/src/test/java/org/springframework/security/userdetails/jdbc/JdbcDaoImplTests.java b/core/src/test/java/org/springframework/security/userdetails/jdbc/JdbcDaoImplTests.java
index 0b94726265..938c522f5c 100644
--- a/core/src/test/java/org/springframework/security/userdetails/jdbc/JdbcDaoImplTests.java
+++ b/core/src/test/java/org/springframework/security/userdetails/jdbc/JdbcDaoImplTests.java
@@ -37,14 +37,6 @@ import java.util.HashSet;
* @version $Id$
*/
public class JdbcDaoImplTests extends TestCase {
- //~ Constructors ===================================================================================================
-
- public JdbcDaoImplTests() {
- }
-
- public JdbcDaoImplTests(String arg0) {
- super(arg0);
- }
//~ Methods ========================================================================================================