]> source.dussan.org Git - archiva.git/commitdiff
package move to o.a.a.r module redback-rbac-memory
authorOlivier Lamy <olamy@apache.org>
Sat, 7 Apr 2012 23:00:01 +0000 (23:00 +0000)
committerOlivier Lamy <olamy@apache.org>
Sat, 7 Apr 2012 23:00:01 +0000 (23:00 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/redback/redback-core/trunk@1310908 13f79535-47bb-0310-9956-ffa450edef68

21 files changed:
redback-rbac/redback-authorization-rbac/src/test/java/org/apache/archiva/redback/authorization/rbac/evaluator/PermissionEvaluatorTest.java
redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/apache/archiva/redback/rbac/memory/MemoryAuthorizationDataSource.java [new file with mode: 0644]
redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/apache/archiva/redback/rbac/memory/MemoryAuthorizer.java [new file with mode: 0644]
redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/apache/archiva/redback/rbac/memory/MemoryOperation.java [new file with mode: 0644]
redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/apache/archiva/redback/rbac/memory/MemoryPermission.java [new file with mode: 0644]
redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/apache/archiva/redback/rbac/memory/MemoryRbacManager.java [new file with mode: 0644]
redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/apache/archiva/redback/rbac/memory/MemoryResource.java [new file with mode: 0644]
redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/apache/archiva/redback/rbac/memory/MemoryRole.java [new file with mode: 0644]
redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/apache/archiva/redback/rbac/memory/MemoryUserAssignment.java [new file with mode: 0644]
redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryAuthorizationDataSource.java [deleted file]
redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryAuthorizer.java [deleted file]
redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryOperation.java [deleted file]
redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryPermission.java [deleted file]
redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryRbacManager.java [deleted file]
redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryResource.java [deleted file]
redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryRole.java [deleted file]
redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryUserAssignment.java [deleted file]
redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/resources/META-INF/spring-context.xml
redback-rbac/redback-rbac-providers/redback-rbac-memory/src/test/java/org/apache/archiva/redback/rbac/memory/MemoryRbacManagerTest.java [new file with mode: 0644]
redback-rbac/redback-rbac-providers/redback-rbac-memory/src/test/java/org/codehaus/plexus/redback/rbac/memory/MemoryRbacManagerTest.java [deleted file]
redback-rbac/redback-rbac-providers/redback-rbac-memory/src/test/resources/spring-context.xml

index ef6789714d09a4bd21d5f650303beac836b504d4..fdff955c963a92d09a040144e9540b9c740de1d9 100644 (file)
@@ -20,14 +20,12 @@ package org.apache.archiva.redback.authorization.rbac.evaluator;
  */
 
 import junit.framework.TestCase;
-import org.apache.archiva.redback.authorization.rbac.evaluator.PermissionEvaluationException;
-import org.apache.archiva.redback.authorization.rbac.evaluator.PermissionEvaluator;
 import org.apache.archiva.redback.rbac.Permission;
 import org.apache.archiva.redback.rbac.Operation;
 import org.apache.archiva.redback.rbac.Resource;
-import org.codehaus.plexus.redback.rbac.memory.MemoryOperation;
-import org.codehaus.plexus.redback.rbac.memory.MemoryPermission;
-import org.codehaus.plexus.redback.rbac.memory.MemoryResource;
+import org.apache.archiva.redback.rbac.memory.MemoryOperation;
+import org.apache.archiva.redback.rbac.memory.MemoryPermission;
+import org.apache.archiva.redback.rbac.memory.MemoryResource;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.springframework.test.context.ContextConfiguration;
diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/apache/archiva/redback/rbac/memory/MemoryAuthorizationDataSource.java b/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/apache/archiva/redback/rbac/memory/MemoryAuthorizationDataSource.java
new file mode 100644 (file)
index 0000000..21ccaa6
--- /dev/null
@@ -0,0 +1,75 @@
+package org.apache.archiva.redback.rbac.memory;
+
+/*
+ * 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.
+ */
+
+import org.apache.archiva.redback.users.User;
+
+/**
+ * MemoryAuthorizationDataSource:
+ *
+ * @author Jesse McConnell <jmcconnell@apache.org>
+ * @version $Id$
+ */
+public class MemoryAuthorizationDataSource
+//    implements AuthorizationDataSource
+{
+    Object principal;
+
+    User user;
+
+    Object permission;
+
+    public MemoryAuthorizationDataSource( Object principal, User user, Object permission )
+    {
+        this.principal = principal;
+        this.user = user;
+        this.permission = permission;
+    }
+
+    public Object getPrincipal()
+    {
+        return principal;
+    }
+
+    public void setPrincipal( String principal )
+    {
+        this.principal = principal;
+    }
+
+    public User getUser()
+    {
+        return user;
+    }
+
+    public void setUser( User user )
+    {
+        this.user = user;
+    }
+
+    public Object getPermission()
+    {
+        return permission;
+    }
+
+    public void setPermission( Object permission )
+    {
+        this.permission = permission;
+    }
+}
diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/apache/archiva/redback/rbac/memory/MemoryAuthorizer.java b/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/apache/archiva/redback/rbac/memory/MemoryAuthorizer.java
new file mode 100644 (file)
index 0000000..f0365cf
--- /dev/null
@@ -0,0 +1,59 @@
+package org.apache.archiva.redback.rbac.memory;
+
+/*
+ * 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.
+ */
+
+import org.apache.archiva.redback.authorization.AuthorizationDataSource;
+import org.apache.archiva.redback.authorization.AuthorizationException;
+import org.apache.archiva.redback.authorization.AuthorizationResult;
+import org.apache.archiva.redback.authorization.Authorizer;
+import org.springframework.stereotype.Service;
+
+/**
+ * @author: Jesse McConnell <jesse@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 );
+        }
+    }
+}
+
diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/apache/archiva/redback/rbac/memory/MemoryOperation.java b/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/apache/archiva/redback/rbac/memory/MemoryOperation.java
new file mode 100644 (file)
index 0000000..ab01232
--- /dev/null
@@ -0,0 +1,167 @@
+package org.apache.archiva.redback.rbac.memory;
+
+/*
+ * 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.
+ */
+
+import org.apache.archiva.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;
+    }
+}
diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/apache/archiva/redback/rbac/memory/MemoryPermission.java b/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/apache/archiva/redback/rbac/memory/MemoryPermission.java
new file mode 100644 (file)
index 0000000..b9275e9
--- /dev/null
@@ -0,0 +1,196 @@
+package org.apache.archiva.redback.rbac.memory;
+
+/*
+ * 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.
+ */
+
+import org.apache.archiva.redback.rbac.Operation;
+import org.apache.archiva.redback.rbac.Resource;
+import org.apache.archiva.redback.rbac.Permission;
+
+/**
+ * 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;
+    }
+}
diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/apache/archiva/redback/rbac/memory/MemoryRbacManager.java b/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/apache/archiva/redback/rbac/memory/MemoryRbacManager.java
new file mode 100644 (file)
index 0000000..2c14b31
--- /dev/null
@@ -0,0 +1,542 @@
+package org.apache.archiva.redback.rbac.memory;
+
+/*
+ * 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.
+ */
+
+import org.apache.archiva.redback.rbac.AbstractRBACManager;
+import org.apache.archiva.redback.rbac.Operation;
+import org.apache.archiva.redback.rbac.Permission;
+import org.apache.archiva.redback.rbac.RBACManager;
+import org.apache.archiva.redback.rbac.RBACObjectAssertions;
+import org.apache.archiva.redback.rbac.RbacManagerException;
+import org.apache.archiva.redback.rbac.RbacObjectInvalidException;
+import org.apache.archiva.redback.rbac.RbacObjectNotFoundException;
+import org.apache.archiva.redback.rbac.Resource;
+import org.apache.archiva.redback.rbac.Role;
+import org.apache.archiva.redback.rbac.UserAssignment;
+import org.apache.archiva.redback.rbac.RbacPermanentException;
+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 <jmcconnell@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;
+        }
+    }
+}
diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/apache/archiva/redback/rbac/memory/MemoryResource.java b/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/apache/archiva/redback/rbac/memory/MemoryResource.java
new file mode 100644 (file)
index 0000000..1bc2417
--- /dev/null
@@ -0,0 +1,149 @@
+package org.apache.archiva.redback.rbac.memory;
+
+/*
+ * 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.
+ */
+
+import org.apache.archiva.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;
+    }
+}
diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/apache/archiva/redback/rbac/memory/MemoryRole.java b/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/apache/archiva/redback/rbac/memory/MemoryRole.java
new file mode 100644 (file)
index 0000000..5f7b8fa
--- /dev/null
@@ -0,0 +1,254 @@
+package org.apache.archiva.redback.rbac.memory;
+
+/*
+ * 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.
+ */
+
+import org.apache.archiva.redback.rbac.AbstractRole;
+import org.apache.archiva.redback.rbac.Permission;
+import org.apache.archiva.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;
+    }
+}
diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/apache/archiva/redback/rbac/memory/MemoryUserAssignment.java b/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/apache/archiva/redback/rbac/memory/MemoryUserAssignment.java
new file mode 100644 (file)
index 0000000..a5990c4
--- /dev/null
@@ -0,0 +1,150 @@
+package org.apache.archiva.redback.rbac.memory;
+
+/*
+ * 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.
+ */
+
+import org.apache.archiva.redback.rbac.AbstractUserAssignment;
+import org.apache.archiva.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;
+    }
+}
diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryAuthorizationDataSource.java b/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryAuthorizationDataSource.java
deleted file mode 100644 (file)
index 65dcb30..0000000
+++ /dev/null
@@ -1,75 +0,0 @@
-package org.codehaus.plexus.redback.rbac.memory;
-
-/*
- * 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.
- */
-
-import org.apache.archiva.redback.users.User;
-
-/**
- * MemoryAuthorizationDataSource:
- *
- * @author Jesse McConnell <jmcconnell@apache.org>
- * @version $Id$
- */
-public class MemoryAuthorizationDataSource
-//    implements AuthorizationDataSource
-{
-    Object principal;
-
-    User user;
-
-    Object permission;
-
-    public MemoryAuthorizationDataSource( Object principal, User user, Object permission )
-    {
-        this.principal = principal;
-        this.user = user;
-        this.permission = permission;
-    }
-
-    public Object getPrincipal()
-    {
-        return principal;
-    }
-
-    public void setPrincipal( String principal )
-    {
-        this.principal = principal;
-    }
-
-    public User getUser()
-    {
-        return user;
-    }
-
-    public void setUser( User user )
-    {
-        this.user = user;
-    }
-
-    public Object getPermission()
-    {
-        return permission;
-    }
-
-    public void setPermission( Object permission )
-    {
-        this.permission = permission;
-    }
-}
diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryAuthorizer.java b/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryAuthorizer.java
deleted file mode 100644 (file)
index 17dd493..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-package org.codehaus.plexus.redback.rbac.memory;
-
-/*
- * 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.
- */
-
-import org.apache.archiva.redback.authorization.AuthorizationDataSource;
-import org.apache.archiva.redback.authorization.AuthorizationException;
-import org.apache.archiva.redback.authorization.AuthorizationResult;
-import org.apache.archiva.redback.authorization.Authorizer;
-import org.springframework.stereotype.Service;
-
-/**
- * @author: Jesse McConnell <jesse@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 );
-        }
-    }
-}
-
diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryOperation.java b/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryOperation.java
deleted file mode 100644 (file)
index c4856eb..0000000
+++ /dev/null
@@ -1,167 +0,0 @@
-package org.codehaus.plexus.redback.rbac.memory;
-
-/*
- * 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.
- */
-
-import org.apache.archiva.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;
-    }
-}
diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryPermission.java b/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryPermission.java
deleted file mode 100644 (file)
index 476c557..0000000
+++ /dev/null
@@ -1,196 +0,0 @@
-package org.codehaus.plexus.redback.rbac.memory;
-
-/*
- * 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.
- */
-
-import org.apache.archiva.redback.rbac.Operation;
-import org.apache.archiva.redback.rbac.Resource;
-import org.apache.archiva.redback.rbac.Permission;
-
-/**
- * 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;
-    }
-}
diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryRbacManager.java b/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryRbacManager.java
deleted file mode 100644 (file)
index 2336f82..0000000
+++ /dev/null
@@ -1,542 +0,0 @@
-package org.codehaus.plexus.redback.rbac.memory;
-
-/*
- * 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.
- */
-
-import org.apache.archiva.redback.rbac.AbstractRBACManager;
-import org.apache.archiva.redback.rbac.Operation;
-import org.apache.archiva.redback.rbac.Permission;
-import org.apache.archiva.redback.rbac.RBACManager;
-import org.apache.archiva.redback.rbac.RBACObjectAssertions;
-import org.apache.archiva.redback.rbac.RbacManagerException;
-import org.apache.archiva.redback.rbac.RbacObjectInvalidException;
-import org.apache.archiva.redback.rbac.RbacObjectNotFoundException;
-import org.apache.archiva.redback.rbac.Resource;
-import org.apache.archiva.redback.rbac.Role;
-import org.apache.archiva.redback.rbac.UserAssignment;
-import org.apache.archiva.redback.rbac.RbacPermanentException;
-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 <jmcconnell@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;
-        }
-    }
-}
diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryResource.java b/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryResource.java
deleted file mode 100644 (file)
index 0e99462..0000000
+++ /dev/null
@@ -1,149 +0,0 @@
-package org.codehaus.plexus.redback.rbac.memory;
-
-/*
- * 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.
- */
-
-import org.apache.archiva.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;
-    }
-}
diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryRole.java b/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryRole.java
deleted file mode 100644 (file)
index 7105d65..0000000
+++ /dev/null
@@ -1,254 +0,0 @@
-package org.codehaus.plexus.redback.rbac.memory;
-
-/*
- * 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.
- */
-
-import org.apache.archiva.redback.rbac.AbstractRole;
-import org.apache.archiva.redback.rbac.Permission;
-import org.apache.archiva.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;
-    }
-}
diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryUserAssignment.java b/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/main/java/org/codehaus/plexus/redback/rbac/memory/MemoryUserAssignment.java
deleted file mode 100644 (file)
index f1afeed..0000000
+++ /dev/null
@@ -1,150 +0,0 @@
-package org.codehaus.plexus.redback.rbac.memory;
-
-/*
- * 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.
- */
-
-import org.apache.archiva.redback.rbac.AbstractUserAssignment;
-import org.apache.archiva.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;
-    }
-}
index 39f3a1ab63babca719bfd7b13141896bcd3882bd..b672723bbe26ce284a7027536e4b8b0c234e9aa6 100644 (file)
@@ -29,6 +29,6 @@
 
   <context:annotation-config />
   <context:component-scan 
-    base-package="org.codehaus.plexus.redback.rbac.memory"/>
+    base-package="org.apache.archiva.redback.rbac.memory"/>
  
 </beans>
\ No newline at end of file
diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/test/java/org/apache/archiva/redback/rbac/memory/MemoryRbacManagerTest.java b/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/test/java/org/apache/archiva/redback/rbac/memory/MemoryRbacManagerTest.java
new file mode 100644 (file)
index 0000000..02df93a
--- /dev/null
@@ -0,0 +1,59 @@
+package org.apache.archiva.redback.rbac.memory;
+
+/*
+ * 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.
+ */
+
+import org.apache.archiva.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 );
+    }
+}
diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/test/java/org/codehaus/plexus/redback/rbac/memory/MemoryRbacManagerTest.java b/redback-rbac/redback-rbac-providers/redback-rbac-memory/src/test/java/org/codehaus/plexus/redback/rbac/memory/MemoryRbacManagerTest.java
deleted file mode 100644 (file)
index 78eb7cc..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-package org.codehaus.plexus.redback.rbac.memory;
-
-/*
- * 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.
- */
-
-import org.apache.archiva.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 );
-    }
-}
index f151879d9f261a393b4ec9cf7ac0f34a11bd69b5..7adf5f759fab3f01e479888cbff59ae4ca29e96d 100755 (executable)
   -->
 <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">
+           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
 
   <bean name="jdoFactory#users" class="org.codehaus.plexus.jdo.DefaultConfigurableJdoFactory">
     <property name="driverName" value="org.hsqldb.jdbcDriver"/>