【发布时间】:2018-10-24 04:44:48
【问题描述】:
我正在使用 Spring secutiry LDAP 对其用户进行身份验证的应用程序,身份验证工作正常,我的问题是,如果有人尝试使用未经授权的凭据登录,应用程序会立即发送错误 401,而我不想这样,我想自定义一些友好的消息来显示这个用户,但是即使在调试中我也找不到应用程序在哪里执行 de 身份验证,甚至似乎我的后端没有被调用,我该如何自定义这个异常?
这是我的安全配置类的配置:
@Configuration
@Order(2147483640)
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
protected void configure(HttpSecurity http) throws Exception {
http.httpBasic().and()
.cors().and()
.csrf().disable()
.authorizeRequests()
.antMatchers(HttpMethod.OPTIONS, "/**").permitAll()
.antMatchers(HttpMethod.GET, "/**").permitAll()
.antMatchers(HttpMethod.POST, "/**").permitAll()
.antMatchers(HttpMethod.PUT, "/**").permitAll()
.antMatchers(HttpMethod.DELETE, "/**").permitAll()
.antMatchers("/**").permitAll();
}
@Configuration
protected static class AuthenticationConfiguration extends GlobalAuthenticationConfigurerAdapter {
@Autowired
private UsrPessoaService usrPessoaService;
@Override
public void init(AuthenticationManagerBuilder auth) throws Exception {
auth.ldapAuthentication().userDetailsContextMapper(usrPessoaService)
.userDnPatterns("secret")
.groupSearchBase("secret")
.contextSource()
.root("secret")
.url("secret").port(000);
System.out.println(auth.toString());
}
}
}
提前感谢您的帮助!
【问题讨论】:
标签: java spring-security spring-ldap