The Wayback Machine - https://web.archive.org/web/20180210203922/http://security.sys-con.com/node/250254

Welcome!

Cloud Security Authors: Otto Berkes, Rostyslav Demush, John Katrick, Kevin Jackson, Elizabeth White

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

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.

 JavaServer Faces, the new J2EE standard for building feature-rich Web applications with JEE 1.5, has few integrated security features. JSF generously delegates the task of implementing application security such as page authorization to the application developer, leaving many developers pondering where to start, where best to put security, and which security technology to choose.

This article aims to answer such questions for authorization in JavaServer Faces, demonstrating how a custom PhaseListener that uses J2EE container-managed security can be used to implement access control for JSF pages. Besides page authorization, the security PhaseListener supports protocol switching between HTTP and HTTPS, a common requirement of applications that work with sensitive data on a Web page.

The J2EE Security Choices
The J2EE platform provides two built-in security technologies for the application developer to use: the Java Authentication and Authorization Service (JAAS) and container-managed security, also known as J2EE security.

The Java Authentication and Authorization Service is a J2SE 1.4 security standard designed for the Java desktop that's also used as an implementation technology for security in J2EE. The JAAS authentication infrastructure is built as a Java version of the Pluggable Authentication Module (PAM) architecture that allows one or more authentication providers to be used for user identification. Before JAAS, the Java 2 security platform was code-centric, determining access privileges based solely on the location of the Java sources. Using JAAS, Java security now also looks at the authenticated user when evaluating access control to resources. JAAS's benefit is its ability to implement fine-grained access control through external Java permission classes, which associate users with a list of resources and allowed actions.

Authentication and authorization in J2EE security is configured declaratively in the application's web.xml deployment descriptor and handled by the J2EE container at runtime. Working with APIs defined in the J2EE servlet standard, application developers don't have to worry about the implementation of security in a container. In container-managed security, authorization is enforced on URL patterns, which are absolute or relative URLs. This however also means that authorization is only enforced on requests that are initiated by the client, not as server-side forward requests.

Ease of use, the clean separation of security definition and application code, and portability across application servers are the main reasons for the wide adoption of container-managed security among business application developers. J2EE security is sufficient to implement many common security use cases. As a reflection of its popularity and its portability, container-managed security is used in the code examples of this article to illustrate effective page authorization in JavaServer Faces.

Container-Managed Security in J2EE
In container-managed security, a user is granted access to protected URL resources through security roles defined in the web.xml deployment descriptor. Security roles in J2EE are logical names used in Web applications that are mapped during or after deployment to user groups that exist on the target application server platform.

Listing 1 Web.xml excerpt granting the app_user security role access to the protected URL resource /faces/protected/*

<security-constraint>
    <Web-resource-collection>
    <Web-resource-name>Members</Web-resource-name>
    <url-pattern>/faces/protected/*</url-pattern>
    </Web-resource-collection>
    <auth-constraint>
       <role-name>app_user</role-name>
    </auth-constraint>
</security-constraint>
...
<security-role>
    <role-name>app_user</role-name>
</security-role>

To access a protected application resource, Web application users must first authenticate, which in container-managed security is handled by the J2EE container. Either the application developer or the application deployer configures the type of authentication in the web.xml deployment descriptor.

Listing 2 Basic authentication defined for the jazn.com realm

<login-config>
     <auth-method>BASIC</auth-method>
     <realm-name>jazn.com</realm-name>
</login-config>

To check authorization programmatically in an J2EE application - like in JavaServer Faces - application developers use the isUserInRole method in the servlet API. This isUserInRole method is also exposed via a convenience method in JavaServer Faces through the static FacesContext class. Role names referenced in application code ought to be mapped to roles defined in the web.xml file using the <security-role-ref> element if the role names don't match. Using the <security-role-ref> element, developers don't have to be aware of the security role names that exist in the web.xml descriptor when developing an application.

Listing 3 Mapping the "user" role name used in the application code to the security role name "manager_role" defined in the web.xml file

<security-role-ref>
     <role-name>user</role-name>
     <role-link>app_user</role-link>
</security-role-ref>

If the authenticated user isn't authorized to access the requested URL resource, the J2EE container responds with HTTP error 403, indicating a bad request. A HTTP error 401 is returned if a user cancels the authentication process. HTTP error codes and Java exceptions are handled declaratively in the web.xml file using the <error-page> element.

Listing 4 Redirecting a request in response to unauthorized page access handling error code 403 and 401

<error-page>
     <error-code>403</error-code>
     <location>Error.jsp</location>
</error-page>
<error-page>
     <error-code>401</error-code>
     <location>Logon_cancelled.jsp</location>
</error-page>

If SSL is required to ensure secure communication when accessing a specific Web resource, the <security-constraint> element added for a protected resource contains an additional <user-data-constraint> element. Setting the transport guarantee to "confidential" indicates that SSL is required.


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.

@ThingsExpo Stories
Widespread fragmentation is stalling the growth of the IIoT and making it difficult for partners to work together. The number of software platforms, apps, hardware and connectivity standards is creating paralysis among businesses that are afraid of being locked into a solution. EdgeX Foundry is unifying the community around a common IoT edge framework and an ecosystem of interoperable components.
DX World EXPO, LLC, a Lighthouse Point, Florida-based startup trade show producer and the creator of "DXWorldEXPO® - Digital Transformation Conference & Expo" has announced its executive management team. The team is headed by Levent Selamoglu, who has been named CEO. "Now is the time for a truly global DX event, to bring together the leading minds from the technology world in a conversation about Digital Transformation," he said in making the announcement.
In this strange new world where more and more power is drawn from business technology, companies are effectively straddling two paths on the road to innovation and transformation into digital enterprises. The first path is the heritage trail – with “legacy” technology forming the background. Here, extant technologies are transformed by core IT teams to provide more API-driven approaches. Legacy systems can restrict companies that are transitioning into digital enterprises. To truly become a lead...
Digital Transformation (DX) is not a "one-size-fits all" strategy. Each organization needs to develop its own unique, long-term DX plan. It must do so by realizing that we now live in a data-driven age, and that technologies such as Cloud Computing, Big Data, the IoT, Cognitive Computing, and Blockchain are only tools. In her general session at 21st Cloud Expo, Rebecca Wanta explained how the strategy must focus on DX and include a commitment from top management to create great IT jobs, monitor ...
"Cloud Academy is an enterprise training platform for the cloud, specifically public clouds. We offer guided learning experiences on AWS, Azure, Google Cloud and all the surrounding methodologies and technologies that you need to know and your teams need to know in order to leverage the full benefits of the cloud," explained Alex Brower, VP of Marketing at Cloud Academy, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clar...
The IoT Will Grow: In what might be the most obvious prediction of the decade, the IoT will continue to expand next year, with more and more devices coming online every single day. What isn’t so obvious about this prediction: where that growth will occur. The retail, healthcare, and industrial/supply chain industries will likely see the greatest growth. Forrester Research has predicted the IoT will become “the backbone” of customer value as it continues to grow. It is no surprise that retail is ...
"Space Monkey by Vivent Smart Home is a product that is a distributed cloud-based edge storage network. Vivent Smart Home, our parent company, is a smart home provider that places a lot of hard drives across homes in North America," explained JT Olds, Director of Engineering, and Brandon Crowfeather, Product Manager, at Vivint Smart Home, in this SYS-CON.tv interview at @ThingsExpo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
SYS-CON Events announced today that Conference Guru has been named “Media Sponsor” of the 22nd International Cloud Expo, which will take place on June 5-7, 2018, at the Javits Center in New York, NY. A valuable conference experience generates new contacts, sales leads, potential strategic partners and potential investors; helps gather competitive intelligence and even provides inspiration for new products and services. Conference Guru works with conference organizers to pass great deals to gre...
The Internet of Things will challenge the status quo of how IT and development organizations operate. Or will it? Certainly the fog layer of IoT requires special insights about data ontology, security and transactional integrity. But the developmental challenges are the same: People, Process and Platform. In his session at @ThingsExpo, Craig Sproule, CEO of Metavine, demonstrated how to move beyond today's coding paradigm and shared the must-have mindsets for removing complexity from the develop...
In his Opening Keynote at 21st Cloud Expo, John Considine, General Manager of IBM Cloud Infrastructure, led attendees through the exciting evolution of the cloud. He looked at this major disruption from the perspective of technology, business models, and what this means for enterprises of all sizes. John Considine is General Manager of Cloud Infrastructure Services at IBM. In that role he is responsible for leading IBM’s public cloud infrastructure including strategy, development, and offering m...
"Evatronix provides design services to companies that need to integrate the IoT technology in their products but they don't necessarily have the expertise, knowledge and design team to do so," explained Adam Morawiec, VP of Business Development at Evatronix, in this SYS-CON.tv interview at @ThingsExpo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
To get the most out of their data, successful companies are not focusing on queries and data lakes, they are actively integrating analytics into their operations with a data-first application development approach. Real-time adjustments to improve revenues, reduce costs, or mitigate risk rely on applications that minimize latency on a variety of data sources. In his session at @BigDataExpo, Jack Norris, Senior Vice President, Data and Applications at MapR Technologies, reviewed best practices to ...
Large industrial manufacturing organizations are adopting the agile principles of cloud software companies. The industrial manufacturing development process has not scaled over time. Now that design CAD teams are geographically distributed, centralizing their work is key. With large multi-gigabyte projects, outdated tools have stifled industrial team agility, time-to-market milestones, and impacted P&L; stakeholders.
"Akvelon is a software development company and we also provide consultancy services to folks who are looking to scale or accelerate their engineering roadmaps," explained Jeremiah Mothersell, Marketing Manager at Akvelon, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
"IBM is really all in on blockchain. We take a look at sort of the history of blockchain ledger technologies. It started out with bitcoin, Ethereum, and IBM evaluated these particular blockchain technologies and found they were anonymous and permissionless and that many companies were looking for permissioned blockchain," stated René Bostic, Technical VP of the IBM Cloud Unit in North America, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Conventi...
In his session at 21st Cloud Expo, Carl J. Levine, Senior Technical Evangelist for NS1, will objectively discuss how DNS is used to solve Digital Transformation challenges in large SaaS applications, CDNs, AdTech platforms, and other demanding use cases. Carl J. Levine is the Senior Technical Evangelist for NS1. A veteran of the Internet Infrastructure space, he has over a decade of experience with startups, networking protocols and Internet infrastructure, combined with the unique ability to it...
22nd International Cloud Expo, taking place June 5-7, 2018, at the Javits Center in New York City, NY, and co-located with the 1st DXWorld Expo will feature technical sessions from a rock star conference faculty and the leading industry players in the world. Cloud computing is now being embraced by a majority of enterprises of all sizes. Yesterday's debate about public vs. private has transformed into the reality of hybrid cloud: a recent survey shows that 74% of enterprises have a hybrid cloud ...
Gemini is Yahoo’s native and search advertising platform. To ensure the quality of a complex distributed system that spans multiple products and components and across various desktop websites and mobile app and web experiences – both Yahoo owned and operated and third-party syndication (supply), with complex interaction with more than a billion users and numerous advertisers globally (demand) – it becomes imperative to automate a set of end-to-end tests 24x7 to detect bugs and regression. In th...
"MobiDev is a software development company and we do complex, custom software development for everybody from entrepreneurs to large enterprises," explained Alan Winters, U.S. Head of Business Development at MobiDev, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
Coca-Cola’s Google powered digital signage system lays the groundwork for a more valuable connection between Coke and its customers. Digital signs pair software with high-resolution displays so that a message can be changed instantly based on what the operator wants to communicate or sell. In their Day 3 Keynote at 21st Cloud Expo, Greg Chambers, Global Group Director, Digital Innovation, Coca-Cola, and Vidya Nagarajan, a Senior Product Manager at Google, discussed how from store operations and ...