| By Duncan Mills, Frank Nimphius | Article Rating: |
|
| August 10, 2006 05:15 PM EDT | Reads: |
68,397 |
Listing 9 The J2EESecurityPhaseListener listens to any event but responds to RestoreView and InvokeApplication only
public void afterPhase(PhaseEvent phaseEvent)
{
PhaseId phaseid = phaseEvent.getPhaseId();
if ( phaseid == PhaseId.RESTORE_VIEW||
phaseid == PhaseId.INVOKE_APPLICATION )
{ ... }
}
The J2EESecurityPhaseListener uses an extra XML configuration file, faces-security-config.xml, to define JSF pages that require authentication, authorization, or secure communication with SSL. The faces-security-config.xml file is located in the WEB-INF directory like the JavaServer Faces faces-config.xml file.
The security PhaseListener parses the faces-security-config.xml file with the Apache Digester [DIGESTER] to create a Java security object that is subsequently cached in the application scope. The security object contains security information about the configured HTTP and HTTPS ports, whether or not to keep SSL after it's used the first time, and individual authentication, authorization, and SSL requirements for each page.
The PhaseListener determines page authorization only once per session for each JSF page (viewId) that a user requests. At successful authorization, a reference to the JSF page is cached in the session to improve performance on subsequent requests for the same resource.
A user who requests a protected page without first having been authenticated is redirected to an authentication servlet. The authentication servlet is configured in the web.xml deployment descriptor and protected by a J2EE security role that all users are members of. All JSF pages configured in the faces-security-comfig.xml file to require authorization implicitly also require authentication. If an unauthenticated user tries to access a page that requires SSL, a container-managed logon form is launched over HTTPS.
The faces-security-config.xml file consists of two parts:
- A global configuration section to provide HTTP and HTTPS port information and whether SSL communication should be kept once established. The keep-SSL-mode information overrides the individual page configuration for SSL.
- Multiple jsf-page elements to configure page and directory authorization. The page is identified by its viewId, which starts with a leading slash followed by the relative URI, not excluding the faces virtual mapping (for example, /protected/main.jsp). Directory names are indicated by an appended wildcard character '*' (for example, /protected/*).
JSF pages and directories that require authorization have to reference the name of one or more J2EE security roles defined in the web.xml file. The role-concatenation attribute lets developers specify whether a user has to be a member of all the configured roles (AND) or only a single role (OR).
Because the security configurations are stored in an XML file, the page authentication strategy and the authorization definitions can be changed at any time without recompiling or redeploying the application.
To use the J2EESecurityPhaseListener in custom JSF applications, developers do the following
- Deploy the jsfj2ee-security-util.jar file as a library with the application.
- Create and configure the faces-security-config.xml file in the application WEB-INF directory.
- For protocol switching, configure the HTTP and HTTPS ports and ensure that the application server is set up to share a session between the two ports.
- Configure the authentication servlet in the web.xml file.
- Configure container-managed authentication and J2EE security roles in the web.xml file.
To improve default container-managed security, the J2EESecurityPhaseListener also lets developers configure page authorizations that use multiple J2EE roles, rather than having to define multiple roles to achieve fine-grained authorization in conventional container-managed security.
Completing the Page Authorization Picture with a Custom Property Resolver
The "limited view" security design pattern defines what users can view
and access and lets them access accordingly. Protecting a page from
unauthorized access alone isn't enough. UI components that initiate
page navigation should be hidden if the user is not allowed access the
navigation target. To set a component's rendered property to false,
expression language (EL) can be used. The EL can be sourced from
handcrafted managed beans defined as part of the application or more
generically through a security-aware custom variable resolver. A sample
resolver of this type is available for download at jsf-security.sourceforge.net/.
Summary
Without a doubt, JavaServer Faces is a
great step forward for J2EE application development. Application
security is, however, an important component in the development
lifecycle and, unfortunately, this is where the current JavaServer
Faces specification falls short. In the future, we would hope and
expect that security integration, perhaps of a nature similar to that
discussed in this article and the associated code, will be added to the
specification.
The custom J2EESecurityPhase-Listener developed for this article uses container-managed security for the sake of simplicity, but it can be adapted to use either JAAS or a custom security provider. The source code for this PhaseListener based solution can be downloaded with this article.
References
- E. Burns, C. Schalk. JavaServer Faces: The Complete Reference. ISBN 0072262400
- D. Alur, J. Crupi, and D. Malks. Core J2EE Patterns: Best Practices and Design Strategies. 2d ed. ISBN 0-13-142246-4
- jsf-security.sourceforge.net/
- DIGESTER: jakarta.apache.org/commons/digester/
Published August 10, 2006 Reads 68,397
Copyright © 2006 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Duncan Mills
Duncan Mills is senior director of product management for Oracle's Application Development Tools - including the JDeveloper IDE, and the Oracle Application Development Framework. He has been in the IT industry for the past 19 years working with Oracle, Java, and a variety of more obscure programming languages and frameworks along the way. Duncan is the co-author of the Oracle Press book: Oracle JDeveloper 10g for Forms and PL/SQL Developers - a Guide to Web Development with Oracle ADF.
More Stories By Frank Nimphius
Frank Nimphius is a principal product manager for application development tools at Oracle Corporation. As a conference speaker, Frank represents the Oracle J2EE development team at J2EE conferences world wide, including various Oracle user groups and the Oracle Open World conference.
![]() |
y_alomoush 09/01/08 04:29:19 PM EDT | |||
Hi Duncan and Frank, Thanks for your great efforts. It is a job well done. In fact,I have installed the module and plugged it to my own application for evaluation purposes.However, I have found a scenario where a user can access into a unauthorized page, I don't know if I can call it as a bug or not. The scenario is as the following: 3-enter a correct username/password but not authorized to access that page. 3-system shall redirect you to error page using the sendError method. 4-call the same page again (using the same session). the system strangely forward you to the page that you are not authorized to access.(because the page is already cached as an authorized page) I think after the page is redirected to the error page the handleSecurity method must return, in this case, false instead of retuning true, this in order not to cache an unauthorized page. Thank yo once again. |
||||
![]() |
keerthi 09/21/06 10:22:56 AM EDT | |||
Hi Duncan and Frank, This article is really an interesting one. I found it at a right moment of time as I was trying to implement Page level security in a Project based on JSF. |
||||
![]() |
SYS-CON Italy News Desk 08/10/06 05:42:31 PM EDT | |||
Application security - the art of applications defending themselves - represents an important line of defence in an overall in-depth security strategy. Web applications that follow the Model-View-Controller (MVC) architecture can, and should, have security implemented on all three layers. Normally it's the controller component that handles page authorization in MVC, the view layer that hides controls and information based on user authorization, and the model that enforces the business rules and input validation. However, it's up to the developer, based on an individual security policy and the programming technology used, to decide where to put security. Using pluggable validator components in JavaServer Faces (JSF), for example, developers may decide to verify user input on the view layer as well as on the model layer. |
||||
![]() |
AJAXWorld News Desk 08/10/06 05:26:41 PM EDT | |||
Application security - the art of applications defending themselves - represents an important line of defence in an overall in-depth security strategy. Web applications that follow the Model-View-Controller (MVC) architecture can, and should, have security implemented on all three layers. Normally it's the controller component that handles page authorization in MVC, the view layer that hides controls and information based on user authorization, and the model that enforces the business rules and input validation. However, it's up to the developer, based on an individual security policy and the programming technology used, to decide where to put security. Using pluggable validator components in JavaServer Faces (JSF), for example, developers may decide to verify user input on the view layer as well as on the model layer. |
||||
![]() |
JDJ News Desk 07/26/06 05:18:34 PM EDT | |||
Application security - the art of applications defending themselves - represents an important line of defence in an overall in-depth security strategy. Web applications that follow the Model-View-Controller (MVC) architecture can, and should, have security implemented on all three layers. Normally it's the controller component that handles page authorization in MVC, the view layer that hides controls and information based on user authorization, and the model that enforces the business rules and input validation. However, it's up to the developer, based on an individual security policy and the programming technology used, to decide where to put security. Using pluggable validator components in JavaServer Faces (JSF), for example, developers may decide to verify user input on the view layer as well as on the model layer. |
||||
![]() |
JDJ News Desk 07/26/06 04:40:02 PM EDT | |||
Application security - the art of applications defending themselves - represents an important line of defence in an overall in-depth security strategy. Web applications that follow the Model-View-Controller (MVC) architecture can, and should, have security implemented on all three layers. Normally it's the controller component that handles page authorization in MVC, the view layer that hides controls and information based on user authorization, and the model that enforces the business rules and input validation. However, it's up to the developer, based on an individual security policy and the programming technology used, to decide where to put security. Using pluggable validator components in JavaServer Faces (JSF), for example, developers may decide to verify user input on the view layer as well as on the model layer. |
||||
- Kindle 2 vs Nook
- Why IBM’s Server Chief Got Busted
- Is Cloud Computing Like Teenage Sex?
- Industry Experts Discuss the State of Cloud Computing
- Performance Tuning Essentials for Java
- Confessions of a Ulitzer Addict
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- It's the Java vs. C++ Shootout Revisited!
- Cloud Computing Can Revitalize Your Career as Software Developer
- IBM Could "Reinvent" Java: Mills
- Oracle & Cloud Computing: Exclusive Q&A with SVP Richard Sarwal
- A Brief History of Cloud Computing
- Kindle 2 vs Nook
- Cloud CEOs, CTOs & SVPs to Speak at 4th International Cloud Computing Expo
- Why IBM’s Server Chief Got Busted
- Is Cloud Computing Like Teenage Sex?
- Industry Experts Discuss the State of Cloud Computing
- Performance Tuning Essentials for Java
- The Difference Between Web Hosting and Cloud Computing
- Cloud Computing Expo: Exclusive Q&A with Yahoo! SVP Cloud Computing
- Ajax in RichFaces 3.3, JSF 2 and RichFaces 4
- Confessions of a Ulitzer Addict
- My Thoughts on Ulitzer
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- A Cup of AJAX? Nay, Just Regular Java Please
- Java Developer's Journal Exclusive: 2006 "JDJ Editors' Choice" Awards
- The i-Technology Right Stuff
- JavaServer Faces (JSF) vs Struts
- Rich Internet Applications with Adobe Flex 2 and Java
- Java vs C++ "Shootout" Revisited
- Bean-Managed Persistence Using a Proxy List
- Reporting Made Easy with JasperReports and Hibernate
- Creating a Pet Store Application with JavaServer Faces, Spring, and Hibernate
- What's New in Eclipse?
- Why Do 'Cool Kids' Choose Ruby or PHP to Build Websites Instead of Java?
- i-Technology Predictions for 2007: Where's It All Headed?










































