You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@archiva.apache.org by ol...@apache.org on 2012/04/06 11:59:32 UTC
svn commit: r1310268 [34/42] - in /archiva/redback/redback-core/trunk: ./
redback-authentication/ redback-authentication/redback-authentication-api/
redback-authentication/redback-authentication-api/src/
redback-authentication/redback-authentication-ap...
Propchange: archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryAuthorizationDataSource.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryAuthorizationDataSource.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryAuthorizer.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryAuthorizer.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryAuthorizer.java (added)
+++ archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryAuthorizer.java Fri Apr 6 09:58:14 2012
@@ -0,0 +1,56 @@
+package org.codehaus.plexus.redback.rbac.memory;
+
+/*
+ * Copyright 2005 The Codehaus.
+ *
+ * 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.
+ */
+
+import org.codehaus.plexus.redback.authorization.AuthorizationDataSource;
+import org.codehaus.plexus.redback.authorization.AuthorizationException;
+import org.codehaus.plexus.redback.authorization.AuthorizationResult;
+import org.codehaus.plexus.redback.authorization.Authorizer;
+import org.springframework.stereotype.Service;
+
+/**
+ * @author: Jesse McConnell <je...@codehaus.org>
+ * @version: $Id$
+ */
+@Service("authorizer#memory")
+public class MemoryAuthorizer
+ implements Authorizer
+{
+ public String getId()
+ {
+ return MemoryAuthorizer.class.getName();
+ }
+
+ public AuthorizationResult isAuthorized( AuthorizationDataSource source )
+ throws AuthorizationException
+ {
+ Object principal = source.getPrincipal();
+
+ Object permission = source.getPermission();
+
+ // TODO: Actually use a real permission!
+ if ( "foo".equals( permission.toString() ) )
+ {
+ return new AuthorizationResult( true, principal, null );
+ }
+ else
+ {
+ return new AuthorizationResult( false, principal, null );
+ }
+ }
+}
+
Propchange: archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryAuthorizer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryAuthorizer.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryOperation.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryOperation.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryOperation.java (added)
+++ archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryOperation.java Fri Apr 6 09:58:14 2012
@@ -0,0 +1,164 @@
+package org.codehaus.plexus.redback.rbac.memory;
+
+/*
+ * Copyright 2001-2006 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.
+ */
+
+import org.codehaus.plexus.redback.rbac.Operation;
+
+/**
+ * MemoryOperation
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class MemoryOperation
+ implements Operation, java.io.Serializable
+{
+
+ /**
+ * Field name
+ */
+ private String name;
+
+ /**
+ * Field description
+ */
+ private String description;
+
+ /**
+ * Field resourceRequired
+ */
+ private boolean resourceRequired = false;
+
+ /**
+ * Field permanent
+ */
+ private boolean permanent = false;
+
+ /**
+ * Method equals
+ *
+ * @param other
+ */
+ public boolean equals( Object other )
+ {
+ if ( this == other )
+ {
+ return true;
+ }
+
+ if ( !( other instanceof MemoryOperation ) )
+ {
+ return false;
+ }
+
+ MemoryOperation that = (MemoryOperation) other;
+ boolean result = true;
+ result = result && ( getName() == null ? that.getName() == null : getName().equals( that.getName() ) );
+ return result;
+ }
+
+ /**
+ * Get null
+ */
+ public String getDescription()
+ {
+ return this.description;
+ }
+
+ /**
+ * Get null
+ */
+ public String getName()
+ {
+ return this.name;
+ }
+
+ /**
+ * Method hashCode
+ */
+ public int hashCode()
+ {
+ int result = 17;
+ result = 37 * result + ( name != null ? name.hashCode() : 0 );
+ return result;
+ }
+
+ /**
+ * Get
+ * true if the resource is required for
+ * authorization to be granted
+ *
+ */
+ public boolean isResourceRequired()
+ {
+ return this.resourceRequired;
+ }
+
+ /**
+ * Set null
+ *
+ * @param description
+ */
+ public void setDescription( String description )
+ {
+ this.description = description;
+ }
+
+ /**
+ * Set null
+ *
+ * @param name
+ */
+ public void setName( String name )
+ {
+ this.name = name;
+ }
+
+ /**
+ * Set
+ * true if the resource is required for
+ * authorization to be granted
+ *
+ *
+ * @param resourceRequired
+ */
+ public void setResourceRequired( boolean resourceRequired )
+ {
+ this.resourceRequired = resourceRequired;
+ }
+
+ /**
+ * Method toString
+ */
+ public String toString()
+ {
+ StringBuffer buf = new StringBuffer();
+ buf.append( "name = '" );
+ buf.append( getName() + "'" );
+ return buf.toString();
+ }
+
+ public boolean isPermanent()
+ {
+ return permanent;
+ }
+
+ public void setPermanent( boolean permanent )
+ {
+ this.permanent = permanent;
+ }
+}
Propchange: archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryOperation.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryOperation.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryPermission.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryPermission.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryPermission.java (added)
+++ archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryPermission.java Fri Apr 6 09:58:14 2012
@@ -0,0 +1,193 @@
+package org.codehaus.plexus.redback.rbac.memory;
+
+/*
+ * Copyright 2001-2006 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.
+ */
+
+import org.codehaus.plexus.redback.rbac.Operation;
+import org.codehaus.plexus.redback.rbac.Permission;
+import org.codehaus.plexus.redback.rbac.Resource;
+
+/**
+ * MemoryPermission
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class MemoryPermission
+ implements Permission, java.io.Serializable
+{
+
+ /**
+ * Field name
+ */
+ private String name;
+
+ /**
+ * Field description
+ */
+ private String description;
+
+ /**
+ * Field operation
+ */
+ private MemoryOperation operation;
+
+ /**
+ * Field resource
+ */
+ private MemoryResource resource;
+
+ /**
+ * Field permanent
+ */
+ private boolean permanent = false;
+
+ /**
+ * Method equals
+ *
+ * @param other
+ */
+ public boolean equals( Object other )
+ {
+ if ( this == other )
+ {
+ return true;
+ }
+
+ if ( !( other instanceof MemoryPermission ) )
+ {
+ return false;
+ }
+
+ MemoryPermission that = (MemoryPermission) other;
+ boolean result = true;
+ result = result && ( getName() == null ? that.getName() == null : getName().equals( that.getName() ) );
+ return result;
+ }
+
+ /**
+ * Get null
+ */
+ public String getDescription()
+ {
+ return this.description;
+ }
+
+ /**
+ * Get null
+ */
+ public String getName()
+ {
+ return this.name;
+ }
+
+ /**
+ * Get null
+ */
+ public Operation getOperation()
+ {
+ return (Operation) this.operation;
+ }
+
+ /**
+ * Get null
+ */
+ public Resource getResource()
+ {
+ return (Resource) this.resource;
+ }
+
+ /**
+ * Method hashCode
+ */
+ public int hashCode()
+ {
+ int result = 17;
+ result = 37 * result + ( name != null ? name.hashCode() : 0 );
+ return result;
+ }
+
+ /**
+ * Set null
+ *
+ * @param description
+ */
+ public void setDescription( String description )
+ {
+ this.description = description;
+ }
+
+ /**
+ * Set null
+ *
+ * @param name
+ */
+ public void setName( String name )
+ {
+ this.name = name;
+ }
+
+ /**
+ * Set null
+ *
+ * @param operation
+ */
+ public void setOperation( Operation operation )
+ {
+ if ( !( operation instanceof Operation ) )
+ {
+ throw new ClassCastException( "MemoryPermission.setOperation(operation) parameter must be instanceof "
+ + Operation.class.getName() );
+ }
+ this.operation = (MemoryOperation) operation;
+ }
+
+ /**
+ * Set null
+ *
+ * @param resource
+ */
+ public void setResource( Resource resource )
+ {
+ if ( !( resource instanceof Resource ) )
+ {
+ throw new ClassCastException( "MemoryPermission.setResource(resource) parameter must be instanceof "
+ + Resource.class.getName() );
+ }
+ this.resource = (MemoryResource) resource;
+ }
+
+ /**
+ * Method toString
+ */
+ public String toString()
+ {
+ StringBuffer buf = new StringBuffer();
+ buf.append( "name = '" );
+ buf.append( getName() + "'" );
+ return buf.toString();
+ }
+
+ public boolean isPermanent()
+ {
+ return permanent;
+ }
+
+ public void setPermanent( boolean permanent )
+ {
+ this.permanent = permanent;
+ }
+}
Propchange: archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryPermission.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryPermission.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryRbacManager.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryRbacManager.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryRbacManager.java (added)
+++ archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryRbacManager.java Fri Apr 6 09:58:14 2012
@@ -0,0 +1,539 @@
+package org.codehaus.plexus.redback.rbac.memory;
+
+/*
+ * Copyright 2001-2006 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.
+ */
+
+import org.codehaus.plexus.redback.rbac.AbstractRBACManager;
+import org.codehaus.plexus.redback.rbac.Operation;
+import org.codehaus.plexus.redback.rbac.Permission;
+import org.codehaus.plexus.redback.rbac.RBACManager;
+import org.codehaus.plexus.redback.rbac.RBACObjectAssertions;
+import org.codehaus.plexus.redback.rbac.RbacManagerException;
+import org.codehaus.plexus.redback.rbac.RbacObjectInvalidException;
+import org.codehaus.plexus.redback.rbac.RbacObjectNotFoundException;
+import org.codehaus.plexus.redback.rbac.RbacPermanentException;
+import org.codehaus.plexus.redback.rbac.Resource;
+import org.codehaus.plexus.redback.rbac.Role;
+import org.codehaus.plexus.redback.rbac.UserAssignment;
+import org.codehaus.plexus.util.StringUtils;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * MemoryRbacManager: a very quick and dirty implementation of a rbac store
+ * <p/>
+ * WARNING: not for actual usage, its not sound - jesse
+ *
+ * @author Jesse McConnell <jm...@apache.org>
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+@Service( "rBACManager#memory" )
+public class MemoryRbacManager
+ extends AbstractRBACManager
+ implements RBACManager
+{
+ private Map<String, Role> roles = new HashMap<String, Role>();
+
+ private Map<String, Permission> permissions = new HashMap<String, Permission>();
+
+ private Map<String, Operation> operations = new HashMap<String, Operation>();
+
+ private Map<String, Resource> resources = new HashMap<String, Resource>();
+
+ private Map<String, UserAssignment> userAssignments = new HashMap<String, UserAssignment>();
+
+ // ----------------------------------------------------------------------
+ // Role methods
+ // ----------------------------------------------------------------------
+
+ public Role saveRole( Role role )
+ throws RbacManagerException
+ {
+ RBACObjectAssertions.assertValid( "Save Role", role );
+
+ triggerInit();
+
+ roles.put( role.getName(), role );
+
+ fireRbacRoleSaved( role );
+
+ if ( role.getPermissions() != null )
+ {
+ for ( Permission p : role.getPermissions() )
+ {
+ savePermission( p );
+ }
+ }
+
+ return role;
+ }
+
+ public void saveRoles( Collection<Role> roles )
+ throws RbacObjectInvalidException, RbacManagerException
+ {
+ if ( roles == null )
+ {
+ // Nothing to do.
+ return;
+ }
+
+ for ( Role role : roles )
+ {
+ saveRole( role );
+ }
+ }
+
+ private void assertRoleExists( String roleName )
+ throws RbacObjectNotFoundException
+ {
+ if ( !roles.containsKey( roleName ) )
+ {
+ throw new RbacObjectNotFoundException( "Role '" + roleName + "' does not exist." );
+ }
+ }
+
+ public Role getRole( String roleName )
+ throws RbacObjectNotFoundException
+ {
+ triggerInit();
+
+ assertRoleExists( roleName );
+
+ return roles.get( roleName );
+ }
+
+ public void removeRole( Role role )
+ throws RbacManagerException, RbacObjectNotFoundException
+ {
+ RBACObjectAssertions.assertValid( "Remove Role", role );
+
+ if ( role.isPermanent() )
+ {
+ throw new RbacPermanentException( "Unable to delete permanent role [" + role.getName() + "]" );
+ }
+
+ assertRoleExists( role.getName() );
+
+ fireRbacRoleRemoved( role );
+
+ roles.remove( role.getName() );
+ }
+
+ public List<Role> getAllRoles()
+ throws RbacManagerException
+ {
+ triggerInit();
+
+ return Collections.unmodifiableList( new ArrayList<Role>( roles.values() ) );
+ }
+
+ // ----------------------------------------------------------------------
+ // Permission methods
+ // ----------------------------------------------------------------------
+
+ public Operation saveOperation( Operation operation )
+ throws RbacManagerException
+ {
+ triggerInit();
+
+ RBACObjectAssertions.assertValid( "Save Operation", operation );
+
+ operations.put( operation.getName(), operation );
+ return operation;
+ }
+
+ public Permission savePermission( Permission permission )
+ throws RbacManagerException
+ {
+ triggerInit();
+
+ RBACObjectAssertions.assertValid( "Save Permission", permission );
+
+ permissions.put( permission.getName(), permission );
+
+ fireRbacPermissionSaved( permission );
+
+ saveOperation( permission.getOperation() );
+ saveResource( permission.getResource() );
+ return permission;
+ }
+
+ public Resource saveResource( Resource resource )
+ throws RbacManagerException
+ {
+ triggerInit();
+
+ RBACObjectAssertions.assertValid( "Save Resource", resource );
+
+ resources.put( resource.getIdentifier(), resource );
+ return resource;
+ }
+
+ public UserAssignment saveUserAssignment( UserAssignment userAssignment )
+ throws RbacManagerException
+ {
+ triggerInit();
+
+ RBACObjectAssertions.assertValid( "Save UserAssignment", userAssignment );
+
+ fireRbacUserAssignmentSaved( userAssignment );
+
+ userAssignments.put( userAssignment.getPrincipal(), userAssignment );
+ return userAssignment;
+ }
+
+ public Operation createOperation( String name )
+ throws RbacManagerException
+ {
+ Operation operation;
+
+ try
+ {
+ operation = getOperation( name );
+ }
+ catch ( RbacObjectNotFoundException e )
+ {
+ operation = new MemoryOperation();
+ operation.setName( name );
+ }
+
+ return operation;
+ }
+
+ public Permission createPermission( String name )
+ throws RbacManagerException
+ {
+ Permission permission;
+
+ try
+ {
+ permission = getPermission( name );
+ }
+ catch ( RbacObjectNotFoundException e )
+ {
+ permission = new MemoryPermission();
+ permission.setName( name );
+ }
+
+ return permission;
+ }
+
+ public Permission createPermission( String name, String operationName, String resourceIdentifier )
+ throws RbacManagerException
+ {
+ Permission permission;
+
+ try
+ {
+ permission = getPermission( name );
+
+ if ( StringUtils.equals( operationName, permission.getOperation().getName() ) )
+ {
+ throw new RbacManagerException( "Attempted to create a permission named '" + name +
+ "' with an operation named '" + operationName
+ + "', but that overides the existing '" + name +
+ "' permission with operation '"
+ + permission.getOperation().getName() + "'" );
+ }
+
+ }
+ catch ( RbacObjectNotFoundException e )
+ {
+ permission = new MemoryPermission();
+ permission.setName( name );
+
+ permission.setOperation( createOperation( operationName ) );
+ permission.setResource( createResource( resourceIdentifier ) );
+ }
+
+ return permission;
+ }
+
+ public Resource createResource( String identifier )
+ throws RbacManagerException
+ {
+ Resource resource;
+
+ try
+ {
+ resource = getResource( identifier );
+ }
+ catch ( RbacObjectNotFoundException e )
+ {
+ resource = new MemoryResource();
+ resource.setIdentifier( identifier );
+ }
+
+ return resource;
+ }
+
+ public Role createRole( String name )
+ {
+ Role role = new MemoryRole();
+ role.setName( name );
+
+ return role;
+ }
+
+ private void assertPermissionExists( String permissionName )
+ throws RbacObjectNotFoundException
+ {
+ if ( !permissions.containsKey( permissionName ) )
+ {
+ throw new RbacObjectNotFoundException( "Permission '" + permissionName + "' does not exist." );
+ }
+ }
+
+ public Permission getPermission( String permissionName )
+ throws RbacObjectNotFoundException, RbacManagerException
+ {
+ triggerInit();
+
+ assertPermissionExists( permissionName );
+
+ return permissions.get( permissionName );
+ }
+
+ public List<Resource> getResources()
+ throws RbacManagerException
+ {
+ triggerInit();
+
+ return Collections.unmodifiableList( new ArrayList<Resource>( resources.values() ) );
+ }
+
+ public void removeOperation( Operation operation )
+ throws RbacObjectNotFoundException, RbacManagerException
+ {
+ RBACObjectAssertions.assertValid( "Remove Operation", operation );
+
+ if ( operation.isPermanent() )
+ {
+ throw new RbacPermanentException( "Unable to delete permanent operation [" + operation.getName() + "]" );
+ }
+
+ assertOpertionExists( operation.getName() );
+
+ operations.remove( operation.getName() );
+ }
+
+ private void assertOpertionExists( String operationName )
+ throws RbacObjectNotFoundException
+ {
+ if ( !operations.containsKey( operationName ) )
+ {
+ throw new RbacObjectNotFoundException( "Operation '" + operationName + "' not found." );
+ }
+ }
+
+ public void removePermission( Permission permission )
+ throws RbacObjectNotFoundException, RbacManagerException
+ {
+ RBACObjectAssertions.assertValid( "Remove Permission", permission );
+
+ if ( permission.isPermanent() )
+ {
+ throw new RbacPermanentException( "Unable to delete permanent permission [" + permission.getName() + "]" );
+ }
+
+ assertPermissionExists( permission.getName() );
+
+ fireRbacPermissionRemoved( permission );
+
+ permissions.remove( permission.getName() );
+ }
+
+ public void removeResource( Resource resource )
+ throws RbacObjectNotFoundException, RbacManagerException
+ {
+ RBACObjectAssertions.assertValid( "Remove Resource", resource );
+
+ if ( resource.isPermanent() )
+ {
+ throw new RbacPermanentException(
+ "Unable to delete permanent resource [" + resource.getIdentifier() + "]" );
+ }
+
+ assertResourceExists( resource.getIdentifier() );
+
+ resources.remove( resource.getIdentifier() );
+ }
+
+ private void assertResourceExists( String resourceIdentifier )
+ throws RbacObjectNotFoundException
+ {
+ if ( !resources.containsKey( resourceIdentifier ) )
+ {
+ throw new RbacObjectNotFoundException( "Resource '" + resourceIdentifier + "' not found." );
+ }
+ }
+
+ private void assertUserAssignmentExists( String principal )
+ throws RbacObjectNotFoundException
+ {
+ if ( !userAssignments.containsKey( principal ) )
+ {
+ throw new RbacObjectNotFoundException( "UserAssignment '" + principal + "' not found." );
+ }
+ }
+
+ public void removeUserAssignment( UserAssignment userAssignment )
+ throws RbacObjectNotFoundException, RbacManagerException
+ {
+ RBACObjectAssertions.assertValid( "Remove User Assignment", userAssignment );
+
+ if ( userAssignment.isPermanent() )
+ {
+ throw new RbacPermanentException(
+ "Unable to delete permanent user assignment [" + userAssignment.getPrincipal() + "]" );
+ }
+
+ fireRbacUserAssignmentRemoved( userAssignment );
+
+ assertUserAssignmentExists( userAssignment.getPrincipal() );
+
+ userAssignments.remove( userAssignment.getPrincipal() );
+ }
+
+ public void eraseDatabase()
+ {
+ userAssignments.clear();
+ resources.clear();
+ operations.clear();
+ permissions.clear();
+ roles.clear();
+ }
+
+ public UserAssignment createUserAssignment( String principal )
+ throws RbacManagerException
+ {
+ try
+ {
+ return getUserAssignment( principal );
+ }
+ catch ( RbacObjectNotFoundException e )
+ {
+ UserAssignment ua = new MemoryUserAssignment();
+ ua.setPrincipal( principal );
+
+ fireRbacUserAssignmentSaved( ua );
+
+ return ua;
+ }
+ }
+
+ public List<Operation> getAllOperations()
+ throws RbacManagerException
+ {
+ triggerInit();
+
+ return Collections.unmodifiableList( new ArrayList<Operation>( operations.values() ) );
+ }
+
+ public List<Permission> getAllPermissions()
+ throws RbacManagerException
+ {
+ triggerInit();
+
+ return Collections.unmodifiableList( new ArrayList<Permission>( permissions.values() ) );
+ }
+
+ public List<Resource> getAllResources()
+ throws RbacManagerException
+ {
+ triggerInit();
+
+ return Collections.unmodifiableList( new ArrayList<Resource>( resources.values() ) );
+ }
+
+ public List<UserAssignment> getAllUserAssignments()
+ throws RbacManagerException
+ {
+ triggerInit();
+
+ return Collections.unmodifiableList( new ArrayList<UserAssignment>( userAssignments.values() ) );
+ }
+
+ public List<UserAssignment> getUserAssignmentsForRoles( Collection<String> roleNames )
+ throws RbacManagerException
+ {
+
+ List<UserAssignment> allUserAssignments = getAllUserAssignments();
+ List<UserAssignment> userAssignments = new ArrayList<UserAssignment>( allUserAssignments.size() );
+
+ for ( UserAssignment ua : allUserAssignments )
+ {
+ for ( String roleName : roleNames )
+ {
+ if ( ua.getRoleNames().contains( roleName ) )
+ {
+ userAssignments.add( ua );
+ break;
+ }
+ }
+ }
+
+ return userAssignments;
+ }
+
+ public UserAssignment getUserAssignment( String principal )
+ throws RbacObjectNotFoundException, RbacManagerException
+ {
+ triggerInit();
+
+ assertUserAssignmentExists( principal );
+
+ return userAssignments.get( principal );
+ }
+
+ public Operation getOperation( String operationName )
+ throws RbacObjectNotFoundException, RbacManagerException
+ {
+ triggerInit();
+
+ assertOpertionExists( operationName );
+
+ return operations.get( operationName );
+ }
+
+ public Resource getResource( String resourceIdentifier )
+ throws RbacObjectNotFoundException, RbacManagerException
+ {
+ triggerInit();
+
+ assertResourceExists( resourceIdentifier );
+
+ return resources.get( resourceIdentifier );
+ }
+
+ private boolean hasTriggeredInit = false;
+
+ public void triggerInit()
+ {
+ if ( !hasTriggeredInit )
+ {
+ fireRbacInit( roles.isEmpty() );
+ hasTriggeredInit = true;
+ }
+ }
+}
Propchange: archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryRbacManager.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryRbacManager.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryResource.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryResource.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryResource.java (added)
+++ archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryResource.java Fri Apr 6 09:58:14 2012
@@ -0,0 +1,146 @@
+package org.codehaus.plexus.redback.rbac.memory;
+
+/*
+ * Copyright 2001-2006 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.
+ */
+
+import org.codehaus.plexus.redback.rbac.Resource;
+
+/**
+ * MemoryResource
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class MemoryResource
+ implements Resource, java.io.Serializable
+{
+ /**
+ * Field identifier
+ */
+ private String identifier;
+
+ /**
+ * Field pattern
+ */
+ private boolean pattern = false;
+
+ /**
+ * Field permanent
+ */
+ private boolean permanent = false;
+
+ /**
+ * Method equals
+ *
+ * @param other
+ */
+ public boolean equals( Object other )
+ {
+ if ( this == other )
+ {
+ return true;
+ }
+
+ if ( !( other instanceof MemoryResource ) )
+ {
+ return false;
+ }
+
+ MemoryResource that = (MemoryResource) other;
+ boolean result = true;
+ result = result
+ && ( getIdentifier() == null ? that.getIdentifier() == null : getIdentifier().equals( that.getIdentifier() ) );
+ return result;
+ }
+
+ /**
+ * Get
+ * The string identifier for an operation.
+ *
+ */
+ public String getIdentifier()
+ {
+ return this.identifier;
+ }
+
+ /**
+ * Method hashCode
+ */
+ public int hashCode()
+ {
+ int result = 17;
+ result = 37 * result + ( identifier != null ? identifier.hashCode() : 0 );
+ return result;
+ }
+
+ /**
+ * Get
+ * true if the identifer is a pattern that is to be
+ * evaluated, for example x.* could match x.a or x.b and x.**
+ * could match x.foo
+ *
+ */
+ public boolean isPattern()
+ {
+ return this.pattern;
+ }
+
+ /**
+ * Set
+ * The string identifier for an operation.
+ *
+ *
+ * @param identifier
+ */
+ public void setIdentifier( String identifier )
+ {
+ this.identifier = identifier;
+ }
+
+ /**
+ * Set
+ * true if the identifer is a pattern that is to be
+ * evaluated, for example x.* could match x.a or x.b and x.**
+ * could match x.foo
+ *
+ *
+ * @param pattern
+ */
+ public void setPattern( boolean pattern )
+ {
+ this.pattern = pattern;
+ }
+
+ /**
+ * Method toString
+ */
+ public String toString()
+ {
+ StringBuffer buf = new StringBuffer();
+ buf.append( "identifier = '" ).append( getIdentifier() + "'" );
+ return buf.toString();
+ }
+
+ public boolean isPermanent()
+ {
+ return permanent;
+ }
+
+ public void setPermanent( boolean permanent )
+ {
+ this.permanent = permanent;
+ }
+}
Propchange: archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryResource.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryResource.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryRole.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryRole.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryRole.java (added)
+++ archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryRole.java Fri Apr 6 09:58:14 2012
@@ -0,0 +1,251 @@
+package org.codehaus.plexus.redback.rbac.memory;
+
+/*
+ * Copyright 2001-2006 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.
+ */
+
+import org.codehaus.plexus.redback.rbac.AbstractRole;
+import org.codehaus.plexus.redback.rbac.Permission;
+import org.codehaus.plexus.redback.rbac.Role;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * MemoryRole
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class MemoryRole
+ extends AbstractRole
+ implements Role, java.io.Serializable
+{
+
+ /**
+ * Field name
+ */
+ private String name;
+
+ /**
+ * Field description
+ */
+ private String description;
+
+ /**
+ * Field assignable
+ */
+ private boolean assignable = false;
+
+ /**
+ * Field childRoleNames
+ */
+ private List<String> childRoleNames = new ArrayList<String>( 0 );
+
+ /**
+ * Field permissions
+ */
+ private List<Permission> permissions = new ArrayList<Permission>( 0 );
+
+ /**
+ * Field permanent
+ */
+ private boolean permanent = false;
+
+ /**
+ * Method addPermission
+ *
+ * @param memoryPermission
+ */
+ public void addPermission( Permission memoryPermission )
+ {
+ if ( !( memoryPermission instanceof MemoryPermission ) )
+ {
+ throw new ClassCastException( "MemoryRole.addPermissions(memoryPermission) parameter must be instanceof "
+ + MemoryPermission.class.getName() );
+ }
+ getPermissions().add( ( (MemoryPermission) memoryPermission ) );
+ }
+
+ /**
+ * Method equals
+ *
+ * @param other
+ */
+ public boolean equals( Object other )
+ {
+ if ( this == other )
+ {
+ return true;
+ }
+
+ if ( !( other instanceof MemoryRole ) )
+ {
+ return false;
+ }
+
+ MemoryRole that = (MemoryRole) other;
+ boolean result = true;
+ result = result && ( getName() == null ? that.getName() == null : getName().equals( that.getName() ) );
+ return result;
+ }
+
+ /**
+ * Method getChildRoles
+ */
+ public List<String> getChildRoleNames()
+ {
+ return this.childRoleNames;
+ }
+
+ /**
+ * Get null
+ */
+ public String getDescription()
+ {
+ return this.description;
+ }
+
+ /**
+ * Get null
+ */
+ public String getName()
+ {
+ return this.name;
+ }
+
+ /**
+ * Method getPermissions
+ */
+ public List<Permission> getPermissions()
+ {
+ return this.permissions;
+ }
+
+ /**
+ * Method hashCode
+ */
+ public int hashCode()
+ {
+ int result = 17;
+ result = 37 * result + ( name != null ? name.hashCode() : 0 );
+ return result;
+ }
+
+ /**
+ * Get
+ * true if this role is available to be assigned to
+ * a user
+ */
+ public boolean isAssignable()
+ {
+ return this.assignable;
+ }
+
+ /**
+ * Method removePermission
+ *
+ * @param memoryPermission
+ */
+ public void removePermission( Permission memoryPermission )
+ {
+ if ( !( memoryPermission instanceof MemoryPermission ) )
+ {
+ throw new ClassCastException( "MemoryRole.removePermissions(memoryPermission) parameter must be instanceof "
+ + MemoryPermission.class.getName() );
+ }
+ getPermissions().remove( ( (MemoryPermission) memoryPermission ) );
+ }
+
+ /**
+ * Set
+ * true if this role is available to be assigned to
+ * a user
+ *
+ * @param assignable
+ */
+ public void setAssignable( boolean assignable )
+ {
+ this.assignable = assignable;
+ }
+
+ /**
+ * Set null
+ *
+ * @param description
+ */
+ public void setDescription( String description )
+ {
+ this.description = description;
+ }
+
+ /**
+ * Set null
+ *
+ * @param name
+ */
+ public void setName( String name )
+ {
+ this.name = name;
+ }
+
+ /**
+ * Set null
+ *
+ * @param permissions
+ */
+ public void setPermissions( List<Permission> permissions )
+ {
+ this.permissions = permissions;
+ }
+
+ /**
+ * Method toString
+ */
+ public java.lang.String toString()
+ {
+ StringBuffer buf = new StringBuffer();
+ buf.append( "name = '" );
+ buf.append( getName() + "'" );
+ return buf.toString();
+ }
+
+ public void addChildRoleName( String name )
+ {
+ this.childRoleNames.add( name );
+ }
+
+ public void setChildRoleNames( List<String> names )
+ {
+ if ( names == null )
+ {
+ this.childRoleNames.clear();
+ }
+ else
+ {
+ this.childRoleNames = names;
+ }
+ }
+
+ public boolean isPermanent()
+ {
+ return permanent;
+ }
+
+ public void setPermanent( boolean permanent )
+ {
+ this.permanent = permanent;
+ }
+}
Propchange: archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryRole.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryRole.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryUserAssignment.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryUserAssignment.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryUserAssignment.java (added)
+++ archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryUserAssignment.java Fri Apr 6 09:58:14 2012
@@ -0,0 +1,147 @@
+package org.codehaus.plexus.redback.rbac.memory;
+
+/*
+ * Copyright 2001-2006 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.
+ */
+
+import org.codehaus.plexus.redback.rbac.AbstractUserAssignment;
+import org.codehaus.plexus.redback.rbac.UserAssignment;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * MemoryUserAssignment
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class MemoryUserAssignment
+ extends AbstractUserAssignment
+ implements UserAssignment, java.io.Serializable
+{
+
+ /**
+ * Field principal
+ */
+ private String principal;
+
+ /**
+ * Field roles
+ */
+ private List<String> roles = new ArrayList<String>( 0 );
+
+ /**
+ * Field permanent
+ */
+ private boolean permanent = false;
+
+ /**
+ * Method equals
+ *
+ * @param other
+ */
+ public boolean equals( Object other )
+ {
+ if ( this == other )
+ {
+ return true;
+ }
+
+ if ( !( other instanceof MemoryUserAssignment ) )
+ {
+ return false;
+ }
+
+ MemoryUserAssignment that = (MemoryUserAssignment) other;
+ boolean result = true;
+ result = result && ( getPrincipal() == null
+ ? that.getPrincipal() == null
+ : getPrincipal().equals( that.getPrincipal() ) );
+ return result;
+ }
+
+ /**
+ * Get null
+ */
+ public String getPrincipal()
+ {
+ return this.principal;
+ }
+
+ /**
+ * Method getRoles
+ */
+ public List<String> getRoleNames()
+ {
+ if ( this.roles == null )
+ {
+ this.roles = new ArrayList<String>( 0 );
+ }
+
+ return this.roles;
+ }
+
+ /**
+ * Method hashCode
+ */
+ public int hashCode()
+ {
+ int result = 17;
+ result = 37 * result + ( principal != null ? principal.hashCode() : 0 );
+ return result;
+ }
+
+ /**
+ * Set null
+ *
+ * @param principal
+ */
+ public void setPrincipal( String principal )
+ {
+ this.principal = principal;
+ }
+
+ /**
+ * Set null
+ *
+ * @param roles
+ */
+ public void setRoleNames( List<String> roles )
+ {
+ this.roles = roles;
+ }
+
+ /**
+ * Method toString
+ */
+ public java.lang.String toString()
+ {
+ StringBuffer buf = new StringBuffer();
+ buf.append( "principal = '" );
+ buf.append( getPrincipal() + "'" );
+ return buf.toString();
+ }
+
+ public boolean isPermanent()
+ {
+ return permanent;
+ }
+
+ public void setPermanent( boolean permanent )
+ {
+ this.permanent = permanent;
+ }
+}
Propchange: archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryUserAssignment.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryUserAssignment.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/resources/META-INF/spring-context.xml
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/resources/META-INF/spring-context.xml?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/resources/META-INF/spring-context.xml (added)
+++ archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/resources/META-INF/spring-context.xml Fri Apr 6 09:58:14 2012
@@ -0,0 +1,34 @@
+<?xml version="1.0"?>
+
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you 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.
+ -->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
+ http://www.springframework.org/schema/context
+ http://www.springframework.org/schema/context/spring-context-3.0.xsd"
+ default-lazy-init="true">
+
+ <context:annotation-config />
+ <context:component-scan
+ base-package="org.codehaus.plexus.redback.rbac.memory"/>
+
+</beans>
\ No newline at end of file
Propchange: archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/resources/META-INF/spring-context.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/resources/META-INF/spring-context.xml
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/test/java/org/codehaus/plexus/redback/rbac/memory/MemoryRbacManagerTest.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/test/java/org/codehaus/plexus/redback/rbac/memory/MemoryRbacManagerTest.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/test/java/org/codehaus/plexus/redback/rbac/memory/MemoryRbacManagerTest.java (added)
+++ archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/test/java/org/codehaus/plexus/redback/rbac/memory/MemoryRbacManagerTest.java Fri Apr 6 09:58:14 2012
@@ -0,0 +1,58 @@
+package org.codehaus.plexus.redback.rbac.memory;
+
+/*
+ * Copyright 2001-2006 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.
+ */
+
+import net.sf.ehcache.CacheManager;
+
+import org.codehaus.plexus.redback.rbac.RBACManager;
+import org.codehaus.plexus.redback.tests.AbstractRbacManagerTestCase;
+import org.junit.Before;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+
+/**
+ * MemoryRbacManagerTest
+ *
+ * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
+ * @version $Id$
+ */
+public class MemoryRbacManagerTest
+ extends AbstractRbacManagerTestCase
+{
+
+ @Inject
+ @Named (value = "rBACManager#memory")
+ RBACManager rbacManager;
+
+ /**
+ * Creates a new RbacStore which contains no data.
+ */
+ @Before
+ public void setUp()
+ throws Exception
+ {
+ /*
+ CacheManager.getInstance().removeCache( "usersCache" );
+ CacheManager.getInstance().removalAll();
+ CacheManager.getInstance().shutdown();
+ */
+ super.setUp();
+
+ setRbacManager( rbacManager );
+ }
+}
Propchange: archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/test/java/org/codehaus/plexus/redback/rbac/memory/MemoryRbacManagerTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/test/java/org/codehaus/plexus/redback/rbac/memory/MemoryRbacManagerTest.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/test/resources/spring-context.xml
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/test/resources/spring-context.xml?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/test/resources/spring-context.xml (added)
+++ archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/test/resources/spring-context.xml Fri Apr 6 09:58:14 2012
@@ -0,0 +1,55 @@
+<?xml version="1.0"?>
+
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements. See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership. The ASF licenses this file
+ ~ to you 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.
+ -->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
+ http://www.springframework.org/schema/context
+ http://www.springframework.org/schema/context/spring-context-3.0.xsd">
+
+ <bean name="jdoFactory#users" class="org.codehaus.plexus.jdo.DefaultConfigurableJdoFactory">
+ <property name="driverName" value="org.hsqldb.jdbcDriver"/>
+ <property name="url" value="jdbc:hsqldb:mem:redback-users-tests" />
+ <property name="userName" value="sa"/>
+ <property name="password" value=""/>
+ <property name="persistenceManagerFactoryClass" value="org.jpox.PersistenceManagerFactoryImpl"/>
+ <property name="otherProperties">
+ <props>
+ <prop key="org.jpox.rdbms.dateTimezone">JDK_DEFAULT_TIMEZONE</prop>
+ <prop key="org.jpox.autoCreateTables">true</prop>
+ </props>
+ </property>
+ </bean>
+
+ <bean name="userConfiguration" class="org.codehaus.plexus.redback.configuration.UserConfiguration">
+ <property name="registry" ref="test-conf"/>
+ </bean>
+
+ <bean name="commons-configuration" class="org.codehaus.redback.components.registry.commons.CommonsConfigurationRegistry">
+ </bean>
+
+ <alias name="commons-configuration" alias="test-conf"/>
+
+
+
+
+</beans>
\ No newline at end of file
Propchange: archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/test/resources/spring-context.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/test/resources/spring-context.xml
------------------------------------------------------------------------------
svn:executable =
Propchange: archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/test/resources/spring-context.xml
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-xstream/pom.xml
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-xstream/pom.xml?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-xstream/pom.xml (added)
+++ archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-xstream/pom.xml Fri Apr 6 09:58:14 2012
@@ -0,0 +1,18 @@
+<project>
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.codehaus.redback</groupId>
+ <artifactId>plexus-security-authorization-rbac-stores</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+ <artifactId>plexus-security-authorization-rbac-store-xstream</artifactId>
+ <packaging>pom</packaging>
+ <scm>
+ <connection>
+ scm:svn:http://svn.codehaus.org/redback/redback/trunk/redback-rbac/redback-rbac-providers/redback-rbac-xstream
+ </connection>
+ <developerConnection>
+ scm:svn:https://svn.codehaus.org/redback/redback/trunk/redback-rbac/redback-rbac-providers/redback-rbac-xstream
+ </developerConnection>
+ </scm>
+</project>
Propchange: archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-xstream/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-xstream/pom.xml
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-role-manager/pom.xml
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-role-manager/pom.xml?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-role-manager/pom.xml (added)
+++ archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-role-manager/pom.xml Fri Apr 6 09:58:14 2012
@@ -0,0 +1,132 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.codehaus.redback</groupId>
+ <artifactId>redback-rbac</artifactId>
+ <version>1.5-SNAPSHOT</version>
+ </parent>
+ <artifactId>redback-rbac-role-manager</artifactId>
+ <name>Redback :: RBAC Role Manager</name>
+ <packaging>jar</packaging>
+ <dependencies>
+ <dependency>
+ <groupId>net.java.dev.stax-utils</groupId>
+ <artifactId>stax-utils</artifactId>
+ <version>20060502</version>
+ <exclusions>
+ <!-- Can't use BEA's proprietary java.xml.stream provider.
+ Using woodstox provider instead (see below) -->
+ <exclusion>
+ <groupId>com.bea.xml</groupId>
+ <artifactId>jsr173-ri</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>javax.xml.stream</groupId>
+ <artifactId>stax-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.woodstox</groupId>
+ <artifactId>wstx-asl</artifactId>
+ <version>3.2.1</version>
+ <exclusions>
+ <exclusion>
+ <groupId>stax</groupId>
+ <artifactId>stax-api</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-context-support</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>javax.annotation</groupId>
+ <artifactId>jsr250-api</artifactId>
+ </dependency>
+ <dependency>
+ <artifactId>redback-rbac-memory</artifactId>
+ <groupId>org.codehaus.redback</groupId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <artifactId>redback-rbac-jdo</artifactId>
+ <groupId>org.codehaus.redback</groupId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.redback</groupId>
+ <artifactId>redback-rbac-model</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.redback</groupId>
+ <artifactId>redback-common-jdo</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.redback</groupId>
+ <artifactId>redback-rbac-cached</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>stax</groupId>
+ <artifactId>stax</artifactId>
+ <version>1.1.1-dev</version>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>xmlbeans</groupId>
+ <artifactId>xmlbeans-jsr173-api</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.hsqldb</groupId>
+ <artifactId>hsqldb</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.redback</groupId>
+ <artifactId>redback-common-test-resources</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.modello</groupId>
+ <artifactId>modello-maven-plugin</artifactId>
+ <version>1.0-alpha-15</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>java</goal>
+ <goal>xsd</goal>
+ <goal>stax-reader</goal>
+ <goal>stax-writer</goal>
+ </goals>
+ <configuration>
+ <model>src/main/mdo/redback-role-profiles.mdo</model>
+ <version>1.0.0</version>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <forkMode>always</forkMode>
+ <systemPropertyVariables>
+ <basedir>${basedir}</basedir>
+ </systemPropertyVariables>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
Propchange: archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-role-manager/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-role-manager/pom.xml
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-role-manager/src/main/java/org/codehaus/plexus/redback/role/DefaultRoleManager.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-role-manager/src/main/java/org/codehaus/plexus/redback/role/DefaultRoleManager.java?rev=1310268&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-role-manager/src/main/java/org/codehaus/plexus/redback/role/DefaultRoleManager.java (added)
+++ archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-role-manager/src/main/java/org/codehaus/plexus/redback/role/DefaultRoleManager.java Fri Apr 6 09:58:14 2012
@@ -0,0 +1,591 @@
+package org.codehaus.plexus.redback.role;
+
+/*
+ * Copyright 2005 The Codehaus.
+ *
+ * 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.
+ */
+
+import org.apache.commons.lang.SystemUtils;
+import org.codehaus.plexus.redback.rbac.RBACManager;
+import org.codehaus.plexus.redback.rbac.RbacManagerException;
+import org.codehaus.plexus.redback.rbac.Resource;
+import org.codehaus.plexus.redback.rbac.Role;
+import org.codehaus.plexus.redback.rbac.UserAssignment;
+import org.codehaus.plexus.redback.role.model.ModelApplication;
+import org.codehaus.plexus.redback.role.model.ModelRole;
+import org.codehaus.plexus.redback.role.model.ModelTemplate;
+import org.codehaus.plexus.redback.role.model.RedbackRoleModel;
+import org.codehaus.plexus.redback.role.model.io.stax.RedbackRoleModelStaxReader;
+import org.codehaus.plexus.redback.role.processor.RoleModelProcessor;
+import org.codehaus.plexus.redback.role.template.RoleTemplateProcessor;
+import org.codehaus.plexus.redback.role.util.RoleModelUtils;
+import org.codehaus.plexus.redback.role.validator.RoleModelValidator;
+import org.codehaus.plexus.util.IOUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.PostConstruct;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.xml.stream.XMLStreamException;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Arrays;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * RoleProfileManager:
+ *
+ * @author: Jesse McConnell <je...@codehaus.org>
+ * @version: $Id$
+ */
+@Service( "roleManager" )
+public class DefaultRoleManager
+ implements RoleManager
+{
+ private Logger log = LoggerFactory.getLogger( DefaultRoleManager.class );
+
+ /**
+ * the blessed model that has been validated as complete
+ */
+ private RedbackRoleModel blessedModel;
+
+ /**
+ * the merged model that can be validated as complete
+ */
+ private RedbackRoleModel unblessedModel;
+
+ /**
+ * a map of the resources, and the model that they loaded
+ */
+ private Map<String, ModelApplication> knownResources = new HashMap<String, ModelApplication>();
+
+ @Inject
+ @Named( value = "roleModelValidator" )
+ private RoleModelValidator modelValidator;
+
+ @Inject
+ @Named( value = "roleModelProcessor" )
+ private RoleModelProcessor modelProcessor;
+
+ @Inject
+ @Named( value = "roleTemplateProcessor" )
+ private RoleTemplateProcessor templateProcessor;
+
+ @Inject
+ @Named( value = "rBACManager#cached" )
+ private RBACManager rbacManager;
+
+
+ @SuppressWarnings( "unchecked" )
+ public void loadRoleModel( URL resource )
+ throws RoleManagerException
+ {
+ RedbackRoleModelStaxReader reader = new RedbackRoleModelStaxReader();
+
+ InputStreamReader inputStreamReader = null;
+
+ try
+ {
+
+ inputStreamReader = new InputStreamReader( resource.openStream() );
+
+ RedbackRoleModel roleModel = reader.read( inputStreamReader );
+
+ for ( ModelApplication app : (List<ModelApplication>) roleModel.getApplications() )
+ {
+ if ( !knownResources.containsKey( app.getId() ) )
+ {
+ log.info( "loading " + app.getId() );
+ loadApplication( app );
+ }
+ }
+ }
+ catch ( MalformedURLException e )
+ {
+ throw new RoleManagerException( "error locating redback profile", e );
+ }
+ catch ( IOException e )
+ {
+ throw new RoleManagerException( "error reading redback profile", e );
+ }
+ catch ( XMLStreamException e )
+ {
+ throw new RoleManagerException( "error parsing redback profile", e );
+ }
+ finally
+ {
+ IOUtil.close( inputStreamReader );
+ }
+ }
+
+ @SuppressWarnings( "unchecked" )
+ public void loadRoleModel( RedbackRoleModel roleModel )
+ throws RoleManagerException
+ {
+ for ( ModelApplication app : (List<ModelApplication>) roleModel.getApplications() )
+ {
+ if ( !knownResources.containsKey( app.getId() ) )
+ {
+ loadApplication( app );
+ }
+ }
+
+ }
+
+ public void loadApplication( ModelApplication app )
+ throws RoleManagerException
+ {
+ if ( unblessedModel == null )
+ {
+ unblessedModel = new RedbackRoleModel();
+ }
+
+ unblessedModel.addApplication( app );
+
+ if ( modelValidator.validate( unblessedModel ) )
+ {
+ blessedModel = unblessedModel;
+ }
+ else
+ {
+ StringBuilder stringBuilder = new StringBuilder( "Role Model Validation Errors:" );
+
+ for ( String error : modelValidator.getValidationErrors() )
+ {
+ stringBuilder.append( error ).append( SystemUtils.LINE_SEPARATOR );
+ }
+
+ log.error( stringBuilder.toString() );
+
+ throw new RoleManagerException(
+ "Role Model Validation Error " + SystemUtils.LINE_SEPARATOR + stringBuilder.toString() );
+ }
+
+ modelProcessor.process( blessedModel );
+
+ knownResources.put( app.getId(), app );
+ }
+
+ /**
+ * create a role for the given roleName using the resource passed in for
+ * resolving the ${resource} expression
+ */
+ public void createTemplatedRole( String templateId, String resource )
+ throws RoleManagerException
+ {
+ templateProcessor.create( blessedModel, templateId, resource );
+ }
+
+ /**
+ * remove the role corresponding to the role using the resource passed in for resolving the
+ * ${resource} expression
+ */
+ public void removeTemplatedRole( String templateId, String resource )
+ throws RoleManagerException
+ {
+ ModelTemplate template = RoleModelUtils.getModelTemplate( blessedModel, templateId );
+
+ String roleName = template.getNamePrefix() + template.getDelimiter() + resource;
+
+ try
+ {
+ Role role = rbacManager.getRole( roleName );
+
+ for ( UserAssignment assignment : rbacManager.getUserAssignmentsForRoles(
+ Arrays.asList( role.getName() ) ) )
+ {
+ assignment.removeRoleName( role );
+ rbacManager.saveUserAssignment( assignment );
+ }
+
+ }
+ catch ( RbacManagerException e )
+ {
+ throw new RoleManagerException( "unable to remove role", e );
+ }
+
+ templateProcessor.remove( blessedModel, templateId, resource );
+ }
+
+ /**
+ * update the role from templateId from oldResource to newResource
+ * <p/>
+ * NOTE: this requires removal and creation of the role since the jdo store does not tolerate renaming
+ * because of the use of the name as an identifier
+ */
+ public void updateRole( String templateId, String oldResource, String newResource )
+ throws RoleManagerException
+ {
+ // make the new role
+ templateProcessor.create( blessedModel, templateId, newResource );
+
+ ModelTemplate template = RoleModelUtils.getModelTemplate( blessedModel, templateId );
+
+ String oldRoleName = template.getNamePrefix() + template.getDelimiter() + oldResource;
+ String newRoleName = template.getNamePrefix() + template.getDelimiter() + newResource;
+
+ try
+ {
+ Role role = rbacManager.getRole( oldRoleName );
+
+ // remove the user assignments
+ for ( UserAssignment assignment : rbacManager.getUserAssignmentsForRoles(
+ Arrays.asList( role.getName() ) ) )
+ {
+ assignment.removeRoleName( oldRoleName );
+ assignment.addRoleName( newRoleName );
+ rbacManager.saveUserAssignment( assignment );
+ }
+ }
+ catch ( RbacManagerException e )
+ {
+ throw new RoleManagerException( "unable to update role", e );
+ }
+
+ templateProcessor.remove( blessedModel, templateId, oldResource );
+ }
+
+ public void assignRole( String roleId, String principal )
+ throws RoleManagerException
+ {
+ ModelRole modelRole = RoleModelUtils.getModelRole( blessedModel, roleId );
+
+ if ( modelRole == null )
+ {
+ throw new RoleManagerException( "Unable to assign role: " + roleId + " does not exist." );
+ }
+
+ try
+ {
+ UserAssignment userAssignment;
+
+ if ( rbacManager.userAssignmentExists( principal ) )
+ {
+ userAssignment = rbacManager.getUserAssignment( principal );
+ }
+ else
+ {
+ userAssignment = rbacManager.createUserAssignment( principal );
+ }
+
+ userAssignment.addRoleName( modelRole.getName() );
+ rbacManager.saveUserAssignment( userAssignment );
+ }
+ catch ( RbacManagerException e )
+ {
+ throw new RoleManagerException( "Unable to assign role: unable to manage user assignment", e );
+ }
+ }
+
+ public void assignRoleByName( String roleName, String principal )
+ throws RoleManagerException
+ {
+ try
+ {
+ UserAssignment userAssignment;
+
+ if ( rbacManager.userAssignmentExists( principal ) )
+ {
+ userAssignment = rbacManager.getUserAssignment( principal );
+ }
+ else
+ {
+ userAssignment = rbacManager.createUserAssignment( principal );
+ }
+
+ if ( !rbacManager.roleExists( roleName ) )
+ {
+ throw new RoleManagerException( "Unable to assign role: " + roleName + " does not exist." );
+ }
+
+ userAssignment.addRoleName( roleName );
+ rbacManager.saveUserAssignment( userAssignment );
+ }
+ catch ( RbacManagerException e )
+ {
+ throw new RoleManagerException( "Unable to assign role: unable to manage user assignment", e );
+ }
+ }
+
+ public void assignTemplatedRole( String templateId, String resource, String principal )
+ throws RoleManagerException
+ {
+ ModelTemplate modelTemplate = RoleModelUtils.getModelTemplate( blessedModel, templateId );
+
+ if ( modelTemplate == null )
+ {
+ throw new RoleManagerException( "Unable to assign role: " + templateId + " does not exist." );
+ }
+ try
+ {
+ if ( !rbacManager.resourceExists( resource ) )
+ {
+ Resource newResource = rbacManager.createResource( resource );
+ rbacManager.saveResource( newResource );
+ }
+
+ UserAssignment userAssignment;
+
+ if ( rbacManager.userAssignmentExists( principal ) )
+ {
+ userAssignment = rbacManager.getUserAssignment( principal );
+ }
+ else
+ {
+ userAssignment = rbacManager.createUserAssignment( principal );
+ }
+
+ userAssignment.addRoleName( modelTemplate.getNamePrefix() + modelTemplate.getDelimiter() + resource );
+ rbacManager.saveUserAssignment( userAssignment );
+ }
+ catch ( RbacManagerException e )
+ {
+ throw new RoleManagerException( "Unable to assign role: unable to manage user assignment", e );
+ }
+ }
+
+ public void unassignRole( String roleId, String principal )
+ throws RoleManagerException
+ {
+ ModelRole modelRole = RoleModelUtils.getModelRole( blessedModel, roleId );
+
+ if ( modelRole == null )
+ {
+ throw new RoleManagerException( "Unable to assign role: " + roleId + " does not exist." );
+ }
+
+ try
+ {
+ UserAssignment userAssignment;
+
+ if ( rbacManager.userAssignmentExists( principal ) )
+ {
+ userAssignment = rbacManager.getUserAssignment( principal );
+ }
+ else
+ {
+ throw new RoleManagerException(
+ "UserAssignment for principal " + principal + "does not exist, can't unassign role." );
+ }
+
+ userAssignment.removeRoleName( modelRole.getName() );
+ rbacManager.saveUserAssignment( userAssignment );
+ }
+ catch ( RbacManagerException e )
+ {
+ throw new RoleManagerException( "Unable to unassign role: unable to manage user assignment", e );
+ }
+ }
+
+ public void unassignRoleByName( String roleName, String principal )
+ throws RoleManagerException
+ {
+ try
+ {
+ UserAssignment userAssignment;
+
+ if ( rbacManager.userAssignmentExists( principal ) )
+ {
+ userAssignment = rbacManager.getUserAssignment( principal );
+ }
+ else
+ {
+ throw new RoleManagerException(
+ "UserAssignment for principal " + principal + "does not exist, can't unassign role." );
+ }
+
+ if ( !rbacManager.roleExists( roleName ) )
+ {
+ throw new RoleManagerException( "Unable to unassign role: " + roleName + " does not exist." );
+ }
+
+ userAssignment.removeRoleName( roleName );
+ rbacManager.saveUserAssignment( userAssignment );
+ }
+ catch ( RbacManagerException e )
+ {
+ throw new RoleManagerException( "Unable to unassign role: unable to manage user assignment", e );
+ }
+ }
+
+ public boolean roleExists( String roleId )
+ throws RoleManagerException
+ {
+ ModelRole modelRole = RoleModelUtils.getModelRole( blessedModel, roleId );
+
+ if ( modelRole == null )
+ {
+ return false;
+ }
+ else
+ {
+ if ( rbacManager.roleExists( modelRole.getName() ) )
+ {
+ return true;
+ }
+ else
+ {
+ // perhaps try and reload the model here?
+ throw new RoleManagerException(
+ "breakdown in role management, role exists in configuration but was not created in underlying store" );
+ }
+ }
+ }
+
+ public boolean templatedRoleExists( String templateId, String resource )
+ throws RoleManagerException
+ {
+ ModelTemplate modelTemplate = RoleModelUtils.getModelTemplate( blessedModel, templateId );
+
+ // template not existing is valid to check, it will throw exception on trying to create
+ if ( modelTemplate == null )
+ {
+ return false;
+ }
+ else
+ {
+ if ( rbacManager.roleExists( modelTemplate.getNamePrefix() + modelTemplate.getDelimiter() + resource ) )
+ {
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+ }
+
+ @PostConstruct
+ public void initialize()
+ {
+ try
+ {
+ URL baseResource = RoleManager.class.getResource( "/META-INF/redback/redback-core.xml" );
+
+ if ( baseResource == null )
+ {
+ throw new RuntimeException( "unable to initialize role manager, missing redback-core.xml" );
+ }
+
+ loadRoleModel( baseResource );
+
+ Enumeration<URL> enumerator =
+ RoleManager.class.getClassLoader().getResources( "META-INF/redback/redback.xml" );
+
+ while ( enumerator.hasMoreElements() )
+ {
+ URL redbackResource = enumerator.nextElement();
+
+ loadRoleModel( redbackResource );
+ }
+ }
+ catch ( RoleManagerException e )
+ {
+ throw new RuntimeException( "unable to initialize RoleManager", e );
+ }
+ catch ( IOException e )
+ {
+ throw new RuntimeException( "unable to initialize RoleManager, problem with redback.xml loading", e );
+ }
+ }
+
+ public RedbackRoleModel getModel()
+ {
+ return blessedModel;
+ }
+
+ public void verifyTemplatedRole( String templateId, String resource )
+ throws RoleManagerException
+ {
+ // create also serves as update
+ templateProcessor.create( blessedModel, templateId, resource );
+ }
+
+ public RedbackRoleModel getBlessedModel()
+ {
+ return blessedModel;
+ }
+
+ public void setBlessedModel( RedbackRoleModel blessedModel )
+ {
+ this.blessedModel = blessedModel;
+ }
+
+ public RedbackRoleModel getUnblessedModel()
+ {
+ return unblessedModel;
+ }
+
+ public void setUnblessedModel( RedbackRoleModel unblessedModel )
+ {
+ this.unblessedModel = unblessedModel;
+ }
+
+ public Map<String, ModelApplication> getKnownResources()
+ {
+ return knownResources;
+ }
+
+ public void setKnownResources( Map<String, ModelApplication> knownResources )
+ {
+ this.knownResources = knownResources;
+ }
+
+ public RoleModelValidator getModelValidator()
+ {
+ return modelValidator;
+ }
+
+ public void setModelValidator( RoleModelValidator modelValidator )
+ {
+ this.modelValidator = modelValidator;
+ }
+
+ public RoleModelProcessor getModelProcessor()
+ {
+ return modelProcessor;
+ }
+
+ public void setModelProcessor( RoleModelProcessor modelProcessor )
+ {
+ this.modelProcessor = modelProcessor;
+ }
+
+ public RoleTemplateProcessor getTemplateProcessor()
+ {
+ return templateProcessor;
+ }
+
+ public void setTemplateProcessor( RoleTemplateProcessor templateProcessor )
+ {
+ this.templateProcessor = templateProcessor;
+ }
+
+ public RBACManager getRbacManager()
+ {
+ return rbacManager;
+ }
+
+ public void setRbacManager( RBACManager rbacManager )
+ {
+ this.rbacManager = rbacManager;
+ }
+}
Propchange: archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-role-manager/src/main/java/org/codehaus/plexus/redback/role/DefaultRoleManager.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-role-manager/src/main/java/org/codehaus/plexus/redback/role/DefaultRoleManager.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision