Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@RolesAllowed rejects unauthenticated users when they mapped to an allowed (EVERYONE) role #12050

Closed
lmsurpre opened this issue May 5, 2020 · 9 comments · Fixed by #19653
Closed
Assignees

Comments

@lmsurpre
Copy link

lmsurpre commented May 5, 2020

Describe the bug
The special-subject EVERYONE doesn't play well with the @RolesAllowed annotation on JAX-RS resources.

Steps to Reproduce

  1. Define a simple webapp with a single JAX-RS resource such as this one thats based on the guide:
package io.openliberty.guides.rest;

import java.util.Properties;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

@Path("properties")
public class PropertiesResource {

  @GET
  @Produces(MediaType.APPLICATION_JSON)
  public Properties getProperties() {
      return System.getProperties();
  }

}
  1. Add a @RolesAllowed("User") annotation to this class and bind the special-subject EVERYONE to this security-role:
<server description="Auth issue example">

<featureManager>
    <feature>jaxrs-2.1</feature>
    <feature>appSecurity-2.0</feature>
</featureManager>

<httpEndpoint httpPort="${default.http.port}" httpsPort="${default.https.port}" host="*"/>

<webApplication location="guide-rest-intro.war" contextRoot="${app.context.root}">
  <application-bnd>
    <security-role name="User">
      <special-subject type="EVERYONE"/>
    </security-role>
  </application-bnd>
</webApplication>

<webAppSecurity singleSignonEnabled="false"/>
</server>
  1. Invoke the endpoint (e.g. http://localhost:9080/LibertyProject/System/properties) without passing auth information. Note that the server rejects the request with status of HTTP 401.

Expected behavior
When the special-subject EVERYONE is bound to a security-role, unauthenticated users should be considered to be in that role and should have access to the endpoints allowed for that role.

Diagnostic information:

  • OpenLiberty Version: 20.0.0.4
  • Java Version:
openjdk version "11.0.5" 2019-10-15
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.5+10)
Eclipse OpenJ9 VM AdoptOpenJDK (build openj9-0.17.0, JRE 11 Mac OS X amd64-64-Bit Compressed References 20191016_371 (JIT enabled, AOT enabled)
OpenJ9   - 77c1cf708
OMR      - 20db4fbc
JCL      - 2a7af5674b based on jdk-11.0.5+10)

Additional context
If I remove the @RolesAllowed("User") annotation, I am now able to access this endpoint, even when my web.xml includes a security-constraint like the following:

    <security-constraint>
        <web-resource-collection>
            <web-resource-name>Properties</web-resource-name>
            <url-pattern>/*</url-pattern>
            <http-method>GET</http-method>
        </web-resource-collection>
        <auth-constraint>
            <role-name>User</role-name>
        </auth-constraint>
    </security-constraint>

If I remove the special-subject mapping and keep this in the web.xml, it returns a 401 as expected. So it seems that special-subject works as expected with the auth-constraint in web.xml.

Similarly, if I add a basicRegistry to the server.xml, then this user is able to access the resource, despite not being explicitly mapped to the seurity-role.

  <basicRegistry> 
    <user name="a" password="a"/>
  </basicRegistry>

So it seems like special-subject EVERYONE is actually behaving the way I would expect special-subject ALL_AUTHENTICATED_USERS to behave.

@lmsurpre lmsurpre added the bug This bug is not present in a released version of Open Liberty label May 5, 2020
@lmsurpre lmsurpre changed the title @RolesAllowed rejects unauthenticated users when they are in the requested role @RolesAllowed rejects unauthenticated users when they mapped to an allowed role May 5, 2020
@arkarkala
Copy link

Hi, have you tried using @permitAll annotation? JAX-RS is using the standard security annotations to perform the security checks. The EVERYONE special subject is specific to WebSphere.

@lmsurpre
Copy link
Author

lmsurpre commented May 5, 2020

Thanks @arkarkala, in our case we normally have a user group mapped to this security-role.
Its only for a handful of special deployments that we'd like to override that binding and map the EVERYONE special subject instead. So, we really don't want @permitAll on the resources.

@prb112
Copy link

prb112 commented Sep 29, 2020

HI @arkarkala @andymc12 do you have any other approaches or ideas on how to approach the case that @lmsurpre highlights in this issue?

@andymc12
Copy link
Contributor

I chatted with @arkarkala and we think that the reason this is failing is because the RoleMethodAuthUtil is checking that the request is authenticated before checking whether the user is in one of the specified roles. The EVERYONE subject should make the isUserInRole method return true, but we're throwing a UnauthenticatedException before checking the isUserInRole method. We're thinking that if we reverse the order of this, this scenario should work - without breaking more traditional scenarios.

Our plan is to create a test case using the EVERYONE subject and validating that we get the same failure you are seeing - and then swap the order so that isUserInRole is checked before authentication is checked to see if it resolves it.

Hope this helps!

@prb112
Copy link

prb112 commented Sep 29, 2020

awesome - thank you so much

@WhiteCat22 WhiteCat22 self-assigned this Oct 14, 2020
@andymc12
Copy link
Contributor

Just an update (sorry for the long delay) - in our tests, even when we switched the order so that we check that the user is authorized after checking that the user is in the role, the isUserInRole method still returned false. @WhiteCat22 will be working with @arkarkala to figure out why that is - possibly the test case is mis-configured, or possibly the EVERYONE role is not working correctly with the web container.

@lmsurpre
Copy link
Author

@andymc12 we're still quite interested in this one. Having this supported would give us a way to ship a Liberty application which has endpoints that are tied to specific security roles (protected via a JAX-RS @RolesAllowed annotation) while still allowing deployers to bind the "unauthenticated" user to this role.

Is it still on your radar?

@sdehors-ibm
Copy link

we are also interested by the support of EVERYONE, any update ? I facing the issue with 21.0.0.9

@andymc12 andymc12 changed the title @RolesAllowed rejects unauthenticated users when they mapped to an allowed role @RolesAllowed rejects unauthenticated users when they mapped to an allowed (EVERYONE) role Dec 9, 2021
@WhiteCat22
Copy link
Member

@lmsurpre, prb112, sdehors-ibm,

Thank you for your patience, this has been merged into our integration branch and should be released with 22.0.0.3.

@WhiteCat22 WhiteCat22 added release bug This bug is present in a released version of Open Liberty and removed bug This bug is not present in a released version of Open Liberty labels Feb 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants