It's not a secret anymore!
The moose likes JSF and the fly likes How to protect URL web resources through declarative security in a JSF application? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » JSF
Reply Bookmark "How to protect URL web resources through declarative security in a JSF application?" Watch "How to protect URL web resources through declarative security in a JSF application?" New topic
Author

How to protect URL web resources through declarative security in a JSF application?

Tomasz Romanowski
Ranch Hand

Joined: May 06, 2009
Posts: 38
I'm trying to implement web resource security in a JSF application but the behavior is strange. It seems like it's protecting not the resource that should be protected but the next resource that is requested afterwards. Maybe it has something to do with the fact that in a JSF application the URL you see in the browser is always one step "behind"?
Example:
<security-constraint>
<web-resource-collection>
<web-resource-name>Create Customer</web-resource-name>
<url-pattern>/faces/customer/New.jsp</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>poweruser</role-name>
</auth-constraint>
</security-constraint>

I would expect the be prompted for the password when I open up the new customer form. Instead, the customer form opens up without any protection, while I get prompted "After the fact", i.e. when I submit the form or click any button I made available on the form.
I'm using Netbeans and glassfish.
Tom
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 14491
    
    7

Yup. Container (declarative) security is based on the incoming URL and not on what's actually being accessed. One of the more annoying things about JSF.

The way around this is to add the "<redirect/>" element to your navigation rule that's displaying the new page. That will cause JSF to internally redirect, setting the URL to indicate the actual new view and thereby applying the proper security filtering.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: How to protect URL web resources through declarative security in a JSF application?
 
Similar Threads
Neat Way of Writing my web.xml
Keep having to login with container based authentaction.
security-constraint login error
Form Authentication not working
Tomcat with multiple auth-constraints