You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@turbine.apache.org by ep...@apache.org on 2003/12/06 00:39:08 UTC

cvs commit: jakarta-turbine-fulcrum/security/adapters/opensymphony/src/test/org/apache/fulcrum/security/adapter/osuser OSUserAdapterTest.java

epugh       2003/12/05 15:39:08

  Added:       security/adapters/opensymphony maven.xml project.properties
                        project.xml
               security/adapters/opensymphony/src/java/org/apache/fulcrum/security/adapter/osuser
                        FulcrumAccessProvider.java
                        FulcrumCredentialsProvider.java
                        BaseFulcrumProvider.java
               security/adapters/opensymphony/src/test OSUserAvalonConf.xml
                        Log4j.properties osuser.xml
               security/adapters/opensymphony/src/test/org/apache/fulcrum/security/adapter/osuser
                        OSUserAdapterTest.java
  Log:
  add opensymphony adapter
  
  Revision  Changes    Path
  1.1                  jakarta-turbine-fulcrum/security/adapters/opensymphony/maven.xml
  
  Index: maven.xml
  ===================================================================
  <project default="jar:jar" xmlns:maven="jelly:maven" xmlns:j="jelly:core" xmlns:util="jelly:util">
  
    <preGoal name="java:compile">
      <attainGoal name="avalon:meta"/>
    </preGoal>
  
  </project>
  
  
  1.1                  jakarta-turbine-fulcrum/security/adapters/opensymphony/project.properties
  
  Index: project.properties
  ===================================================================
  maven.multiproject.type=jar
  maven.junit.usefile=true
  maven.junit.fork=true
  
  
  
  1.1                  jakarta-turbine-fulcrum/security/adapters/opensymphony/project.xml
  
  Index: project.xml
  ===================================================================
  <?xml version="1.0"?>
  <project>
    <extend>${basedir}/../../../project.xml</extend>
    <id>fulcrum-security-adapter-opensymphony</id>
    <name>Fulcrum Security OpenSymphony Adapter</name>
    <currentVersion>1.0-alpha-4</currentVersion>
    <package>org.apache.fulcrum.security</package>
  
    <dependencies>
      <dependency>
        <groupId>fulcrum</groupId>   
        <artifactId>fulcrum-security-api</artifactId>
        <version>1.0-alpha-4</version>
      </dependency>   
      <dependency>
        <groupId>fulcrum</groupId>   
        <artifactId>fulcrum-security-spi</artifactId>
        <version>1.0-alpha-4</version>
      </dependency>      
      <dependency>
        <groupId>fulcrum</groupId>   
        <artifactId>fulcrum-crypto</artifactId>
        <version>1.0-alpha-3</version>
      </dependency>
      
      <dependency>
        <groupId>fulcrum</groupId>    
        <artifactId>fulcrum-factory</artifactId>
        <version>1.0-alpha-1</version>
      </dependency>
  
      <dependency>
        <groupId>avalon-framework</groupId>
        <artifactId>avalon-framework-api</artifactId>
        <version>4.1.5</version>
      </dependency> 
      
      <dependency>
        <id>commons-logging</id>
        <version>1.0.3</version>
      </dependency>      
      <dependency>
        <id>commons-lang</id>
        <version>2.0</version>
      </dependency>  
      <dependency>
        <id>cryptix</id>
        <version>3.2.0</version>
        <url>http://www.cryptix.org/</url>
      </dependency>    
       <dependency>
         <id>commons-beanutils</id>
         <version>1.6.1</version>
       </dependency>    
   <!-- Needed only for the OSUser Adapter -->
      <dependency>
        <groupId>opensymphony</groupId>
          <artifactId>osuser</artifactId>
          <version>1.0-dev</version>         
      </dependency>
      <dependency>
      <groupId>opensymphony</groupId>
          <artifactId>propertyset</artifactId>
          <version>1.3-1Oct03</version>
    </dependency>   
    <dependency>
          <groupId>opensymphony</groupId>
          <artifactId>oscore</artifactId>
      <version>2.2.1</version>
    </dependency>     
      
    
      <!-- testing -->
      <dependency>
        <groupId>fulcrum</groupId>    
        <artifactId>fulcrum-security-memory</artifactId>
        <version>1.0-alpha-4</version>
      </dependency>      
      <dependency>
        <groupId>fulcrum</groupId>    
        <artifactId>fulcrum-testcontainer</artifactId>
        <version>1.0-alpha-1</version>
      </dependency>        
  
   
    </dependencies>
  
  
   <build>
      <nagEmailAddress>turbine-dev@jakarta.apache.org</nagEmailAddress>
  
      <sourceDirectory>${basedir}/src/java/</sourceDirectory>
      <unitTestSourceDirectory>${basedir}/src/test/</unitTestSourceDirectory>
      <unitTest>
        <includes>
          <include>**/*Test.*</include>
          <include>**/*TestCase.*</include>
        </includes>
        <excludes>
          <include>**/Abstract*.*</include>
        </excludes>
        <resources>
          <resource>     
           <directory>${basedir}/src/test</directory>
            <includes>
              <include>**/*.x*</include>
            </includes>
          </resource>      
          <resource>
            <directory>${basedir}/src/java</directory>
            <includes>
              <include>**/*.x*</include>
            </includes>
          </resource>
          <resource>
            <directory>${basedir}/conf</directory>
            <targetPath>BLOCK-INF</targetPath>
            <includes>
              <include>block.xml</include>
            </includes>
          </resource>
        </resources>      
      </unitTest>
      <resources>
         <resource>
           <directory>${basedir}/conf</directory>
           <targetPath>BLOCK-INF</targetPath>
           <includes>
             <include>block.xml</include>
           </includes>
         </resource>
         <resource>
           <directory>${basedir}/src/java</directory>
           <includes>
             <include>**/*.x*</include>
           </includes>
         </resource>
      </resources>
    </build>
  </project>
  
  
  
  
  1.1                  jakarta-turbine-fulcrum/security/adapters/opensymphony/src/java/org/apache/fulcrum/security/adapter/osuser/FulcrumAccessProvider.java
  
  Index: FulcrumAccessProvider.java
  ===================================================================
  package org.apache.fulcrum.security.adapter.osuser;
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001-2003 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 apache@apache.org.
   *
   * 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/>.
   */
  
  import java.util.ArrayList;
  import java.util.List;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.apache.fulcrum.security.entity.Role;
  import org.apache.fulcrum.security.entity.User;
  import org.apache.fulcrum.security.model.dynamic.DynamicAccessControlList;
  import org.apache.fulcrum.security.util.DataBackendException;
  import org.apache.fulcrum.security.util.UnknownEntityException;
  
  import com.opensymphony.user.Entity.Accessor;
  import com.opensymphony.user.provider.AccessProvider;
  
  /**
   * Fulcrum provider for OSUser.  Primarily provides support for requesting
   * whether a user exists in a role.  In OSUser, there are no roles, just groups,
   * so this maps Fulcrum roles on OSUser groups.  This means some the the method
   * names refer to groups, but interact with Fulcrum roles.
   * 
   * @author <a href="mailto:epugh@upstate.com">Eric Pugh</a>
   * @version $Id: FulcrumAccessProvider.java,v 1.1 2003/12/05 23:39:08 epugh Exp $
   */
  public class FulcrumAccessProvider
  	extends BaseFulcrumProvider
  	implements AccessProvider
  {
  	/** Logging */
  	private static Log log = LogFactory.getLog(FulcrumAccessProvider.class);
  	
  	/*
  	 * Not implemented.   Should use SecurityService directly.
  	 * 
  	 * @see com.opensymphony.user.provider.AccessProvider#addToGroup(java.lang.String,
  	 *      java.lang.String)
  	 */
  	public boolean addToGroup(String username, String groupname)
  	{
  		return false;
  	}
  
  	/*
  	 * Returns whether a user in part of a what OSUser calls a group. <strong>
  	 * However, since Fulcrum Security has the concept of roles being
  	 * assignable to groups, then what this method really checks is that the
  	 * user has a specific role. </strong> This is because the mapping between
  	 * OSUser and Fulcurm Security is not a 1 to 1 mapping.
  	 * 
  	 * @see com.opensymphony.user.provider.AccessProvider#inGroup(java.lang.String,
  	 *      java.lang.String)
  	 */
  	public boolean inGroup(String username, String groupname)
  	{
  		try
  		{
  			User user = getSecurityService().getUserManager().getUser(username);
  			DynamicAccessControlList acl =
  			(DynamicAccessControlList)getSecurityService().getUserManager().getACL(user);
  			Role role = acl.getRoles().getRoleByName(groupname);
  			boolean result =acl.hasRole(role); 
  			return result;
  		}
  		catch (UnknownEntityException uee)
  		{
  			return false;
  		}
  		catch (DataBackendException dbe)
  		{
  			throw new RuntimeException(dbe);
  		}
  
  	}
  
  	/*
  	 * This returns all the ROLES that a user has. This is similar to the
  	 * problems with the inGroup() method of this provider.
  	 * 
  	 * @see com.opensymphony.user.provider.AccessProvider#listGroupsContainingUser(java.lang.String)
  	 * @see org.apache.fulcrum.security.adapter.osuser.FulcrumAccessProvider#inGroup(java.lang.String,java.lang.String)
  	 */
  	public List listGroupsContainingUser(String username)
  	{
  		List roles = new ArrayList();
  		try
  		{
  			User user = getSecurityService().getUserManager().getUser(username);
  			DynamicAccessControlList acl =
  				(DynamicAccessControlList)getSecurityService().getUserManager().getACL(user);
  			roles.addAll(acl.getRoles().getNames());
  			
  		}
  		catch (UnknownEntityException uee)
  		{
  			throw new RuntimeException(uee);
  		}
  		catch (DataBackendException dbe)
  		{
  			throw new RuntimeException(dbe);
  		}
  		return roles;
  
  	}
  
  	/*
  	 * Not implemented yet.
  	 * 
  	 * @see com.opensymphony.user.provider.AccessProvider#listUsersInGroup(java.lang.String)
  	 */
  	public List listUsersInGroup(String groupname)
  	{
  		return null;
  	}
  
  	/*
  	 * Not implemented.  Should probably use SecurityService directly.
  	 * 
  	 * @see com.opensymphony.user.provider.AccessProvider#removeFromGroup(java.lang.String,
  	 *      java.lang.String)
  	 */
  	public boolean removeFromGroup(String username, String groupname)
  	{
  		return false;
  	}
  
  	/*
  	 * Not implemented.  Should use SecurityService directly.
  	 * 
  	 * @see com.opensymphony.user.provider.UserProvider#create(java.lang.String)
  	 */
  	public boolean create(String name)
  	{
  		return false;
  	}
  
  	/*
  	 * Doesn't do anything.
  	 * 
  	 * @see com.opensymphony.user.provider.UserProvider#flushCaches()
  	 */
  	public void flushCaches()
  	{
  
  	}
  
  	/*
  	 * Returns true if the user exists, otherwise returns false.
  	 * 
  	 * @see com.opensymphony.user.provider.UserProvider#handles(java.lang.String)
  	 */
  	public boolean handles(String name)
  	{
  		try
  		{
  			User user = getSecurityService().getUserManager().getUser(name);
  			return true;
  		}
  		catch (UnknownEntityException uee)
  		{
  			return false;
  		}
  		catch (DataBackendException dbe)
  		{
  			throw new RuntimeException(dbe);
  		}
  	}
  
  
  
  	/*
  	 * not implemented.
  	 * 
  	 * @see com.opensymphony.user.provider.UserProvider#list()
  	 */
  	public List list()
  	{
  		return null;
  	}
  
  
  
  	/*
  	 * Not implemented.   Should use SecurityService directly.
  	 * 
  	 * @see com.opensymphony.user.provider.UserProvider#remove(java.lang.String)
  	 */
  	public boolean remove(String name)
  	{
  		return false;
  	}
  
  	/*
  	 * Not implemented.   Should use SecurityService directly.
  	 * 
  	 * @see com.opensymphony.user.provider.UserProvider#store(java.lang.String,
  	 *      com.opensymphony.user.Entity.Accessor)
  	 */
  	public boolean store(String arg0, Accessor arg1)
  	{	
  		return false;
  	}
  
  }
  
  
  
  1.1                  jakarta-turbine-fulcrum/security/adapters/opensymphony/src/java/org/apache/fulcrum/security/adapter/osuser/FulcrumCredentialsProvider.java
  
  Index: FulcrumCredentialsProvider.java
  ===================================================================
  package org.apache.fulcrum.security.adapter.osuser;
  /*
   * ==================================================================== The
   * Apache Software License, Version 1.1
   * 
   * Copyright (c) 2001-2003 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 apache@apache.org. 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/> .
   */
  
  import java.util.List;
  
  import org.apache.fulcrum.security.entity.User;
  import org.apache.fulcrum.security.util.DataBackendException;
  import org.apache.fulcrum.security.util.PasswordMismatchException;
  import org.apache.fulcrum.security.util.UnknownEntityException;
  
  import com.opensymphony.user.Entity.Accessor;
  import com.opensymphony.user.provider.CredentialsProvider;
  
  /**
   * Fulcrum provider for OSUser. Primarily provides support for authenticating a
   * user. This delegates to whatever authenticator is configured in the
   * getSecurityService().
   * 
   * @author <a href="mailto:epugh@upstate.com">Eric Pugh</a>
   * @version $Id: FulcrumCredentialsProvider.java,v 1.2 2003/10/21 10:16:29
   *          epugh Exp $
   */
  public class FulcrumCredentialsProvider
      extends BaseFulcrumProvider
      implements CredentialsProvider
  {
  
      /*
  	 * Authenticate a user with their password.
  	 * 
  	 * @see com.opensymphony.user.provider.CredentialsProvider#authenticate(java.lang.String,
  	 *      java.lang.String)
  	 */
      public boolean authenticate(String name, String password)
      {
          try
          {
              User user = getSecurityService().getUserManager().getUser(name);
              getSecurityService().getUserManager().authenticate(user, password);
              return true;
          }
          catch (PasswordMismatchException pme)
          {
              return false;
          }
          catch (UnknownEntityException uee)
          {
              return false;
          }
          catch (DataBackendException dbe)
          {
              throw new RuntimeException(dbe);
          }
  
      }
  
      /*
  	 * Not implemented.
  	 * 
  	 * @see com.opensymphony.user.provider.CredentialsProvider#changePassword(java.lang.String,
  	 *      java.lang.String)
  	 */
      public boolean changePassword(String arg0, String arg1)
      {
  		throw new RuntimeException("Not implemented");
      }
  
      /*
  	 * Not implemented.
  	 * 
  	 * @see com.opensymphony.user.provider.UserProvider#create(java.lang.String)
  	 */
      public boolean create(String name)
      {
  
          throw new RuntimeException("Not implemented");
  
      }
  
      /*
  	 * Does nothing.
  	 * 
  	 * @see com.opensymphony.user.provider.UserProvider#flushCaches()
  	 */
      public void flushCaches()
      {
  
      }
  
      /*
  	 * Returns whether a user exists or not.
  	 * 
  	 * @see com.opensymphony.user.provider.UserProvider#handles(java.lang.String)
  	 */
      public boolean handles(String name)
      {
          try
          {
              User user = getSecurityService().getUserManager().getUser(name);
              return true;
          }
          catch (UnknownEntityException uee)
          {
              return false;
          }
          catch (DataBackendException dbe)
          {
              throw new RuntimeException(dbe);
          }
      }
  
      /*
  	 * Not implemented.
  	 * 
  	 * @see com.opensymphony.user.provider.UserProvider#list()
  	 */
      public List list()
      {
          return null;
      }
  
      /*
  	 * Not implemented.
  	 * 
  	 * @see com.opensymphony.user.provider.UserProvider#remove(java.lang.String)
  	 */
      public boolean remove(String arg0)
      {
  		throw new RuntimeException("Not implemented");
      }
  
      /*
  	 * Not implemented.
  	 * 
  	 * @see com.opensymphony.user.provider.UserProvider#store(java.lang.String,
  	 *      com.opensymphony.user.Entity.Accessor)
  	 */
      public boolean store(String arg0, Accessor arg1)
      {
  		throw new RuntimeException("Not implemented");
      }
  
  }
  
  
  
  1.1                  jakarta-turbine-fulcrum/security/adapters/opensymphony/src/java/org/apache/fulcrum/security/adapter/osuser/BaseFulcrumProvider.java
  
  Index: BaseFulcrumProvider.java
  ===================================================================
  package org.apache.fulcrum.security.adapter.osuser;
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001-2003 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 apache@apache.org.
   *
   * 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/>.
   */
  import java.util.Properties;
  
  import org.apache.avalon.framework.component.ComponentException;
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.apache.fulcrum.security.SecurityService;
  import org.apache.fulcrum.security.util.DataBackendException;
  
  import com.opensymphony.user.Entity.Accessor;
  import com.opensymphony.user.provider.UserProvider;
  
  /**
   * Base implementation of the Fulcrum provider for OSUser. This is meant to
   * provide access from OSUser to the Fulcrum Security implementation.
   * Currently, to change things you should use the Fulcrum Security system
   * directly, this is a very mimimal implementation.
   * 
   * @author <a href="mailto:epugh@upstate.com">Eric Pugh</a>
   * @version $Id: BaseFulcrumProvider.java,v 1.1 2003/12/05 23:39:08 epugh Exp $
   */
  public abstract class BaseFulcrumProvider implements UserProvider
  {
  
  	/** Logging */
  	private static Log log = LogFactory.getLog(BaseFulcrumProvider.class);
  	/** Our Fulcrum Security Service to use */
  	private static SecurityService securityService;
  
  	/*
  	 * Does nothing for now.
  	 * 
  	 * @see com.opensymphony.user.provider.UserProvider#create(java.lang.String)
  	 */
  	public boolean create(String arg0)
  	{
  		return true;
  	}
  
  	/*
  	 * Does nothign for now.
  	 * 
  	 * @see com.opensymphony.user.provider.UserProvider#flushCaches()
  	 */
  	public void flushCaches()
  	{
  
  	}
  
  	/*
  	 * Doesn't do anything. Init isn't required as the Fulcrum Security is
  	 * assumed to be running in an Avalon container.
  	 * 
  	 * @see com.opensymphony.user.provider.UserProvider#init(java.util.Properties)
  	 */
  	public boolean init(Properties arg0)
  	{
  		return true;
  	}
  
  	/*
  	 * Sets the accessor to be mutable, and returns true.
  	 * 
  	 * @see com.opensymphony.user.provider.UserProvider#load(java.lang.String,
  	 *      com.opensymphony.user.Entity.Accessor)
  	 */
  	public boolean load(String name, Accessor accessor)
  	{
  		accessor.setMutable(true);
  
  		return true;
  	}
  
  	/*
  	 * Returns false, this doesn't do anything.
  	 * 
  	 * @see com.opensymphony.user.provider.UserProvider#remove(java.lang.String)
  	 */
  	public boolean remove(String arg0)
  	{
  		return false;
  	}
  
  	/*
  	 * Returns false, this doesn't do anything right now.
  	 * 
  	 * @see com.opensymphony.user.provider.UserProvider#store(java.lang.String,
  	 *      com.opensymphony.user.Entity.Accessor)
  	 */
  	public boolean store(String arg0, Accessor arg1)
  	{
  		return false;
  	}
  
  	/**
  	  * Lazy loads the SecurityService.
  	  * 
  	  * @return
  	  */
  	 public SecurityService getSecurityService() throws DataBackendException
  	 {
  		 if (securityService == null)
  		 {
  			 try
  			 {
  			    throw new ComponentException(SecurityService.ROLE,"SecurityService not initialized!");
  	//			securityService = (SecurityService) manager.lookup(SecurityService.ROLE);
  			 }
  			 catch (ComponentException ce)
  			 {
  				 throw new DataBackendException(ce.getMessage(), ce);
  			 }
  		 }
  		 return securityService;
  	 }
  	
  	/**
  	 * The Fulcrum Security Service that will back the Fulcrum
  	 * providers.
  	 * 
  	 * @param securityService
  	 *            The securityService to set.
  	 */
  	public static void setSecurityService(SecurityService asecurityService)
  	{
  		securityService = asecurityService;
  	}
  
  
  }
  
  
  
  1.1                  jakarta-turbine-fulcrum/security/adapters/opensymphony/src/test/OSUserAvalonConf.xml
  
  Index: OSUserAvalonConf.xml
  ===================================================================
  <my-system>
  
   <component
      role="org.apache.fulcrum.security.adapter.osuser.BaseFulcrumProvider"
      class="org.apache.fulcrum.security.adapter.osuser.BaseFulcrumProvider">   
    </component>  
  	
    <component
      role="org.apache.fulcrum.factory.FactoryService"
      class="org.apache.fulcrum.factory.DefaultFactoryService">   
    </component>  
    
    
    <!-- standard components for In Memory -->
    <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.memory.MemoryUserManagerImpl">   
          <className>org.apache.fulcrum.security.model.dynamic.entity.DynamicUser</className>    
    </component>   
    <component
      role="org.apache.fulcrum.security.GroupManager"
      class="org.apache.fulcrum.security.memory.MemoryGroupManagerImpl">   
          <className>org.apache.fulcrum.security.model.dynamic.entity.DynamicGroup</className>    
    </component>     
  
    <component
      role="org.apache.fulcrum.security.RoleManager"
      class="org.apache.fulcrum.security.memory.MemoryRoleManagerImpl">  
      <className>org.apache.fulcrum.security.model.dynamic.entity.DynamicRole</className>         
    </component>     
  
    <component
      role="org.apache.fulcrum.security.PermissionManager"
      class="org.apache.fulcrum.security.memory.MemoryPermissionManagerImpl">   
          <className>org.apache.fulcrum.security.model.dynamic.entity.DynamicPermission</className>    
    </component>       
  
    <component
      role="org.apache.fulcrum.security.ModelManager"
      class="org.apache.fulcrum.security.memory.dynamic.MemoryModelManagerImpl">   
    </component> 
    
    <component
      role="org.apache.fulcrum.security.authenticator.Authenticator"
      class="org.apache.fulcrum.security.authenticator.TextMatchAuthenticator">   
    </component>   
    
    <component
      role="org.apache.fulcrum.security.model.ACLFactory"
      class="org.apache.fulcrum.security.model.dynamic.DynamicACLFactory">   
    </component>   
  </my-system>
  
  
  1.1                  jakarta-turbine-fulcrum/security/adapters/opensymphony/src/test/Log4j.properties
  
  Index: Log4j.properties
  ===================================================================
  # ------------------------------------------------------------------------
  #
  # Logging Configuration
  #
  # Mix of Turbine logging configuration and Hibernate configuration
  #
  # ------------------------------------------------------------------------
  
  #
  # If we don't know the logging facility, put it into the
  # turbine.log
  #
  log4j.rootLogger = INFO, turbine
  
  #
  # Turbine goes into Turbine Log
  #
  log4j.category.org.apache.turbine = INFO, turbine
  log4j.additivity.org.apache.turbine = false
  
  #
  # Avalon Logfile
  #
  log4j.category.avalon = INFO, avalon
  log4j.additivity.avalon = false
  
  ########################################################################
  #
  # Logfile definitions
  #
  ########################################################################
  
  #
  # turbine.log
  #
  log4j.appender.turbine = org.apache.log4j.FileAppender
  log4j.appender.turbine.file = turbine.log
  log4j.appender.turbine.layout = org.apache.log4j.PatternLayout
  log4j.appender.turbine.layout.conversionPattern = %d [%t] %-5p %c - %m%n
  log4j.appender.turbine.append = false
  
  #
  # torque.log
  # 
  log4j.appender.torque = org.apache.log4j.FileAppender
  log4j.appender.torque.file = target/torque.log
  log4j.appender.torque.layout = org.apache.log4j.PatternLayout
  log4j.appender.torque.layout.conversionPattern = %d [%t] %-5p %c - %m%n
  log4j.appender.torque.append = false
  
  #
  # Avalon gets configured to write its output onto the avalon
  # category.
  #
  log4j.appender.avalon = org.apache.log4j.FileAppender
  log4j.appender.avalon.file = target/avalon.log
  log4j.appender.avalon.layout = org.apache.log4j.PatternLayout
  log4j.appender.avalon.layout.conversionPattern = %d [%t] %-5p %c - %m%n
  log4j.appender.avalon.append = false
  
  
  # BEGIN HIBERNATE SECTION
  ### direct log messages to stdout ###
  log4j.appender.stdout=org.apache.log4j.ConsoleAppender
  log4j.appender.stdout.Target=System.out
  log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
  log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
  
  ### direct messages to file hibernate.log ###
  #log4j.appender.file=org.apache.log4j.FileAppender
  #log4j.appender.file.File=hibernate.log
  #log4j.appender.file.layout=org.apache.log4j.PatternLayout
  #log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
  
  ### set log levels - for more verbose logging change 'info' to 'debug' ##
  
  log4j.rootLogger=warn, stdout
  
  log4j.logger.net.sf.hibernate=warn
  
  ### enable the following line if you want to track down connection ###
  ### leakages when using DriverManagerConnectionProvider ###
  #log4j.logger.net.sf.hibernate.connection.DriverManagerConnectionProvider=trace
  
  ### log JDBC bind parameters ###
  log4j.logger.net.sf.hibernate.type=info
  
  ### log prepared statement cache activity ###
  log4j.logger.net.sf.hibernate.ps.PreparedStatementCache=info
  
  
  
  
  1.1                  jakarta-turbine-fulcrum/security/adapters/opensymphony/src/test/osuser.xml
  
  Index: osuser.xml
  ===================================================================
  <opensymphony-user>
      <!--
  		Authenticators can take properties just like providers.
  
  		This smart authenticator should work for 'most' cases - it dynamically looks up
  		the most appropriate authenticator for the current server.
  	-->
  	<authenticator class="com.opensymphony.user.authenticator.SmartAuthenticator" />
  
      <!-- Fulcrum providers -->
      <provider class="org.apache.fulcrum.security.adapter.osuser.FulcrumAccessProvider"/>       
      <provider class="org.apache.fulcrum.security.adapter.osuser.FulcrumCredentialsProvider"/>
  	<!-- don't have a propertyset provider, so just return a memory one. -->
      <provider class="com.opensymphony.user.provider.memory.MemoryProfileProvider" />
  </opensymphony-user>
  
  
  
  1.1                  jakarta-turbine-fulcrum/security/adapters/opensymphony/src/test/org/apache/fulcrum/security/adapter/osuser/OSUserAdapterTest.java
  
  Index: OSUserAdapterTest.java
  ===================================================================
  package org.apache.fulcrum.security.adapter.osuser;
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2001-2003 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 apache@apache.org.
   *
   * 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/>.
   */
  import java.util.Collection;
  
  import org.apache.fulcrum.security.SecurityService;
  import org.apache.fulcrum.security.entity.Group;
  import org.apache.fulcrum.security.entity.Permission;
  import org.apache.fulcrum.security.entity.Role;
  import org.apache.fulcrum.security.model.dynamic.DynamicAccessControlList;
  import org.apache.fulcrum.security.model.dynamic.DynamicModelManager;
  import org.apache.fulcrum.security.model.dynamic.entity.DynamicUser;
  
  import org.apache.fulcrum.testcontainer.BaseUnitTest;
  
  import com.opensymphony.user.User;
  import com.opensymphony.user.UserManager;
  import com.opensymphony.user.provider.AccessProvider;
  import com.opensymphony.user.provider.CredentialsProvider;
  
  /**
   * Test that we can load up OSUser backed by Fulcrum Security. The fulcrum Security service is just
   * running in memory.
   * 
   * @author <a href="mailto:epugh@upstate.com">Eric Pugh</a>
   * @version $Id: OSUserAdapterTest.java,v 1.1 2003/12/05 23:39:08 epugh Exp $
   */
  
  public class OSUserAdapterTest extends BaseUnitTest
  {
  
      protected UserManager osUserManager;
  
      protected SecurityService securityService;
      private org.apache.fulcrum.security.entity.User fulcrumUser;
      private User osUser;
  
      public OSUserAdapterTest(String name) throws Exception
      {
          super(name);
      }
      public void setUp()
      {
          try
          {
              this.setRoleFileName(null);
              this.setConfigurationFileName("src/test/OSUserAvalonConf.xml");
              securityService = (SecurityService) lookup(SecurityService.ROLE);
              BaseFulcrumProvider.setSecurityService(securityService);
  
              osUserManager = new UserManager("osuser.xml");
          }
          catch (Exception e)
          {
              fail(e.toString());
          }
      }
      public void tearDown()
      {
  
          osUserManager = null;
  
          securityService = null;
      }
      public void testUsingAvalonComponents() throws Exception
      {
          Group fulcrumGroup = securityService.getGroupManager().getGroupInstance("TEST_REVOKEALL");
          securityService.getGroupManager().addGroup(fulcrumGroup);
          Group fulcrumGroup2 = securityService.getGroupManager().getGroupInstance("TEST_REVOKEALL2");
          securityService.getGroupManager().addGroup(fulcrumGroup2);
          Role fulcrumRole = securityService.getRoleManager().getRoleInstance("role1");
          Role fulcrumRole2 = securityService.getRoleManager().getRoleInstance("role2");
          securityService.getRoleManager().addRole(fulcrumRole);
          securityService.getRoleManager().addRole(fulcrumRole2);
          Permission fulcrumPermission =
              securityService.getPermissionManager().getPermissionInstance("perm1");
          Permission fulcrumPermission2 =
              securityService.getPermissionManager().getPermissionInstance("perm2");
          Permission fulcrumPermission3 =
              securityService.getPermissionManager().getPermissionInstance("perm3");
          securityService.getPermissionManager().addPermission(fulcrumPermission);
          securityService.getPermissionManager().addPermission(fulcrumPermission2);
          securityService.getPermissionManager().addPermission(fulcrumPermission3);
          DynamicModelManager modelManager = (DynamicModelManager) securityService.getModelManager();
          modelManager.grant(fulcrumRole, fulcrumPermission);
          modelManager.grant(fulcrumRole2, fulcrumPermission2);
          modelManager.grant(fulcrumRole2, fulcrumPermission3);
          modelManager.grant(fulcrumGroup, fulcrumRole);
          modelManager.grant(fulcrumGroup, fulcrumRole2);
          modelManager.grant(fulcrumGroup2, fulcrumRole2);
          fulcrumUser = securityService.getUserManager().getUserInstance("Jeannie");
          securityService.getUserManager().addUser(fulcrumUser, "wyatt");
          modelManager.grant(fulcrumUser, fulcrumGroup);
          modelManager.grant(fulcrumUser, fulcrumGroup2);
          assertEquals(2, ((DynamicUser) fulcrumUser).getGroups().size());
  
          Collection accessProviders = osUserManager.getAccessProviders();
          assertEquals(1, accessProviders.size());
          AccessProvider accessProvider = (AccessProvider) accessProviders.toArray()[0];
          assertTrue(accessProvider.handles("Jeannie"));
          assertTrue(securityService.getUserManager().checkExists("Jeannie"));
  
          assertEquals(
              "Both should not handle user Bob",
              accessProvider.handles("Bob"),
              securityService.getUserManager().checkExists("Bob"));
  
          fulcrumUser = securityService.getUserManager().getUser("Jeannie");
          DynamicAccessControlList acl = (DynamicAccessControlList)securityService.getUserManager().getACL(fulcrumUser);
          assertEquals(
              "Both should have role1",
              acl.hasRole("role1"),
              accessProvider.inGroup("Jeannie", "role1"));
  
          System.out.println("hi");
          
          assertEquals(
              "Neither should have role3",
              acl.hasRole("role3"),
              accessProvider.inGroup("Jeannie", "role3"));
  
          Collection credentialProviders = osUserManager.getCredentialsProviders();
          assertEquals(1, credentialProviders.size());
          CredentialsProvider credentialProvider =
              (CredentialsProvider) credentialProviders.toArray()[0];
  
          assertTrue(credentialProvider.authenticate("Jeannie", "wyatt"));
  
      }
  
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org