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/cocoon/transformation UsecaseMenuTransformer.java
Date Wed, 13 Aug 2003 13:14:45 GMT
andreas     2003/08/13 06:14:45

  Modified:    src/java/org/apache/lenya/cms/cocoon/transformation
                        UsecaseMenuTransformer.java
  Log:
  - using AC resolver to get authorizer
  - reflecting changes to usecase authorizer
  
  Revision  Changes    Path
  1.2       +42 -10    cocoon-lenya/src/java/org/apache/lenya/cms/cocoon/transformation/UsecaseMenuTransformer.java
  
  Index: UsecaseMenuTransformer.java
  ===================================================================
  RCS file: /home/cvs/cocoon-lenya/src/java/org/apache/lenya/cms/cocoon/transformation/UsecaseMenuTransformer.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- UsecaseMenuTransformer.java	5 Aug 2003 16:27:41 -0000	1.1
  +++ UsecaseMenuTransformer.java	13 Aug 2003 13:14:45 -0000	1.2
  @@ -67,8 +67,16 @@
   import org.apache.cocoon.environment.SourceResolver;
   import org.apache.cocoon.transformation.AbstractSAXTransformer;
   import org.apache.lenya.cms.ac.AccessControlException;
  +import org.apache.lenya.cms.ac.Role;
  +import org.apache.lenya.cms.ac2.AccessController;
  +import org.apache.lenya.cms.ac2.AccessControllerResolver;
   import org.apache.lenya.cms.ac2.Authorizer;
  +import org.apache.lenya.cms.ac2.DefaultAccessController;
  +import org.apache.lenya.cms.ac2.PolicyAuthorizer;
   import org.apache.lenya.cms.ac2.usecase.UsecaseAuthorizer;
  +import org.apache.lenya.cms.publication.Publication;
  +import org.apache.lenya.cms.publication.PublicationFactory;
  +import org.apache.lenya.util.ServletHelper;
   import org.xml.sax.Attributes;
   import org.xml.sax.SAXException;
   import org.xml.sax.helpers.AttributesImpl;
  @@ -94,7 +102,7 @@
   
           Attributes attributes = attr;
   
  -        if (localName.equals(ITEM_ELEMENT)) {
  +        if (authorizer != null && localName.equals(ITEM_ELEMENT)) {
               String usecase = attr.getValue(NAMESPACE, USECASE_ATTRIBUTE);
   
               // filter item if usecase not allowed 
  @@ -102,12 +110,12 @@
                   getLogger().debug("Found usecase [" + usecase + "]");
   
                   try {
  -                    if (!authorizer.authorizeUsecase(webappUrl, usecase)) {
  +                    if (!authorizer.authorizeUsecase(webappUrl, usecase, roles, publication))
{
                           int hrefIndex = attributes.getIndex("href");
                           if (hrefIndex > -1) {
                               attributes = new AttributesImpl(attr);
                               ((AttributesImpl) attributes).removeAttribute(hrefIndex);
  -                        } 
  +                        }
                       }
                   } catch (AccessControlException e) {
                       throw new SAXException(e);
  @@ -122,6 +130,9 @@
       private UsecaseAuthorizer authorizer;
       private ComponentSelector selector = null;
       private String webappUrl;
  +    private Role[] roles;
  +    private Publication publication;
  +    private AccessControllerResolver acResolver;
   
       /**
        * @see org.apache.cocoon.sitemap.SitemapModelComponent#setup(org.apache.cocoon.environment.SourceResolver,
java.util.Map, java.lang.String, org.apache.avalon.framework.parameters.Parameters)
  @@ -131,16 +142,37 @@
   
           getLogger().debug("Setting up transformer");
   
  -        ComponentSelector selector = null;
  +        selector = null;
  +        acResolver = null;
           authorizer = null;
   
           Request request = ObjectModelHelper.getRequest(objectModel);
   
           try {
  -            selector = (ComponentSelector) manager.lookup(Authorizer.ROLE + "Selector");
  -            authorizer = (UsecaseAuthorizer) selector.select(UsecaseAuthorizer.TYPE);
  +            roles = PolicyAuthorizer.getRoles(request);
  +            publication = PublicationFactory.getPublication(objectModel);
  +            selector =
  +                (ComponentSelector) manager.lookup(AccessControllerResolver.ROLE + "Selector");
  +            acResolver =
  +                (AccessControllerResolver) selector.select(
  +                    AccessControllerResolver.DEFAULT_RESOLVER);
  +            getLogger().debug("Resolved AC resolver [" + acResolver + "]");
  +
  +            String webappUrl = ServletHelper.getWebappURI(request);
  +            AccessController accessController = acResolver.resolveAccessController(webappUrl);
  +
  +            if (accessController instanceof DefaultAccessController) {
  +                DefaultAccessController defaultAccessController =
  +                    (DefaultAccessController) accessController;
  +                Authorizer[] authorizers = defaultAccessController.getAuthorizers();
  +                for (int i = 0; i < authorizers.length; i++) {
  +                    if (authorizers[i] instanceof UsecaseAuthorizer) {
  +                        authorizer = (UsecaseAuthorizer) authorizers[i];
  +                    }
  +                }
  +            }
  +
               getLogger().debug("Using authorizer [" + authorizer + "]");
  -            authorizer.setup(request);
           } catch (Exception e) {
               throw new ProcessingException(e);
           }
  @@ -152,8 +184,8 @@
       public void dispose() {
           getLogger().debug("Disposing transformer");
           if (selector != null) {
  -            if (authorizer != null) {
  -                selector.release(authorizer);
  +            if (acResolver != null) {
  +                selector.release(acResolver);
               }
               manager.release(selector);
           }
  
  
  

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