directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cp...@apache.org
Subject [02/10] directory-fortress-core git commit: updated mgr and property p methods, added property provider to all relevant DAOs
Date Mon, 28 Nov 2016 21:13:29 GMT
updated mgr and property p methods, added property provider to all relevant DAOs


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/a0b871af
Tree: http://git-wip-us.apache.org/repos/asf/directory-fortress-core/tree/a0b871af
Diff: http://git-wip-us.apache.org/repos/asf/directory-fortress-core/diff/a0b871af

Branch: refs/heads/master
Commit: a0b871af73186b9355d8bd77fd2f194ccf2412c1
Parents: 3b7de7d
Author: clp207 <clp207@psu.edu>
Authored: Thu Oct 27 11:22:36 2016 -0400
Committer: clp207 <clp207@psu.edu>
Committed: Thu Oct 27 11:22:36 2016 -0400

----------------------------------------------------------------------
 .../directory/fortress/core/GlobalErrIds.java   |  8 ++
 .../directory/fortress/core/PropertyMgr.java    | 32 ++++++-
 .../fortress/core/impl/AdminRoleDAO.java        | 15 +++-
 .../directory/fortress/core/impl/GroupDAO.java  | 16 +++-
 .../directory/fortress/core/impl/PermDAO.java   |  6 +-
 .../fortress/core/impl/PermObjDAO.java          | 23 +++++
 .../directory/fortress/core/impl/PermOpDAO.java | 23 +++++
 .../fortress/core/impl/PropertyDAO.java         | 12 +++
 .../fortress/core/impl/PropertyMgrImpl.java     | 90 +++++++++++++++++---
 .../directory/fortress/core/impl/PropertyP.java | 39 +++++++--
 10 files changed, 238 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/a0b871af/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 c392717..414bdb4 100755
--- a/src/main/java/org/apache/directory/fortress/core/GlobalErrIds.java
+++ b/src/main/java/org/apache/directory/fortress/core/GlobalErrIds.java
@@ -1724,5 +1724,13 @@ public final class GlobalErrIds
      */
     public static final int RCON_NULL = 10401;
 
+    /**
+     * 10500's - Property Management Error Ids
+     */
+
+    /**
+     * The entity does not support properties
+     */
+    public static final int ENTITY_PROP_NOT_SUPPORTED = 10501;
 
 }

http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/a0b871af/src/main/java/org/apache/directory/fortress/core/PropertyMgr.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/directory/fortress/core/PropertyMgr.java b/src/main/java/org/apache/directory/fortress/core/PropertyMgr.java
index 9e7ba34..d244546 100644
--- a/src/main/java/org/apache/directory/fortress/core/PropertyMgr.java
+++ b/src/main/java/org/apache/directory/fortress/core/PropertyMgr.java
@@ -25,11 +25,41 @@ import org.apache.directory.fortress.core.model.FortEntity;
 
 public interface PropertyMgr
 {
+    /**
+     * Adds properties (ftProps) to a supplied fortress entity (Group, Role, AdminRole, Permission,
PermObj) 
+     *
+     * @param entity Entity to add properties
+     * @param props Properties to add to entity
+     * @return Updated entity
+     * @throws SecurityException
+     */
     FortEntity add( FortEntity entity, Properties props ) throws SecurityException;
     
+    /**
+     * Update properties (ftProps) to a supplied fortress entity (Group, Role, AdminRole,
Permission, PermObj) 
+     *
+     * @param entity Entity to update properties
+     * @param props Properties to update to entity
+     * @return Updated entity
+     * @throws SecurityException
+     */
     FortEntity update( FortEntity entity, Properties props ) throws SecurityException;
     
+    /**
+     * Delete properties (ftProps) from a supplied fortress entity (Group, Role, AdminRole,
Permission, PermObj) 
+     *
+     * @param entity Entity to delete properties from
+     * @param props Properties to delete from entity
+     * @throws SecurityException
+     */
     void delete( FortEntity entity, Properties props ) throws SecurityException;
     
-    String get( FortEntity entity, String key ) throws SecurityException;
+    /**
+     * Retrieve properties (ftProps) from a supplied fortress entity (Group, Role, AdminRole,
Permission, PermObj) 
+     *
+     * @param entity Entity to return properties from
+     * @return Properties for the supplied entity
+     * @throws SecurityException
+     */
+    Properties get( FortEntity entity ) throws SecurityException;
 }

http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/a0b871af/src/main/java/org/apache/directory/fortress/core/impl/AdminRoleDAO.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/directory/fortress/core/impl/AdminRoleDAO.java b/src/main/java/org/apache/directory/fortress/core/impl/AdminRoleDAO.java
index c33c029..4640f08 100755
--- a/src/main/java/org/apache/directory/fortress/core/impl/AdminRoleDAO.java
+++ b/src/main/java/org/apache/directory/fortress/core/impl/AdminRoleDAO.java
@@ -46,6 +46,7 @@ import org.apache.directory.fortress.core.UpdateException;
 import org.apache.directory.fortress.core.ldap.LdapDataProvider;
 import org.apache.directory.fortress.core.model.AdminRole;
 import org.apache.directory.fortress.core.model.ConstraintUtil;
+import org.apache.directory.fortress.core.model.FortEntity;
 import org.apache.directory.fortress.core.model.Graphable;
 import org.apache.directory.fortress.core.model.ObjectFactory;
 import org.apache.directory.fortress.core.model.Role;
@@ -107,7 +108,7 @@ import org.apache.directory.ldap.client.api.LdapConnection;
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-final class AdminRoleDAO extends LdapDataProvider
+final class AdminRoleDAO extends LdapDataProvider implements PropertyProvider<AdminRole>
 {
     private static final String ROLE_OCCUPANT = "roleOccupant";
     private static final String ROLE_OSP = "ftOSP";
@@ -686,10 +687,18 @@ final class AdminRoleDAO extends LdapDataProvider
         return entity;
     }
 
-
-    private String getDn( AdminRole adminRole )
+    
+    @Override
+    public String getDn( AdminRole adminRole )
     {
         return SchemaConstants.CN_AT + "=" + adminRole.getName() + ","
             + getRootDn( adminRole.getContextId(), GlobalIds.ADMIN_ROLE_ROOT );
     }
+
+
+    @Override
+    public FortEntity getEntity( AdminRole entity ) throws FinderException
+    {
+        return this.getEntity( entity );
+    }
 }

http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/a0b871af/src/main/java/org/apache/directory/fortress/core/impl/GroupDAO.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/directory/fortress/core/impl/GroupDAO.java b/src/main/java/org/apache/directory/fortress/core/impl/GroupDAO.java
index 08c332b..3dea0fe 100755
--- a/src/main/java/org/apache/directory/fortress/core/impl/GroupDAO.java
+++ b/src/main/java/org/apache/directory/fortress/core/impl/GroupDAO.java
@@ -58,7 +58,7 @@ import org.slf4j.LoggerFactory;
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-final class GroupDAO extends LdapDataProvider
+final class GroupDAO extends LdapDataProvider implements PropertyProvider<Group>
 {
     private static final String CLS_NM = GroupDAO.class.getName();
     private static final Logger LOG = LoggerFactory.getLogger( CLS_NM );
@@ -561,4 +561,18 @@ final class GroupDAO extends LdapDataProvider
     {
         return SchemaConstants.CN_AT + "=" + name + "," + getRootDn( contextId, GlobalIds.GROUP_ROOT
);
     }
+
+
+    @Override
+    public String getDn( Group entity )
+    {
+        return getDn( entity.getName(), entity.getContextId() );
+    }
+
+
+    @Override
+    public FortEntity getEntity( Group entity ) throws FinderException
+    {
+        return this.get( entity );
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/a0b871af/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 cbe9912..9b4f4e0 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
@@ -154,7 +154,7 @@ import org.apache.directory.ldap.client.api.LdapConnection;
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-final class PermDAO extends LdapDataProvider
+class PermDAO extends LdapDataProvider
 {
     /*
       *  *************************************************************************
@@ -2098,14 +2098,14 @@ final class PermDAO extends LdapDataProvider
     }
 
 
-    private String getDn( Permission pOp, String contextId )
+    protected String getDn( Permission pOp, String contextId )
     {
         return getOpRdn( pOp.getOpName(), pOp.getObjId() ) + "," + GlobalIds.POBJ_NAME +
"=" + pOp.getObjName()
             + "," + getRootDn( pOp.isAdmin(), contextId );
     }
 
 
-    private String getDn( PermObj pObj, String contextId )
+    protected String getDn( PermObj pObj, String contextId )
     {
         return GlobalIds.POBJ_NAME + "=" + pObj.getObjName() + "," + getRootDn( pObj.isAdmin(),
contextId );
     }

http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/a0b871af/src/main/java/org/apache/directory/fortress/core/impl/PermObjDAO.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/directory/fortress/core/impl/PermObjDAO.java b/src/main/java/org/apache/directory/fortress/core/impl/PermObjDAO.java
new file mode 100644
index 0000000..05be56b
--- /dev/null
+++ b/src/main/java/org/apache/directory/fortress/core/impl/PermObjDAO.java
@@ -0,0 +1,23 @@
+
+package org.apache.directory.fortress.core.impl;
+
+import org.apache.directory.fortress.core.FinderException;
+import org.apache.directory.fortress.core.model.FortEntity;
+import org.apache.directory.fortress.core.model.PermObj;
+
+public class PermObjDAO extends PermDAO implements PropertyProvider<PermObj>
+{
+
+    @Override
+    public String getDn( PermObj entity )
+    {
+        return this.getDn( entity, entity.getContextId() );
+    }
+
+    @Override
+    public FortEntity getEntity( PermObj entity ) throws FinderException
+    {
+        return this.getPerm( entity );
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/a0b871af/src/main/java/org/apache/directory/fortress/core/impl/PermOpDAO.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/directory/fortress/core/impl/PermOpDAO.java b/src/main/java/org/apache/directory/fortress/core/impl/PermOpDAO.java
new file mode 100644
index 0000000..d368ffd
--- /dev/null
+++ b/src/main/java/org/apache/directory/fortress/core/impl/PermOpDAO.java
@@ -0,0 +1,23 @@
+
+package org.apache.directory.fortress.core.impl;
+
+import org.apache.directory.fortress.core.FinderException;
+import org.apache.directory.fortress.core.model.FortEntity;
+import org.apache.directory.fortress.core.model.Permission;
+
+public class PermOpDAO extends PermDAO implements PropertyProvider<Permission>
+{
+
+    @Override
+    public String getDn( Permission entity )
+    {
+        return this.getDn( entity, entity.getContextId() );
+    }
+
+    @Override
+    public FortEntity getEntity( Permission entity ) throws FinderException
+    {
+        return this.getPerm( entity );
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/a0b871af/src/main/java/org/apache/directory/fortress/core/impl/PropertyDAO.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/directory/fortress/core/impl/PropertyDAO.java b/src/main/java/org/apache/directory/fortress/core/impl/PropertyDAO.java
index d8febdf..e54aa69 100644
--- a/src/main/java/org/apache/directory/fortress/core/impl/PropertyDAO.java
+++ b/src/main/java/org/apache/directory/fortress/core/impl/PropertyDAO.java
@@ -68,4 +68,16 @@ public class PropertyDAO extends LdapDataProvider
 
         return propProvider.getEntity( entity );
     }
+    
+    public FortEntity updateProperties( FortEntity entity, Properties properties, PropertyProvider
propProvider ) throws UpdateException, FinderException{ 
+        return null;
+    }
+    
+    public void deleteProperties( FortEntity entity, Properties properties, PropertyProvider
propProvider ) throws UpdateException, FinderException{
+        
+    }
+    
+    public Properties getProperties( FortEntity entity, PropertyProvider propProvider ) throws
FinderException{ 
+        return null;
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/a0b871af/src/main/java/org/apache/directory/fortress/core/impl/PropertyMgrImpl.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/directory/fortress/core/impl/PropertyMgrImpl.java b/src/main/java/org/apache/directory/fortress/core/impl/PropertyMgrImpl.java
index 3e55e2f..badeed2 100644
--- a/src/main/java/org/apache/directory/fortress/core/impl/PropertyMgrImpl.java
+++ b/src/main/java/org/apache/directory/fortress/core/impl/PropertyMgrImpl.java
@@ -22,10 +22,15 @@ package org.apache.directory.fortress.core.impl;
 import java.io.Serializable;
 import java.util.Properties;
 
+import org.apache.directory.fortress.core.GlobalErrIds;
 import org.apache.directory.fortress.core.PropertyMgr;
 import org.apache.directory.fortress.core.ReviewMgr;
 import org.apache.directory.fortress.core.SecurityException;
+import org.apache.directory.fortress.core.model.AdminRole;
 import org.apache.directory.fortress.core.model.FortEntity;
+import org.apache.directory.fortress.core.model.Group;
+import org.apache.directory.fortress.core.model.PermObj;
+import org.apache.directory.fortress.core.model.Permission;
 import org.apache.directory.fortress.core.model.Role;
 
 public class PropertyMgrImpl extends Manageable implements PropertyMgr, Serializable
@@ -33,6 +38,9 @@ public class PropertyMgrImpl extends Manageable implements PropertyMgr,
Serializ
 
     private PropertyP propP = new PropertyP();
     
+    /**
+     * {@inheritDoc}
+     */
     @Override
     public FortEntity add( FortEntity entity, Properties props ) throws SecurityException
     {
@@ -41,35 +49,69 @@ public class PropertyMgrImpl extends Manageable implements PropertyMgr,
Serializ
         return propP.addProperties( entity, props );
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     public FortEntity update( FortEntity entity, Properties props ) throws SecurityException
     {
-        // TODO Auto-generated method stub
-        return null;
+        checkPropertyUpdateAccess( entity );
+        entity.setContextId( this.contextId );
+        return propP.updateProperties( entity, props );
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
     public void delete( FortEntity entity, Properties props ) throws SecurityException
     {
-        // TODO Auto-generated method stub
-        
+        checkPropertyUpdateAccess( entity );
+        entity.setContextId( this.contextId );
+        propP.deleteProperties( entity, props );
     }
 
+    /**
+     * {@inheritDoc}
+     */
     @Override
-    public String get( FortEntity entity, String key ) throws SecurityException
+    public Properties get( FortEntity entity ) throws SecurityException
     {
-        // TODO Auto-generated method stub
-        return null;
+        checkPropertyGetAccess( entity );
+        entity.setContextId( this.contextId );
+        return propP.getProperties( entity );
     }
     
     private void checkPropertyUpdateAccess( FortEntity entity ) throws SecurityException{
         if( entity instanceof Role ){
             checkAccess( AdminMgrImpl.class.getName(), "updateRole" );
         }
-        //TODO: add checks for other instances
+        else if( entity instanceof AdminRole ){
+            checkAccess( DelAdminMgrImpl.class.getName(), "updateRole" );
+        }
+        else if( entity instanceof Group ){
+            checkAccess( GroupMgrImpl.class.getName(), "update" );
+        }
+        else if( entity instanceof PermObj ){
+            PermObj pObj = (PermObj)entity;
+            if(pObj.isAdmin()){
+                checkAccess( DelAdminMgrImpl.class.getName(), "updatePermObj" );
+            }
+            else{
+                checkAccess( AdminMgrImpl.class.getName(), "updatePermObj" );
+            }       
+        }
+        else if( entity instanceof Permission ){
+            Permission perm = (Permission)entity;
+            if(perm.isAdmin()){
+                checkAccess( DelAdminMgrImpl.class.getName(), "updatePermission" );
+            }
+            else{
+                checkAccess( AdminMgrImpl.class.getName(), "updatePermission" );
+            }  
+        }
         else{
-            //TODO: valid error code
-            throw new SecurityException( 1, "Properties not allowed on supplied entity" );
+            throw new SecurityException( GlobalErrIds.ENTITY_PROP_NOT_SUPPORTED, "Properties
not allowed on supplied entity" );
         }
     }
     
@@ -77,10 +119,32 @@ public class PropertyMgrImpl extends Manageable implements PropertyMgr,
Serializ
         if( entity instanceof Role ){
             checkAccess( ReviewMgrImpl.class.getName(), "readRole" );
         }
-        //TODO: add checks for other instances
+        else if( entity instanceof AdminRole ){
+            checkAccess( DelReviewMgrImpl.class.getName(), "readRole" );
+        }
+        else if( entity instanceof Group ){
+            checkAccess( GroupMgrImpl.class.getName(), "read" );
+        }
+        else if( entity instanceof PermObj ){
+            PermObj pObj = (PermObj)entity;
+            if(pObj.isAdmin()){
+                checkAccess( DelReviewMgrImpl.class.getName(), "readPermObj" );
+            }
+            else{
+                checkAccess( ReviewMgrImpl.class.getName(), "readPermObj" );
+            }       
+        }
+        else if( entity instanceof Permission ){
+            Permission perm = (Permission)entity;
+            if(perm.isAdmin()){
+                checkAccess( DelReviewMgrImpl.class.getName(), "readPermission" );
+            }
+            else{
+                checkAccess( ReviewMgrImpl.class.getName(), "readPermission" );
+            }  
+        }
         else{
-            //TODO: valid error code
-            throw new SecurityException( 1, "Properties not allowed on supplied entity" );
+            throw new SecurityException( GlobalErrIds.ENTITY_PROP_NOT_SUPPORTED, "Properties
not allowed on supplied entity" );
         }
     }
 

http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/a0b871af/src/main/java/org/apache/directory/fortress/core/impl/PropertyP.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/directory/fortress/core/impl/PropertyP.java b/src/main/java/org/apache/directory/fortress/core/impl/PropertyP.java
index 84985dc..1b9609c 100644
--- a/src/main/java/org/apache/directory/fortress/core/impl/PropertyP.java
+++ b/src/main/java/org/apache/directory/fortress/core/impl/PropertyP.java
@@ -23,27 +23,56 @@ import java.util.Properties;
 
 import org.apache.directory.fortress.core.FinderException;
 import org.apache.directory.fortress.core.UpdateException;
+import org.apache.directory.fortress.core.model.AdminRole;
 import org.apache.directory.fortress.core.model.FortEntity;
+import org.apache.directory.fortress.core.model.Group;
+import org.apache.directory.fortress.core.model.PermObj;
+import org.apache.directory.fortress.core.model.Permission;
 import org.apache.directory.fortress.core.model.Role;
 
 public class PropertyP
 {
     private PropertyDAO propDAO = new PropertyDAO();
     private RoleDAO rDAO = new RoleDAO();
+    private AdminRoleDAO arDAO = new AdminRoleDAO();
+    private GroupDAO gDAO = new GroupDAO();
+    private PermOpDAO popDAO = new PermOpDAO();
+    private PermObjDAO pobjDAO = new PermObjDAO();
     
-    public FortEntity addProperties( FortEntity entity, Properties props ) throws UpdateException,
FinderException {
-        
+    public FortEntity addProperties( FortEntity entity, Properties props ) throws UpdateException,
FinderException {        
         return propDAO.addProperties( entity, props, this.getPropertyProvider( entity ) );
     }
     
+    public FortEntity updateProperties( FortEntity entity, Properties props ) throws UpdateException,
FinderException {        
+        return propDAO.updateProperties( entity, props, this.getPropertyProvider( entity
) );
+    }
+    
+    public void deleteProperties( FortEntity entity, Properties props ) throws UpdateException,
FinderException {        
+        propDAO.deleteProperties( entity, props, this.getPropertyProvider( entity ) );
+    }
+    
+    public Properties getProperties( FortEntity entity ) throws FinderException {       

+        return propDAO.getProperties( entity, this.getPropertyProvider( entity ) );
+    }
+    
     private PropertyProvider getPropertyProvider( FortEntity entity ){
         if( entity instanceof Role ){
             return rDAO;
         }
-        //TODO: add rest of DAOs
+        else if( entity instanceof AdminRole ){
+            return arDAO;
+        }
+        else if( entity instanceof Group ){
+            return gDAO;
+        }
+        else if( entity instanceof PermObj ){
+            return pobjDAO;
+        }
+        else if( entity instanceof Permission ){
+            return popDAO;
+        }
         else{
-            //TODO: throw exception
-            return null;
+            throw new IllegalArgumentException( "Provided entity does not have an associated
property provider DAO" );
         }
     }
 }


Mime
View raw message