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/10/20 20:28:48 UTC
cvs commit: jakarta-turbine-fulcrum/security/src/test osuser.xml
epugh 2003/10/20 11:28:48
Added: security/src/java/org/apache/fulcrum/security/adapter/osuser
BaseFulcrumProvider.java
FulcrumCredentialsProvider.java
FulcrumAccessProvider.java
security/src/test/org/apache/fulcrum/security/adapter/osuser
OSUserAdapterTest.java
security/src/test osuser.xml
Log:
First cut of adapter for OSUser. Thanks to Youngho for getting me started!
Revision Changes Path
1.1 jakarta-turbine-fulcrum/security/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.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.fulcrum.security.SecurityService;
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/10/20 18:28:47 epugh Exp $
*/
public abstract class BaseFulcrumProvider implements UserProvider
{
/** Logging */
private static Log log = LogFactory.getLog(BaseFulcrumProvider.class);
/** Our Fulcrum Security Service to use */
protected 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;
}
/**
* The Fulcrum Security Service that will back the Fulcrum
* providers.
*
* @param securityService
* The securityService to set.
*/
public void setSecurityService(SecurityService securityService)
{
this.securityService = securityService;
}
}
1.1 jakarta-turbine-fulcrum/security/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
* SecurityService.
*
* @author <a href="mailto:epugh@upstate.com">Eric Pugh</a>
* @version $Id: FulcrumCredentialsProvider.java,v 1.1 2003/10/20 18:28:47 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 = securityService.getUserManager().getUser(name);
securityService.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)
{
return false;
}
/*
* Not implemented.
*
* @see com.opensymphony.user.provider.UserProvider#create(java.lang.String)
*/
public boolean create(String arg0)
{
return false;
}
/*
* 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 = securityService.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)
{
return false;
}
/*
* Not implemented.
*
* @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/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.acl.AccessControlList;
import org.apache.fulcrum.security.entity.User;
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/10/20 18:28:47 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 = securityService.getUserManager().getUser(username);
AccessControlList acl =
securityService.getUserManager().getACL(user);
return acl.hasRole(acl.getRoles().getRoleByName(groupname));
}
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 = securityService.getUserManager().getUser(username);
AccessControlList acl =
securityService.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 = securityService.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/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 java.util.List;
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.simple.entity.SimpleUser;
import org.apache.fulcrum.security.model.simple.manager.SimpleGroupManager;
import org.apache.fulcrum.security.model.simple.manager.SimpleRoleManager;
import org.apache.fulcrum.security.model.simple.manager.SimpleUserManager;
import org.apache.fulcrum.testcontainer.BaseUnitTest;
import com.opensymphony.user.UserManager;
import com.opensymphony.user.provider.AccessProvider;
/**
* 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: AccessControlListAdaptorTest.java,v 1.3 2003/10/20 17:40:12
* epugh Exp $
*/
public class OSUserAdapterTest extends BaseUnitTest
{
protected UserManager osUserManager;
protected org.apache.fulcrum.security.UserManager fulcrumUserManager;
protected SecurityService securityService;
public OSUserAdapterTest(String name) throws Exception
{
super(name);
}
public void setUp()
{
try
{
/*
* this.setRoleFileName(null);
* this.setConfigurationFileName("src/test/SimpleMemory.xml");
* securityService = (SecurityService)
* lookup(SecurityService.ROLE); fulcrumUserManager =
* securityService.getUserManager();
*
* osUserManager = new UserManager("osuser.xml");
*/
}
catch (Exception e)
{
fail(e.toString());
}
}
public void tearDown()
{
osUserManager = null;
fulcrumUserManager = null;
securityService = null;
}
public void testUsingAvalonComponents() throws Exception
{
this.setRoleFileName(null);
this.setConfigurationFileName("src/test/SimpleMemory.xml");
securityService = (SecurityService) lookup(SecurityService.ROLE);
fulcrumUserManager = securityService.getUserManager();
osUserManager = new UserManager("osuser.xml");
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);
((SimpleRoleManager) securityService.getRoleManager()).grant(
fulcrumRole,
fulcrumPermission);
((SimpleRoleManager) securityService.getRoleManager()).grant(
fulcrumRole2,
fulcrumPermission2);
((SimpleRoleManager) securityService.getRoleManager()).grant(
fulcrumRole2,
fulcrumPermission3);
((SimpleGroupManager) securityService.getGroupManager()).grant(
fulcrumGroup,
fulcrumRole);
((SimpleGroupManager) securityService.getGroupManager()).grant(
fulcrumGroup,
fulcrumRole2);
((SimpleGroupManager) securityService.getGroupManager()).grant(
fulcrumGroup2,
fulcrumRole2);
org.apache.fulcrum.security.entity.User fulcrumUser =
securityService.getUserManager().getUserInstance("Jeannie");
securityService.getUserManager().addUser(fulcrumUser, "wyatt");
((SimpleUserManager) securityService.getUserManager()).grant(
fulcrumUser,
fulcrumGroup);
((SimpleUserManager) securityService.getUserManager()).grant(
fulcrumUser,
fulcrumGroup2);
assertEquals(2, ((SimpleUser) fulcrumUser).getGroups().size());
Collection accessProviders = osUserManager.getAccessProviders();
assertEquals(1,accessProviders.size());
AccessProvider accessProvider=(AccessProvider)accessProviders.toArray()[0];
assertTrue(accessProvider.handles("Jeannie"));
/*
* GroupSet groupSet = TurbineSecurity.getService().getAllGroups();
* assertEquals(2, groupSet.size()); RoleSet roleSet =
* TurbineSecurity.getService().getAllRoles(); assertEquals(2,
* roleSet.size()); PermissionSet permissionSet =
* TurbineSecurity.getService().getAllPermissions(); assertEquals(3,
* permissionSet.size()); User turbineUser =
* TurbineSecurity.getService().getUser("Jeannie"); AccessControlList
* acl = TurbineSecurity.getService().getACL(turbineUser);
* assertNotNull(acl); assertEquals(3, acl.getPermissions().size());
* MockHttpSession session = new MockHttpSession();
* session.setupGetAttribute(User.SESSION_KEY, turbineUser);
*/
}
}
1.1 jakarta-turbine-fulcrum/security/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">
<property name="datasource">jdbc/DefaultDS</property>
</provider>
<provider class="org.apache.fulcrum.security.adapter.osuser.FulcrumCredentialsProvider">
<property name="datasource">jdbc/DefaultDS</property>
</provider>
<!-- don't have a propertyset provider, so just return a memory one. -->
<provider class="com.opensymphony.user.provider.memory.MemoryProfileProvider" />
</opensymphony-user>
---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-dev-help@jakarta.apache.org