ユーザーがアクティブ化されているかどうかを確認できるカスタム認証マネージャーを作成できます
<bean id="authenticationFilter" class="org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter"
p:authenticationManager-ref="customAuthenticationManager"
p:authenticationFailureHandler-ref="customAuthenticationFailureHandler"
p:authenticationSuccessHandler-ref="customAuthenticationSuccessHandler" />
およびカスタム authenticationManager
<bean id="customAuthenticationManager"
class="com.mycompany.security.CustomAuthenticationManager" />
CustomAuthenticationManager.java
public class CustomAuthenticationManager implements import org.springframework.security.authentication.AuthenticationManager{
@Override
public Authentication authenticate(Authentication auth)
throws AuthenticationException {
User user = null;
if (auth.getName() == null) {
throw new BadCredentialsException("User does not exists!");
}
user = userService.getUserByUsername(auth.getName());
if (user == null) {
throw new BadCredentialsException("User does not exists!");
}
if (passwordEncoder.isPasswordValid(user.getPassword(), (String) auth.getCredentials(), null)) {
//check if user is activated if not throw appropriate excetion
} else {
throw new BadCredentialsException("User does not exists!");
}
}
ユーザーをログインページにリダイレクトします(適切に構成されている場合)
login.jsp で、失敗の理由を取得します。
${sessionScope["SPRING_SECURITY_LAST_EXCEPTION"].message}
適切なメッセージをユーザーに表示します }