You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by Apache Wiki <wi...@apache.org> on 2007/05/15 16:12:12 UTC

[Myfaces Wiki] Update of "SecurityContext" by StephanStrittmatter

Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Myfaces Wiki" for change notification.

The following page has been changed by StephanStrittmatter:
http://wiki.apache.org/myfaces/SecurityContext

The comment on the change is:
adding Portlet SecurityContext

------------------------------------------------------------------------------
  
  Note: User-role Awareness attributes enabledOnUserRole and visibleOnUserRole will be deprecated in future releases.
  
+ == Portlet SecurityContext ==
+ For portlets there is a standardisized way to access these values. You can use following implementation if the portal is JSR-168 conform (tested with Liferay 4.1.3):
+ 
+ {{{
+ 
+ import javax.faces.context.FacesContext;
+ import javax.portlet.PortletRequest;
+ 
+ import org.apache.myfaces.custom.security.SecurityContext;
+ 
+ public class PortletSecurityContext extends SecurityContext {
+ 
+   /**
+    * @see org.apache.myfaces.custom.security.SecurityContext#getAuthType()
+    */
+   public String getAuthType() {
+ 
+     FacesContext context = FacesContext.getCurrentInstance();    
+     PortletRequest portletReq = (PortletRequest) context.getExternalContext().getRequest();
+ 
+     return portletReq.getAuthType();
+   }
+ 
+   /**
+    * @see org.apache.myfaces.custom.security.SecurityContext#getRemoteUser()
+    */
+   public String getRemoteUser() {
+     
+     FacesContext context = FacesContext.getCurrentInstance();    
+     PortletRequest portletReq = (PortletRequest) context.getExternalContext().getRequest();
+  
+     return portletReq.getRemoteUser(); 
+   }
+ 
+   /**
+    * @see org.apache.myfaces.custom.security.SecurityContext#ifGranted(java.lang.String)
+    */
+   public boolean ifGranted(String role) {
+ 
+     FacesContext context = FacesContext.getCurrentInstance();     
+     PortletRequest portletReq = (PortletRequest) context.getExternalContext().getRequest();
+ 
+     return portletReq.isUserInRole(role);
+   }
+ }
+ 
+ }}}
+