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

CCDM: Provide an API to get the Request in Endpoints #7488

Closed
manolo opened this issue Feb 4, 2020 · 2 comments · Fixed by #7522
Closed

CCDM: Provide an API to get the Request in Endpoints #7488

manolo opened this issue Feb 4, 2020 · 2 comments · Fixed by #7522
Assignees
Labels
hilla Issues related to Hilla

Comments

@manolo
Copy link
Member

manolo commented Feb 4, 2020

VaadinRequest.getCurrent is null in @Endpoints methods because they are handled by a different controller, it is causing user issues like is described in this comment https://vaadin.com/docs/v15/flow/typescript/configuring-security.html

There might be different solutions:

  • make VaadinConnectController put the HttpRequest available in ThreadLocal using the vaadin CurrentInstance API
@Endpoint
public class MyEndpoint {

   @AnonymousAllowed
   public String echo(String parameter) {
       HttpRequest request = CurrentInstance.get(HttpRequest.class);
       if ( request.getUserPrincipal() != null) {
           return request.getUserPrincipal().getName();
       } 
      return anonymous;
   }
}
  • add some magic API to the controller so as it can inject the request when needed by the user
@Endpoint
public class MyEndpoint {

   @AnonymousAllowed
   public String echo(String parameter, HttpRequest request) {
       if ( request.getUserPrincipal() != null) {
           return request.getUserPrincipal().getName();
       } 
      return anonymous;
   }
}

At the same time update the wrong snippet in the documentation wich is wrong https://vaadin.com/docs/v15/flow/typescript/configuring-security.html#accessing-user-information-in-an-endpoint-method

@manolo manolo added the hilla Issues related to Hilla label Feb 4, 2020
@Legioth
Copy link
Member

Legioth commented Feb 4, 2020

Just like all other parts of Vaadin, we also want the endpoints to use the VaadinRequest and VaadinResponse abstractions so that your endpoint logic can be the same regardless of whether the runtime environment is Servlet, Portlet or in the future maybe something like Netty.

@manolo
Copy link
Member Author

manolo commented Feb 4, 2020

Decided in grooming to go with Leif's solution.
We don't need to do any change in the documentation, neither we add any additional API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hilla Issues related to Hilla
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants