You can create custom authentication manager where you can check if the user is activated or not
<bean id="authenticationFilter" class="org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter"
p:authenticationManager-ref="customAuthenticationManager"
p:authenticationFailureHandler-ref="customAuthenticationFailureHandler"
p:authenticationSuccessHandler-ref="customAuthenticationSuccessHandler" />
and custom 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!");
}
}
and it will redirect user back to login page (if configured properly)
now in login.jsp, get the failure reason by
${sessionScope["SPRING_SECURITY_LAST_EXCEPTION"].message}
and show the appropriate message to user
}