directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cp...@apache.org
Subject [34/43] directory-fortress-core git commit: added some documentatino and basic validate methods
Date Thu, 06 Oct 2016 17:49:51 GMT
added some documentatino and basic validate methods


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

Branch: refs/heads/master
Commit: 1eebcfc60d5434421a068db6891c43f1d9174f1b
Parents: c70d237
Author: clp207 <clp207@psu.edu>
Authored: Wed Aug 24 14:32:34 2016 -0400
Committer: clp207 <clp207@psu.edu>
Committed: Wed Aug 24 14:32:34 2016 -0400

----------------------------------------------------------------------
 .../fortress/core/impl/AdminMgrImpl.java        |  3 +-
 .../directory/fortress/core/impl/PermP.java     | 94 +++++++++++++-------
 .../fortress/core/impl/AdminMgrImplTest.java    | 10 ++-
 .../fortress/core/impl/PermTestData.java        |  1 +
 .../fortress/core/impl/ReviewMgrImplTest.java   |  9 +-
 5 files changed, 78 insertions(+), 39 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/1eebcfc6/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 3697bd2..0662c0d 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
@@ -404,7 +404,8 @@ public final class AdminMgrImpl extends Manageable implements AdminMgr,
Serializ
     {
         String methodName = "addPermissionAttributeSet";         
         assertContext( CLS_NM, methodName, permAttributeSet, GlobalErrIds.PERM_ATTRIBUTE_SET_NULL
);
-        //TODO: verify with Shawn we don't need to set entity session here...        
+        //TODO: setup ARBAC permissions
+        //setEntitySession( CLS_NM, methodName, permAttributeSet );    
         return permP.add( permAttributeSet );
     }          
     

http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/1eebcfc6/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 8012f0b..47415de 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
@@ -27,8 +27,6 @@ import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang.StringUtils;
 import org.apache.directory.fortress.core.FinderException;
 import org.apache.directory.fortress.core.GlobalErrIds;
-import org.apache.directory.fortress.core.ReviewMgr;
-import org.apache.directory.fortress.core.ReviewMgrFactory;
 import org.apache.directory.fortress.core.SecurityException;
 import org.apache.directory.fortress.core.ValidationException;
 import org.apache.directory.fortress.core.model.AdminRole;
@@ -378,42 +376,44 @@ final class PermP
         return pDao.createOperation( entity );
     }
     
-    //TODO: add documentation
+    /**
+     * Adds a new Permission Attribute Set entity to the directory. 
+     * 
+     * @param entity Permission Attribute Set entity contains data targeted for insertion
+     * @return Permission Attribute Set entity copy of input + additional attributes that
were added
+     * @throws SecurityException in the event of data validation or DAO system error.
+     */
     PermissionAttributeSet add( PermissionAttributeSet entity ) throws SecurityException
     {
-        //TODO: add validation
+        validate( entity );
         return pDao.createPermissionAttributeSet( entity );
     }
     
-    //TODO: add documentation
-    PermissionAttribute add( PermissionAttribute entity, String attributeSetName ) throws
SecurityException
+    /**
+     * Adds a new Permission Attribute entity to an existing Permission Attribute Set
+     * 
+     * @param entity Permissino Attribute entity contains data targeted for insertion
+     * @param paSetName The name of the Permission Attribute Set this entity is being added
to
+     * @return Permission Attribute entity copy of input + additional attributes that were
added
+     * @throws SecurityException in the event of data validation or DAO system error. 
+     */
+    PermissionAttribute add( PermissionAttribute entity, String paSetName ) throws SecurityException
     {
-        //TODO: add validation
-        return pDao.createPermissionAttribute( entity, attributeSetName );
+        validate( entity );
+        return pDao.createPermissionAttribute( entity, paSetName );
     }
 
-    //TODO: add documentation
-    void delete( PermissionAttribute entity, String attributeSetName ) throws SecurityException
-    {
-        //TODO: add validation
-    	
-    	//want to remove by attribute name, not full ftPA value, so find existing and delete
that
-    	PermissionAttribute existingPa = null;
-    	
-    	ReviewMgr reviewMgr = ReviewMgrFactory.createInstance();
-    	PermissionAttributeSet paSet = reviewMgr.readPermAttributeSet(new PermissionAttributeSet(attributeSetName));
-    	for(PermissionAttribute pa : paSet.getAttributes()){
-    		if(pa.getAttributeName().equals(entity.getAttributeName())){
-    			existingPa = pa;
-    			break;
-    		}
-    	}
-    	
-    	if(existingPa == null){
-    		throw new ValidationException(GlobalErrIds.PERM_ATTRIBUTE_NOT_FOUND, "Could not find
permission attribute with name [" + entity.getAttributeName() + "] on attribute set [" + attributeSetName
+ "]");
-    	}
-    	
-        pDao.deletePermissionAttribute( existingPa, attributeSetName );
+    /**
+     * Deletes a Permission Attribute entity from an existing Permission Attribute Set
+     * 
+     * @param entity
+     * @param attributeSetName
+     * @throws SecurityException
+     */     
+    void delete( PermissionAttribute entity, String paSetName ) throws SecurityException
+    {
+        validate( entity );            	
+        pDao.deletePermissionAttribute( entity, paSetName );
     }
 
     /**
@@ -716,4 +716,38 @@ final class PermP
             }
         }
     }
+    
+    private void validate( PermissionAttributeSet paSet )
+            throws SecurityException
+    {
+        if( StringUtils.isNotEmpty(paSet.getType()) ){
+            VUtil.description( paSet.getType() );
+        }
+        if( StringUtils.isNotEmpty(paSet.getDescription()) ){
+            VUtil.description( paSet.getDescription() );
+        }
+    }
+    
+    private void validate( PermissionAttribute pa )
+            throws SecurityException
+    {
+        if( StringUtils.isNotEmpty(pa.getAttributeName()) ){
+            VUtil.description( pa.getAttributeName() );
+        }
+        if( StringUtils.isNotEmpty(pa.getDataType()) ){
+            VUtil.description( pa.getDataType() );
+        }
+        if( StringUtils.isNotEmpty(pa.getDefaultOperator()) ){
+            VUtil.description( pa.getDefaultOperator() );
+        }
+        if( StringUtils.isNotEmpty(pa.getDefaultStrategy()) ){
+            VUtil.description( pa.getDefaultStrategy() );
+        }
+        if( StringUtils.isNotEmpty(pa.getDefaultValue()) ){
+            VUtil.description( pa.getDefaultValue() );
+        }
+        if( StringUtils.isNotEmpty(pa.getDescription()) ){
+            VUtil.description( pa.getDescription() );
+        }        
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/1eebcfc6/src/test/java/org/apache/directory/fortress/core/impl/AdminMgrImplTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/directory/fortress/core/impl/AdminMgrImplTest.java b/src/test/java/org/apache/directory/fortress/core/impl/AdminMgrImplTest.java
index 5a3ae9d..7699943 100755
--- a/src/test/java/org/apache/directory/fortress/core/impl/AdminMgrImplTest.java
+++ b/src/test/java/org/apache/directory/fortress/core/impl/AdminMgrImplTest.java
@@ -23,10 +23,6 @@ package org.apache.directory.fortress.core.impl;
 import java.util.List;
 import java.util.Set;
 
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
 import org.apache.directory.fortress.core.AdminMgr;
 import org.apache.directory.fortress.core.AdminMgrFactory;
 import org.apache.directory.fortress.core.GlobalErrIds;
@@ -47,6 +43,10 @@ import org.apache.directory.fortress.core.util.LogUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
 
 /**
  * AdminMgrImpl Tester.
@@ -1822,6 +1822,8 @@ public class AdminMgrImplTest extends TestCase
     {
     	LogUtil.logIt(msg);
     	PermissionAttributeSet paSet = new PermissionAttributeSet(name);  
+    	paSet.setType(PermTestData.TPA_SET_TYPE);
+    	
     	try
     	{
     		paSet.setAttributes(permAttr);

http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/1eebcfc6/src/test/java/org/apache/directory/fortress/core/impl/PermTestData.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/directory/fortress/core/impl/PermTestData.java b/src/test/java/org/apache/directory/fortress/core/impl/PermTestData.java
index f3cd4e2..8624b55 100755
--- a/src/test/java/org/apache/directory/fortress/core/impl/PermTestData.java
+++ b/src/test/java/org/apache/directory/fortress/core/impl/PermTestData.java
@@ -2772,6 +2772,7 @@ public class PermTestData extends TestCase
      */
     public static final String TPA_SET_1_NAME = "TPASET1";
     public static final String TPA_SET_2_NAME = "TPASET2";
+    public static final String TPA_SET_TYPE = "paSetType";
     public static final String TPA_SET_NOT_EXIST_NAME = "NOTEXISTTPASETNAME";
     
     public static final String[][] PA_TPSASET1 =

http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/1eebcfc6/src/test/java/org/apache/directory/fortress/core/impl/ReviewMgrImplTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/directory/fortress/core/impl/ReviewMgrImplTest.java
b/src/test/java/org/apache/directory/fortress/core/impl/ReviewMgrImplTest.java
index 7ecd7b1..0dd3453 100755
--- a/src/test/java/org/apache/directory/fortress/core/impl/ReviewMgrImplTest.java
+++ b/src/test/java/org/apache/directory/fortress/core/impl/ReviewMgrImplTest.java
@@ -25,10 +25,6 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
 import org.apache.directory.fortress.core.GlobalErrIds;
 import org.apache.directory.fortress.core.ReviewMgr;
 import org.apache.directory.fortress.core.ReviewMgrFactory;
@@ -47,6 +43,10 @@ import org.apache.directory.fortress.core.util.LogUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
 
 /**
  * ReviewMgrImpl Tester.
@@ -178,6 +178,7 @@ public class ReviewMgrImplTest extends TestCase
             PermissionAttributeSet entity = reviewMgr.readPermAttributeSet(new PermissionAttributeSet(name));
             assertNotNull(entity);
             assertEquals(name, entity.getName());
+            assertEquals(PermTestData.TPA_SET_TYPE, entity.getType());
             
             for(PermissionAttribute pa : permAttributes){
             	assertTrue(entity.getAttributes().contains(pa));


Mime
View raw message