directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smckin...@apache.org
Subject [14/23] directory-fortress-core git commit: FC-54 - Benchmark activities - add accessmgr console
Date Tue, 27 Jan 2015 12:54:41 GMT
FC-54 - Benchmark activities - add accessmgr console


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

Branch: refs/heads/master
Commit: 7cc98592fe12ade315ae55ebf00a78fb5f27bcc4
Parents: 64bfbe6
Author: Shawn McKinney <smckinney@apache.org>
Authored: Mon Jan 5 14:12:41 2015 -0600
Committer: Shawn McKinney <smckinney@apache.org>
Committed: Mon Jan 5 14:12:41 2015 -0600

----------------------------------------------------------------------
 .../fortress/core/AccelMgrConsole.java          | 212 +++++++++++++++++++
 .../fortress/core/ProcessMenuCommand.java       |  75 +++++++
 2 files changed, 287 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/7cc98592/src/test/java/org/apache/directory/fortress/core/AccelMgrConsole.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/directory/fortress/core/AccelMgrConsole.java b/src/test/java/org/apache/directory/fortress/core/AccelMgrConsole.java
new file mode 100644
index 0000000..d1e79b9
--- /dev/null
+++ b/src/test/java/org/apache/directory/fortress/core/AccelMgrConsole.java
@@ -0,0 +1,212 @@
+/*
+ *   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;
+
+import org.apache.directory.fortress.core.rbac.TestUtils;
+import org.apache.directory.fortress.core.rbac.UserAdminRole;
+import org.apache.directory.fortress.core.rbac.Permission;
+import org.apache.directory.fortress.core.rbac.Session;
+import org.apache.directory.fortress.core.rbac.User;
+import org.apache.directory.fortress.core.rbac.UserRole;
+
+import java.util.Enumeration;
+import java.util.List;
+
+import org.apache.directory.fortress.core.util.attr.VUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * * Test class for driving Fortress RBAC runtime policy APIs within a console.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+class AccelMgrConsole
+{
+    private AccelMgr am = null;
+    private Session session = null;
+    private static final String CLS_NM = AccelMgrConsole.class.getName();
+    private static final Logger LOG = LoggerFactory.getLogger( CLS_NM );
+
+    /**
+     * put your documentation comment here
+     */
+    public AccelMgrConsole()
+    {
+        try
+        {
+            am = AccelMgrFactory.createInstance( TestUtils.getContext() );
+        }
+        catch ( org.apache.directory.fortress.core.SecurityException e)
+        {
+            LOG.error("constructor caught SecurityException  rc=" + e.getErrorId() + ", msg="
+ e.getMessage(), e);
+        }
+    }
+
+
+    void createSession()
+    {
+        try
+        {
+            ReaderUtil.clearScreen();
+            System.out.println("Enter userId:");
+            String userId = ReaderUtil.readLn();
+            System.out.println("Enter password:");
+            String password = ReaderUtil.readLn();
+            session = am.createSession(new User(userId, password.toCharArray()), false);
+            System.out.println("Session created successfully for userId [" + userId + "]");
+            System.out.println("session [" + session + "]");
+            System.out.println("ENTER to continue");
+        }
+        catch (SecurityException e)
+        {
+            LOG.error("createSession caught SecurityException rc=" + e.getErrorId() + ",
msg=" + e.getMessage(), e);
+        }
+        ReaderUtil.readChar();
+    }
+
+    /**
+     *
+     */
+    void checkAccess()
+    {
+        //Session session = null;
+        try
+        {
+            VUtil.assertNotNull(session, GlobalErrIds.USER_SESS_NULL, "AccelMgrConsole.checkAccess");
+            ReaderUtil.clearScreen();
+            Permission perm = new Permission();
+            System.out.println("Enter object name:");
+            perm.setObjName( ReaderUtil.readLn() );
+            System.out.println("Enter operation name:");
+            perm.setOpName( ReaderUtil.readLn() );
+            System.out.println("Enter object id (or NULL to skip):");
+            String val = ReaderUtil.readLn();
+            if ( val != null && val.length() > 0 )
+            {
+                perm.setObjId( val );
+            }
+
+            boolean result = am.checkAccess( session, perm );
+            System.out.println("CheckAccess return [" + result + "] for user [" + session.getUserId()
+ "], objName [" + perm.getObjName() + "], operationName [" + perm.getOpName() + "]" +
+                ", objId [" + perm.getObjId() + "]");
+            System.out.println("ENTER to continue");
+        }
+        catch (SecurityException e)
+        {
+            LOG.error("checkAccess caught SecurityException rc=" + e.getErrorId() + ", msg="
+ e.getMessage(), e);
+        }
+        ReaderUtil.readChar();
+    }
+
+    void sessionRoles()
+    {
+        try
+        {
+            VUtil.assertNotNull(session, GlobalErrIds.USER_SESS_NULL, "AccelMgrConsole.sessionRoles");
+            ReaderUtil.clearScreen();
+            List<UserRole> roles = am.sessionRoles( session );
+            //System.out.println("    USER [" + session.getUserId() + "]:");
+            if (roles != null)
+            {
+                for (int i = 0; i < roles.size(); i++)
+                {
+                    UserRole ur = roles.get(i);
+                    System.out.println("    USER ROLE[" + i + "]:");
+                    System.out.println("        role name [" + ur.getName() + "]");
+                    System.out.println("        begin time [" + ur.getBeginTime() + "]");
+                    System.out.println("        end time [" + ur.getEndTime() + "]");
+                    System.out.println("        begin date [" + ur.getBeginDate() + "]");
+                    System.out.println("        end date [" + ur.getEndDate() + "]");
+                    System.out.println("        begin lock [" + ur.getBeginLockDate() + "]");
+                    System.out.println("        end lock [" + ur.getEndLockDate() + "]");
+                    System.out.println("        day mask [" + ur.getDayMask() + "]");
+                    System.out.println("        time out [" + ur.getTimeout() + "]");
+                }
+            }
+
+            System.out.println("ENTER to continue");
+        }
+        catch (SecurityException e)
+        {
+            LOG.error("sessionRoles caught SecurityException=" + e, e);
+        }
+        ReaderUtil.readChar();
+    }
+
+
+    void addActiveRole()
+    {
+        try
+        {
+            VUtil.assertNotNull(session, GlobalErrIds.USER_SESS_NULL, "AccelMgrConsole.addActiveRole");
+            ReaderUtil.clearScreen();
+            System.out.println("Enter role name");
+            String role = ReaderUtil.readLn();
+            am.addActiveRole(session, new UserRole(role));
+            System.out.println("addActiveRole successful");
+            System.out.println("ENTER to continue");
+        }
+        catch (SecurityException e)
+        {
+            LOG.error("addActiveRole caught SecurityException rc=" + e.getErrorId() + ",
msg=" + e.getMessage(), e);
+        }
+        ReaderUtil.readChar();
+    }
+
+    void dropActiveRole()
+    {
+        try
+        {
+            VUtil.assertNotNull(session, GlobalErrIds.USER_SESS_NULL, "AccelMgrConsole.dropActiveRole");
+            ReaderUtil.clearScreen();
+            System.out.println("Enter role name");
+            String role = ReaderUtil.readLn();
+            am.dropActiveRole( session, new UserRole( role ) );
+            System.out.println("dropActiveRole successful");
+            System.out.println("ENTER to continue");
+        }
+        catch (SecurityException e)
+        {
+            LOG.error("dropActiveRole caught SecurityException rc=" + e.getErrorId() + ",
msg=" + e.getMessage(), e);
+        }
+        ReaderUtil.readChar();
+    }
+
+    void deleteSession()
+    {
+        try
+        {
+            VUtil.assertNotNull(session, GlobalErrIds.USER_SESS_NULL, "AccelMgrConsole.deleteSession");
+            am.deleteSession( session );
+            System.out.println("deleteSession successful");
+            System.out.println("ENTER to continue");
+        }
+        catch (SecurityException e)
+        {
+            LOG.error("deleteSession caught SecurityException rc=" + e.getErrorId() + ",
msg=" + e.getMessage(), e);
+        }
+        ReaderUtil.readChar();
+    }
+
+}
+
+

http://git-wip-us.apache.org/repos/asf/directory-fortress-core/blob/7cc98592/src/test/java/org/apache/directory/fortress/core/ProcessMenuCommand.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/directory/fortress/core/ProcessMenuCommand.java b/src/test/java/org/apache/directory/fortress/core/ProcessMenuCommand.java
index 9506d57..3547d9a 100755
--- a/src/test/java/org/apache/directory/fortress/core/ProcessMenuCommand.java
+++ b/src/test/java/org/apache/directory/fortress/core/ProcessMenuCommand.java
@@ -36,6 +36,7 @@ class ProcessMenuCommand
     final private AdminMgrConsole adminConsole = new AdminMgrConsole();
     final private ReviewMgrConsole reviewConsole = new ReviewMgrConsole();
     final private AccessMgrConsole accessConsole = new AccessMgrConsole();
+    final private AccelMgrConsole accelConsole = new AccelMgrConsole();
     final private PolicyMgrConsole policyConsole = new PolicyMgrConsole();
     final private AuditMgrConsole auditConsole = new AuditMgrConsole();
     final private DelegatedAdminMgrConsole delAdminConsole = new DelegatedAdminMgrConsole();
@@ -63,6 +64,7 @@ class ProcessMenuCommand
         System.out.println( "9. CONFIG MANAGER FUNCTIONS" );
         System.out.println( "A. ENCRYPTION MANAGER FUNCTIONS" );
         System.out.println( "B. GROUP MANAGER FUNCTIONS" );
+        System.out.println( "C. ACCEL MANAGER FUNCTIONS" );
         System.out.println( "Enter q or Q to quit" );
     }
 
@@ -118,6 +120,10 @@ class ProcessMenuCommand
                     case 'B':
                         processGroupManagerFunction();
                         break;
+                    case 'c':
+                    case 'C':
+                        processAccelFunction();
+                        break;
                     case 'q':
                     case 'Q':
                         done = true;
@@ -753,6 +759,75 @@ class ProcessMenuCommand
     /**
      *
      */
+    private void showAccelFunctionMenu()
+    {
+        ReaderUtil.clearScreen();
+        System.out.println( "CHOOSE ACCEL MANAGER FUNCTION" );
+        System.out.println( "1. Create Session" );
+        System.out.println( "2. Check Access - RBAC" );
+        System.out.println( "3. Session Roles" );
+        System.out.println( "4. Add Active Role to Session" );
+        System.out.println( "5. Drop Active Role from Session" );
+        System.out.println( "6. Delete Session" );
+        System.out.println( "Enter q or Q to return to previous menu" );
+    }
+
+
+    /**
+     *
+     */
+    void processAccelFunction()
+    {
+        BufferedReader br = new BufferedReader( new InputStreamReader( System.in ) );
+        boolean done = false;
+        int input;
+
+        try
+        {
+            while ( !done )
+            {
+                showAccelFunctionMenu();
+                input = br.read();
+                switch ( input )
+                {
+                    case '1':
+                        accelConsole.createSession();
+                        break;
+                    case '2':
+                        accelConsole.checkAccess();
+                        break;
+                    case '3':
+                        accelConsole.sessionRoles();
+                        break;
+                    case '4':
+                        accelConsole.addActiveRole();
+                        break;
+                    case '5':
+                        accelConsole.dropActiveRole();
+                        break;
+                    case '6':
+                        accelConsole.deleteSession();
+                        break;
+                    case 'q':
+                    case 'Q':
+                        done = true;
+                        break;
+                    default:
+                        break;
+                }
+            }
+        }
+        catch ( Exception e )
+        {
+            LOG.error( "Exception caught in processAccelFunction = " + e );
+            e.printStackTrace();
+        }
+    }
+
+
+    /**
+     *
+     */
     void processPasswordPolicyFunction()
     {
         BufferedReader br = new BufferedReader( new InputStreamReader( System.in ) );


Mime
View raw message