【发布时间】:2016-09-04 13:32:46
【问题描述】:
我有一个简单的AuthenticationEntryPoint,它应该为未经授权的请求设置 WWW-Authenticate 标头。
@Component
public class CustomAuthenticationEntryPoint implements AuthenticationEntryPoint {
@Override
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException)
throws IOException, ServletException {
response.setHeader("WWW-Authenticate", "FormBased");
response.sendError(401, authException.getMessage());
}
}
我在AuthorizationServerConfigurer的配置方法之一中使用它
@Override
public void configure(AuthorizationServerSecurityConfigurer authorizationServerSecurityConfigurer) throws Exception {
authorizationServerSecurityConfigurer.authenticationEntryPoint(authenticationEntryPoint);
}
不过,这个开始方法并不总是被调用。当请求中没有 Authorize 标头或 Authorize 标头值不以“Basic”开头时,它会被调用。但是,如果 Authorize 标头以 'Basic' 开头,则不会调用 begin 方法(并且响应的值为Basic realm="oauth2/client")。如何确保调用此方法?
【问题讨论】:
-
您将请求发送到哪些 URL?
-
这些请求是发给
/oauth/token的POST
标签: java spring authentication spring-security spring-security-oauth2