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/fusion/src/java/org/apache/jetspeed/fusion/engine/servlet FusionServletRequestFactoryImpl.java FusionServletRequestImpl.java
Date Thu, 12 Aug 2004 18:41:19 GMT
taylor      2004/08/12 11:41:19

  Modified:    fusion/src/java/org/apache/jetspeed/fusion/engine/servlet
                        FusionServletRequestImpl.java
  Added:       fusion/src/java/org/apache/jetspeed/fusion/engine/servlet
                        FusionServletRequestFactoryImpl.java
  Log:
  complete impl of hybrid isUserInRole which makes use of both J1 and JAAS security checks
  
  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.3       +51 -2     jakarta-jetspeed/fusion/src/java/org/apache/jetspeed/fusion/engine/servlet/FusionServletRequestImpl.java
  
  Index: FusionServletRequestImpl.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed/fusion/src/java/org/apache/jetspeed/fusion/engine/servlet/FusionServletRequestImpl.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- FusionServletRequestImpl.java	12 Aug 2004 17:37:44 -0000	1.2
  +++ FusionServletRequestImpl.java	12 Aug 2004 18:41:19 -0000	1.3
  @@ -15,12 +15,22 @@
    */
   package org.apache.jetspeed.fusion.engine.servlet;
   
  +import java.util.Iterator;
  +
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   import org.apache.jetspeed.engine.servlet.ServletRequestImpl;
   import org.apache.jetspeed.services.JetspeedSecurity;
  +import org.apache.jetspeed.services.rundata.JetspeedRunDataService;
   import org.apache.jetspeed.services.security.JetspeedSecurityException;
  +import org.apache.pluto.om.common.SecurityRole;
  +import org.apache.pluto.om.common.SecurityRoleRef;
  +import org.apache.pluto.om.common.SecurityRoleRefSet;
  +import org.apache.pluto.om.common.SecurityRoleSet;
  +import org.apache.pluto.om.portlet.PortletDefinition;
   import org.apache.pluto.om.window.PortletWindow;
  +import org.apache.turbine.services.TurbineServices;
  +import org.apache.turbine.services.rundata.RunDataService;
   
   /**
    * @author <a href="mailto:jford@apache.org">Jeremy Ford</a>
  @@ -41,6 +51,14 @@
           this.portletWindow = window;
       }
       
  +    private String getUserName()
  +    {
  +        JetspeedRunDataService runDataService =
  +            (JetspeedRunDataService)TurbineServices.getInstance()
  +                .getService(RunDataService.SERVICE_NAME);
  +        return runDataService.getCurrentRunData().getJetspeedUser().getUserName();    
   
  +    }
  +    
       /**
        * @see javax.servlet.http.HttpServletRequest#isUserInRole(java.lang.String)
        */
  @@ -52,7 +70,8 @@
           {
               try
               {
  -                result = JetspeedSecurity.hasRole(getRemoteUser(), roleName);
  +                String mappedName = mapRoleRefToRole(roleName);
  +                result = JetspeedSecurity.hasRole(getUserName(), mappedName);
               }
               catch (JetspeedSecurityException e)
               {
  @@ -66,5 +85,35 @@
           }
           
           return result;
  +    }
  +    
  +    private String mapRoleRefToRole(String roleName)
  +    {
  +        PortletDefinition portletDefinition = portletWindow.getPortletEntity().getPortletDefinition();
  +        SecurityRoleRefSet roleRefSet = portletDefinition.getInitSecurityRoleRefSet();
  +        SecurityRoleSet roleSet = portletDefinition.getPortletApplicationDefinition().getWebApplicationDefinition()
  +                .getSecurityRoles();
  +
  +        Iterator roleRefIter = roleRefSet.iterator();
  +        while (roleRefIter.hasNext())
  +        {
  +            SecurityRoleRef roleRef = (SecurityRoleRef) roleRefIter.next();
  +            if (roleName.equals(roleRef.getRoleName()))
  +            {
  +                String roleLinkName = roleRef.getRoleLink();
  +                if (roleLinkName == null || roleLinkName.length() == 0)
  +                {
  +                    roleLinkName = roleName;
  +                }
  +                Iterator roleIter = roleSet.iterator();
  +                while (roleIter.hasNext())
  +                {
  +                    SecurityRole role = (SecurityRole) roleIter.next();
  +                    if (roleLinkName.equals(role.getRoleName()))
  +                        return role.getRoleName();
  +                }
  +            }
  +        }
  +        return roleName;        
       }
   }
  
  
  
  1.1                  jakarta-jetspeed/fusion/src/java/org/apache/jetspeed/fusion/engine/servlet/FusionServletRequestFactoryImpl.java
  
  Index: FusionServletRequestFactoryImpl.java
  ===================================================================
  /*
   * Copyright 2000-2001,2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.jetspeed.fusion.engine.servlet;
  
  
  import javax.servlet.http.HttpServletRequest;
  
  import org.apache.jetspeed.engine.servlet.ServletRequestFactory;
  import org.apache.jetspeed.engine.servlet.ServletRequestFactoryImpl;
  import org.apache.pluto.om.window.PortletWindow;
  
  /**
   * Factory implementation for creating HTTP Request Wrappers
   *
   * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
   * @version $Id: FusionServletRequestFactoryImpl.java,v 1.1 2004/08/12 18:41:19 taylor Exp
$
   */
  public class FusionServletRequestFactoryImpl 
      extends ServletRequestFactoryImpl 
      implements ServletRequestFactory
  {
      protected HttpServletRequest createRequest(HttpServletRequest request, PortletWindow
window)
      {
          return new FusionServletRequestImpl(request, window);        
      }
  
  }
  
  
  

---------------------------------------------------------------------
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