我已经实现了不记名令牌身份验证(在每个请求中使用客户端 ID 和标头中的访问令牌进行身份验证)。
当我使用错误的凭据(访问令牌)时,我会返回一个空正文的“200 OK”,这是预期的吗?不应该是401或404吗?当我使用正确的凭据时,我会返回“200 OK”预期的 Json 响应以及正文内容。
我正在使用 DefaultPasswordService 和 AuthorizingRealm。也许我错过了什么?
使用 Shiro 1.2.3
我已经实现了不记名令牌身份验证(在每个请求中使用客户端 ID 和标头中的访问令牌进行身份验证)。
当我使用错误的凭据(访问令牌)时,我会返回一个空正文的“200 OK”,这是预期的吗?不应该是401或404吗?当我使用正确的凭据时,我会返回“200 OK”预期的 Json 响应以及正文内容。
我正在使用 DefaultPasswordService 和 AuthorizingRealm。也许我错过了什么?
使用 Shiro 1.2.3
我想我解决了这个问题。
在我的 onAccessDenied() 看起来像这样之前:
@Override
protected boolean onAccessDenied(ServletRequest request, ServletResponse response)
throws Exception {
if (hasAuthorizationToken(request)) {
// Proceed with authentication
return executeLogin(request, response);
}
// Return 401 if authentication failed
WebUtils.toHttp(response).sendError(
Status.UNAUTHORIZED.getStatusCode(),
"Oops, Authentication required");
return false;
}
现在看起来像这样:
@Override
protected boolean onAccessDenied(ServletRequest request, ServletResponse response)
throws Exception {
boolean authenticated = false;
if (hasAuthorizationToken(request)) {
// Proceed with authentication
authenticated = executeLogin(request, response);
}
// Return 401 if authentication failed
if (!authenticated)
WebUtils.toHttp(response).sendError(
Status.UNAUTHORIZED.getStatusCode(),
"Oops, Authentication required");
return authenticated;
}
身份验证失败时,我需要手动返回 Status.UNAUTHORIZED。