How to set auth role programically for tomcat 8.5

96 Views Asked by At

I have the following config web.xml

   <security-constraint>
      <display-name>Login Security Constraint</display-name>
      <web-resource-collection>
         <web-resource-name>Login Protection</web-resource-name>
         <url-pattern>/servlet/*</url-pattern>
         <http-method>DELETE</http-method>
         <http-method>GET</http-method>
         <http-method>POST</http-method>
         <http-method>PUT</http-method>
      </web-resource-collection>
      <auth-constraint>
         <role-name>Login Access</role-name>
      </auth-constraint>
   </security-constraint>

I have my own Login servlet which I have authenticated the user and created a session using

HttpSession session = request.getSession(true);

But how do I add the role name "Login Access" to the session?

1

There are 1 best solutions below

0
On

I found I had to implement a JDBCRelam and use call in servlet to authenticate the session

request.login(username, password);