You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by sm...@apache.org on 2019/04/16 23:12:59 UTC

[directory-fortress-core] branch FC-267 updated: FC-267 - New Configuration entity working over rest

This is an automated email from the ASF dual-hosted git repository.

smckinney pushed a commit to branch FC-267
in repository https://gitbox.apache.org/repos/asf/directory-fortress-core.git


The following commit(s) were added to refs/heads/FC-267 by this push:
     new b653ca1  FC-267 - New Configuration entity working over rest
b653ca1 is described below

commit b653ca104ac368eca7284e84be8472bf88d3fcb2
Author: Shawn McKinney <sm...@apache.org>
AuthorDate: Tue Apr 16 18:12:53 2019 -0500

    FC-267 - New Configuration entity working over rest
---
 .../directory/fortress/core/model/FortEntity.java  |  6 +-
 .../fortress/core/rest/ConfigMgrRestImpl.java      | 68 ++++++++++++++++++++++
 .../directory/fortress/core/util/Config.java       | 23 --------
 3 files changed, 71 insertions(+), 26 deletions(-)

diff --git a/src/main/java/org/apache/directory/fortress/core/model/FortEntity.java b/src/main/java/org/apache/directory/fortress/core/model/FortEntity.java
index 2d83507..88084cc 100755
--- a/src/main/java/org/apache/directory/fortress/core/model/FortEntity.java
+++ b/src/main/java/org/apache/directory/fortress/core/model/FortEntity.java
@@ -93,7 +93,8 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo.Id;
         Props.class,
         PermissionAttribute.class,
         PermissionAttributeSet.class,
-        RoleConstraint.class
+        RoleConstraint.class,
+        Configuration.class
 })
 @JsonTypeInfo(use=Id.CLASS, include=As.PROPERTY, property="fqcn", visible=false)
 public abstract class FortEntity
@@ -105,8 +106,7 @@ public abstract class FortEntity
     protected long sequenceId;
     @XmlTransient
     protected String contextId;
-    
-    
+
     /**
      * Default constructor will call the setter to load a new internal ID into entity.
      */
diff --git a/src/main/java/org/apache/directory/fortress/core/rest/ConfigMgrRestImpl.java b/src/main/java/org/apache/directory/fortress/core/rest/ConfigMgrRestImpl.java
index 5fe8930..b5641b8 100644
--- a/src/main/java/org/apache/directory/fortress/core/rest/ConfigMgrRestImpl.java
+++ b/src/main/java/org/apache/directory/fortress/core/rest/ConfigMgrRestImpl.java
@@ -23,6 +23,7 @@ import java.util.Properties;
 
 import org.apache.directory.fortress.core.ConfigMgr;
 import org.apache.directory.fortress.core.GlobalErrIds;
+import org.apache.directory.fortress.core.GlobalIds;
 import org.apache.directory.fortress.core.SecurityException;
 import org.apache.directory.fortress.core.model.Configuration;
 import org.apache.directory.fortress.core.model.FortRequest;
@@ -53,8 +54,30 @@ public class ConfigMgrRestImpl implements ConfigMgr
     @Override
     public Configuration add(Configuration cfg) throws SecurityException
     {
+        VUtil.assertNotNull( cfg, GlobalErrIds.FT_CONFIG_NULL, CLS_NM + ".add" );
+        Configuration retCfg;
+        FortRequest request = RestUtils.getRequest( GlobalIds.HOME );
+        request.setEntity( cfg );
+        String szRequest = RestUtils.marshal( request );
+        String szResponse = RestUtils.getInstance().post( szRequest, HttpIds.CFG_ADD );
+        FortResponse response = RestUtils.unmarshall( szResponse );
+        if ( response.getErrorCode() == 0 )
+        {
+            retCfg = ( Configuration ) response.getEntity();
+        }
+        else
+        {
+            throw new SecurityException( response.getErrorCode(), response.getErrorMessage() );
+        }
+        return retCfg;
+    }
+/*
+    @Override
+    public Configuration add(Configuration cfg) throws SecurityException
+    {
         throw new UnsupportedOperationException( "not implemented" );
     }
+*/
 /*
     @Override
     public Properties add(String name, Properties inProperties) throws SecurityException
@@ -89,8 +112,30 @@ public class ConfigMgrRestImpl implements ConfigMgr
     @Override
     public Configuration update(Configuration cfg) throws SecurityException
     {
+        VUtil.assertNotNull( cfg, GlobalErrIds.FT_CONFIG_NULL, CLS_NM + ".update" );
+        Configuration retCfg;
+        FortRequest request = RestUtils.getRequest( GlobalIds.HOME );
+        request.setEntity( cfg );
+        String szRequest = RestUtils.marshal( request );
+        String szResponse = RestUtils.getInstance().post( szRequest, HttpIds.CFG_UPDATE );
+        FortResponse response = RestUtils.unmarshall( szResponse );
+        if ( response.getErrorCode() == 0 )
+        {
+            retCfg = ( Configuration ) response.getEntity();
+        }
+        else
+        {
+            throw new SecurityException( response.getErrorCode(), response.getErrorMessage() );
+        }
+        return retCfg;
+    }
+/*
+    @Override
+    public Configuration update(Configuration cfg) throws SecurityException
+    {
         throw new UnsupportedOperationException( "not implemented" );
     }
+*/
 /*
     @Override
     public Properties update(String name, Properties inProperties) throws SecurityException
@@ -176,8 +221,31 @@ public class ConfigMgrRestImpl implements ConfigMgr
     @Override
     public Configuration read(String name) throws SecurityException
     {
+        VUtil.assertNotNull(name, GlobalErrIds.FT_CONFIG_NAME_NULL, CLS_NM + ".readRole");
+        Configuration retCfg;
+        FortRequest request = new FortRequest();
+        request.setValue(name);
+        String szRequest = RestUtils.marshal(request);
+        String szResponse = RestUtils.getInstance().post(szRequest, HttpIds.CFG_READ);
+        FortResponse response = RestUtils.unmarshall(szResponse);
+        Props props;
+        if (response.getErrorCode() == 0)
+        {
+            retCfg = (Configuration) response.getEntity();
+        }
+        else
+        {
+            throw new SecurityException(response.getErrorCode(), response.getErrorMessage());
+        }
+        return retCfg;
+    }
+
+    /*
+    public Configuration read(String name) throws SecurityException
+    {
         throw new java.lang.UnsupportedOperationException();
     }
+*/
 /*
     public Properties read(String name) throws SecurityException
     {
diff --git a/src/main/java/org/apache/directory/fortress/core/util/Config.java b/src/main/java/org/apache/directory/fortress/core/util/Config.java
index 08fd7dc..d8b42fc 100755
--- a/src/main/java/org/apache/directory/fortress/core/util/Config.java
+++ b/src/main/java/org/apache/directory/fortress/core/util/Config.java
@@ -163,29 +163,6 @@ public final class Config
         return value;
     }
 
-/*
-    public synchronized String replacePropertyx( String name, String key, PropUpdater propUpdater ) throws CfgException
-    {
-        String value;
-        try
-        {
-            ConfigMgr cfgMgr = ConfigMgrFactory.createInstance();
-            Properties props = cfgMgr.read( name );
-            // TODO: The key should be scoped to an instance, e.g. FORT104
-            value = props.getProperty( key );
-            String newValue = propUpdater.newValue( value );
-            cfgMgr.updateProperty( name, key, value, newValue );
-            setProperty( key, newValue );
-        }
-        catch ( SecurityException se )
-        {
-            String error = "replaceProperty failed, exception=" + se.getMessage();
-            throw new CfgRuntimeException( GlobalErrIds.FT_CONFIG_UPDATE_FAILED, error, se );
-        }
-        return value;
-    }
-*/
-
     /**
      * Gets the prop attribute as String value from the apache commons cfg component.
      *