portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tay...@apache.org
Subject cvs commit: jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/engine/servlet ServletRequestImpl.java
Date Wed, 11 Aug 2004 21:21:41 GMT
taylor      2004/08/11 14:21:41

  Modified:    portal/src/java/org/apache/jetspeed/engine/servlet
                        ServletRequestImpl.java
  Log:
  hook into Jetspeed's Request Context to get the User Principal provided via Security Valve
  
  CVS: ----------------------------------------------------------------------
  CVS: PR:
  CVS:   If this change addresses a PR in the problem report tracking
  CVS:   database, then enter the PR number(s) here.
  CVS: Obtained from:
  CVS:   If this change has been taken from another system, such as NCSA,
  CVS:   then name the system in this line, otherwise delete it.
  CVS: Submitted by:
  CVS:   If this code has been contributed to Apache by someone else; i.e.,
  CVS:   they sent us a patch or a new module, then include their name/email
  CVS:   address here. If this is your work then delete this line.
  CVS: Reviewed by:
  CVS:   If we are doing pre-commit code reviews and someone else has
  CVS:   reviewed your changes, include their name(s) here.
  CVS:   If you have not had it reviewed then delete this line.
  
  Revision  Changes    Path
  1.21      +27 -3     jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/engine/servlet/ServletRequestImpl.java
  
  Index: ServletRequestImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/engine/servlet/ServletRequestImpl.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- ServletRequestImpl.java	5 Aug 2004 04:50:29 -0000	1.20
  +++ ServletRequestImpl.java	11 Aug 2004 21:21:41 -0000	1.21
  @@ -16,6 +16,7 @@
   package org.apache.jetspeed.engine.servlet;
   
   import java.io.UnsupportedEncodingException;
  +import java.security.Principal;
   import java.util.ArrayList;
   import java.util.Collections;
   import java.util.Enumeration;
  @@ -23,6 +24,7 @@
   import java.util.Iterator;
   import java.util.Locale;
   import java.util.Map;
  +import java.util.Set;
   
   import javax.portlet.PortletRequest;
   
  @@ -171,8 +173,10 @@
        */
       public boolean isUserInRole(String roleName)
       {
  -        // will result in a NullPointerException if roleName == null which is
  -        // just as well I guess.
  +        if (roleName == null)
  +        {
  +            return false;
  +        }
           if (roleName.length() > 0)
           {
               PortletDefinition portletDefinition = portletWindow.getPortletEntity().getPortletDefinition();
  @@ -204,6 +208,26 @@
               }
           }
           return false;
  +   }
  +    
  +
  +    public Principal getUserPrincipal()
  +    {
  +        JetspeedRequestContext context = (JetspeedRequestContext) getAttribute("org.apache.jetspeed.request.RequestContext");
  +        if (context != null)
  +        {
  +            Set principals = context.getSubject().getPrincipals();
  +            if (principals != null)
  +            {
  +                Iterator it = principals.iterator();
  +                if (it.hasNext())
  +                {
  +                    return (Principal)it.next();
  +                }
  +            }
  +        }
  +        return super.getUserPrincipal();
  +        
       }
   
       /**
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org


Mime
View raw message