3

I tried:

@WebServlet(urlPatterns = "/TestServlet")
public class TestServlet extends HttpServlet {
  @Override
  protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
   VaadinSession session = VaadinSession.getCurrent();
   // session is null
  }
}

Context: I have a few standard servlets mixed in with my normal Vaadin application. They handle for example some download or print requests. But I need a way to check for login/permissions.

Reto Höhener
  • 5,419
  • 4
  • 39
  • 79
  • 2
    I don't think you can but you can do the opposite and access the normal session from `VaadinSession` (and store what you need there). – Oleg Oct 14 '17 at 23:03
  • 1
    @Oleg Thank you, I switched to `VaadinSession.getSession()` to store things like login info. From the servlet I access it through the HttpSession. – Reto Höhener Oct 16 '17 at 01:08

1 Answers1

0

I think you can use spring security for this purposes.

Please check this answer to see how to use it How does spring security work on a Servlet

ensarg
  • 31
  • 3
  • That's if he's using spring, which currently is unspecified. Furthermore, while links to external resources are encouraged, they can quickly become obsolete/unavailable. Thus, it would be helpful if you could quote or add a sample based on the linked content (more on [how to answer, here](https://stackoverflow.com/help/how-to-answer)) – Morfic Oct 13 '17 at 23:29
  • Yes, thank you for the link, but I am not using Spring. – Reto Höhener Oct 14 '17 at 14:43
  • Filters: Doesn't ring a bell. – Reto Höhener Oct 16 '17 at 01:05
  • Like This http://tutorials.jenkov.com/java-servlets/servlet-filters.html – ensarg Oct 17 '17 at 07:36