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 2015/03/12 22:56:39 UTC

directory-fortress-commander git commit: FC-79 - throw checked excep

Repository: directory-fortress-commander
Updated Branches:
  refs/heads/master 7e1657c31 -> fdc77617d


FC-79 - throw checked excep


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

Branch: refs/heads/master
Commit: fdc77617da6d39a5565322789ef3582a04cb3c62
Parents: 7e1657c
Author: Shawn McKinney <sm...@apache.org>
Authored: Thu Mar 12 16:56:28 2015 -0500
Committer: Shawn McKinney <sm...@apache.org>
Committed: Thu Mar 12 16:56:28 2015 -0500

----------------------------------------------------------------------
 .../apache/directory/fortress/web/SecUtils.java | 24 ++++++++++++++++----
 1 file changed, 20 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-fortress-commander/blob/fdc77617/src/main/java/org/apache/directory/fortress/web/SecUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/directory/fortress/web/SecUtils.java b/src/main/java/org/apache/directory/fortress/web/SecUtils.java
index ff70914..3553a64 100644
--- a/src/main/java/org/apache/directory/fortress/web/SecUtils.java
+++ b/src/main/java/org/apache/directory/fortress/web/SecUtils.java
@@ -24,7 +24,8 @@ import org.apache.directory.fortress.core.SecurityException;
 import org.apache.directory.fortress.core.cfg.Config;
 import org.apache.directory.fortress.core.rbac.UserRole;
 import org.apache.directory.fortress.core.rbac.Warning;
-import org.apache.directory.fortress.realm.J2eePolicyMgr;
+import org.apache.directory.fortress.realm.*;
+import org.apache.directory.fortress.realm.GlobalIds;
 import org.apache.log4j.Logger;
 import org.apache.wicket.Component;
 import org.apache.directory.fortress.core.rbac.Permission;
@@ -205,12 +206,18 @@ public class SecUtils
      * @param accessMgr used to call fortress api for role op
      * @param szPrincipal contains the instance of fortress session deserialized.
      */
-    public static void initializeSession(Component component, J2eePolicyMgr j2eePolicyMgr, AccessMgr accessMgr, String szPrincipal )
+    public static void initializeSession(Component component, J2eePolicyMgr j2eePolicyMgr, AccessMgr accessMgr, String szPrincipal ) throws SecurityException
     {
         Session realmSession = null;
+
+        if(j2eePolicyMgr == null || accessMgr == null)
+        {
+            throw new SecurityException( GlobalIds.SESSION_INITIALIZATION_FAILED, "initializeSession failed - verify the injection of fortress spring beans into your application" );
+        }
         try
         {
-            realmSession = j2eePolicyMgr.deserialize( szPrincipal );
+            if(VUtil.isNotNullOrEmpty( szPrincipal ))
+                realmSession = j2eePolicyMgr.deserialize( szPrincipal );
         }
         catch( SecurityException se )
         {
@@ -338,7 +345,16 @@ public class SecUtils
         return isSuccessful;
     }
 
-    public static void enableFortress( Component component, HttpServletRequest servletReq, J2eePolicyMgr j2eePolicyMgr, AccessMgr accessMgr )
+    /**
+     * Enables fortress session on behalf of a java.security.Principal retrieved from the container.
+     *
+     * @param component
+     * @param servletReq
+     * @param j2eePolicyMgr
+     * @param accessMgr
+     * @throws SecurityException
+     */
+    public static void enableFortress( Component component, HttpServletRequest servletReq, J2eePolicyMgr j2eePolicyMgr, AccessMgr accessMgr ) throws SecurityException
     {
         // Get the principal from the container:
         Principal principal = servletReq.getUserPrincipal();