directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smckin...@apache.org
Subject directory-fortress-core git commit: FC-189 - add GroupMgrRestImpl
Date Fri, 07 Oct 2016 22:39:49 GMT
Repository: directory-fortress-core
Updated Branches:
  refs/heads/master 733a74aee -> 5f3ae1141


FC-189 - add GroupMgrRestImpl


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

Branch: refs/heads/master
Commit: 5f3ae11413cde0f0f346e2c56bae656aa61cb110
Parents: 733a74a
Author: Shawn McKinney <smckinney@apache.org>
Authored: Fri Oct 7 17:39:45 2016 -0500
Committer: Shawn McKinney <smckinney@apache.org>
Committed: Fri Oct 7 17:39:45 2016 -0500

----------------------------------------------------------------------
 .../directory/fortress/core/GlobalErrIds.java   |   4 +
 .../fortress/core/GroupMgrFactory.java          |  41 ++-
 .../fortress/core/rest/GroupMgrRestImpl.java    | 309 +++++++++++++++++++
 .../directory/fortress/core/rest/HttpIds.java   |   4 +-
 4 files changed, 342 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/5f3ae114/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 6d73d29..c392717 100755
--- a/src/main/java/org/apache/directory/fortress/core/GlobalErrIds.java
+++ b/src/main/java/org/apache/directory/fortress/core/GlobalErrIds.java
@@ -1710,6 +1710,10 @@ public final class GlobalErrIds
      */
     public static final int GROUP_TYPE_INVLD = 10314;
 
+    /**
+     * The Group member is required and cannot be null
+     */
+    public static final int GROUP_MEMBER_NULL = 10315;
 
     /**
      * 10400's - ROLE CONSTRAINT Error Ids

http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/5f3ae114/src/main/java/org/apache/directory/fortress/core/GroupMgrFactory.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/directory/fortress/core/GroupMgrFactory.java b/src/main/java/org/apache/directory/fortress/core/GroupMgrFactory.java
index 22bd0c1..607cf64 100755
--- a/src/main/java/org/apache/directory/fortress/core/GroupMgrFactory.java
+++ b/src/main/java/org/apache/directory/fortress/core/GroupMgrFactory.java
@@ -19,9 +19,11 @@
  */
 package org.apache.directory.fortress.core;
 
+import org.apache.commons.lang.StringUtils;
 import org.apache.directory.api.util.Strings;
 import org.apache.directory.fortress.core.impl.GroupMgrImpl;
 import org.apache.directory.fortress.core.model.Session;
+import org.apache.directory.fortress.core.rest.GroupMgrRestImpl;
 import org.apache.directory.fortress.core.util.ClassUtil;
 import org.apache.directory.fortress.core.util.Config;
 import org.apache.directory.fortress.core.util.VUtil;
@@ -68,28 +70,39 @@ public final class GroupMgrFactory
     public static GroupMgr createInstance(String contextId)
         throws SecurityException
     {
-        VUtil.assertNotNull( contextId, GlobalErrIds.CONTEXT_NULL, CREATE_INSTANCE_METHOD
);
-        String groupClassName = Config.getInstance().getProperty( GlobalIds.GROUP_IMPLEMENTATION
);
-        
-        if ( Strings.isEmpty( groupClassName ) )
+        VUtil.assertNotNull(contextId, GlobalErrIds.CONTEXT_NULL, CLS_NM + ".createInstance");
+
+        String groupClassName = Config.getInstance().getProperty(GlobalIds.GROUP_IMPLEMENTATION);
+
+        GroupMgr groupMgr = null;
+
+        if ( StringUtils.isEmpty( groupClassName ) )
+        {
+            if(Config.getInstance().isRestEnabled())
+            {
+                groupMgr = new GroupMgrRestImpl();
+            }
+            else
+            {
+                groupMgr = new GroupMgrImpl();
+            }
+        }
+        else
         {
-            groupClassName = GroupMgrImpl.class.getName();
+            groupMgr = (GroupMgr) ClassUtil.createInstance( groupClassName );
         }
 
-        GroupMgr groupMgr = (GroupMgr) ClassUtil.createInstance(groupClassName);
-        groupMgr.setContextId(contextId);
-        
         if(groupMgr instanceof GroupMgrImpl){
-        	Config cfg = Config.getInstance();
-        	if(!cfg.isRemoteConfigLoaded()){
-        		cfg.loadRemoteConfig();
-        	}
+            Config cfg = Config.getInstance();
+            if(!cfg.isRemoteConfigLoaded()){
+                cfg.loadRemoteConfig();
+            }
         }
-        
+
+        groupMgr.setContextId(contextId);
         return groupMgr;
     }
 
-
     /**
      * Create and return a reference to {@link GroupMgr} object using HOME context.
      *

http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/5f3ae114/src/main/java/org/apache/directory/fortress/core/rest/GroupMgrRestImpl.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/directory/fortress/core/rest/GroupMgrRestImpl.java b/src/main/java/org/apache/directory/fortress/core/rest/GroupMgrRestImpl.java
new file mode 100644
index 0000000..d69e44e
--- /dev/null
+++ b/src/main/java/org/apache/directory/fortress/core/rest/GroupMgrRestImpl.java
@@ -0,0 +1,309 @@
+/*
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *   or more contributor license agreements.  See the NOTICE file
+ *   distributed with this work for additional information
+ *   regarding copyright ownership.  The ASF licenses this file
+ *   to you under the Apache License, Version 2.0 (the
+ *   "License"); you may not use this file except in compliance
+ *   with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing,
+ *   software distributed under the License is distributed on an
+ *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *   KIND, either express or implied.  See the License for the
+ *   specific language governing permissions and limitations
+ *   under the License.
+ *
+ */
+package org.apache.directory.fortress.core.rest;
+
+import org.apache.directory.fortress.core.*;
+import org.apache.directory.fortress.core.SecurityException;
+import org.apache.directory.fortress.core.impl.Manageable;
+import org.apache.directory.fortress.core.model.FortRequest;
+import org.apache.directory.fortress.core.model.FortResponse;
+import org.apache.directory.fortress.core.model.Group;
+import org.apache.directory.fortress.core.model.Role;
+import org.apache.directory.fortress.core.model.User;
+import org.apache.directory.fortress.core.model.UserRole;
+import org.apache.directory.fortress.core.util.VUtil;
+
+import java.util.List;
+
+public class GroupMgrRestImpl  extends Manageable implements GroupMgr
+{
+    private static final String CLS_NM = GroupMgrRestImpl.class.getName();
+
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public Group add( Group group ) throws SecurityException
+    {
+        VUtil.assertNotNull( group, GlobalErrIds.GROUP_NULL, CLS_NM + ".add" );
+        Group retGroup;
+        FortRequest request = new FortRequest();
+        request.setContextId( this.contextId );
+        request.setEntity( group );
+        if ( this.adminSess != null )
+        {
+            request.setSession( adminSess );
+        }
+        String szRequest = RestUtils.marshal( request );
+        String szResponse = RestUtils.getInstance().post( szRequest, HttpIds.GROUP_ADD );
+        FortResponse response = RestUtils.unmarshall( szResponse );
+        if ( response.getErrorCode() == 0 )
+        {
+            retGroup = ( Group ) response.getEntity();
+        }
+        else
+        {
+            throw new org.apache.directory.fortress.core.SecurityException( response.getErrorCode(),
response.getErrorMessage() );
+        }
+        return retGroup;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public Group update( Group group ) throws SecurityException
+    {
+        VUtil.assertNotNull( group, GlobalErrIds.GROUP_NULL, CLS_NM + ".update" );
+        Group retGroup;
+        FortRequest request = new FortRequest();
+        request.setContextId( this.contextId );
+        request.setEntity( group );
+        if ( this.adminSess != null )
+        {
+            request.setSession( adminSess );
+        }
+        String szRequest = RestUtils.marshal( request );
+        String szResponse = RestUtils.getInstance().post( szRequest, HttpIds.GROUP_UPDATE
);
+        FortResponse response = RestUtils.unmarshall( szResponse );
+        if ( response.getErrorCode() == 0 )
+        {
+            retGroup = ( Group ) response.getEntity();
+        }
+        else
+        {
+            throw new org.apache.directory.fortress.core.SecurityException( response.getErrorCode(),
response.getErrorMessage() );
+        }
+        return retGroup;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public Group delete( Group group ) throws SecurityException
+    {
+        VUtil.assertNotNull( group, GlobalErrIds.GROUP_NULL, CLS_NM + ".delete" );
+        Group retGroup;
+        FortRequest request = new FortRequest();
+        request.setContextId( this.contextId );
+        request.setEntity( group );
+        if ( this.adminSess != null )
+        {
+            request.setSession( adminSess );
+        }
+        String szRequest = RestUtils.marshal( request );
+        String szResponse = RestUtils.getInstance().post( szRequest, HttpIds.GROUP_DELETE
);
+        FortResponse response = RestUtils.unmarshall( szResponse );
+        if ( response.getErrorCode() == 0 )
+        {
+            retGroup = ( Group ) response.getEntity();
+        }
+        else
+        {
+            throw new org.apache.directory.fortress.core.SecurityException( response.getErrorCode(),
response.getErrorMessage() );
+        }
+        return retGroup;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Group add( Group group, String key, String value ) throws SecurityException
+    {
+        throw new UnsupportedOperationException();
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public Group delete( Group group, String key, String value ) throws SecurityException
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public Group read( Group group ) throws SecurityException
+    {
+        VUtil.assertNotNull(group, GlobalErrIds.GROUP_NULL, CLS_NM + ".read");
+        Group retGroup;
+        FortRequest request = new FortRequest();
+        request.setContextId(this.contextId);
+        request.setEntity(group);
+        if (this.adminSess != null)
+        {
+            request.setSession(adminSess);
+        }
+        String szRequest = RestUtils.marshal(request);
+        String szResponse = RestUtils.getInstance().post(szRequest, HttpIds.GROUP_READ);
+        FortResponse response = RestUtils.unmarshall(szResponse);
+        if (response.getErrorCode() == 0)
+        {
+            retGroup = (Group) response.getEntity();
+        }
+        else
+        {
+            throw new SecurityException(response.getErrorCode(), response.getErrorMessage());
+        }
+        return retGroup;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public List<Group> find( Group group ) throws SecurityException
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public List<Group> find( User user ) throws SecurityException
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public List<Group> roleGroups( Role role ) throws SecurityException
+    {
+        VUtil.assertNotNull(role, GlobalErrIds.ROLE_NULL, CLS_NM + ".roleGroups");
+        List<Group> retGroups;
+        FortRequest request = new FortRequest();
+        request.setContextId(this.contextId);
+        request.setEntity(role);
+        if (this.adminSess != null)
+        {
+            request.setSession(adminSess);
+        }
+        String szRequest = RestUtils.marshal(request);
+        String szResponse = RestUtils.getInstance().post(szRequest, HttpIds.GROUP_ASGNED);
+        FortResponse response = RestUtils.unmarshall(szResponse);
+        if (response.getErrorCode() == 0)
+        {
+            retGroups = response.getEntities();
+        }
+        else
+        {
+            throw new SecurityException(response.getErrorCode(), response.getErrorMessage());
+        }
+        return retGroups;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public List<UserRole> groupRoles( Group group ) throws SecurityException
+    {
+        VUtil.assertNotNull(group, GlobalErrIds.GROUP_NULL, CLS_NM + ".groupRoles");
+        List<UserRole> retRoles;
+        FortRequest request = new FortRequest();
+        request.setContextId(this.contextId);
+        request.setEntity(group);
+        if (this.adminSess != null)
+        {
+            request.setSession(adminSess);
+        }
+        String szRequest = RestUtils.marshal(request);
+        String szResponse = RestUtils.getInstance().post(szRequest, HttpIds.GROUP_ROLE_ASGNED);
+        FortResponse response = RestUtils.unmarshall(szResponse);
+        if (response.getErrorCode() == 0)
+        {
+            retRoles = response.getEntities();
+        }
+        else
+        {
+            throw new SecurityException(response.getErrorCode(), response.getErrorMessage());
+        }
+        return retRoles;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public Group assign( Group group, String member ) throws SecurityException
+    {
+        VUtil.assertNotNull( group, GlobalErrIds.GROUP_NULL, CLS_NM + ".assign" );
+        VUtil.assertNotNull( member, GlobalErrIds.GROUP_MEMBER_NULL, CLS_NM + ".assign" );
+        Group retGroup;
+        FortRequest request = new FortRequest();
+        request.setContextId( this.contextId );
+        request.setEntity( group );
+        request.setValue( member );
+        if ( this.adminSess != null )
+        {
+            request.setSession( adminSess );
+        }
+        String szRequest = RestUtils.marshal( request );
+        String szResponse = RestUtils.getInstance().post( szRequest, HttpIds.GROUP_ASGN );
+        FortResponse response = RestUtils.unmarshall( szResponse );
+        if ( response.getErrorCode() == 0 )
+        {
+            retGroup = ( Group ) response.getEntity();
+        }
+        else
+        {
+            throw new SecurityException( response.getErrorCode(), response.getErrorMessage()
);
+        }
+        return retGroup;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public Group deassign( Group group, String member ) throws SecurityException
+    {
+        VUtil.assertNotNull( group, GlobalErrIds.GROUP_NULL, CLS_NM + ".deassign" );
+        VUtil.assertNotNull( member, GlobalErrIds.GROUP_MEMBER_NULL, CLS_NM + ".deassign"
);
+        Group retGroup;
+        FortRequest request = new FortRequest();
+        request.setContextId( this.contextId );
+        request.setEntity( group );
+        request.setValue( member );
+        if ( this.adminSess != null )
+        {
+            request.setSession( adminSess );
+        }
+        String szRequest = RestUtils.marshal( request );
+        String szResponse = RestUtils.getInstance().post( szRequest, HttpIds.GROUP_DEASGN
);
+        FortResponse response = RestUtils.unmarshall( szResponse );
+        if ( response.getErrorCode() == 0 )
+        {
+            retGroup = ( Group ) response.getEntity();
+        }
+        else
+        {
+            throw new SecurityException( response.getErrorCode(), response.getErrorMessage()
);
+        }
+        return retGroup;
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/5f3ae114/src/main/java/org/apache/directory/fortress/core/rest/HttpIds.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/directory/fortress/core/rest/HttpIds.java b/src/main/java/org/apache/directory/fortress/core/rest/HttpIds.java
index 6f6d356..bdc31f1 100644
--- a/src/main/java/org/apache/directory/fortress/core/rest/HttpIds.java
+++ b/src/main/java/org/apache/directory/fortress/core/rest/HttpIds.java
@@ -171,6 +171,6 @@ public class HttpIds
     public static final String GROUP_DELETE = "groupDelete";
     public static final String GROUP_ROLE_ASGNED = "roleGroupAsigned";
     public static final String GROUP_ASGNED = "groupAsigned";
-    public static final String GROUP_ROLE_ASGN = "groupRoleAsgn";
-    public static final String GROUP_ROLE_DEASGN = "groupRoleDeasgn";
+    public static final String GROUP_ASGN = "groupAsgn";
+    public static final String GROUP_DEASGN = "groupDeasgn";
 }
\ No newline at end of file


Mime
View raw message