|
YOUR FEEDBACK
Did you read today's front page stories & breaking news?
SYS-CON.TV |
TOP THREE LINKS YOU MUST CLICK ON Hibernate | JSF | Spring Effective Page Authorization In JavaServer Faces
Application security - the art of applications defending themselves - represents an important line of defence
Aug. 10, 2006 05:15 PM
Listing 5 Indicating that a Web resource requires SSL
<user-data-constraint> Though J2EE Web resources can be configured to require HTTPS this way, the J2EE specification doesn't demand that Web containers respond by automatically switching protocols. Instead, J2EE containers usually return an HTTP error message to indicate a failed user request. Individual J2EE containers like Apache Tomcat provide native support for switching between the HTTP and HTTPS protocol. However, you ought to be aware that such solutions aren't portable to other J2EE containers.
Page Navigation in JavaServer Faces Page navigation in JavaServer Faces is defined in the WEB-INF\faces-config.xml file, where the JSF NavigationHandler component uses it. The application developer configures navigation in JSF either as a server-side forward or, if the <redirect/> element is included in the navigation case, as a browser redirect. Listing 6 JSF navigation case issuing a redirect request for page navigation
<navigation-case> Server-side forwards are the de facto default implementation of navigation cases in JSF, but such navigation harbors two side effects: first, the URL won't change, and so pages in the application aren't bookmarkable; and secondly, there's no new submission of a URL pattern for container-managed security to be applied to. As a consequence, if you've implemented container-managed security, you'll have to use <redirect/> explicitly on any navigation cases that have to trigger a security check across role boundaries. It should be clear by now that authorizing pages and implementing a secure channel for communication isn't easy to achieve in JavaServer Faces. And using JAAS instead of container-managed security offers no better solution. The answer lies in a combined approach: a reusable custom security implementation specifically designed to work with JSF based on JAAS or container-managed J2EE security.
Where Does Security Belong in JavaServer Faces? The authorization enforcer security pattern demands that authorization be handled in a central location. For many Web applications, this central location is a ServletFilter associated with the application front controller. In JSF, though, security is best implemented using the built-in extension points provided by the JavaServer Faces architecture. The two candidate approaches for implementing security in JSF are:
Developing a JavaServer Faces PhaseListener for Security To execute custom logic before and after a specific event, custom application code is added to the beforePhase and afterPhase methods of a PhaseListener. Both methods accept an input argument of a PhaseEvent to provide information about the calling phase, for example, a phase ID. The third method developers have to implement is getPhaseId. The getPhaseId method is used to declare which phases the listener is actually interested in being notified about. Listing 7 Custom PhaseListener listening to any event and implementing the JSf PhaseListener interface
public class J2EESecurityPhaseListener implements PhaseListener An application can have more than one PhaseListener configured. PhaseListeners are configured in the <lifecycle> element of the faces-config.xml configuration file. Listing 8 PhaseListener configuration in faces-config.xml
<lifecycle> Java IDEs like Oracle JDeveloper provide visual editors to simplify this configuration of the faces-config.xml file.
A J2EE security PhaseListener - J2EESecurityPhaseListener YOUR FEEDBACK
LATEST JAVA STORIES & POSTS
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
|
SYS-CON FEATURED WHITEPAPERS MOST READ THIS WEEK SPONSORED BY INFRAGISTICS
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||