I've got a web-app using Jersey3, Tomcat 10 and a DataSourceRealm from Tomcat for authentication.
Running a Servlet works smoothly, but the authorization seems not to take place, as every authenticated user can access resources even though the methods are annotated with @RolesAllowed
My controller looks like this:
@Path("/dataset")
public class DatasetController {
@RolesAllowed({"1, 3"})
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getAllEntries(@DefaultValue("1") @QueryParam("state") int state)
The web.xml looks like this:
<!-- URL-Mappings -->
<servlet-mapping>
<servlet-name>Hello Word</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Entries REST Endpoint</servlet-name>
<url-pattern>/api/*</url-pattern>
</servlet-mapping>
<!-- Security Roles -->
<security-role>
<role-name>1</role-name>
</security-role>
<security-role>
<role-name>2</role-name>
</security-role>
<security-role>
<role-name>3</role-name>
</security-role>
<!-- Login Config -->
<login-config>
<auth-method>BASIC</auth-method>
</login-config>
<!-- Security Constraints-->
<security-constraint>
<web-resource-collection>
<web-resource-name>REST Endpoint</web-resource-name>
<url-pattern>/api/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>1</role-name>
<role-name>2</role-name>
<role-name>3</role-name>
</auth-constraint>
</security-constraint>
I've checked the SecurityContext while debugging, the users authenticated get the correct role, e.g. sc.isUserInRole("1/2/3")
indicates that the authentication works fine. Roles have to be called 1,2,3 but this seems not to be an issue.
What am I missing? Thank you for any input!