[jboss-svn-commits] JBL Code SVN: r25013 - labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/services/security.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Fri Jan 30 07:02:35 EST 2009


Author: kevin.conner at jboss.com
Date: 2009-01-30 07:02:35 -0500 (Fri, 30 Jan 2009)
New Revision: 25013

Modified:
   labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/services/security/SecurityContext.java
Log:
Add constructors back into SecurityContext: JBESB-2325

Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/services/security/SecurityContext.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/services/security/SecurityContext.java	2009-01-30 11:37:58 UTC (rev 25012)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/services/security/SecurityContext.java	2009-01-30 12:02:35 UTC (rev 25013)
@@ -32,6 +32,7 @@
 import javax.crypto.SealedObject;
 import javax.security.auth.Subject;
 
+import org.apache.log4j.Logger;
 import org.jboss.internal.soa.esb.assertion.AssertArgument;
 import org.jboss.internal.soa.esb.services.security.PrivateCryptoUtil;
 import org.jboss.soa.esb.common.Configuration;
@@ -61,8 +62,17 @@
 	private static final long serialVersionUID = 1L;
 
 	private static transient ThreadLocal<SealedObject> securityContextTl = new ThreadLocal<SealedObject>();
+	
+	/**
+	 * Logger instance.
+	 */
+	private static final Logger LOGGER = Logger.getLogger(SecurityConfig.class) ;
+	/**
+	 * default timeout value if not set.
+	 */
+	private static final long DEFAULT_TIMEOUT_VALUE = 30000 ;
 
-	private static long globalConfiguredTimeout;
+	private static final long globalConfiguredTimeout = getGlobalConfigurationTimeout() ;
 
 	/**
 	 * The Subject associated with this context.
@@ -72,7 +82,7 @@
     /**
      * Timeout (ms) for the security context. Defaults to 5 mins.
      */
-    private long timeout = 30000;
+    private final long timeout ;
 
     /**
      * Time of creation.
@@ -80,9 +90,26 @@
     private long timeOfCreation = System.currentTimeMillis();
 
 	/**
+	 * Creates a SecurityContext with a default Subject.
+	 */
+	public SecurityContext()
+	{
+		this(new Subject()) ;
+	}
+	
+	/**
 	 * Creates a SecurityContext associating the passed in Subject with it.
 	 *
 	 * @param subject The Subject that is to be associated with this security context.
+	 */
+	public SecurityContext(final Subject subject)
+	{
+		this(subject, globalConfiguredTimeout) ;
+	}
+	/**
+	 * Creates a SecurityContext associating the passed in Subject with it.
+	 *
+	 * @param subject The Subject that is to be associated with this security context.
 	 * @param timeout A timeout which specifies how long this Security Context is valid for. Must be a positiv value.
 	 */
 	public SecurityContext(final Subject subject, final long timeout)
@@ -230,15 +257,11 @@
 
     /**
      * Get the globally configured security context timeout.
-     * @return
+     * @return the configuration context timeout
      * @throws SecurityServiceException
      */
     public static long getConfigurationTimeout() throws SecurityServiceException
     {
-        if (globalConfiguredTimeout == 0l)
-        {
-            globalConfiguredTimeout = getGlobalConfigurationTimeout();
-        }
         return globalConfiguredTimeout;
     }
 
@@ -252,12 +275,16 @@
         return SecurityContext.securityContextTl.get();
     }
 
-    private static long getGlobalConfigurationTimeout() throws SecurityServiceException
+    private static long getGlobalConfigurationTimeout()
     {
         final String timeoutStr = Configuration.getSecurityServiceContextTimeout();
         if (timeoutStr == null)
         {
-            throw new SecurityServiceException("No timeout was configured for the security context. Please set the value of '" + Environment.SECURITY_SERVICE_CONTEXT_TIMEOUT + "' to the timeout you desire");
+            if (LOGGER.isDebugEnabled())
+            {
+                LOGGER.debug("No timeout was configured for the security context, using the default value. Please set the value of '" + Environment.SECURITY_SERVICE_CONTEXT_TIMEOUT + "' to the timeout you desire");
+            }
+            return DEFAULT_TIMEOUT_VALUE ;
         }
         else
         {
@@ -267,7 +294,8 @@
            }
            catch(final NumberFormatException e)
            {
-                throw new SecurityServiceException("The value of '" + Environment.SECURITY_SERVICE_CONTEXT_TIMEOUT + "' must be specified as a long");
+               LOGGER.warn("The value of '" + Environment.SECURITY_SERVICE_CONTEXT_TIMEOUT + "' is invalid, using default value") ;
+               return DEFAULT_TIMEOUT_VALUE ;
            }
         }
     }




More information about the jboss-svn-commits mailing list