Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to block all the URL's

 
Ankur Srivastav
Ranch Hand
Posts: 57
Eclipse IDE Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the following web.xml

--

<servlet-mapping>
<servlet-name>MainServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>

<security-constraint>
<web-resource-collection>
<web-resource-name>Book</web-resource-name>
<url-pattern>/</url-pattern>
<!-- <http-method>GET</http-method> -->
</web-resource-collection>
<auth-constraint>
<role-name>AppAdmin</role-name>
<role-name>HRAdmin</role-name>
</auth-constraint>
</security-constraint>

<login-config>
<auth-method>FORM</auth-method>
<form-login-config>
<form-login-page>/WEB-INF/jsp/formlogin.jsp</form-login-page>
<form-error-page>/WEB-INF/jsp/formerror.jsp</form-error-page>
</form-login-config>
</login-config>

What I am trying to do is for any URL request to this App like http://localhost:8083/servletbookapp/ the user should get authenticated. But that is not happening unless I specify some specific pattern like
<url-pattern>/test</url-pattern>

Kindly suggest if I should make any changes ...
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64629
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This mapping:

<url-pattern>/*</url-pattern>

means that all request are routed to your servlet. All of them. That includes requests for images, stylesheets, script files and the like.

Is that really what you want?
 
Ankur Srivastav
Ranch Hand
Posts: 57
Eclipse IDE Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes I am trying a single controller example and want everything routed via that servlet. Problem is it goes to that servlet without authenticating.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64629
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So your servlet is also going to be responsible for all images, stylesheets and script files?
 
Ankur Srivastav
Ranch Hand
Posts: 57
Eclipse IDE Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes it will.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64629
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's just odd. What's the reasoning?
 
Ankur Srivastav
Ranch Hand
Posts: 57
Eclipse IDE Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am just trying an example.. its not a real use case.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64629
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd think that it would be a better learning exercise if it were a tad more realistic.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic