0

I'd like to be able to programmatically check whether or not an endpoint in my Helidon MP application has the @PermitAll annotation, e.g. from its SecurityContext or something like that. Is this possible? My reason is to be able to reuse a utility method that takes the security context and/or URI info and do some general validation on it.

For example:

@GET
@Path("/{path: .*}")
@Produces(MediaType.APPLICATION_JSON)
@PermitAll
public Response proxyGetRequests(@PathParam("path") final String path,
 @Context UriInfo uriInfo,
 @Context SecurityContext securityContext) {
 // e.g. securityContext.permitsAll() <- or something like this?
}
Mark Rotteveel
110k237 gold badges158 silver badges229 bronze badges
asked 15 hours ago
1
  • you need interceptor for that Commented 9 hours ago

1 Answer 1

0

If you want to check programmatically whether an endpoint has @PermitAll, you have to inspect resource method metadata, not the SecurityContext.

Option 1: Use Reflection

Since you know the class and method, you can use reflection to see if @PermitAll is present:

Method method = this.getClass().getMethod(
 "proxyGetRequests", String.class, UriInfo.class, SecurityContext.class
);
boolean hasPermitAll = method.isAnnotationPresent(PermitAll.class);

You could generalize this by looking up the ResourceMethod based on the UriInfo path and then inspecting its annotations.

Option 2: JAX-RS ResourceInfo

ResourceInfo tells you which class and method are handling the current request, so you can reflectively inspect their annotations.

julaine
2,0701 gold badge20 silver badges36 bronze badges
answered 8 hours ago
New contributor
Rohit Rathor is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.