How can I program loginConfig in Tomcat 7?

In Tomcat 7, I installed Realm to allow the container to control the authentication process. I also installed web.xml with the appropriate <security-constraint>and

<login-config>
  <auth-method>FORM</auth-method>
  <realm-name>MyRealm</realm-name>
  <form-login-config>
   <form-login-page>/public/login.jsp</form-login-page>
   <form-error-page>/public/loginError.html</form-error-page>
  </form-login-config>
 </login-config>

According to the login protocol chosen by the user in login.jsp (direct or through OAuth), the stream can be redirected to the servlet, where I need to manage some files before the call HttpServletRequest.login(), if it continues.

If this is not the case, I would like to redirect the stream back to the login page (i.e HttpServletResponse.sendRedirect()..

My question is: in my servlet, how can I program the login page in Web.xml?

, loginConfig StandardContext, , , - (StandardContext ApplicationContext, , , ApplicationContextFacade, , )

- , ?

!

+4
1

API, Servlet 3.1, , , Servlet 3.0, Tomcat 7. web.xml , .

oneliner.

String formLoginPage = XPathFactory.newInstance().newXPath().compile("web-app/login-config/form-login-config/form-login-page").evaluate(DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(getServletContext().getResourceAsStream("/WEB-INF/web.xml")));

ServletContextListener#contextInitialized() HttpServlet#init() .

+2

Source: https://habr.com/ru/post/1623605/


All Articles