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 maven.xml
Date Mon, 10 May 2004 17:43:07 GMT
taylor      2004/05/10 10:43:07

  Modified:    portal/src/webapp/WEB-INF/conf Log4j.properties
               portal/src/java/org/apache/jetspeed/tools/pamanager
                        PortletDescriptorUtilities.java FileSystemPAM.java
               portal   maven.xml
  Added:       portal/src/test/org/apache/jetspeed/tools/pamanager
                        TestPortletDescriptorSecurityRoles.java
               portal/test/testdata/deploy/security-roles web.xml
                        portlet.xml
  Log:
  patch applied from Ate Douma for web.xml security roles mapping to portal security roles
  
  PR:
  Obtained from:
  Submitted by:	
  Reviewed by:	
  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.1                  jakarta-jetspeed-2/portal/src/test/org/apache/jetspeed/tools/pamanager/TestPortletDescriptorSecurityRoles.java
  
  Index: TestPortletDescriptorSecurityRoles.java
  ===================================================================
  /*
   * Copyright 2000-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.tools.pamanager;
  
  import java.io.FileInputStream;
  import java.util.Properties;
  
  import junit.framework.Test;
  import junit.textui.TestRunner;
  
  import org.apache.commons.logging.LogFactory;
  import org.apache.commons.logging.impl.Log4jFactory;
  import org.apache.jetspeed.Jetspeed;
  import org.apache.jetspeed.components.AbstractComponentAwareTestCase;
  import org.apache.jetspeed.components.ComponentAwareTestSuite;
  import org.apache.jetspeed.components.portletregistry.PortletRegistryComponent;
  import org.apache.jetspeed.om.common.portlet.MutablePortletApplication;
  import org.apache.jetspeed.om.common.servlet.MutableWebApplication;
  import org.apache.jetspeed.om.servlet.impl.SecurityRoleImpl;
  import org.apache.log4j.PropertyConfigurator;
  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.picocontainer.MutablePicoContainer;
  
  /**
   * TestPortletDescriptorSecurityRoles - test and validate security roles and
   * security role references from portlet.xml and web.xml deployment descriptor.
   * 
   * @author <a href="ate@douma.nu">Ate Douma </a>
   * 
   * @version $Id: TestPortletDescriptorSecurityRoles.java,v 1.1 2004/05/10 17:43:07 taylor
Exp $
   */
  public class TestPortletDescriptorSecurityRoles extends AbstractComponentAwareTestCase {
  
      private PortletRegistryComponent registry;
  
      private MutablePicoContainer container;
  
      /**
       * Defines the testcase name for JUnit.
       * 
       * @param name
       *            the testcase's name.
       */
      public TestPortletDescriptorSecurityRoles(String name) {
          super(name);
      }
  
      /**
       * Start the tests.
       * 
       * @param args
       *            the arguments. Not used
       */
      public static void main(String args[]) {
          TestRunner.main(new String[] { TestPortletDescriptorSecurityRoles.class.getName()});
      }
  
      public static final String LOG4J_CONFIG_FILE = "log4j.file";
  
      // TODO: make this relative, move it into script
      public static final String LOG4J_CONFIG_FILE_DEFAULT = "src/webapp/WEB-INF/conf/Log4j.properties";
  
      protected void setUp() throws Exception {
          // super.setUp();
  
          // TODO: this is REALLY strange. If I don't setup LOG4J here Digester
          // crashes with a NPE
          // if I setup Log4J in my super class, Digester crashes ... mysterious
          // TODO: need a Logging Component
  
          String log4jFile = LOG4J_CONFIG_FILE_DEFAULT;
          Properties p = new Properties();
          try {
              p.load(new FileInputStream(log4jFile));
          } catch (Exception e) {
              e.printStackTrace();
          }
          PropertyConfigurator.configure(p);
  
          System.getProperties().setProperty(LogFactory.class.getName(), Log4jFactory.class.getName());
  
          container = (MutablePicoContainer) getContainer();
          registry = (PortletRegistryComponent) container.getComponentInstance(PortletRegistryComponent.class);
      }
  
      /**
       * Creates the test suite.
       * 
       * @return a test suite (<code>TestSuite</code>) that includes all
       *         methods starting with "test"
       */
      public static Test suite() {
          ComponentAwareTestSuite suite = new ComponentAwareTestSuite(TestPortletDescriptorSecurityRoles.class);
          suite.setScript("org/apache/jetspeed/tools/pamanager/containers/pa-container.groovy");
          return suite;
      }
  
      public void testSecurityRoles() throws Exception {
          System.out.println("Testing securityRoles");
          MutablePortletApplication app = PortletDescriptorUtilities.loadPortletDescriptor("./test/testdata/deploy/security-roles/portlet.xml",
"unit-test");
          assertNotNull("App is null", app);
          MutableWebApplication webApp = (MutableWebApplication) WebDescriptorUtilities.loadDescriptor("./test/testdata/deploy/security-roles/web.xml",
"/",
                  Jetspeed.getDefaultLocale(), "unit-test");
          assertNotNull("WebApp is null", webApp);
  
          app.setWebApplicationDefinition(webApp);
  
          PortletDefinition portlet = app.getPortletDefinitionByName("TestPortlet");
          assertNotNull("TestPortlet is null", portlet);
          checkWebSecurityRoles(webApp);
          checkPortletSecurityRoleRefs(portlet);
          boolean validateFailed = false;
          try {
              PortletDescriptorUtilities.validate(app);
          } catch (PortletApplicationException e) {
              validateFailed = true;
          }
          assertEquals("Invalid PortletDescriptor validation result", true, validateFailed);
          SecurityRoleImpl role = new SecurityRoleImpl();
          role.setRoleName("users.manager");
          webApp.addSecurityRole(role);
          try {
              PortletDescriptorUtilities.validate(app);
              validateFailed = false;
          } catch (PortletApplicationException e) {
          }
          assertEquals("Invalid PortletDescriptor validation result", false, validateFailed);
      }
  
      private void checkWebSecurityRoles(MutableWebApplication webApp) {
          SecurityRoleSet roles = webApp.getSecurityRoles();
          assertEquals("Invalid number of security role definitions found", 1, roles.size());
          SecurityRole role = roles.get("users.admin");
          assertNotNull("Role users.admin undefined", role);
      }
  
      private void checkPortletSecurityRoleRefs(PortletDefinition portlet) {
          SecurityRoleRefSet roleRefs = portlet.getInitSecurityRoleRefSet();
          assertEquals("Invalid number of security role references found", 2, roleRefs.size());
          SecurityRoleRef roleRef = roleRefs.get("admin");
          assertNotNull("Security Role Ref admin undefined", roleRef);
          assertEquals("security Role link expected", "users.admin", roleRef.getRoleLink());
          roleRef = roleRefs.get("users.manager");
          assertNotNull("Security Role Ref users.manager undefined", roleRef);
          assertNull("Undefined security Role link for users.managers expected", roleRef.getRoleLink());
      }
  }
  
  
  
  1.1                  jakarta-jetspeed-2/portal/test/testdata/deploy/security-roles/web.xml
  
  Index: web.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  <!--
  Copyright 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.
  -->
  <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
                           "http://java.sun.com/j2ee/dtds/web-app_2.2.dtd">
  <web-app>
    <display-name>Jetspeed Container Application</display-name>
    <description>MVC Servlet for Jetspeed Portlet Applications</description>
    <servlet>
      <servlet-name>JetspeedContainer</servlet-name>
      <display-name>Jetspeed Container</display-name>
      <description>MVC Servlet for Jetspeed Portlet Applications</description>
      <servlet-class>org.apache.jetspeed.container.JetspeedContainerServlet</servlet-class>
    </servlet>
  
    <servlet-mapping>
         <servlet-name>
            JetspeedContainer
         </servlet-name>
         <url-pattern>
           /portal/*
         </url-pattern>
      </servlet-mapping>
      <servlet-mapping>
         <servlet-name>
            JetspeedContainer
         </servlet-name>
         <url-pattern>
           /container/*
         </url-pattern>
      </servlet-mapping>
  
    <!-- The Usual Welcome File List -->
    <welcome-file-list>
      <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
  
    <!-- Security roles used by this web application -->
    <security-role>
      <description>
        The users.admin role
      </description>
      <role-name>users.admin</role-name>
    </security-role>
  
  </web-app>
  
  
  
  1.1                  jakarta-jetspeed-2/portal/test/testdata/deploy/security-roles/portlet.xml
  
  Index: portlet.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  <!--
  Copyright 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.
  -->
  <portlet-app id="TestSecurityRoles" version="1.0">
   <portlet id="TestPortlet">
      <portlet-name>TestPortlet</portlet-name>
      <portlet-class>org.apache.jetspeed.portlet.helloworld.HelloWorld</portlet-class>
      <display-name lang="en">HelloWorld Portlet Wrapper</display-name>
      <description lang="en">This is a desciption of the HelloWorld portlet</description>
      <expiration-cache>-1</expiration-cache>
      <supports id="Minimal support">
        <mime-type>text/html</mime-type>
        <portlet-mode>EDIT</portlet-mode>
        <portlet-mode>VIEW</portlet-mode>
        <portlet-mode>HELP</portlet-mode>
      </supports>
      <portlet-info>
        <title>HelloWorldTitle</title>
        <short-title>This is the short title</short-title>
        <keywords>Test,David</keywords>
      </portlet-info>
      <portlet-preferences>
        <preference>
          <name>time-server</name>
          <value>http://timeserver.myco.com</value>
          <value>http://timeserver.foo.com</value>
          <read-only>false</read-only>
        </preference>
        <preference>
          <name>port</name>
          <value>404</value>
          <read-only>true</read-only>
        </preference>
      </portlet-preferences>
      <security-role-ref>
          <description lang="en">This is the admin role</description>
          <role-name>admin</role-name>
          <role-link>users.admin</role-link>
      </security-role-ref>
      <security-role-ref>
          <description lang="en">This is the manager role</description>
          <role-name>users.manager</role-name>
      </security-role-ref>
    </portlet>
  
   </portlet-app>
  
  
  
  
  
  1.6       +16 -1     jakarta-jetspeed-2/portal/src/webapp/WEB-INF/conf/Log4j.properties
  
  Index: Log4j.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/portal/src/webapp/WEB-INF/conf/Log4j.properties,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- Log4j.properties	18 Mar 2004 19:36:04 -0000	1.5
  +++ Log4j.properties	10 May 2004 17:43:07 -0000	1.6
  @@ -83,6 +83,12 @@
   log4j.category.console = INFO, console
   log4j.additivity.console = false
   
  +#
  +# struts(-portlet) Category
  +#
  +log4j.category.org.apache.struts = DEBUG, STRUTS
  +log4j.additivity.org.apache.struts = false
  +
   ########################################################################
   #
   # Logfile definitions
  @@ -165,3 +171,12 @@
   
   # Pattern to output the caller's file name and line number.
   log4j.appender.console.layout.ConversionPattern=%5p: %m%n
  +
  +#
  +# struts-portlet.log
  +#
  +log4j.appender.STRUTS = org.apache.log4j.FileAppender
  +log4j.appender.STRUTS.file = ${applicationRoot}/logs/struts.log
  +log4j.appender.STRUTS.layout = org.apache.log4j.PatternLayout
  +log4j.appender.STRUTS.layout.conversionPattern = %d [%t] %-5p %c - %m%n
  +log4j.appender.STRUTS.append = false
  
  
  
  1.9       +50 -1     jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/tools/pamanager/PortletDescriptorUtilities.java
  
  Index: PortletDescriptorUtilities.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/tools/pamanager/PortletDescriptorUtilities.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- PortletDescriptorUtilities.java	7 May 2004 13:45:01 -0000	1.8
  +++ PortletDescriptorUtilities.java	10 May 2004 17:43:07 -0000	1.9
  @@ -17,6 +17,7 @@
   
   import java.io.File;
   import java.io.FileReader;
  +import java.util.Collection;
   import java.util.Iterator;
   
   import org.apache.commons.digester.Digester;
  @@ -38,6 +39,10 @@
   import org.apache.jetspeed.om.portlet.impl.PortletDefinitionImpl;
   import org.apache.jetspeed.om.preference.impl.DefaultPreferenceImpl;
   import org.apache.jetspeed.tools.castor.om.common.portlet.PortletDefinitionDescriptor;
  +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.portlet.PortletDefinitionList;
   import org.exolab.castor.mapping.Mapping;
   import org.exolab.castor.xml.Unmarshaller;
  @@ -235,4 +240,48 @@
           }
       }
   
  +    /**
  +     * Validate a PortletApplicationDefinition tree AFTER its
  +     * WebApplicationDefinition has been loaded. Currently, only the security role
  +     * references of the portlet definitions are validated:
  +     * <ul>
  +     * <li>A security role reference should reference a security role through a
  +     * roleLink. A warning message is logged if a direct reference is used.
  +     * <li>For a security role reference a security role must be defined in the
  +     * web application. An error message is logged and a
  +     * PortletApplicationException is thrown if not.
  +     * </ul>
  +     * 
  +     * @param app
  +     *            The PortletApplicationDefinition to validate
  +     * @throws PortletApplicationException
  +     */
  +     public static void validate(MutablePortletApplication app) throws PortletApplicationException

  +     {
  +         SecurityRoleSet roles = app.getWebApplicationDefinition().getSecurityRoles();
  +         Collection portlets = app.getPortletDefinitions();
  +         Iterator portletIterator = portlets.iterator();
  +         while ( portletIterator.hasNext() ) 
  +         {
  +             PortletDefinition portlet = (PortletDefinition)portletIterator.next();
  +             SecurityRoleRefSet securityRoleRefs = portlet.getInitSecurityRoleRefSet();
  +             Iterator roleRefsIterator = securityRoleRefs.iterator();
  +             while ( roleRefsIterator.hasNext() ) 
  +             {
  +                 SecurityRoleRef roleRef = (SecurityRoleRef)roleRefsIterator.next();
  +                 String roleName = roleRef.getRoleLink();
  +                 if ( roleName == null ) 
  +                 {
  +                     log.warn("No role link specified for portlet " +portlet.getName()+"
security role reference "+ roleRef.getRoleName());
  +                     roleName = roleRef.getRoleName();
  +                 }
  +                 if ( roles.get(roleName) == null ) 
  +                 {
  +                     String errorMsg = "Undefined security role " +roleName+ " referenced
from portlet " + portlet.getName();                    
  +                     log.error(errorMsg);
  +                     throw new PortletApplicationException(errorMsg);
  +                 }
  +             }
  +         }           
  +     }    
   }
  
  
  
  1.26      +4 -1      jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/tools/pamanager/FileSystemPAM.java
  
  Index: FileSystemPAM.java
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/tools/pamanager/FileSystemPAM.java,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- FileSystemPAM.java	7 May 2004 20:34:23 -0000	1.25
  +++ FileSystemPAM.java	10 May 2004 17:43:07 -0000	1.26
  @@ -382,6 +382,9 @@
                   .getDefaultLocale(), paName);
   
           app.setWebApplicationDefinition(webapp);
  +
  +        // validate the application definition
  +        PortletDescriptorUtilities.validate(app);
           
           try
           {
  
  
  
  1.71      +9 -5      jakarta-jetspeed-2/portal/maven.xml
  
  Index: maven.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-jetspeed-2/portal/maven.xml,v
  retrieving revision 1.70
  retrieving revision 1.71
  diff -u -r1.70 -r1.71
  --- maven.xml	7 May 2004 16:57:29 -0000	1.70
  +++ maven.xml	10 May 2004 17:43:07 -0000	1.71
  @@ -34,10 +34,6 @@
                  ignoreFailures="false"/>
    </preGoal>
   
  - <!-- Always rbuild the DB befure we test
  - <preGoal name="test:test">
  - 	<attainGoal name="db.recreate" />
  - </preGoal>
   -->
   
   <!--
  @@ -533,6 +529,14 @@
     </preGoal>
   
     <preGoal name="test:test">
  +    <attainGoal name="dbsetup"/>
  +  </preGoal>
  +
  +  <preGoal name="test:single">
  +    <attainGoal name="dbsetup"/>
  +  </preGoal>
  +
  +  <goal name="dbsetup">  
       <attainGoal name="db.test.properties"/>
       <copy file="src/java/repository_database.xml" todir="${maven.test.dest}" overwrite="true">
       <filterset begintoken="@" endtoken="@">
  @@ -542,7 +546,7 @@
   
       <path id="jdbc.drivers.path" path="${org.apache.jetspeed.test.jdbc.drivers.path}"/>
       <maven:addPath id="maven.dependency.classpath" refid="jdbc.drivers.path"/>
  -  </preGoal>
  +  </goal>
   
     <goal name='remove.wars'>
       <delete dir="${deploy.war.dir}/${webapp.name}"/>
  
  
  

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