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/components/profiler/src/java/org/apache/jetspeed/profiler/impl JetspeedProfiler.java
Date Thu, 23 Sep 2004 22:34:21 GMT
taylor      2004/09/23 15:34:21

  Modified:    components/profiler/src/java/org/apache/jetspeed/profiler/rules/impl
                        GroupCriterionResolver.java StandardResolver.java
                        RoleFallbackProfilingRule.java
                        RoleCriterionResolver.java
               components/profiler/src/java/org/apache/jetspeed/profiler/impl
                        JetspeedProfiler.java
  Log:
   support for 0..n roles or groups in role-based or group-based fallback
  for each role or group that a user is in, an entry is added to the profile locator
  
  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.4       +4 -8      jakarta-jetspeed-2/components/profiler/src/java/org/apache/jetspeed/profiler/rules/impl/GroupCriterionResolver.java
  
  Index: GroupCriterionResolver.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/components/profiler/src/java/org/apache/jetspeed/profiler/rules/impl/GroupCriterionResolver.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- GroupCriterionResolver.java	23 Sep 2004 19:47:28 -0000	1.3
  +++ GroupCriterionResolver.java	23 Sep 2004 22:34:20 -0000	1.4
  @@ -16,6 +16,7 @@
   package org.apache.jetspeed.profiler.rules.impl;
   
   import java.security.Principal;
  +import java.util.Iterator;
   
   import javax.security.auth.Subject;
   
  @@ -61,13 +62,8 @@
                log.error(msg);
                return null;
            }
  -            
  -         Principal principal = SecurityHelper.getPrincipal(subject, GroupPrincipal.class);
  -         if (principal != null)
  -         {
  -             return principal.getName();              
  -         }
  -         return null;
  +
  +         return resolvePrincipals(context, criterion, subject, GroupPrincipal.class);
         }
        
        /* (non-Javadoc)
  
  
  
  1.4       +33 -1     jakarta-jetspeed-2/components/profiler/src/java/org/apache/jetspeed/profiler/rules/impl/StandardResolver.java
  
  Index: StandardResolver.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/components/profiler/src/java/org/apache/jetspeed/profiler/rules/impl/StandardResolver.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- StandardResolver.java	23 Sep 2004 19:47:28 -0000	1.3
  +++ StandardResolver.java	23 Sep 2004 22:34:20 -0000	1.4
  @@ -15,9 +15,16 @@
    */
   package org.apache.jetspeed.profiler.rules.impl;
   
  +import java.security.Principal;
  +import java.util.Iterator;
  +
  +import javax.security.auth.Subject;
  +
   import org.apache.jetspeed.profiler.rules.RuleCriterion;
   import org.apache.jetspeed.profiler.rules.RuleCriterionResolver;
   import org.apache.jetspeed.request.RequestContext;
  +import org.apache.jetspeed.security.GroupPrincipal;
  +import org.apache.jetspeed.security.SecurityHelper;
   
   /**
    * Standard Jetspeed-1 style resolver for criterion.
  @@ -31,6 +38,8 @@
    */
   public class StandardResolver implements RuleCriterionResolver
   {
  +    public static final String VALUE_DELIMITER = ",";
  +    
       /* (non-Javadoc)
        * @see org.apache.jetspeed.profiler.rules.RuleCriterionResolver#resolve(org.apache.jetspeed.request.RequestContext,
org.apache.jetspeed.profiler.rules.RuleCriterion)
        */
  @@ -55,5 +64,28 @@
               return false;
           }
           return true;
  +    }
  +    
  +    protected String resolvePrincipals(RequestContext context, RuleCriterion criterion,
Subject subject, Class classe)
  +    {
  +        StringBuffer result = new StringBuffer();
  +        Iterator principals = SecurityHelper.getPrincipals(subject, classe).iterator();
  +        int count = 0;
  +        while (principals.hasNext())
  +        {
  +            Principal principal = (Principal)principals.next();
  +            if (count > 0)
  +            {
  +                result.append(VALUE_DELIMITER);
  +            }
  +            result.append(principal.getName());
  +            count++;
  +        }
  +        if (count == 0)
  +        {
  +            return null;
  +        }
  +        return result.toString();
  +        
       }
   }
  
  
  
  1.4       +38 -5     jakarta-jetspeed-2/components/profiler/src/java/org/apache/jetspeed/profiler/rules/impl/RoleFallbackProfilingRule.java
  
  Index: RoleFallbackProfilingRule.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/components/profiler/src/java/org/apache/jetspeed/profiler/rules/impl/RoleFallbackProfilingRule.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- RoleFallbackProfilingRule.java	23 Sep 2004 19:47:28 -0000	1.3
  +++ RoleFallbackProfilingRule.java	23 Sep 2004 22:34:20 -0000	1.4
  @@ -16,6 +16,7 @@
   package org.apache.jetspeed.profiler.rules.impl;
   
   import java.util.Iterator;
  +import java.util.StringTokenizer;
   
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  @@ -61,9 +62,28 @@
                   resolver = getDefaultResolver();
               }
               String value = resolver.resolve(context, criterion);
  -            key.append(criterion.getName());
  -            key.append(ProfileLocator.PATH_SEPARATOR);
  -            key.append(value);
  +            if (resolver instanceof RoleCriterionResolver ||
  +                resolver instanceof GroupCriterionResolver)
  +            {
  +                StringTokenizer tokenizer = new StringTokenizer(value, StandardResolver.VALUE_DELIMITER);
  +                while (tokenizer.hasMoreTokens())
  +                {
  +                    String token = (String)tokenizer.nextToken();
  +                    key.append(criterion.getName());
  +                    key.append(ProfileLocator.PATH_SEPARATOR);
  +                    key.append(token);
  +                    if (tokenizer.hasMoreTokens())
  +                    {
  +                        key.append(ProfileLocator.PATH_SEPARATOR);
  +                    }
  +                }
  +            }
  +            else
  +            {
  +                key.append(criterion.getName());
  +                key.append(ProfileLocator.PATH_SEPARATOR);
  +                key.append(value);
  +            }
               if (criteria.hasNext())
               {
                   key.append(ProfileLocator.PATH_SEPARATOR);
  @@ -95,7 +115,20 @@
               {
                   String value = resolver.resolve(context, criterion);
                   boolean isControl = resolver.isControl(criterion);
  -                locator.add(criterion, isControl, value);
  +                if (resolver instanceof RoleCriterionResolver ||
  +                        resolver instanceof GroupCriterionResolver)
  +                    {
  +                        StringTokenizer tokenizer = new StringTokenizer(value, StandardResolver.VALUE_DELIMITER);
  +                        while (tokenizer.hasMoreTokens())
  +                        {
  +                            String token = (String)tokenizer.nextToken();
  +                            locator.add(criterion, isControl, token);
  +                        }
  +                    }
  +                    else
  +                    {
  +                        locator.add(criterion, isControl, value);
  +                    }
               }                
           }               
                
  
  
  
  1.4       +3 -7      jakarta-jetspeed-2/components/profiler/src/java/org/apache/jetspeed/profiler/rules/impl/RoleCriterionResolver.java
  
  Index: RoleCriterionResolver.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/components/profiler/src/java/org/apache/jetspeed/profiler/rules/impl/RoleCriterionResolver.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- RoleCriterionResolver.java	23 Sep 2004 19:47:28 -0000	1.3
  +++ RoleCriterionResolver.java	23 Sep 2004 22:34:20 -0000	1.4
  @@ -24,6 +24,7 @@
   import org.apache.jetspeed.profiler.rules.RuleCriterion;
   import org.apache.jetspeed.profiler.rules.RuleCriterionResolver;
   import org.apache.jetspeed.request.RequestContext;
  +import org.apache.jetspeed.security.GroupPrincipal;
   import org.apache.jetspeed.security.RolePrincipal;
   import org.apache.jetspeed.security.SecurityHelper;
   
  @@ -62,12 +63,7 @@
               return null;
           }
               
  -        Principal principal = SecurityHelper.getPrincipal(subject, RolePrincipal.class);
  -        if (principal != null)
  -        {
  -            return principal.getName();              
  -        }
  -        return null;
  +        return resolvePrincipals(context, criterion, subject, RolePrincipal.class);
        }
       
       /* (non-Javadoc)
  
  
  
  1.4       +1 -2      jakarta-jetspeed-2/components/profiler/src/java/org/apache/jetspeed/profiler/impl/JetspeedProfiler.java
  
  Index: JetspeedProfiler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/components/profiler/src/java/org/apache/jetspeed/profiler/impl/JetspeedProfiler.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- JetspeedProfiler.java	20 Sep 2004 17:17:03 -0000	1.3
  +++ JetspeedProfiler.java	23 Sep 2004 22:34:21 -0000	1.4
  @@ -37,7 +37,6 @@
   import org.apache.jetspeed.profiler.rules.ProfilingRule;
   import org.apache.jetspeed.profiler.rules.impl.AbstractProfilingRule;
   import org.apache.jetspeed.profiler.rules.impl.PrincipalRuleImpl;
  -import org.apache.jetspeed.profiler.rules.impl.StandardProfilingRule;
   import org.apache.jetspeed.request.RequestContext;
   import org.apache.jetspeed.security.SecurityHelper;
   import org.apache.jetspeed.security.UserPrincipal;
  
  
  

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