public class ExceptionAuthenticationEntryPoint
extends org.springframework.security.web.authentication.Http403ForbiddenEntryPoint
当参数中不存在token时的提示信息 处理器
主要解决不存在access_token导致401的问题
参见 https://www.cnblogs.com/mxmbk/p/9782409.html 该类主要解决以下问题:问题:测试发现授权接口,当请求参数中不存在access_token时发现接口返回错误信息: {"timestamp":1539337154336,"status":401,"error":"Unauthorized","message":"No message available","path":"/app/businessCode/list"} 排查:经过前面的分析发现,上面提到Security的FilterSecurityInterceptor对OAuth2中返回的信息和本身配置校验后,抛出AccessDenyException。 解决:经过上面的几个问题的处理,发现思路还是一样的,需要定义响应结果, 即1、自定义响应处理逻辑SecurityAuthenticationEntryPoint 2、自定义处理逻辑SecurityAuthenticationEntryPoint生效(见上面的配置)该配置会被被两处配置收集:
ExceptionAuthorizeProvider
中被配置为异常处理方式HttpBasicAuthorizeProvider
中被配置为异常处理方式Oauth2Resource
收集,然后经public void configure(ResourceServerSecurityConfigurer resources)
注入到oauth2中
Oauth2Server
收集,然后经public void configure(AuthorizationServerSecurityConfigurer security)
注入到oauth2中
HttpBasicAuthorizeProvider
,
ExceptionAuthorizeProvider
,
Oauth2Resource
,
Oauth2Server
Constructor and Description |
---|
ExceptionAuthenticationEntryPoint() |
Modifier and Type | Method and Description |
---|---|
void |
commence(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
org.springframework.security.core.AuthenticationException authException) |
HandlerProcessor |
getHandlerProcessor() |
PropertyResource |
getPropertyResource() |
void |
setHandlerProcessor(HandlerProcessor handlerProcessor) |
void |
setPropertyResource(PropertyResource propertyResource) |
public void commence(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, org.springframework.security.core.AuthenticationException authException) throws IOException
commence
in interface org.springframework.security.web.AuthenticationEntryPoint
commence
in class org.springframework.security.web.authentication.Http403ForbiddenEntryPoint
IOException
public HandlerProcessor getHandlerProcessor()
public void setHandlerProcessor(HandlerProcessor handlerProcessor)
public PropertyResource getPropertyResource()
public void setPropertyResource(PropertyResource propertyResource)
Copyright © 2021. All rights reserved.