Welcome!

Cloud Security Authors: Zakia Bouachraoui, Yeshim Deniz, Terry Ray, Liz McMillan, Pat Romanski

Related Topics: Java IoT, Cloud Security

Java IoT: Article

Effective Page Authorization In JavaServer Faces

Application security - the art of applications defending themselves - represents an important line of defence

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/*).
For each protected page or directory, the developer defines the authentication, authorization, and SSL requirements. If a page requires SSL, but the current request protocol is HTTP, the J2EESecurityPhaseListener redirects the request to a configured HTTPS port. Similarly, if the protocol is currently HTTPS but the page doesn't require a secure channel and the keep-ssl-mode is set to false, the PhaseListener redirects the request to the HTTP port.

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.
Once set up, the J2EESecurityPhaseListener lets developers apply authorization to any JSF page navigation - a forward or a redirect - while still using standard container mechanisms to handle authentication and role definition.

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

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.

Comments (6) View Comments

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


Most Recent Comments
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:
1-start the application by calling a page that requires authentication and authorization.
2-the system shall direct you to the login page.

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.
I was wondering the article is based on Container-Managed Security or reading roles from web.xml. I have a requirement where I need to read the roles from database and not from web.xml, can I achieve this security feature by implementing the points mentioned in this article.
Awaiting for your response.
Thanks and Regards,
Keerthi.

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.

IoT & Smart Cities Stories
The deluge of IoT sensor data collected from connected devices and the powerful AI required to make that data actionable are giving rise to a hybrid ecosystem in which cloud, on-prem and edge processes become interweaved. Attendees will learn how emerging composable infrastructure solutions deliver the adaptive architecture needed to manage this new data reality. Machine learning algorithms can better anticipate data storms and automate resources to support surges, including fully scalable GPU-c...
Machine learning has taken residence at our cities' cores and now we can finally have "smart cities." Cities are a collection of buildings made to provide the structure and safety necessary for people to function, create and survive. Buildings are a pool of ever-changing performance data from large automated systems such as heating and cooling to the people that live and work within them. Through machine learning, buildings can optimize performance, reduce costs, and improve occupant comfort by ...
The explosion of new web/cloud/IoT-based applications and the data they generate are transforming our world right before our eyes. In this rush to adopt these new technologies, organizations are often ignoring fundamental questions concerning who owns the data and failing to ask for permission to conduct invasive surveillance of their customers. Organizations that are not transparent about how their systems gather data telemetry without offering shared data ownership risk product rejection, regu...
René Bostic is the Technical VP of the IBM Cloud Unit in North America. Enjoying her career with IBM during the modern millennial technological era, she is an expert in cloud computing, DevOps and emerging cloud technologies such as Blockchain. Her strengths and core competencies include a proven record of accomplishments in consensus building at all levels to assess, plan, and implement enterprise and cloud computing solutions. René is a member of the Society of Women Engineers (SWE) and a m...
Poor data quality and analytics drive down business value. In fact, Gartner estimated that the average financial impact of poor data quality on organizations is $9.7 million per year. But bad data is much more than a cost center. By eroding trust in information, analytics and the business decisions based on these, it is a serious impediment to digital transformation.
Digital Transformation: Preparing Cloud & IoT Security for the Age of Artificial Intelligence. As automation and artificial intelligence (AI) power solution development and delivery, many businesses need to build backend cloud capabilities. Well-poised organizations, marketing smart devices with AI and BlockChain capabilities prepare to refine compliance and regulatory capabilities in 2018. Volumes of health, financial, technical and privacy data, along with tightening compliance requirements by...
Predicting the future has never been more challenging - not because of the lack of data but because of the flood of ungoverned and risk laden information. Microsoft states that 2.5 exabytes of data are created every day. Expectations and reliance on data are being pushed to the limits, as demands around hybrid options continue to grow.
Digital Transformation and Disruption, Amazon Style - What You Can Learn. Chris Kocher is a co-founder of Grey Heron, a management and strategic marketing consulting firm. He has 25+ years in both strategic and hands-on operating experience helping executives and investors build revenues and shareholder value. He has consulted with over 130 companies on innovating with new business models, product strategies and monetization. Chris has held management positions at HP and Symantec in addition to ...
Enterprises have taken advantage of IoT to achieve important revenue and cost advantages. What is less apparent is how incumbent enterprises operating at scale have, following success with IoT, built analytic, operations management and software development capabilities - ranging from autonomous vehicles to manageable robotics installations. They have embraced these capabilities as if they were Silicon Valley startups.
As IoT continues to increase momentum, so does the associated risk. Secure Device Lifecycle Management (DLM) is ranked as one of the most important technology areas of IoT. Driving this trend is the realization that secure support for IoT devices provides companies the ability to deliver high-quality, reliable, secure offerings faster, create new revenue streams, and reduce support costs, all while building a competitive advantage in their markets. In this session, we will use customer use cases...