eclipse-ee4j / eclipse-ee4j/jersey

RolesAllowedDynamicFeature can return 401 or 403 errors.

Open
#3,090 17 comments 0 reactions 0 assignees View on GitHub
Component: core Component: security Priority: Major Type: Improvement
Dominant language
Java
Stars
730
Forks
382
PR merge metrics
No merged PRs in 30d

Description

Currently, the RolesAllowedRequestFilter will always return HTTP 403 Forbidden. This is accurate in all cases where the security context is aware of the principal (securityContext.getUserPrincipal() is not null), however it is not strictly accurate in the case where a user has not been authenticated. In that case, returning HTTP 401 Unauthorized is more accurate, as the user has not provided the correct credentials.

The following code should suffice, if inserted before the role check loop.

```
if(requestContext.getSecurityContext().getUserPrincipal() == null && rolesAllowed.length > 0) {
throw new NotAuthorizedException();
}
```
#### Affected Versions
[2.16]

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.