自Spring boot 1.4发布以来,我遇到了以下问题.我有一个自定义身份验证提供程序,用于管理Spring Security的JWT令牌解析.基本上,当令牌无效或过期时,我会抛出BadCredentialsException.我还有一个AutenticationEntryPoint,它使用JSON中的Unauthorized HttpServlet响应重新格式化消息
@Override
public void commence(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException e) throws IOException, ServletException
{
httpServletResponse.setContentType("application/json");
httpServletResponse.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
httpServletResponse.getOutputStream().println("{ \"error\": \"" + e.getMessage() + "\" }");
}
Run Code Online (Sandbox Code Playgroud)
以下是管理身份验证提供程序例外的过滤器
@Override
protected void doFilterInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, FilterChain filterChain) throws ServletException, IOException
{
String authToken = httpServletRequest.getHeader("Authorization");
JwtToken token = new JwtToken(authToken);
try
{
Authentication auth = authenticationManager.authenticate(token);
SecurityContextHolder.getContext().setAuthentication(auth);
filterChain.doFilter(httpServletRequest, httpServletResponse);
}
catch(AuthenticationException ae)
{
SecurityContextHolder.clearContext();
unauthorizedHandler.commence(httpServletRequest, httpServletResponse, ae);
}
Run Code Online (Sandbox Code Playgroud)
这在Spring Boot 1.3.6中工作正常现在我收到以下错误
java.lang.IllegalArgumentException:Principal不能为null堆栈跟踪:
java.lang.IllegalArgumentException: Principal must not be null …Run Code Online (Sandbox Code Playgroud) 将我们的堆栈迁移到 Spring Boot 2.0.3 并切换我们的 Spring Boot 管理。一切正常,微服务正在注册(向代码中心致敬)
唯一的问题是,当服务关闭或启动时,我们没有收到任何松弛通知,这与早期版本(工作正常)不同,我们使用与以前相同的配置:
spring.boot.admin.notify.slack.enabled=true
spring.boot.admin.notify.slack.username=Spring Boot Admin Service
spring.boot.admin.notify.slack.message=*#{application.name}* (#
{application.id}) is *#{to.status}*
spring.boot.admin.notify.slack.icon=:bender:
Run Code Online (Sandbox Code Playgroud)
以及 yaml 文件中的 Web hook url
spring:
profiles: production
boot:
admin:
notify:
slack:
webhook-url: xxx
Run Code Online (Sandbox Code Playgroud)
任何帮助表示赞赏