• 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
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

filter validation

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have this filter.

<filter>
<filter-name>authenticator</filter-name>
<filter-class>ex.sample.filters.Auth</filter-class>
</filter>

<filter-mapping>
<filter-name>authenticator</filter-name>
<url-pattern>/*</url-pattern>
</fitler-mapping>

The idea is to validate a user for every request. However, I don't want it to be applied to a request for images or javascripts and such. I only want it to be applied to a request for servlets and JSP's.

Is it possible to use reg-exp for <url-pattern>? If not, what is the best way to do this?
 
author & internet detective
Posts: 42152
937
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's traditional to use the servlet mapping. For example "/myRoot/*". All servlet URLs begin with this mapping. It is good practice to not refer to JSPs directly, but through a servlet. But if you have loose JSPs, you could use a similar pattern to pick them up.
 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bug,
It would be great if you can let me know how your filter works?
From where does it picks up the role access mappings etc etc..
 
Bug Menot
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Gavi,
It checks for a valid session by checking for a session attribute that was assigned to the session when it was first created. The attribute assigned corresponds to the role of the user (when they logged in).

Jeanne,
I already thought about making the url-pattern alike for servlets, it's just huge work because I have lots of servlets. Consider the jsp's that <a href= or <form action= to these servlets.
If reg.exp. was available however, I could probably just say !(/images/ | /js/) and stuff.

Thanks for the reply!
 
Jeanne Boyarsky
author & internet detective
Posts: 42152
937
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bug,
As a hack, you could have the filter run for all requests and use an if statement with your regexp to not do anything for the images and javascript directories.
 
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wouldn't condsider that a hack at all. Some of my filters frequently inspect the incoming request to determine what action to take.
reply
    Bookmark Topic Watch Topic
  • New Topic