[jboss-cvs] JBossAS SVN: r59500 - projects/security/security-jboss-sx/trunk/src/main/org/jboss/security/plugins.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Jan 10 22:38:57 EST 2007


Author: anil.saldhana at jboss.com
Date: 2007-01-10 22:38:55 -0500 (Wed, 10 Jan 2007)
New Revision: 59500

Added:
   projects/security/security-jboss-sx/trunk/src/main/org/jboss/security/plugins/JBossSecurityContextUtil.java
   projects/security/security-jboss-sx/trunk/src/main/org/jboss/security/plugins/SecurityContextAssociation.java
   projects/security/security-jboss-sx/trunk/src/main/org/jboss/security/plugins/SecurityContextFactory.java
Modified:
   projects/security/security-jboss-sx/trunk/src/main/org/jboss/security/plugins/JBossAuthorizationManager.java
   projects/security/security-jboss-sx/trunk/src/main/org/jboss/security/plugins/JBossSecurityContext.java
   projects/security/security-jboss-sx/trunk/src/main/org/jboss/security/plugins/SubjectActions.java
Log:
SecurityContext related temp refactor

Modified: projects/security/security-jboss-sx/trunk/src/main/org/jboss/security/plugins/JBossAuthorizationManager.java
===================================================================
--- projects/security/security-jboss-sx/trunk/src/main/org/jboss/security/plugins/JBossAuthorizationManager.java	2007-01-11 03:37:03 UTC (rev 59499)
+++ projects/security/security-jboss-sx/trunk/src/main/org/jboss/security/plugins/JBossAuthorizationManager.java	2007-01-11 03:38:55 UTC (rev 59500)
@@ -343,7 +343,7 @@
       } 
 
       //Send the final processed (mapping applied) roles
-      return (Group)sc.getData().get(JBossSecurityContext.ROLES);
+      return userRoles;
    } 
    
    /**

Modified: projects/security/security-jboss-sx/trunk/src/main/org/jboss/security/plugins/JBossSecurityContext.java
===================================================================
--- projects/security/security-jboss-sx/trunk/src/main/org/jboss/security/plugins/JBossSecurityContext.java	2007-01-11 03:37:03 UTC (rev 59499)
+++ projects/security/security-jboss-sx/trunk/src/main/org/jboss/security/plugins/JBossSecurityContext.java	2007-01-11 03:38:55 UTC (rev 59500)
@@ -35,7 +35,8 @@
  *  @since  Aug 30, 2006
  */
 public class JBossSecurityContext implements SecurityContext
-{ 
+{  
+   private static final long serialVersionUID = 1L;
    protected static final Logger log = Logger.getLogger(JBossSecurityContext.class); 
    protected boolean trace = log.isTraceEnabled();  
    

Added: projects/security/security-jboss-sx/trunk/src/main/org/jboss/security/plugins/JBossSecurityContextUtil.java
===================================================================
--- projects/security/security-jboss-sx/trunk/src/main/org/jboss/security/plugins/JBossSecurityContextUtil.java	2007-01-11 03:37:03 UTC (rev 59499)
+++ projects/security/security-jboss-sx/trunk/src/main/org/jboss/security/plugins/JBossSecurityContextUtil.java	2007-01-11 03:38:55 UTC (rev 59500)
@@ -0,0 +1,76 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.security.plugins;
+
+import java.security.Principal;
+import java.security.acl.Group;
+
+import org.jboss.security.RunAsIdentity; 
+import org.jboss.security.SecurityContext;
+import org.jboss.security.SecurityContextUtil;
+import org.jboss.security.SubjectInfo;
+
+import static org.jboss.security.SecurityConstants.*;
+
+//$Id$
+
+/**
+ *  Utility class for JBossSecurityContext implementation
+ *  @author <a href="mailto:Anil.Saldhana at jboss.org">Anil Saldhana</a>
+ *  @since  Jan 5, 2007 
+ *  @version $Revision$
+ */
+public class JBossSecurityContextUtil extends SecurityContextUtil
+{ 
+   @Override
+   public <T> T get(SecurityContext sc, String key)
+   { 
+      return (T) sc.getData().get(key);
+   }
+
+   @Override
+   public String getUserName(SubjectInfo subjectInfo)
+   { 
+      Principal p = getUserPrincipal(subjectInfo);
+      return p != null ? p.getName() : null;
+   }
+
+   @Override
+   public Principal getUserPrincipal(SubjectInfo subjectInfo)
+   {  
+      return subjectInfo.getAuthenticationPrincipal();
+   }
+
+   @Override
+   public <T> void set(SecurityContext sc, String key, T obj)
+   { 
+      if(sc instanceof JBossSecurityContext  == false)
+         throw new IllegalArgumentException("Not JBoss security context:"+sc);
+      if(key == null)
+         throw new IllegalArgumentException("Key is null");
+      if(RUNAS_IDENTITY_IDENTIFIER.equals(key) && obj instanceof RunAsIdentity == false)
+            throw new IllegalArgumentException("Not RunAsIdentity:"+obj); 
+      if(ROLES_IDENTIFIER.equals(key) &&  obj instanceof Group == false)
+            throw new IllegalArgumentException("Not Group:"+obj);  
+      sc.getData().put(key, obj);
+   } 
+}

Added: projects/security/security-jboss-sx/trunk/src/main/org/jboss/security/plugins/SecurityContextAssociation.java
===================================================================
--- projects/security/security-jboss-sx/trunk/src/main/org/jboss/security/plugins/SecurityContextAssociation.java	2007-01-11 03:37:03 UTC (rev 59499)
+++ projects/security/security-jboss-sx/trunk/src/main/org/jboss/security/plugins/SecurityContextAssociation.java	2007-01-11 03:38:55 UTC (rev 59500)
@@ -0,0 +1,83 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.security.plugins;
+
+import org.jboss.security.SecurityConstants;
+import org.jboss.security.SecurityContext;
+
+//$Id$
+
+/**
+ *  Security Context association in a threadlocal
+ *  @author <a href="mailto:Anil.Saldhana at jboss.org">Anil Saldhana</a>
+ *  @since  Dec 27, 2006 
+ *  @version $Revision$
+ */
+public class SecurityContextAssociation
+{
+   private static ThreadLocal<SecurityContext> securityContextLocal = new ThreadLocal<SecurityContext>();
+   
+   public static void setSecurityContext(SecurityContext sc)
+   {
+      securityContextLocal.set(sc);
+   }
+   
+   public static SecurityContext getSecurityContext()
+   {
+      return securityContextLocal.get();
+   }
+   
+   /**
+    * Push the security context such that the previous sc on the threadlocal
+    * becomes the parent of this sc
+    * @param sc
+    */
+   public static void push(SecurityContext sc)
+   {
+      if(sc == null)
+         throw new IllegalArgumentException("sc is null");
+      SecurityContext ctx = securityContextLocal.get();
+      if(ctx != null)
+      {
+         sc.getData().put(SecurityConstants.SECURITY_CONTEXT,ctx);
+      } 
+      securityContextLocal.set(sc);
+   }
+   
+   /**
+    * Pop the current security context on the threadlocal such that its parent
+    * gets to be the current
+    *
+    */
+   public static void pop()
+   {
+      SecurityContext ctx = securityContextLocal.get();
+      SecurityContext parent = null;
+      if(ctx != null)
+      {
+         parent = (SecurityContext) ctx.getData().get(SecurityConstants.SECURITY_CONTEXT); 
+         //Nullify
+         ctx = null;
+      }
+      securityContextLocal.set(parent);
+   }
+}

Added: projects/security/security-jboss-sx/trunk/src/main/org/jboss/security/plugins/SecurityContextFactory.java
===================================================================
--- projects/security/security-jboss-sx/trunk/src/main/org/jboss/security/plugins/SecurityContextFactory.java	2007-01-11 03:37:03 UTC (rev 59499)
+++ projects/security/security-jboss-sx/trunk/src/main/org/jboss/security/plugins/SecurityContextFactory.java	2007-01-11 03:38:55 UTC (rev 59500)
@@ -0,0 +1,96 @@
+/*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt in the distribution for a
+  * full listing of individual contributors.
+  *
+  * This is free software; you can redistribute it and/or modify it
+  * under the terms of the GNU Lesser General Public License as
+  * published by the Free Software Foundation; either version 2.1 of
+  * the License, or (at your option) any later version.
+  *
+  * This software is distributed in the hope that it will be useful,
+  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  * Lesser General Public License for more details.
+  *
+  * You should have received a copy of the GNU Lesser General Public
+  * License along with this software; if not, write to the Free
+  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+  */
+package org.jboss.security.plugins;
+
+import java.security.Principal;
+
+import javax.security.auth.Subject;
+
+import org.jboss.security.SecurityContext;
+import org.jboss.security.SecurityContextUtil;
+import org.jboss.security.SubjectInfo;
+
+//$Id$
+
+/**
+ *  Factory class to create Security Context instances
+ *  @author <a href="mailto:Anil.Saldhana at jboss.org">Anil Saldhana</a>
+ *  @since  Dec 28, 2006 
+ *  @version $Revision$
+ */
+public class SecurityContextFactory
+{ 
+   /**
+    * Create a security context 
+    * @param securityDomain Security Domain driving the context
+    * @return
+    */
+   public static SecurityContext createSecurityContext(String securityDomain)
+   {
+      JBossSecurityContext jsc = new JBossSecurityContext(securityDomain);
+      return jsc; 
+   }
+   
+   /**
+    * Create a security context
+    * @param p Principal
+    * @param cred Credential
+    * @param s Subject
+    * @param securityDomain SecurityDomain
+    * @return
+    * @see #createSecurityContext(String)
+    */
+   public static SecurityContext createSecurityContext(Principal p, 
+         Object cred,Subject s, String securityDomain)
+   {
+      JBossSecurityContext jsc = new JBossSecurityContext(securityDomain);
+      jsc.setSubjectInfo(createSubjectInfo(p,cred,s));
+      return jsc;
+   }
+   
+   /**
+    * Create a Subject Info
+    * @param p principal
+    * @param cred credential
+    * @param s Subject
+    * @return
+    * @see #createSecurityContext(Principal, Object, Subject, String)
+    */
+   public static SubjectInfo createSubjectInfo(Principal p, 
+         Object cred,Subject s)
+   {
+      SubjectInfo si = new SubjectInfo();
+      si.setAuthenticatedSubject(s);
+      si.setAuthenticationPrincipal(p);
+      si.setAuthenticationCredential(cred);
+      return si;
+   }
+   
+   /**
+    * Return an instance of the SecurityContextUtil
+    * @return
+    */
+   public static SecurityContextUtil createSecurityContextUtil()
+   {
+      return new JBossSecurityContextUtil();
+   }
+}

Modified: projects/security/security-jboss-sx/trunk/src/main/org/jboss/security/plugins/SubjectActions.java
===================================================================
--- projects/security/security-jboss-sx/trunk/src/main/org/jboss/security/plugins/SubjectActions.java	2007-01-11 03:37:03 UTC (rev 59499)
+++ projects/security/security-jboss-sx/trunk/src/main/org/jboss/security/plugins/SubjectActions.java	2007-01-11 03:38:55 UTC (rev 59500)
@@ -300,14 +300,15 @@
       public Object run()
       {
          String sc = SecurityConstants.SECURITY_CONTEXT;
-         HashMap map = (HashMap)SecurityAssociation.getContextInfo(sc);
+         return SecurityContextAssociation.getSecurityContext();
+         /*HashMap map = (HashMap)SecurityAssociation.getContextInfo(sc);
          if(map == null)
          {
             map = new HashMap();
             SecurityAssociation.setContextInfo(sc, map);
          }
          SecurityAssociation.setContextInfo(sc, map);  
-         return map.get(this.securityDomain); 
+         return map.get(this.securityDomain);*/ 
       }
    }
    




More information about the jboss-cvs-commits mailing list