directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cp...@apache.org
Subject [20/43] directory-fortress-core git commit: added method to delete PASet and add/remove PAs from a set
Date Thu, 06 Oct 2016 17:49:37 GMT
added method to delete PASet and add/remove PAs from a set


Project: http://git-wip-us.apache.org/repos/asf/directory-fortress-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/directory-fortress-core/commit/8dd536cd
Tree: http://git-wip-us.apache.org/repos/asf/directory-fortress-core/tree/8dd536cd
Diff: http://git-wip-us.apache.org/repos/asf/directory-fortress-core/diff/8dd536cd

Branch: refs/heads/master
Commit: 8dd536cd7bf2c42515b4779e790f7ef8c80bb1ac
Parents: b6f3fef
Author: clp207 <clp207@psu.edu>
Authored: Fri Jan 29 10:13:53 2016 -0500
Committer: clp207 <clp207@psu.edu>
Committed: Wed Mar 30 15:44:22 2016 -0400

----------------------------------------------------------------------
 .../directory/fortress/core/AdminMgr.java       |  15 ++-
 .../directory/fortress/core/GlobalErrIds.java   |  26 +++-
 .../fortress/core/impl/AdminMgrImpl.java        |  47 +++++++-
 .../directory/fortress/core/impl/PermDAO.java   | 120 +++++++++++++++----
 .../directory/fortress/core/impl/PermP.java     |  21 +++-
 .../core/model/PermissionAttributeSet.java      |   4 +
 6 files changed, 196 insertions(+), 37 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/8dd536cd/src/main/java/org/apache/directory/fortress/core/AdminMgr.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/directory/fortress/core/AdminMgr.java b/src/main/java/org/apache/directory/fortress/core/AdminMgr.java
index 30a77b4..de3639a 100755
--- a/src/main/java/org/apache/directory/fortress/core/AdminMgr.java
+++ b/src/main/java/org/apache/directory/fortress/core/AdminMgr.java
@@ -22,6 +22,7 @@ package org.apache.directory.fortress.core;
 
 import org.apache.directory.fortress.core.model.PermObj;
 import org.apache.directory.fortress.core.model.Permission;
+import org.apache.directory.fortress.core.model.PermissionAttribute;
 import org.apache.directory.fortress.core.model.PermissionAttributeSet;
 import org.apache.directory.fortress.core.model.Role;
 import org.apache.directory.fortress.core.model.RoleConstraint;
@@ -520,10 +521,22 @@ public interface AdminMgr extends Manageable
         throws SecurityException;
 
     
-    //TODO: fill the documentation in
+    //TODO: add documentation
     PermissionAttributeSet addPermissionAttributeSet( PermissionAttributeSet permAttributeSet
)
     	throws SecurityException;
     
+    //TODO: add documentation
+    void deletePermissionAttributeSet( PermissionAttributeSet permAttributeSet )
+        throws SecurityException;
+    
+    //TODO: add documentation
+    PermissionAttribute addPermissionAttributeToSet( PermissionAttribute permAttribute, String
attributeSetName )
+    	throws SecurityException;
+    
+    //TODO: add documentation
+    void removePermissionAttributeFromSet( PermissionAttribute permAttribute, String attributeSetName
)
+    	throws SecurityException;    
+    
     /**
      * This method will update permission operation pre-existing in target directory under

      * {@code ou=Permissions,ou=RBAC,dc=yourHostName,dc=com} container in directory information
tree.

http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/8dd536cd/src/main/java/org/apache/directory/fortress/core/GlobalErrIds.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/directory/fortress/core/GlobalErrIds.java b/src/main/java/org/apache/directory/fortress/core/GlobalErrIds.java
index a0f6f7e..a170274 100755
--- a/src/main/java/org/apache/directory/fortress/core/GlobalErrIds.java
+++ b/src/main/java/org/apache/directory/fortress/core/GlobalErrIds.java
@@ -645,7 +645,27 @@ public final class GlobalErrIds
      * The supplied Permission does not exist in LDAP DIT.
      */
     public static final int PERM_NOT_EXIST = 3029;
-
+    /**
+     * The supplied Permission Attribute Set is required but was passed as null.
+     */
+    public static final int PERM_ATTRIBUTE_SET_NULL = 3030;
+    /**
+     * The supplied Permission Attribute Set could not be removed from ldap server.
+     */
+    public static final int PERM_ATTRIBUTE_SET_DELETE_FAILED = 3031;
+    /**
+     * The supplied Permission Attribute is required but was passed as null.
+     */
+    public static final int PERM_ATTRIBUTE_NULL = 3032;
+    /**
+     * The supplied Permission Attribute could not be removed from ldap server.
+     */
+    public static final int PERM_ATTRIBUTE_DELETE_FAILED = 3033;
+    /**
+     * The supplied Permission Attribute could not be added to ldap server.
+     */
+    public static final int PERM_ATTR_ADD_FAILED = 3034;
+    
     /**
      * 4000's - Password Policy Entity
      */
@@ -1656,8 +1676,4 @@ public final class GlobalErrIds
      */
     public static final int GROUP_PROTOCOL_INVLD = 10313;
     
-    /**
-     * The supplied Permission Attribute could not be added to ldap server.
-     */
-    public static final int PERM_ATTR_ADD_FAILED = 10314;
 }

http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/8dd536cd/src/main/java/org/apache/directory/fortress/core/impl/AdminMgrImpl.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/directory/fortress/core/impl/AdminMgrImpl.java b/src/main/java/org/apache/directory/fortress/core/impl/AdminMgrImpl.java
index 61f090d..2248b73 100755
--- a/src/main/java/org/apache/directory/fortress/core/impl/AdminMgrImpl.java
+++ b/src/main/java/org/apache/directory/fortress/core/impl/AdminMgrImpl.java
@@ -34,6 +34,7 @@ import org.apache.directory.fortress.core.model.ConstraintUtil;
 import org.apache.directory.fortress.core.model.Hier;
 import org.apache.directory.fortress.core.model.PermObj;
 import org.apache.directory.fortress.core.model.Permission;
+import org.apache.directory.fortress.core.model.PermissionAttribute;
 import org.apache.directory.fortress.core.model.PermissionAttributeSet;
 import org.apache.directory.fortress.core.model.Relationship;
 import org.apache.directory.fortress.core.model.Role;
@@ -402,12 +403,48 @@ public final class AdminMgrImpl extends Manageable implements AdminMgr,
Serializ
     public PermissionAttributeSet addPermissionAttributeSet( PermissionAttributeSet permAttributeSet
) throws SecurityException
     {
         String methodName = "addPermissionAttributeSet";         
-        //TODO: add better global err ids
-        assertContext( CLS_NM, methodName, permAttributeSet, GlobalErrIds.PERM_OPERATION_NULL
);
-        //TODO: set entity session...
-        //setEntitySession( CLS_NM, methodName, permAttribute );
+        assertContext( CLS_NM, methodName, permAttributeSet, GlobalErrIds.PERM_ATTRIBUTE_SET_NULL
);
+        //TODO: verify with Shawn we don't need to set entity session here...        
         return permP.add( permAttributeSet );
-    }    
+    }          
+    
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void deletePermissionAttributeSet( PermissionAttributeSet permAttributeSet ) throws
SecurityException
+    {
+        String methodName = "deletePermissionAttributeSet";         
+        assertContext( CLS_NM, methodName, permAttributeSet, GlobalErrIds.PERM_ATTRIBUTE_SET_NULL
);
+        //TODO: verify with Shawn we don't need to set entity session here...        
+        permP.delete( permAttributeSet );
+    }
+    
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public PermissionAttribute addPermissionAttributeToSet( PermissionAttribute permAttribute,
String attributeSetName )
+    	throws SecurityException
+    {
+    	String methodName = "addPermissionAttributeToSet";         
+        assertContext( CLS_NM, methodName, permAttribute, GlobalErrIds.PERM_ATTRIBUTE_NULL
);
+        //TODO: verify with Shawn we don't need to set entity session here...        
+        return permP.add( permAttribute, attributeSetName );    	
+    }
+    
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public void removePermissionAttributeFromSet( PermissionAttribute permAttribute, String
attributeSetName )
+    	throws SecurityException
+    {
+    	String methodName = "removePermissionAttributeFromSet";         
+        assertContext( CLS_NM, methodName, permAttribute, GlobalErrIds.PERM_ATTRIBUTE_NULL
);
+        //TODO: verify with Shawn we don't need to set entity session here...        
+        permP.delete( permAttribute, attributeSetName );       	
+    }
     
     /**
      * {@inheritDoc}

http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/8dd536cd/src/main/java/org/apache/directory/fortress/core/impl/PermDAO.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/directory/fortress/core/impl/PermDAO.java b/src/main/java/org/apache/directory/fortress/core/impl/PermDAO.java
index e4d334c..a8f5373 100755
--- a/src/main/java/org/apache/directory/fortress/core/impl/PermDAO.java
+++ b/src/main/java/org/apache/directory/fortress/core/impl/PermDAO.java
@@ -459,7 +459,7 @@ final class PermDAO extends ApacheDsDataProvider
     PermissionAttributeSet createPermissionAttributeSet( PermissionAttributeSet entity )
throws CreateException
     {
         LdapConnection ld = null;
-        String dn = getDn( entity , entity.getContextId() );
+        String dn = getPASetDn( entity.getName() , entity.getContextId() );
 
         try
         {
@@ -496,36 +496,46 @@ final class PermDAO extends ApacheDsDataProvider
         {
             closeAdminConnection( ld );
         }
-        
-        
+                
         //add each ftPA
         for(PermissionAttribute pa : entity.getAttributes()){        
-	        try
-	        {
-	            List<Modification> mods = new ArrayList<Modification>();
-	            mods.add( new DefaultModification(
-	                ModificationOperation.ADD_ATTRIBUTE, GlobalIds.FT_PERMISSION_ATTRIBUTE,
pa.toFtPAString()) );
-	            ld = getAdminConnection();
-	            modify( ld, dn, mods, entity );
-	            
-	            //TODO: make sure not adding same attribute twice...???
-	        }
-	        catch ( LdapException e )
-	        {
-	            String error = "create perm attribute [" + pa.getAttributeName() + "] caught
LdapException="
-	                + e.getMessage();
-	            throw new CreateException( GlobalErrIds.PERM_ATTR_ADD_FAILED, error, e );
-	        }
-	        finally
-	        {
-	            closeAdminConnection( ld );
-	        }
+	        this.createPermissionAttribute(pa, entity.getName());
         }
         
         //TODO: need to do anything to returned entity?
         return entity;
     }
     
+    //TODO: add documentation
+    PermissionAttribute createPermissionAttribute( PermissionAttribute entity, String attributeSetName
) throws CreateException
+    {
+        LdapConnection ld = null;
+        String dn = getPASetDn( attributeSetName, entity.getContextId() );
+    
+    	try
+        {
+            List<Modification> mods = new ArrayList<Modification>();
+            mods.add( new DefaultModification(
+                ModificationOperation.ADD_ATTRIBUTE, GlobalIds.FT_PERMISSION_ATTRIBUTE, entity.toFtPAString())
);
+            ld = getAdminConnection();
+            modify( ld, dn, mods, entity );
+            
+            //TODO: make sure not adding same attribute twice...???
+        }
+        catch ( LdapException e )
+        {
+            String error = "create perm attribute [" + entity.getAttributeName() + "] caught
LdapException="
+                + e.getMessage();
+            throw new CreateException( GlobalErrIds.PERM_ATTR_ADD_FAILED, error, e );
+        }
+        finally
+        {
+            closeAdminConnection( ld );
+        }
+    	
+    	return entity;    	
+    }
+        
     /**
      * @param entity
      * @return
@@ -630,6 +640,66 @@ final class PermDAO extends ApacheDsDataProvider
         }
     }
 
+    /**     
+     * @param entity
+     * @throws RemoveException
+     */
+    void deleteAttributeSet( PermissionAttributeSet entity ) throws RemoveException
+    {
+        LdapConnection ld = null;
+        String dn = getPASetDn( entity.getName(), entity.getContextId() );
+
+        try
+        {
+            ld = getAdminConnection();
+            deleteRecursive( ld, dn, entity );
+        }
+        catch ( LdapException e )
+        {
+            String error = "deleteAttributeSet name [" + entity.getName() + "]"
+            		+ " caught LdapException=" + e.getMessage();
+            throw new RemoveException( GlobalErrIds.PERM_ATTRIBUTE_SET_DELETE_FAILED, error,
e );
+        }
+        catch ( CursorException e )
+        {
+            String error = "deleteAttributeSet name [" + entity.getName() + "] "
+            		+ " caught LdapException=" + e.getMessage();
+            throw new RemoveException( GlobalErrIds.PERM_ATTRIBUTE_SET_DELETE_FAILED, error,
e );
+        }
+        finally
+        {
+            closeAdminConnection( ld );
+        }
+    }
+    
+    /**     
+     * @param entity
+     * @throws RemoveException
+     */
+    void deletePermissionAttribute( PermissionAttribute entity, String attributeSetName )
throws RemoveException
+    {
+        LdapConnection ld = null;
+        String dn = getPASetDn( attributeSetName, entity.getContextId() );
+
+        try
+        {
+            List<Modification> mods = new ArrayList<Modification>();
+            mods.add( new DefaultModification(
+                ModificationOperation.REMOVE_ATTRIBUTE, GlobalIds.FT_PERMISSION_ATTRIBUTE,
entity.toFtPAString() ) );
+            ld = getAdminConnection();
+            modify( ld, dn, mods, new PermissionAttributeSet(attributeSetName) );
+        }
+        catch ( LdapException e )
+        {
+            String error = "deletePermissionAttribute name [" + entity.getAttributeName()
+ "] set ["
+            		+ attributeSetName + "] caught LdapException=" + e.getMessage();
+            throw new RemoveException( GlobalErrIds.PERM_ATTRIBUTE_DELETE_FAILED, error,
e );
+        }     
+        finally
+        {
+            closeAdminConnection( ld );
+        }
+    }
 
     /**
      * @param pOp
@@ -1762,10 +1832,10 @@ final class PermDAO extends ApacheDsDataProvider
     }
     
 
-    private String getDn( PermissionAttributeSet paSet, String contextId )
+    private String getPASetDn( String name, String contextId )
     {
     	//TODO: what ou to put this?
-        return SchemaConstants.CN_AT + "=" + paSet.getName() + "," + getRootDn( contextId,
GlobalIds.SD_ROOT );
+        return SchemaConstants.CN_AT + "=" + name + "," + getRootDn( contextId, GlobalIds.SD_ROOT
);
     }
 
 

http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/8dd536cd/src/main/java/org/apache/directory/fortress/core/impl/PermP.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/directory/fortress/core/impl/PermP.java b/src/main/java/org/apache/directory/fortress/core/impl/PermP.java
index 585323e..4284c47 100755
--- a/src/main/java/org/apache/directory/fortress/core/impl/PermP.java
+++ b/src/main/java/org/apache/directory/fortress/core/impl/PermP.java
@@ -33,6 +33,7 @@ import org.apache.directory.fortress.core.model.AdminRole;
 import org.apache.directory.fortress.core.model.OrgUnit;
 import org.apache.directory.fortress.core.model.PermObj;
 import org.apache.directory.fortress.core.model.Permission;
+import org.apache.directory.fortress.core.model.PermissionAttribute;
 import org.apache.directory.fortress.core.model.PermissionAttributeSet;
 import org.apache.directory.fortress.core.model.Role;
 import org.apache.directory.fortress.core.model.Session;
@@ -374,7 +375,20 @@ final class PermP
         //TODO: add validation
         return pDao.createPermissionAttributeSet( entity );
     }
+    
+    //TODO: add documentation
+    PermissionAttribute add( PermissionAttribute entity, String attributeSetName ) throws
SecurityException
+    {
+        //TODO: add validation
+        return pDao.createPermissionAttribute( entity, attributeSetName );
+    }
 
+    //TODO: add documentation
+    void delete( PermissionAttribute entity, String attributeSetName ) throws SecurityException
+    {
+        //TODO: add validation
+        pDao.deletePermissionAttribute( entity, attributeSetName );
+    }
 
     /**
      * Update existing Permission Object attributes with the input entity.  Null or empty
attributes will be ignored.
@@ -476,7 +490,12 @@ final class PermP
         pDao.deleteOperation( entity );
     }
 
-
+    //TODO: add documentation
+    void delete( PermissionAttributeSet entity ) throws SecurityException
+    {
+        pDao.deleteAttributeSet( entity );
+    }
+    
     /**
      * This command grants a role the permission to perform an operation on an object to
a role.
      * The command is implemented by granting permission by setting the access control list
of

http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/8dd536cd/src/main/java/org/apache/directory/fortress/core/model/PermissionAttributeSet.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/directory/fortress/core/model/PermissionAttributeSet.java
b/src/main/java/org/apache/directory/fortress/core/model/PermissionAttributeSet.java
index 46fb95a..070c278 100644
--- a/src/main/java/org/apache/directory/fortress/core/model/PermissionAttributeSet.java
+++ b/src/main/java/org/apache/directory/fortress/core/model/PermissionAttributeSet.java
@@ -28,6 +28,10 @@ public class PermissionAttributeSet extends FortEntity {
     private String description;
     private String dn;
 	
+    public PermissionAttributeSet(String name){
+    	this.name = name;
+    }
+    
 	public PermissionAttributeSet(){
 		
 	}


Mime
View raw message