You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by cp...@apache.org on 2016/10/06 17:49:52 UTC
[35/43] directory-fortress-core git commit: added perm attr update
method
added perm attr update method
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/7df32358
Tree: http://git-wip-us.apache.org/repos/asf/directory-fortress-core/tree/7df32358
Diff: http://git-wip-us.apache.org/repos/asf/directory-fortress-core/diff/7df32358
Branch: refs/heads/master
Commit: 7df323584adfcbeae7d13fed05b67a85e38f2612
Parents: 1eebcfc
Author: clp207 <cl...@psu.edu>
Authored: Wed Aug 24 15:16:01 2016 -0400
Committer: clp207 <cl...@psu.edu>
Committed: Wed Aug 24 15:16:01 2016 -0400
----------------------------------------------------------------------
.../directory/fortress/core/AdminMgr.java | 14 ++-
.../directory/fortress/core/GlobalErrIds.java | 5 +-
.../fortress/core/impl/AdminMgrImpl.java | 13 +++
.../directory/fortress/core/impl/PermDAO.java | 93 ++++++++++++++++++--
.../directory/fortress/core/impl/PermP.java | 14 +++
.../fortress/core/rest/AdminMgrRestImpl.java | 7 ++
6 files changed, 138 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/7df32358/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 f46703a..42fa15a 100755
--- a/src/main/java/org/apache/directory/fortress/core/AdminMgr.java
+++ b/src/main/java/org/apache/directory/fortress/core/AdminMgr.java
@@ -614,11 +614,21 @@ public interface AdminMgr extends Manageable
* </ul>
*
* @param permAttribute must contain {@link PermissionAttribute#attributeName}
- * @param attributeSetName The name of the permission attribute set this ftPA should be removed from
+ * @param attributeSetName The name of the permission attribute set this pa should be removed from
* @throws SecurityException - thrown in the event of data or system error
*/
void removePermissionAttributeFromSet( PermissionAttribute permAttribute, String attributeSetName )
- throws SecurityException;
+ throws SecurityException;
+
+ /**
+ *
+ * @param permAttribute must contain {@link PermissionAttribute#attributeName}
+ * @param attributeSetName The name of the permission attribute set this pa should be removed from
+ * @param replaceValidValues Set to true to replace all of the valid values and set to false to add to the existing valid values
+ * @throws SecurityException - thrown in the event of data or system error
+ */
+ void updatePermissionAttributeInSet( PermissionAttribute permAttribute, String attributeSetName, boolean replaceValidValues )
+ throws SecurityException;
/**
* This method will update permission operation pre-existing in target directory under
http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/7df32358/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 7704d89..4a0fbfa 100755
--- a/src/main/java/org/apache/directory/fortress/core/GlobalErrIds.java
+++ b/src/main/java/org/apache/directory/fortress/core/GlobalErrIds.java
@@ -677,7 +677,10 @@ public final class GlobalErrIds
* The supplied Permission Attribute was not found
*/
public static final int PERM_ATTRIBUTE_NOT_FOUND = 3037;
-
+ /**
+ * The supplied Permission Attribute update failed
+ */
+ public static final int PERM_ATTRIBUTE_UPDATE_FAILED = 3038;
/**
* 4000's - Password Policy Entity
http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/7df32358/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 0662c0d..50f8ea2 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
@@ -450,6 +450,19 @@ public final class AdminMgrImpl extends Manageable implements AdminMgr, Serializ
/**
* {@inheritDoc}
*/
+ @Override
+ public void updatePermissionAttributeInSet(PermissionAttribute permAttribute, String attributeSetName, boolean replaceValidValues)
+ throws SecurityException
+ {
+ String methodName = "updatePermissionAttributeInSet";
+ assertContext( CLS_NM, methodName, permAttribute, GlobalErrIds.PERM_ATTRIBUTE_NULL );
+ //TODO: verify with Shawn we don't need to set entity session here...
+ permP.update( permAttribute, attributeSetName, replaceValidValues );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
@Override
public Permission updatePermission( Permission perm ) throws SecurityException
{
http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/7df32358/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 1a2a599..623dbec 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
@@ -476,7 +476,12 @@ final class PermDAO extends LdapDataProvider
return entity;
}
- //TODO: add documentation
+ /**
+ *
+ * @param entity
+ * @return
+ * @throws CreateException
+ */
PermissionAttributeSet createPermissionAttributeSet( PermissionAttributeSet entity ) throws CreateException
{
LdapConnection ld = null;
@@ -529,12 +534,17 @@ final class PermDAO extends LdapDataProvider
for(PermissionAttribute pa : entity.getAttributes()){
this.createPermissionAttribute(pa, entity.getName());
}
-
- //TODO: need to do anything to returned entity?
+
return entity;
}
- //TODO: add documentation
+ /**
+ *
+ * @param entity
+ * @param attributeSetName
+ * @return
+ * @throws CreateException
+ */
PermissionAttribute createPermissionAttribute( PermissionAttribute entity, String attributeSetName ) throws CreateException
{
LdapConnection ld = null;
@@ -607,7 +617,80 @@ final class PermDAO extends LdapDataProvider
return entity;
}
-
+
+ PermissionAttribute updatePermissionAttribute( PermissionAttribute entity, String paSetName, boolean replaceValidValues ) throws UpdateException
+ {
+ LdapConnection ld = null;
+ String dn = getDn( entity, paSetName, entity.getContextId() );
+
+ try
+ {
+ List<Modification> mods = new ArrayList<Modification>();
+
+ if ( StringUtils.isNotEmpty( entity.getDataType() ) )
+ {
+ mods.add( new DefaultModification(
+ ModificationOperation.REPLACE_ATTRIBUTE, GlobalIds.FT_PERMISSION_ATTRIBUTE_DATA_TYPE, entity.getDataType() ) );
+ }
+
+ if ( StringUtils.isNotEmpty( entity.getDescription() ) )
+ {
+ mods.add( new DefaultModification(
+ ModificationOperation.REPLACE_ATTRIBUTE, SchemaConstants.DESCRIPTION_AT, entity.getDescription() ) );
+ }
+
+ if ( StringUtils.isNotEmpty( entity.getDefaultOperator() ) )
+ {
+
+ mods.add( new DefaultModification(
+ ModificationOperation.REPLACE_ATTRIBUTE, GlobalIds.FT_PERMISSION_ATTRIBUTE_DEFAULT_OPERATOR, entity.getDefaultOperator() ) );
+ }
+
+ if ( StringUtils.isNotEmpty( entity.getDefaultStrategy() ) )
+ {
+
+ mods.add( new DefaultModification(
+ ModificationOperation.REPLACE_ATTRIBUTE, GlobalIds.FT_PERMISSION_ATTRIBUTE_DEFAULT_STRATEGY, entity.getDefaultStrategy() ) );
+ }
+
+ if ( StringUtils.isNotEmpty( entity.getDefaultValue() ) )
+ {
+
+ mods.add( new DefaultModification(
+ ModificationOperation.REPLACE_ATTRIBUTE, GlobalIds.FT_PERMISSION_ATTRIBUTE_DEFAULT_VALUE, entity.getDefaultValue() ) );
+ }
+
+ //if replace, then remove first
+ if(replaceValidValues){
+ mods.add( new DefaultModification(
+ ModificationOperation.REMOVE_ATTRIBUTE, GlobalIds.FT_PERMISSION_ATTRIBUTE_VALID_VALUES ) );
+ }
+
+ for(String validValue : entity.getValidValues()){
+ mods.add( new DefaultModification(
+ ModificationOperation.ADD_ATTRIBUTE, GlobalIds.FT_PERMISSION_ATTRIBUTE_VALID_VALUES, validValue ) );
+ }
+
+ if ( mods.size() > 0 )
+ {
+ ld = getAdminConnection();
+ modify( ld, dn, mods, entity );
+ entity.setDn( dn );
+ }
+ }
+ catch ( LdapException e )
+ {
+ String error = "updatePermissionAttribute name [" + entity.getAttributeName() + "] caught LdapException=" + e.getMessage();
+ throw new UpdateException( GlobalErrIds.PERM_ATTRIBUTE_UPDATE_FAILED, error, e );
+ }
+ finally
+ {
+ closeAdminConnection( ld );
+ }
+
+ return entity;
+ }
+
/**
* @param entity
* @return
http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/7df32358/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 47415de..e87bb33 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
@@ -417,6 +417,20 @@ final class PermP
}
/**
+ * Updates a Permission Attribute entity
+ *
+ * @param entity
+ * @param paSetName
+ * @param replaceValidValues
+ * @throws SecurityException
+ */
+ void update( PermissionAttribute entity, String paSetName, boolean replaceValidValues ) throws SecurityException
+ {
+ validate( entity );
+ pDao.updatePermissionAttribute( entity, paSetName, replaceValidValues );
+ }
+
+ /**
* Update existing Permission Object attributes with the input entity. Null or empty attributes will be ignored.
* The Permission Object entity input will be validated to ensure that:
* object name is present, orgUnitId is valid, reasonability checks on all of the other populated values.
http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/7df32358/src/main/java/org/apache/directory/fortress/core/rest/AdminMgrRestImpl.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/directory/fortress/core/rest/AdminMgrRestImpl.java b/src/main/java/org/apache/directory/fortress/core/rest/AdminMgrRestImpl.java
index eb41427..1d641c2 100644
--- a/src/main/java/org/apache/directory/fortress/core/rest/AdminMgrRestImpl.java
+++ b/src/main/java/org/apache/directory/fortress/core/rest/AdminMgrRestImpl.java
@@ -1292,4 +1292,11 @@ public final class AdminMgrRestImpl extends Manageable implements AdminMgr
// TODO Auto-generated method stub
}
+
+ @Override
+ public void updatePermissionAttributeInSet(PermissionAttribute permAttribute, String attributeSetName,
+ boolean replaceValidValues) throws SecurityException {
+ // TODO Auto-generated method stub
+
+ }
}
\ No newline at end of file