directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From smckin...@apache.org
Subject directory-fortress-realm git commit: FC-78 - add deserializer to realm policymgr
Date Tue, 10 Mar 2015 07:52:42 GMT
Repository: directory-fortress-realm
Updated Branches:
  refs/heads/master e8e2d1cbf -> 074a7272c


FC-78 - add deserializer to realm policymgr


Project: http://git-wip-us.apache.org/repos/asf/directory-fortress-realm/repo
Commit: http://git-wip-us.apache.org/repos/asf/directory-fortress-realm/commit/074a7272
Tree: http://git-wip-us.apache.org/repos/asf/directory-fortress-realm/tree/074a7272
Diff: http://git-wip-us.apache.org/repos/asf/directory-fortress-realm/diff/074a7272

Branch: refs/heads/master
Commit: 074a7272c0e753d5f8d78c726494ab3a8c5da14e
Parents: e8e2d1c
Author: Shawn McKinney <smckinney@apache.org>
Authored: Tue Mar 10 02:52:29 2015 -0500
Committer: Shawn McKinney <smckinney@apache.org>
Committed: Tue Mar 10 02:52:29 2015 -0500

----------------------------------------------------------------------
 .../directory/fortress/realm/J2eePolicyMgr.java |  9 +++++
 .../fortress/realm/J2eePolicyMgrImpl.java       | 41 +++++++++++++++++++-
 2 files changed, 49 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-fortress-realm/blob/074a7272/impl/src/main/java/org/apache/directory/fortress/realm/J2eePolicyMgr.java
----------------------------------------------------------------------
diff --git a/impl/src/main/java/org/apache/directory/fortress/realm/J2eePolicyMgr.java b/impl/src/main/java/org/apache/directory/fortress/realm/J2eePolicyMgr.java
index 70094aa..a3db6a0 100644
--- a/impl/src/main/java/org/apache/directory/fortress/realm/J2eePolicyMgr.java
+++ b/impl/src/main/java/org/apache/directory/fortress/realm/J2eePolicyMgr.java
@@ -307,5 +307,14 @@ public interface J2eePolicyMgr
      * @throws SecurityException If user not found or system error occurs.
      */
     public List<String> authorizedRoles( String userId ) throws SecurityException;
+
+
+    /**
+     * This utility method can deserialize java.security.Principal to Fortress RBAC session
object.
+     *
+     * @param str contains String to deserialize
+     * @return deserialization target object
+     */
+    public Session deserialize( String str ) throws SecurityException;
 }
 

http://git-wip-us.apache.org/repos/asf/directory-fortress-realm/blob/074a7272/impl/src/main/java/org/apache/directory/fortress/realm/J2eePolicyMgrImpl.java
----------------------------------------------------------------------
diff --git a/impl/src/main/java/org/apache/directory/fortress/realm/J2eePolicyMgrImpl.java
b/impl/src/main/java/org/apache/directory/fortress/realm/J2eePolicyMgrImpl.java
index dade14d..e429960 100644
--- a/impl/src/main/java/org/apache/directory/fortress/realm/J2eePolicyMgrImpl.java
+++ b/impl/src/main/java/org/apache/directory/fortress/realm/J2eePolicyMgrImpl.java
@@ -19,8 +19,10 @@
  */
 package org.apache.directory.fortress.realm;
 
+import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
+import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -57,7 +59,10 @@ public class J2eePolicyMgrImpl implements J2eePolicyMgr
     private static AccessMgr accessMgr;
     private static ReviewMgr reviewMgr;
     private static final String SESSION = "session";
-    private static int CONTEXT_SERIALIZATION_FAILED = 102;
+    private static int CONTEXT_SERIALIZATION_FAILED = 201;
+    private static int CONTEXT_DESERIALIZATION_FAILED_IO = 202;
+    private static int CONTEXT_DESERIALIZATION_FAILED_UNSUPPORTED_ENCODING = 203;
+    private static int CONTEXT_DESERIALIZATION_FAILED_CLASS_NOT_FOUND = 204;
 
     static
     {
@@ -559,4 +564,38 @@ public class J2eePolicyMgrImpl implements J2eePolicyMgr
         
         return szRetVal;
     }
+
+
+    /**
+     * This utility method deserializes java.security.Principal to Fortress RBAC session
object.
+     *
+     * @param str contains String to deserialize
+     * @return deserialization target object
+     */
+    public Session deserialize( String str ) throws SecurityException
+    {
+        // deserialize the object
+        try
+        {
+            // This encoding induces a bijection between byte[] and String (unlike UTF-8)
+            byte b[] = str.getBytes("ISO-8859-1");
+            ByteArrayInputStream bi = new ByteArrayInputStream(b);
+            ObjectInputStream si = new ObjectInputStream(bi);
+            return Session.class.cast(si.readObject());
+        }
+        catch (java.io.UnsupportedEncodingException e)
+        {
+            throw new SecurityException( CONTEXT_DESERIALIZATION_FAILED_UNSUPPORTED_ENCODING,
"deserialize caught UnsupportedEncodingException:" + e);
+        }
+        catch (IOException e)
+        {
+            LOG.warn( "deserialize caught IOException:" + e);
+            throw new SecurityException( CONTEXT_DESERIALIZATION_FAILED_IO, "deserialize
caught IOException:" + e);
+        }
+        catch (ClassNotFoundException e)
+        {
+            LOG.warn( "deserialize caught ClassNotFoundException:" + e);
+            throw new SecurityException( CONTEXT_DESERIALIZATION_FAILED_CLASS_NOT_FOUND,
"deserialize caught ClassNotFoundException:" + e);
+        }
+    }
 }


Mime
View raw message