Package dev.hilla.auth
Class EndpointAccessChecker
- java.lang.Object
-
- dev.hilla.auth.EndpointAccessChecker
-
public class EndpointAccessChecker extends Object
Component used for checking role-based ACL in Vaadin Endpoints.For each request that is trying to access the method in the corresponding Vaadin Endpoint, the permission check is carried on.
It looks for
AnonymousAllowedPermitAll,DenyAllandRolesAllowedannotations in endpoint methods and classes containing these methods (no super classes' annotations are taken into account).Method-level annotation override Class-level ones.
In the next example, since the class is denied to all, method1 is not accessible to anyone, method2 can be executed by any authorized used, method3 is only allowed to the accounts having the ROLE_USER authority and method4 is available for every user, including anonymous ones that don't provide any token in their requests.
@Endpoint @DenyAll public class DemoEndpoint { public void method1() { } @PermitAll public void method2() { } @RolesAllowed("ROLE_USER") public void method3() { } @AnonymousAllowed public void method4() { } }
-
-
Field Summary
Fields Modifier and Type Field Description static StringACCESS_DENIED_MSGstatic StringACCESS_DENIED_MSG_DEV_MODE
-
Constructor Summary
Constructors Constructor Description EndpointAccessChecker(com.vaadin.flow.server.auth.AccessAnnotationChecker accessAnnotationChecker)Creates a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Stringcheck(Method method, Principal principal, Function<String,Boolean> rolesChecker)Check that the endpoint is accessible for the current user.Stringcheck(Method method, javax.servlet.http.HttpServletRequest request)Check that the endpoint is accessible for the current user.com.vaadin.flow.server.auth.AccessAnnotationCheckergetAccessAnnotationChecker()Returns the instance used for checking access based on annotations.
-
-
-
Field Detail
-
ACCESS_DENIED_MSG
public static final String ACCESS_DENIED_MSG
- See Also:
- Constant Field Values
-
ACCESS_DENIED_MSG_DEV_MODE
public static final String ACCESS_DENIED_MSG_DEV_MODE
- See Also:
- Constant Field Values
-
-
Method Detail
-
check
public String check(Method method, javax.servlet.http.HttpServletRequest request)
Check that the endpoint is accessible for the current user.- Parameters:
method- the Vaadin endpoint method to check ACLrequest- the request that triggers themethodinvocation- Returns:
- an error String with an issue description, if any validation
issues occur,
nullotherwise
-
check
public String check(Method method, Principal principal, Function<String,Boolean> rolesChecker)
Check that the endpoint is accessible for the current user.- Parameters:
method- the Vaadin endpoint method to check ACLprincipal- the user principal objectrolesChecker- a function for checking if a user is in a given role- Returns:
- an error String with an issue description, if any validation
issues occur,
nullotherwise
-
getAccessAnnotationChecker
public com.vaadin.flow.server.auth.AccessAnnotationChecker getAccessAnnotationChecker()
Returns the instance used for checking access based on annotations.- Returns:
- the instance used for checking access based on annotations
-
-