|
@@ -40,6 +40,7 @@ import org.springframework.security.core.authority.AuthorityUtils;
|
|
|
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
|
|
import org.springframework.security.core.context.SecurityContext;
|
|
|
import org.springframework.security.core.context.SecurityContextHolder;
|
|
|
+import org.springframework.security.core.context.SecurityContextHolderStrategy;
|
|
|
import org.springframework.security.core.userdetails.User;
|
|
|
import org.springframework.security.core.userdetails.UserCache;
|
|
|
import org.springframework.security.core.userdetails.UserDetails;
|
|
@@ -108,6 +109,9 @@ public class JdbcUserDetailsManager extends JdbcDaoImpl implements UserDetailsMa
|
|
|
|
|
|
protected final Log logger = LogFactory.getLog(getClass());
|
|
|
|
|
|
+ private SecurityContextHolderStrategy securityContextHolderStrategy = SecurityContextHolder
|
|
|
+ .getContextHolderStrategy();
|
|
|
+
|
|
|
private String createUserSql = DEF_CREATE_USER_SQL;
|
|
|
|
|
|
private String deleteUserSql = DEF_DELETE_USER_SQL;
|
|
@@ -260,7 +264,7 @@ public class JdbcUserDetailsManager extends JdbcDaoImpl implements UserDetailsMa
|
|
|
|
|
|
@Override
|
|
|
public void changePassword(String oldPassword, String newPassword) throws AuthenticationException {
|
|
|
- Authentication currentUser = SecurityContextHolder.getContext().getAuthentication();
|
|
|
+ Authentication currentUser = this.securityContextHolderStrategy.getContext().getAuthentication();
|
|
|
if (currentUser == null) {
|
|
|
// This would indicate bad coding somewhere
|
|
|
throw new AccessDeniedException(
|
|
@@ -280,9 +284,9 @@ public class JdbcUserDetailsManager extends JdbcDaoImpl implements UserDetailsMa
|
|
|
this.logger.debug("Changing password for user '" + username + "'");
|
|
|
getJdbcTemplate().update(this.changePasswordSql, newPassword, username);
|
|
|
Authentication authentication = createNewAuthentication(currentUser, newPassword);
|
|
|
- SecurityContext context = SecurityContextHolder.createEmptyContext();
|
|
|
+ SecurityContext context = this.securityContextHolderStrategy.createEmptyContext();
|
|
|
context.setAuthentication(authentication);
|
|
|
- SecurityContextHolder.setContext(context);
|
|
|
+ this.securityContextHolderStrategy.setContext(context);
|
|
|
this.userCache.removeUserFromCache(username);
|
|
|
}
|
|
|
|
|
@@ -419,6 +423,17 @@ public class JdbcUserDetailsManager extends JdbcDaoImpl implements UserDetailsMa
|
|
|
return getJdbcTemplate().queryForObject(this.findGroupIdSql, Integer.class, group);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Sets the {@link SecurityContextHolderStrategy} to use. The default action is to use
|
|
|
+ * the {@link SecurityContextHolderStrategy} stored in {@link SecurityContextHolder}.
|
|
|
+ *
|
|
|
+ * @since 5.8
|
|
|
+ */
|
|
|
+ public void setSecurityContextHolderStrategy(SecurityContextHolderStrategy securityContextHolderStrategy) {
|
|
|
+ Assert.notNull(securityContextHolderStrategy, "securityContextHolderStrategy cannot be null");
|
|
|
+ this.securityContextHolderStrategy = securityContextHolderStrategy;
|
|
|
+ }
|
|
|
+
|
|
|
public void setAuthenticationManager(AuthenticationManager authenticationManager) {
|
|
|
this.authenticationManager = authenticationManager;
|
|
|
}
|