Answer the question
In order to leave comments, you need to log in
How to restrict access in Spring Security to users with blocked status?
Good afternoon, I want to make sure that a user with blocked statuses cannot log in and issue an appropriate error. Is there any tool in spring for this?
Here is my Spring Security config.
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/","/login","/resources/*","/favicon.ico").permitAll()
.antMatchers("/user/**").access("hasRole('ROLE_USER')")
.antMatchers("/admin/**").access("hasRole('ROLE_ADMIN') or hasRole('ROLE_SUPER_ADMIN')")
.and()
.formLogin()
.loginProcessingUrl("/login")
.loginPage("/login")
.successHandler(authenticationSuccessHandler)
.failureUrl("/login?error=true")
.and()
.logout().logoutUrl("/logout").logoutSuccessUrl("/login")
.and().csrf().disable();
}
Answer the question
In order to leave comments, you need to log in
You're digging a little in the wrong place. The UserDetail interface assumes that the user can be blocked. When you implement your
public class CustomUserDetails implements UserDetails
, override the method@Override
public boolean isAccountNonLocked() {
return true;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question