epugh       2003/10/30 10:23:43

  Modified:    security/src/java/org/apache/fulcrum/security
                        BaseSecurityService.java
               security/src/test/org/apache/fulcrum/security
                        StartingSecurityServicesTest.java
  Added:       security/src/test LazyLoadServices.xml
  Log:
  Lazy load the services, that way you don't have to define them all, only the onces 
we need.
  
  Should also cut down on resource usage...
  
  Revision  Changes    Path
  1.1                  jakarta-turbine-fulcrum/security/src/test/LazyLoadServices.xml
  
  Index: LazyLoadServices.xml
  ===================================================================
  <my-system>
    <component
      role="org.apache.fulcrum.security.SecurityService"
      class="org.apache.fulcrum.security.BaseSecurityService">   
    </component>  
  
    <component
      role="org.apache.fulcrum.security.UserManager"
      class="org.apache.fulcrum.security.spi.memory.simple.MemoryUserManagerImpl">   
    </component>   
  
    <component
      role="org.apache.fulcrum.security.authenticator.Authenticator"
      class="org.apache.fulcrum.security.authenticator.TextMatchAuthenticator">   
    </component> 
    
    
  </my-system>
  
  
  1.6       +62 -6     
jakarta-turbine-fulcrum/security/src/java/org/apache/fulcrum/security/BaseSecurityService.java
  
  Index: BaseSecurityService.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-fulcrum/security/src/java/org/apache/fulcrum/security/BaseSecurityService.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- BaseSecurityService.java  30 Oct 2003 14:25:35 -0000      1.5
  +++ BaseSecurityService.java  30 Oct 2003 18:23:43 -0000      1.6
  @@ -86,6 +86,18 @@
         */
       public UserManager getUserManager()
       {
  +        if (userManager == null)
  +        {
  +            try
  +            {
  +                userManager = (UserManager) manager.lookup(UserManager.ROLE);
  +
  +            }
  +            catch (ComponentException ce)
  +            {
  +                throw new RuntimeException(ce.getMessage(), ce);
  +            }
  +        }
           return userManager;
       }
       /**
  @@ -95,6 +107,18 @@
         */
       public GroupManager getGroupManager()
       {
  +        if (groupManager == null)
  +        {
  +            try
  +            {
  +                groupManager = (GroupManager) manager.lookup(GroupManager.ROLE);
  +
  +            }
  +            catch (ComponentException ce)
  +            {
  +                throw new RuntimeException(ce.getMessage(), ce);
  +            }
  +        }
           return groupManager;
       }
       /**
  @@ -104,6 +128,18 @@
         */
       public RoleManager getRoleManager()
       {
  +        if (roleManager == null)
  +        {
  +            try
  +            {
  +                roleManager = (RoleManager) manager.lookup(RoleManager.ROLE);
  +
  +            }
  +            catch (ComponentException ce)
  +            {
  +                throw new RuntimeException(ce.getMessage(), ce);
  +            }
  +        }
           return roleManager;
       }
       /**
  @@ -113,6 +149,18 @@
         */
       public PermissionManager getPermissionManager()
       {
  +        if (permissionManager == null)
  +        {
  +            try
  +            {
  +                permissionManager = (PermissionManager) 
manager.lookup(PermissionManager.ROLE);
  +
  +            }
  +            catch (ComponentException ce)
  +            {
  +                throw new RuntimeException(ce.getMessage(), ce);
  +            }
  +        }
           return permissionManager;
       }
       /**
  @@ -122,6 +170,18 @@
         */
       public ModelManager getModelManager()
       {
  +        if (modelManager == null)
  +        {
  +            try
  +            {
  +                modelManager = (ModelManager) manager.lookup(ModelManager.ROLE);
  +
  +            }
  +            catch (ComponentException ce)
  +            {
  +                throw new RuntimeException(ce.getMessage(), ce);
  +            }
  +        }
           return modelManager;
       }
       /**
  @@ -143,11 +203,7 @@
       public void compose(ComponentManager manager) throws ComponentException
       {
           this.manager = manager;
  -        userManager = (UserManager) manager.lookup(UserManager.ROLE);
  -        roleManager = (RoleManager) manager.lookup(RoleManager.ROLE);
  -        groupManager = (GroupManager) manager.lookup(GroupManager.ROLE);
  -        permissionManager = (PermissionManager) 
manager.lookup(PermissionManager.ROLE);
  -        modelManager = (ModelManager) manager.lookup(ModelManager.ROLE);
  +        
   
       }
       /**
  
  
  
  1.7       +62 -60    
jakarta-turbine-fulcrum/security/src/test/org/apache/fulcrum/security/StartingSecurityServicesTest.java
  
  Index: StartingSecurityServicesTest.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-fulcrum/security/src/test/org/apache/fulcrum/security/StartingSecurityServicesTest.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- StartingSecurityServicesTest.java 30 Oct 2003 14:25:37 -0000      1.6
  +++ StartingSecurityServicesTest.java 30 Oct 2003 18:23:43 -0000      1.7
  @@ -1,57 +1,40 @@
   package org.apache.fulcrum.security;
  -/* ====================================================================
  - * The Apache Software License, Version 1.1
  - *
  - * Copyright (c) 2001-2002 The Apache Software Foundation.  All rights
  - * reserved.
  - *
  - * Redistribution and use in source and binary forms, with or without
  - * modification, are permitted provided that the following conditions
  - * are met:
  - *
  - * 1. Redistributions of source code must retain the above copyright
  - *    notice, this list of conditions and the following disclaimer.
  - *
  - * 2. Redistributions in binary form must reproduce the above copyright
  - *    notice, this list of conditions and the following disclaimer in
  - *    the documentation and/or other materials provided with the
  - *    distribution.
  - *
  - * 3. The end-user documentation included with the redistribution,
  - *    if any, must include the following acknowledgment:
  - *       "This product includes software developed by the
  - *        Apache Software Foundation (http://www.apache.org/)."
  - *    Alternately, this acknowledgment may appear in the software itself,
  - *    if and wherever such third-party acknowledgments normally appear.
  - *
  - * 4. The names "Apache" and "Apache Software Foundation" and
  - *    "Apache Turbine" must not be used to endorse or promote products
  - *    derived from this software without prior written permission. For
  - *    written permission, please contact [EMAIL PROTECTED]
  - *
  - * 5. Products derived from this software may not be called "Apache",
  - *    "Apache Turbine", nor may "Apache" appear in their name, without
  - *    prior written permission of the Apache Software Foundation.
  - *
  - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  - * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  - * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  - * SUCH DAMAGE.
  +/*
  + * ==================================================================== The Apache 
Software
  + * License, Version 1.1
  + * 
  + * Copyright (c) 2001-2002 The Apache Software Foundation. All rights reserved.
  + * 
  + * Redistribution and use in source and binary forms, with or without modification, 
are permitted
  + * provided that the following conditions are met: 1. Redistributions of source 
code must retain
  + * the above copyright notice, this list of conditions and the following 
disclaimer. 2.
  + * Redistributions in binary form must reproduce the above copyright notice, this 
list of
  + * conditions and the following disclaimer in the documentation and/or other 
materials provided
  + * with the distribution. 3. The end-user documentation included with the 
redistribution, if any,
  + * must include the following acknowledgment: "This product includes software 
developed by the
  + * Apache Software Foundation (http://www.apache.org/)." Alternately, this 
acknowledgment may
  + * appear in the software itself, if and wherever such third-party acknowledgments 
normally appear. 4.
  + * The names "Apache" and "Apache Software Foundation" and "Apache Turbine" must 
not be used to
  + * endorse or promote products derived from this software without prior written 
permission. For
  + * written permission, please contact [EMAIL PROTECTED] 5. Products derived from 
this software may
  + * not be called "Apache", "Apache Turbine", nor may "Apache" appear in their name, 
without prior
  + * written permission of the Apache Software Foundation.
  + * 
  + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, 
INCLUDING, BUT NOT
  + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 
PARTICULAR PURPOSE ARE
  + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS 
BE LIABLE FOR
  + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
(INCLUDING, BUT
  + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
OR PROFITS; OR
  + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
CONTRACT,
  + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 
OUT OF THE USE
  + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    * ====================================================================
  - *
  - * This software consists of voluntary contributions made by many
  - * individuals on behalf of the Apache Software Foundation.  For more
  - * information on the Apache Software Foundation, please see
  - * <http://www.apache.org/>.
  + * 
  + * This software consists of voluntary contributions made by many individuals on 
behalf of the
  + * Apache Software Foundation. For more information on the Apache Software 
Foundation, please see
  + * <http://www.apache.org/> .
    */
  +import org.apache.avalon.framework.component.ComponentException;
   import org.apache.fulcrum.security.model.simple.SimpleModelManager;
   import org.apache.fulcrum.security.model.turbine.TurbineModelManager;
   import org.apache.fulcrum.security.spi.hibernate.simple.HibernateGroupManagerImpl;
  @@ -69,9 +52,9 @@
   import org.apache.fulcrum.testcontainer.BaseUnitTest;
   
   /**
  -* @author <a href="mailto:[EMAIL PROTECTED]">Marco Kn&uuml;ttel</a>
  + * @author <a href="mailto:[EMAIL PROTECTED]">Marco Kn&uuml;ttel</a>
    * @version $Id$
  -*/
  + */
   
   public class StartingSecurityServicesTest extends BaseUnitTest
   {
  @@ -89,23 +72,23 @@
       {
           this.setRoleFileName(null);
           this.setConfigurationFileName("src/test/TorqueSecurity.xml");
  -        securityService = (SecurityService) lookup(SecurityService.ROLE);       
  +        securityService = (SecurityService) lookup(SecurityService.ROLE);
           assertTrue(securityService.getUserManager() instanceof TorqueUserManager);
           assertTrue(securityService.getRoleManager() instanceof TorqueRoleManager);
           assertTrue(securityService.getPermissionManager() instanceof 
TorquePermissionManager);
           assertTrue(securityService.getGroupManager() instanceof TorqueGroupManager);
  -             assertTrue(securityService.getModelManager() instanceof 
TurbineModelManager);
  +        assertTrue(securityService.getModelManager() instanceof 
TurbineModelManager);
       }
       public void testStartingInMemorySecurity() throws Exception
       {
           this.setRoleFileName(null);
           this.setConfigurationFileName("src/test/SimpleMemory.xml");
  -        securityService = (SecurityService) lookup(SecurityService.ROLE);       
  +        securityService = (SecurityService) lookup(SecurityService.ROLE);
           assertTrue(securityService.getUserManager() instanceof 
MemoryUserManagerImpl);
           assertTrue(securityService.getRoleManager() instanceof 
MemoryRoleManagerImpl);
           assertTrue(securityService.getPermissionManager() instanceof 
MemoryPermissionManagerImpl);
           assertTrue(securityService.getGroupManager() instanceof 
MemoryGroupManagerImpl);
  -             assertTrue(securityService.getModelManager() instanceof 
SimpleModelManager);
  +        assertTrue(securityService.getModelManager() instanceof SimpleModelManager);
       }
       public void testStartingHibernateSecurity() throws Exception
       {
  @@ -114,8 +97,27 @@
           securityService = (SecurityService) lookup(SecurityService.ROLE);
           assertTrue(securityService.getUserManager() instanceof 
HibernateUserManagerImpl);
           assertTrue(securityService.getRoleManager() instanceof 
HibernateRoleManagerImpl);
  -        assertTrue(securityService.getPermissionManager() instanceof 
HibernatePermissionManagerImpl);
  +        assertTrue(
  +            securityService.getPermissionManager() instanceof 
HibernatePermissionManagerImpl);
           assertTrue(securityService.getGroupManager() instanceof 
HibernateGroupManagerImpl);
  -             assertTrue(securityService.getModelManager() instanceof 
SimpleModelManager);
  +        assertTrue(securityService.getModelManager() instanceof SimpleModelManager);
  +    }
  +
  +    public void testLazyLoadingOfServices() throws Exception
  +    {
  +        this.setRoleFileName(null);
  +        this.setConfigurationFileName("src/test/LazyLoadServices.xml");
  +        securityService = (SecurityService) lookup(SecurityService.ROLE);
  +        assertTrue(securityService.getUserManager() instanceof 
MemoryUserManagerImpl);
  +        try
  +        {
  +            securityService.getModelManager();
  +            fail("Should have throw runtime error");
  +        }
  +        catch (RuntimeException re)
  +        {
  +            assertTrue(re.getCause() instanceof ComponentException);
  +        }
       }
  +
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to