lenya-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From andr...@apache.org
Subject cvs commit: cocoon-lenya/src/java/org/apache/lenya/cms/ac2/xsp PolicyHelper.java
Date Wed, 20 Aug 2003 18:52:11 GMT
andreas     2003/08/20 11:52:11

  Modified:    src/java/org/apache/lenya/cms/ac2/xsp PolicyHelper.java
  Log:
  added getUsersWithRole(String)
  
  Revision  Changes    Path
  1.7       +40 -1     cocoon-lenya/src/java/org/apache/lenya/cms/ac2/xsp/PolicyHelper.java
  
  Index: PolicyHelper.java
  ===================================================================
  RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/ac2/xsp/PolicyHelper.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- PolicyHelper.java	19 Aug 2003 18:46:03 -0000	1.6
  +++ PolicyHelper.java	20 Aug 2003 18:52:11 -0000	1.7
  @@ -67,11 +67,14 @@
   import org.apache.lenya.cms.ac.AccessControlException;
   import org.apache.lenya.cms.ac.Item;
   import org.apache.lenya.cms.ac.Role;
  +import org.apache.lenya.cms.ac.User;
  +import org.apache.lenya.cms.ac.UserManager;
   import org.apache.lenya.cms.ac2.AccessControllerResolver;
   import org.apache.lenya.cms.ac2.Accreditable;
   import org.apache.lenya.cms.ac2.Credential;
   import org.apache.lenya.cms.ac2.DefaultAccessController;
   import org.apache.lenya.cms.ac2.DefaultPolicy;
  +import org.apache.lenya.cms.ac2.Identity;
   import org.apache.lenya.cms.ac2.InheritingPolicyManager;
   import org.apache.lenya.cms.ac2.Policy;
   import org.apache.lenya.cms.publication.PageEnvelope;
  @@ -330,6 +333,42 @@
           } catch (AccessControlException e) {
               throw new ProcessingException("Resolving policy failed: ", e);
           }
  +    }
  +    
  +    /**
  +     * Returns the users with a certain role on the current URL.
  +     * @param roleId The role ID.
  +     * @return An array of users.
  +     * @throws ProcessingException when something went wrong.
  +     */
  +    public User[] getUsersWithRole(String roleId) throws ProcessingException {
  +        List users = new ArrayList();
  +        try {
  +            Policy policy = policyManager.getPolicy(accessController.getAccreditableManager(),
getUrl());
  +            UserManager userManager = accessController.getAccreditableManager().getUserManager();
  +            for (Iterator i = userManager.getUsers(); i.hasNext(); ) {
  +                User user = (User) i.next();
  +                Identity identity = new Identity();
  +                identity.addIdentifiable(user);
  +                Role[] roles = policy.getRoles(identity);
  +                for (int roleIndex = 0; roleIndex < roles.length; roleIndex++) {
  +                    if (roles[roleIndex].getId().equals(roleId)) {
  +                        users.add(user);
  +                    }
  +                }
  +            }
  +        } catch (AccessControlException e) {
  +            throw new ProcessingException(e);
  +        }
  +        return (User[]) users.toArray(new User[users.size()]);
  +    }
  +
  +    /**
  +     * Returns the URL.
  +     * @return A string.
  +     */
  +    public String getUrl() {
  +        return url;
       }
   
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: lenya-cvs-unsubscribe@cocoon.apache.org
For additional commands, e-mail: lenya-cvs-help@cocoon.apache.org


Mime
View raw message