[jboss-svn-commits] JBL Code SVN: r21131 - in labs/jbossesb/workspace/dbevenius/security/product/rosetta: tests/src/org/jboss/soa/esb/services/security and 1 other directory.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Sat Jul 19 05:22:32 EDT 2008


Author: beve
Date: 2008-07-19 05:22:32 -0400 (Sat, 19 Jul 2008)
New Revision: 21131

Added:
   labs/jbossesb/workspace/dbevenius/security/product/rosetta/src/org/jboss/soa/esb/services/security/JaasSecurityService.java
   labs/jbossesb/workspace/dbevenius/security/product/rosetta/tests/src/org/jboss/soa/esb/services/security/JaasSecurityServiceUnitTest.java
Removed:
   labs/jbossesb/workspace/dbevenius/security/product/rosetta/src/org/jboss/soa/esb/services/security/SecurityServiceImpl.java
   labs/jbossesb/workspace/dbevenius/security/product/rosetta/tests/src/org/jboss/soa/esb/services/security/SecurityServiceImplUnitTest.java
Modified:
   labs/jbossesb/workspace/dbevenius/security/product/rosetta/src/org/jboss/soa/esb/services/security/SecurityConfigUtil.java
   labs/jbossesb/workspace/dbevenius/security/product/rosetta/src/org/jboss/soa/esb/services/security/SecurityServiceFactory.java
Log:
Some minor refactoring


Copied: labs/jbossesb/workspace/dbevenius/security/product/rosetta/src/org/jboss/soa/esb/services/security/JaasSecurityService.java (from rev 21122, labs/jbossesb/workspace/dbevenius/security/product/rosetta/src/org/jboss/soa/esb/services/security/SecurityServiceImpl.java)
===================================================================
--- labs/jbossesb/workspace/dbevenius/security/product/rosetta/src/org/jboss/soa/esb/services/security/JaasSecurityService.java	                        (rev 0)
+++ labs/jbossesb/workspace/dbevenius/security/product/rosetta/src/org/jboss/soa/esb/services/security/JaasSecurityService.java	2008-07-19 09:22:32 UTC (rev 21131)
@@ -0,0 +1,102 @@
+/*
+ * JBoss, Home of Professional Open Source Copyright 2008, Red Hat Middleware
+ * LLC, and individual contributors 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.soa.esb.services.security;
+
+import java.net.URL;
+import java.security.Security;
+import javax.security.auth.login.LoginContext;
+import javax.security.auth.login.LoginException;
+import org.apache.log4j.Logger;
+import org.jboss.soa.esb.ConfigurationException;
+import com.sun.security.auth.login.ConfigFile;
+
+/**
+ * Concreate impl of a SecurityService in JBoss ESB
+ * <p/>
+ * 
+ * @author <a href="mailto:dbevenius at redhat.com">Daniel Bevenius</a>
+ * @Since 4.4
+ */
+public class JaasSecurityService implements SecurityService
+{
+	public static final String POLICY_URL_PRIFIX = "login.config.url.";
+	
+	private Logger log = Logger.getLogger(JaasSecurityService.class);
+	
+	/**
+	 * Authenticates a Subject using the information contained in the passed in 
+	 * Security context
+	 * 
+	 * @param context	the security context to be used.
+	 * @throws LoginException	if the authentication fails
+	 */
+	public void authenticate( final SecurityContext context) throws LoginException
+	{
+		log.info( context );
+		System.setProperty("java.security.auth.login.config", context.getConfigInfo().getPolicyConfig().toExternalForm() );
+		LoginContext loginContext = new LoginContext(context.getConfigInfo().getModuleName(), context.getSubject(), null, new ConfigFile());
+		loginContext.login();
+	}
+	
+	public void addPolicy(final URL policyUrl) throws ConfigurationException
+	{
+		if (policyUrl == null)
+		{
+			throw new ConfigurationException("Could not locate the policy file at Url [" + policyUrl + "]");
+		}
+		
+		int urlIndex = 1;
+		boolean policyUrlRegistered = false;
+		String registeredPolicyUrl;
+        while ((registeredPolicyUrl = Security.getProperty(POLICY_URL_PRIFIX + urlIndex)) != null)
+        {
+        	policyUrlRegistered = registeredPolicyUrl.equals(policyUrl.toString());
+        	if (policyUrlRegistered)
+        	{
+        		break;
+        	}
+        	else
+        	{
+        		urlIndex++;
+        	}
+        }
+        
+        if (!policyUrlRegistered)
+        {
+    		log.info("Adding file [ " + policyUrl + "] as [" + POLICY_URL_PRIFIX + urlIndex + "]");
+        	System.setProperty(POLICY_URL_PRIFIX + urlIndex, policyUrl.toString());
+        }
+	}
+
+	@SuppressWarnings("unused")
+	private void dumpSetPolicyUrl()
+	{
+		int urlIndex = 1;
+		String registeredPolicyUrl;
+		log.info("Dump registeredPolicies:");
+	    while ((registeredPolicyUrl = Security.getProperty(POLICY_URL_PRIFIX + urlIndex)) != null)
+	    {
+	    	log.info(POLICY_URL_PRIFIX + urlIndex + "=" + registeredPolicyUrl);
+	    	urlIndex++;
+	    }
+	}
+
+}

Modified: labs/jbossesb/workspace/dbevenius/security/product/rosetta/src/org/jboss/soa/esb/services/security/SecurityConfigUtil.java
===================================================================
--- labs/jbossesb/workspace/dbevenius/security/product/rosetta/src/org/jboss/soa/esb/services/security/SecurityConfigUtil.java	2008-07-19 05:47:40 UTC (rev 21130)
+++ labs/jbossesb/workspace/dbevenius/security/product/rosetta/src/org/jboss/soa/esb/services/security/SecurityConfigUtil.java	2008-07-19 09:22:32 UTC (rev 21131)
@@ -39,7 +39,7 @@
 	{
 		String moduleName = null;
 		String policyFile = null;
-		final String runAs = securityFragment .getAttribute(ListenerTagNames.RUN_AS_TAG);
+		final String runAs = securityFragment.getAttribute(ListenerTagNames.RUN_AS_TAG);
 		final String useCallersIdentity = securityFragment.getAttribute(ListenerTagNames.USE_CALLERS_IDENTIDY_TAG);
 		final ConfigTree[] authElements = securityFragment.getChildren(ListenerTagNames.AUTHENTICATION_TAG);
 		if (authElements.length > 0)
@@ -54,5 +54,4 @@
 		}
 		return SecurityConfigInfo.createSecurityInfo(policyFile, runAs, useCallersIdentity, moduleName);
 	}
-
 }

Modified: labs/jbossesb/workspace/dbevenius/security/product/rosetta/src/org/jboss/soa/esb/services/security/SecurityServiceFactory.java
===================================================================
--- labs/jbossesb/workspace/dbevenius/security/product/rosetta/src/org/jboss/soa/esb/services/security/SecurityServiceFactory.java	2008-07-19 05:47:40 UTC (rev 21130)
+++ labs/jbossesb/workspace/dbevenius/security/product/rosetta/src/org/jboss/soa/esb/services/security/SecurityServiceFactory.java	2008-07-19 09:22:32 UTC (rev 21131)
@@ -22,7 +22,7 @@
 
 public class SecurityServiceFactory 
 {
-	private static SecurityService jaasSecurityService = new SecurityServiceImpl();
+	private static SecurityService jaasSecurityService = new JaasSecurityService();
 	
 	private SecurityServiceFactory() {}
 	

Deleted: labs/jbossesb/workspace/dbevenius/security/product/rosetta/src/org/jboss/soa/esb/services/security/SecurityServiceImpl.java
===================================================================
--- labs/jbossesb/workspace/dbevenius/security/product/rosetta/src/org/jboss/soa/esb/services/security/SecurityServiceImpl.java	2008-07-19 05:47:40 UTC (rev 21130)
+++ labs/jbossesb/workspace/dbevenius/security/product/rosetta/src/org/jboss/soa/esb/services/security/SecurityServiceImpl.java	2008-07-19 09:22:32 UTC (rev 21131)
@@ -1,102 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source Copyright 2008, Red Hat Middleware
- * LLC, and individual contributors 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.soa.esb.services.security;
-
-import java.net.URL;
-import java.security.Security;
-import javax.security.auth.login.LoginContext;
-import javax.security.auth.login.LoginException;
-import org.apache.log4j.Logger;
-import org.jboss.soa.esb.ConfigurationException;
-import com.sun.security.auth.login.ConfigFile;
-
-/**
- * Concreate impl of a SecurityService in JBoss ESB
- * <p/>
- * 
- * @author <a href="mailto:dbevenius at redhat.com">Daniel Bevenius</a>
- * @Since 4.4
- */
-public class SecurityServiceImpl implements SecurityService
-{
-	public static final String POLICY_URL_PRIFIX = "login.config.url.";
-	
-	private Logger log = Logger.getLogger(SecurityServiceImpl.class);
-	
-	/**
-	 * Authenticates a Subject using the information contained in the passed in 
-	 * Security context
-	 * 
-	 * @param context	the security context to be used.
-	 * @throws LoginException	if the authentication fails
-	 */
-	public void authenticate( final SecurityContext context) throws LoginException
-	{
-		log.info( context );
-		System.setProperty("java.security.auth.login.config", context.getConfigInfo().getPolicyConfig().toExternalForm() );
-		LoginContext loginContext = new LoginContext(context.getConfigInfo().getModuleName(), context.getSubject(), null, new ConfigFile());
-		loginContext.login();
-	}
-	
-	public void addPolicy(final URL policyUrl) throws ConfigurationException
-	{
-		if (policyUrl == null)
-		{
-			throw new ConfigurationException("Could not locate the policy file at Url [" + policyUrl + "]");
-		}
-		
-		int urlIndex = 1;
-		boolean policyUrlRegistered = false;
-		String registeredPolicyUrl;
-        while ((registeredPolicyUrl = Security.getProperty(POLICY_URL_PRIFIX + urlIndex)) != null)
-        {
-        	policyUrlRegistered = registeredPolicyUrl.equals(policyUrl.toString());
-        	if (policyUrlRegistered)
-        	{
-        		break;
-        	}
-        	else
-        	{
-        		urlIndex++;
-        	}
-        }
-        
-        if (!policyUrlRegistered)
-        {
-    		log.info("Adding file [ " + policyUrl + "] as [" + POLICY_URL_PRIFIX + urlIndex + "]");
-        	System.setProperty(POLICY_URL_PRIFIX + urlIndex, policyUrl.toString());
-        }
-	}
-
-	@SuppressWarnings("unused")
-	private void dumpSetPolicyUrl()
-	{
-		int urlIndex = 1;
-		String registeredPolicyUrl;
-		log.info("Dump registeredPolicies:");
-	    while ((registeredPolicyUrl = Security.getProperty(POLICY_URL_PRIFIX + urlIndex)) != null)
-	    {
-	    	log.info(POLICY_URL_PRIFIX + urlIndex + "=" + registeredPolicyUrl);
-	    	urlIndex++;
-	    }
-	}
-
-}

Copied: labs/jbossesb/workspace/dbevenius/security/product/rosetta/tests/src/org/jboss/soa/esb/services/security/JaasSecurityServiceUnitTest.java (from rev 21116, labs/jbossesb/workspace/dbevenius/security/product/rosetta/tests/src/org/jboss/soa/esb/services/security/SecurityServiceImplUnitTest.java)
===================================================================
--- labs/jbossesb/workspace/dbevenius/security/product/rosetta/tests/src/org/jboss/soa/esb/services/security/JaasSecurityServiceUnitTest.java	                        (rev 0)
+++ labs/jbossesb/workspace/dbevenius/security/product/rosetta/tests/src/org/jboss/soa/esb/services/security/JaasSecurityServiceUnitTest.java	2008-07-19 09:22:32 UTC (rev 21131)
@@ -0,0 +1,82 @@
+/*
+ * JBoss, Home of Professional Open Source Copyright 2008, Red Hat Middleware
+ * LLC, and individual contributors 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.soa.esb.services.security;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.Set;
+
+import javax.security.auth.Subject;
+import javax.security.auth.login.FailedLoginException;
+import javax.security.auth.login.LoginException;
+
+import junit.framework.JUnit4TestAdapter;
+
+import org.jboss.soa.esb.ConfigurationException;
+import org.junit.Test;
+
+/**
+ * Unit test for {@link SecurityServiceImpl}
+ * <p/>
+ * 
+ * @author <a href="mailto:dbevenius at redhat.com">Daniel Bevenius</a>
+ * @since 4.4
+ */
+public class JaasSecurityServiceUnitTest
+{
+	private SecurityService service = new JaasSecurityService();
+	private Subject subject = new Subject();			
+	
+	private static String policyFileName = "jaas-test.config";
+	
+	@Test
+	public void loginSuccess() throws LoginException, ConfigurationException
+	{
+		SecurityConfigInfo configInfo = SecurityConfigInfo.createSecurityInfo(policyFileName, null, null, "SuccessfulLogin");
+		JaasSecurityContext context = new JaasSecurityContext(configInfo, subject);
+		service.authenticate(context);
+		Set<TestPrincipal> principals = context.getSubject().getPrincipals( TestPrincipal.class );
+		assertEquals( 1, principals.size() );
+		assertEquals( "test", principals.iterator().next().getName() );
+	}
+	
+	@Test ( expected = FailedLoginException.class )
+	public void loginFailure() throws LoginException, ConfigurationException
+	{
+		SecurityConfigInfo configInfo = SecurityConfigInfo.createSecurityInfo(policyFileName, null, null, "FailureLogin");
+		JaasSecurityContext context = new JaasSecurityContext(configInfo, subject);
+		service.authenticate( context );
+	}
+	
+	@Test
+	public void addPolicy() throws ConfigurationException
+	{
+		SecurityConfigInfo configInfo = SecurityConfigInfo.createSecurityInfo(policyFileName, null, null, "FailureLogin");
+		service.addPolicy(configInfo.getPolicyConfig());
+		assertEquals(configInfo.getPolicyConfig().toString(), System.getProperty(JaasSecurityService.POLICY_URL_PRIFIX+1));
+	}
+	
+	public static junit.framework.Test suite()
+	{
+		return new JUnit4TestAdapter( JaasSecurityServiceUnitTest.class );
+	}
+	
+}

Deleted: labs/jbossesb/workspace/dbevenius/security/product/rosetta/tests/src/org/jboss/soa/esb/services/security/SecurityServiceImplUnitTest.java
===================================================================
--- labs/jbossesb/workspace/dbevenius/security/product/rosetta/tests/src/org/jboss/soa/esb/services/security/SecurityServiceImplUnitTest.java	2008-07-19 05:47:40 UTC (rev 21130)
+++ labs/jbossesb/workspace/dbevenius/security/product/rosetta/tests/src/org/jboss/soa/esb/services/security/SecurityServiceImplUnitTest.java	2008-07-19 09:22:32 UTC (rev 21131)
@@ -1,82 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source Copyright 2008, Red Hat Middleware
- * LLC, and individual contributors 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.soa.esb.services.security;
-
-import static org.junit.Assert.assertEquals;
-
-import java.util.Set;
-
-import javax.security.auth.Subject;
-import javax.security.auth.login.FailedLoginException;
-import javax.security.auth.login.LoginException;
-
-import junit.framework.JUnit4TestAdapter;
-
-import org.jboss.soa.esb.ConfigurationException;
-import org.junit.Test;
-
-/**
- * Unit test for {@link SecurityServiceImpl}
- * <p/>
- * 
- * @author <a href="mailto:dbevenius at redhat.com">Daniel Bevenius</a>
- * @since 4.4
- */
-public class SecurityServiceImplUnitTest
-{
-	private SecurityService service = new SecurityServiceImpl();
-	private Subject subject = new Subject();			
-	
-	private static String policyFileName = "jaas-test.config";
-	
-	@Test
-	public void loginSuccess() throws LoginException, ConfigurationException
-	{
-		SecurityConfigInfo configInfo = SecurityConfigInfo.createSecurityInfo(policyFileName, null, null, "SuccessfulLogin");
-		JaasSecurityContext context = new JaasSecurityContext(configInfo, subject);
-		service.authenticate(context);
-		Set<TestPrincipal> principals = context.getSubject().getPrincipals( TestPrincipal.class );
-		assertEquals( 1, principals.size() );
-		assertEquals( "test", principals.iterator().next().getName() );
-	}
-	
-	@Test ( expected = FailedLoginException.class )
-	public void loginFailure() throws LoginException, ConfigurationException
-	{
-		SecurityConfigInfo configInfo = SecurityConfigInfo.createSecurityInfo(policyFileName, null, null, "FailureLogin");
-		JaasSecurityContext context = new JaasSecurityContext(configInfo, subject);
-		service.authenticate( context );
-	}
-	
-	@Test
-	public void addPolicy() throws ConfigurationException
-	{
-		SecurityConfigInfo configInfo = SecurityConfigInfo.createSecurityInfo(policyFileName, null, null, "FailureLogin");
-		service.addPolicy(configInfo.getPolicyConfig());
-		assertEquals(configInfo.getPolicyConfig().toString(), System.getProperty(SecurityServiceImpl.POLICY_URL_PRIFIX+1));
-	}
-	
-	public static junit.framework.Test suite()
-	{
-		return new JUnit4TestAdapter( SecurityServiceImplUnitTest.class );
-	}
-	
-}




More information about the jboss-svn-commits mailing list