Package com.vaadin.hilla
Class EndpointInvoker
java.lang.Object
com.vaadin.hilla.EndpointInvoker
Handles invocation of endpoint methods after checking the user has proper
access.
This class is a generic invoker that does not have knowledge of HTTP requests or the context that the method is being invoked in.
For internal use only. May be renamed or removed in a future release.
-
Constructor Summary
ConstructorsConstructorDescriptionEndpointInvoker(org.springframework.context.ApplicationContext applicationContext, tools.jackson.databind.ObjectMapper endpointObjectMapper, ExplicitNullableTypeChecker explicitNullableTypeChecker, jakarta.servlet.ServletContext servletContext, EndpointRegistry endpointRegistry) Creates an instance of this bean. -
Method Summary
Modifier and TypeMethodDescriptioncheckAccess(EndpointRegistry.VaadinEndpointData endpointData, Method methodToInvoke, Principal principal, Function<String, Boolean> rolesChecker) Checks that the given user is allowed to call the given endpoint method.Class<?> getReturnType(String endpointName, String methodName) Gets the return type of the given method.getVaadinEndpointData(String endpointName) invoke(String endpointName, String methodName, tools.jackson.databind.node.ObjectNode body, Principal principal, Function<String, Boolean> rolesChecker) Invoke the given endpoint method with the given parameters if the user has access to do so.
-
Constructor Details
-
EndpointInvoker
public EndpointInvoker(org.springframework.context.ApplicationContext applicationContext, @Qualifier("hillaEndpointObjectMapper") tools.jackson.databind.ObjectMapper endpointObjectMapper, ExplicitNullableTypeChecker explicitNullableTypeChecker, jakarta.servlet.ServletContext servletContext, EndpointRegistry endpointRegistry) Creates an instance of this bean.- Parameters:
applicationContext- The Spring application contextendpointObjectMapper- The object mapper to be used for serialization and deserialization of request and response bodies. To override the mapper, use theEndpointController.ENDPOINT_MAPPER_FACTORY_BEAN_QUALIFIERqualifier on a JacksonObjectMapperFactory bean definition.explicitNullableTypeChecker- the method parameter and return value type checker to verify that null values are explicitservletContext- the servlet contextendpointRegistry- the registry used to store endpoint information
-
-
Method Details
-
getReturnType
Gets the return type of the given method.- Parameters:
endpointName- the name of the endpointmethodName- the name of the method
-
invoke
public Object invoke(String endpointName, String methodName, tools.jackson.databind.node.ObjectNode body, Principal principal, Function<String, Boolean> rolesChecker) throws EndpointInvocationException.EndpointHttpExceptionInvoke the given endpoint method with the given parameters if the user has access to do so.- Parameters:
endpointName- the name of the endpointmethodName- the name of the method in the endpointbody- optional request body, that should be specified if the method called has parametersprincipal- the user principal objectrolesChecker- a function for checking if a user is in a given role- Returns:
- the return value of the invoked endpoint method, wrapped in a response entity
- Throws:
EndpointInvocationException.EndpointHttpException- if thrown by the endpoint
-
getVaadinEndpointData
public EndpointRegistry.VaadinEndpointData getVaadinEndpointData(String endpointName) throws EndpointInvocationException.EndpointNotFoundException -
checkAccess
public String checkAccess(EndpointRegistry.VaadinEndpointData endpointData, Method methodToInvoke, Principal principal, Function<String, Boolean> rolesChecker) Checks that the given user is allowed to call the given endpoint method.When the access is denied and an
AuthorizationEventPublisherbean is available, anAuthorizationDeniedEventcarrying anEndpointInvocationis published, so that endpoint calls can be audited the same way as Spring method security invocations. The event is published for denied calls of unauthenticated users as well, and, like in Spring, the authentication it supplies is the anonymous authentication of the user rather thannull.- Parameters:
endpointData- the data of the endpoint to checkmethodToInvoke- the endpoint method to checkprincipal- the user principal objectrolesChecker- a function for checking if a user is in a given role- Returns:
- an error message if the access is denied,
nullotherwise
-