Java 如何处理和自定义Spring boot ldap中的错误401?
我在一个使用Spring secutiry LDAP对其用户进行身份验证的应用程序中工作,身份验证工作正常,我的问题是,如果有人试图使用未经授权的凭据登录,应用程序会立即发送一个错误401,我不希望这样,我想定制一些友好的消息来显示此用户,但即使在调试中,我也找不到应用程序在哪里执行反身份验证,甚至我的后端似乎没有被调用,我如何自定义此异常 以下是我在安全配置类上的配置:Java 如何处理和自定义Spring boot ldap中的错误401?,java,spring-security,spring-ldap,Java,Spring Security,Spring Ldap,我在一个使用Spring secutiry LDAP对其用户进行身份验证的应用程序中工作,身份验证工作正常,我的问题是,如果有人试图使用未经授权的凭据登录,应用程序会立即发送一个错误401,我不希望这样,我想定制一些友好的消息来显示此用户,但即使在调试中,我也找不到应用程序在哪里执行反身份验证,甚至我的后端似乎没有被调用,我如何自定义此异常 以下是我在安全配置类上的配置: @Configuration @Order(2147483640) public class SecurityConfigu
@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());
}
}
}
提前感谢您的帮助 你考虑过一个新的计划吗
例如:
还有一个示例error.html模板:
<!DOCTYPE html>
<html>
<body>
<h1>Page not found</h1>
<h2>Sorry, we couldn't find the page you were looking for</h2>
<a href="/">Go Home</a>
</body>
</html>
增编:
由于OP有一个角度前端,这些链接也可能适用:
在本教程中,我们将展示Spring安全性的一些优秀特性,Spring
后备箱和角形支架一起工作,提供舒适和安全的外观
用户体验
初学者应该可以使用Spring和Angular,但是
此外,还有大量细节可供相关领域的专家参考
要么
另见:
嗨@paulsm4!感谢您的帮助,我认为您的建议无法用于此应用程序,原因是该应用程序已经在angular中有一个前端,该前端调用后端,并期望返回一个包含结果或异常详细信息的对象,其中一个属性是友好消息,我可能错了,但在这种情况下,我看不出如何使用白色标签页。
<!DOCTYPE html>
<html>
<body>
<h1>Page not found</h1>
<h2>Sorry, we couldn't find the page you were looking for</h2>
<a href="/">Go Home</a>
</body>
</html>