Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Authentication in web-app Security

 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Great Ranchers,

I've a query regarding enabling security....

I am using Apache Tomcat 6.0.14 . I put entries in "tomcat-users.xml" as shown ...

-----------------------------------------------------------------------------------
"tomcat-users.xml"


<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>
<role rolename="admin"/>
<user username="Maneesh" password="jaisairam" roles="admin"/>
</tomcat-users>

-----------------------------------------------------------------------------------

Then I wrote web.xml as shown....



-----------------------------------------------------------------------------------
"web.xml"


<login-config>
<auth-method>BASIC</auth-method>
</login-config>


<security-role>
<role-name>admin</role-name>
</security-role>

<security-constraint>
<web-resource-collection>
<web-resource-name>SomeResource</web-resource-name>
<url-pattern>/com/mine/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>admin</role-name>
</auth-constraint>
</security-constraint>

<servlet>
<description></description>
<display-name>ControllerServ</display-name>
<servlet-name>ControllerServ</servlet-name>
<servlet-class>com.mine.ControllerServ</servlet-class>
</servlet>


<servlet-mapping>
<servlet-name>ControllerServ</servlet-name>
<url-pattern>/ControllerServ</url-pattern>
</servlet-mapping>




-----------------------------------------------------------------------------------

Now This's the Restricted resource as shown ..... A Simple Servlet



package com.mine;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class ControllerServ extends HttpServlet {
private static final long serialVersionUID = 1L;



public ControllerServ() {
super();

}

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
// Some Code
}


protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException

{
// Some Code
}
}

-----------------------------------------------------------------------------------

I was expecting a login page asking for username & password when I try to access ControllerServ. But inspite of accessing a constrained resource, Container is not asking me for any authaontication (username & password). Please let me know where I am doing a mistake.

Thanks & Regards
Maneesh Saxena
 
Ranch Hand
Posts: 368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The security constraint is applied on the url pattern
<url-pattern>/com/mine/*</url-pattern>
and the url-pattern of the servlet is
<url-pattern>/ControllerServ</url-pattern>

The url-pattern of the servlet should lie within the defined patterns in security constraints in order to get the constraint applied on that servlet.
 
Maneessh saxena
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Satya .....

I got your point .....

Best Regards
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic