[jboss-cvs] JBossAS SVN: r80248 - in projects/security/security-jboss-sx/trunk: jbosssx and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Oct 30 10:43:34 EDT 2008


Author: anil.saldhana at jboss.com
Date: 2008-10-30 10:43:34 -0400 (Thu, 30 Oct 2008)
New Revision: 80248

Added:
   projects/security/security-jboss-sx/trunk/jbosssx/src/test/java/org/jboss/test/authentication/jaspi/JASPIServerAuthenticationManagerUnitTestCase.java
Modified:
   projects/security/security-jboss-sx/trunk/jbosssx/pom.xml
   projects/security/security-jboss-sx/trunk/jbosssx/src/main/java/org/jboss/security/auth/message/config/JBossServerAuthConfig.java
   projects/security/security-jboss-sx/trunk/pom.xml
Log:
SECURITY-297: consider passed callbackhandler

Modified: projects/security/security-jboss-sx/trunk/jbosssx/pom.xml
===================================================================
--- projects/security/security-jboss-sx/trunk/jbosssx/pom.xml	2008-10-30 14:38:28 UTC (rev 80247)
+++ projects/security/security-jboss-sx/trunk/jbosssx/pom.xml	2008-10-30 14:43:34 UTC (rev 80248)
@@ -43,7 +43,7 @@
       <properties>
          <test.env>-Dtest.basedir=${basedir}/target/test-classes</test.env>
          <policy.file>${basedir}/src/tests/resources/java.policy</policy.file>
-         <surefire.jvm.args>-Djava.security.manager -Djava.security.policy=${policy.file} -Djava.security.debug=failure,access ${test.env}</surefire.jvm.args>
+         <surefire.jvm.args>-Djava.security.manager -Djava.security.policy=${policy.file} -Djava.security.debug=policy,failure,access ${test.env}</surefire.jvm.args>
       </properties>
     </profile>
    </profiles>

Modified: projects/security/security-jboss-sx/trunk/jbosssx/src/main/java/org/jboss/security/auth/message/config/JBossServerAuthConfig.java
===================================================================
--- projects/security/security-jboss-sx/trunk/jbosssx/src/main/java/org/jboss/security/auth/message/config/JBossServerAuthConfig.java	2008-10-30 14:38:28 UTC (rev 80247)
+++ projects/security/security-jboss-sx/trunk/jbosssx/src/main/java/org/jboss/security/auth/message/config/JBossServerAuthConfig.java	2008-10-30 14:43:34 UTC (rev 80248)
@@ -60,7 +60,7 @@
 {
    private String layer;
    private String contextId;
-   private CallbackHandler callbackHandler;
+   private CallbackHandler callbackHandler = new SecurityAssociationHandler();
    @SuppressWarnings("unchecked")
    private List modules = new ArrayList();
    @SuppressWarnings({"unused", "unchecked"})
@@ -120,7 +120,7 @@
          ServerAuthModule sam = new DelegatingServerAuthModule();
          Map options = new HashMap();
          options.put("javax.security.auth.login.LoginContext", secDomain); //Name of sec domain
-         sam.initialize(null, null, new SecurityAssociationHandler(), options); 
+         sam.initialize(null, null, this.callbackHandler, options); 
          modules.add(sam);
       }
       else
@@ -134,9 +134,14 @@
                try
                {
                   mapOptionsByName.put(ame.getAuthModuleName(), ame.getOptions());
-                  controlFlags.add(ame.getControlFlag());            
-                  modules.add(this.createSAM(ame.getAuthModuleName(), 
-                        ame.getLoginModuleStackHolderName()));
+                  controlFlags.add(ame.getControlFlag());   
+                  ServerAuthModule sam = this.createSAM(ame.getAuthModuleName(), 
+                        ame.getLoginModuleStackHolderName());
+                  
+                  Map options = new HashMap();
+                  
+                  sam.initialize(null, null, callbackHandler, options);
+                  modules.add(sam);
                }
                catch (Exception e)
                {
@@ -148,8 +153,12 @@
                try
                {
                   mapOptionsByName.put(ame.getAuthModuleName(), ame.getOptions());
-                  controlFlags.add(ame.getControlFlag());            
-                  modules.add(this.createSAM(ame.getAuthModuleName()));
+                  controlFlags.add(ame.getControlFlag());             
+                  ServerAuthModule sam = this.createSAM(ame.getAuthModuleName());
+                  
+                  Map options = new HashMap(); 
+                  sam.initialize(null, null, callbackHandler, options);
+                  modules.add(sam);
                }
                catch (Exception e)
                {

Added: projects/security/security-jboss-sx/trunk/jbosssx/src/test/java/org/jboss/test/authentication/jaspi/JASPIServerAuthenticationManagerUnitTestCase.java
===================================================================
--- projects/security/security-jboss-sx/trunk/jbosssx/src/test/java/org/jboss/test/authentication/jaspi/JASPIServerAuthenticationManagerUnitTestCase.java	                        (rev 0)
+++ projects/security/security-jboss-sx/trunk/jbosssx/src/test/java/org/jboss/test/authentication/jaspi/JASPIServerAuthenticationManagerUnitTestCase.java	2008-10-30 14:43:34 UTC (rev 80248)
@@ -0,0 +1,99 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.test.authentication.jaspi;
+
+import java.net.URL;
+import java.util.HashMap;
+
+import javax.security.auth.Subject;
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.message.MessageInfo;
+import javax.security.auth.message.config.AuthConfigFactory;
+
+import org.jboss.security.SecurityConstants;
+import org.jboss.security.SecurityContext;
+import org.jboss.security.SecurityContextAssociation;
+import org.jboss.security.auth.callback.AppCallbackHandler;
+import org.jboss.security.auth.login.XMLLoginConfigImpl;
+import org.jboss.security.auth.message.GenericMessageInfo;
+import org.jboss.security.auth.message.config.JBossAuthConfigProvider;
+import org.jboss.security.plugins.JBossSecurityContext;
+import org.jboss.security.plugins.auth.JASPIServerAuthenticationManager;
+import org.jboss.test.SecurityActions;
+
+import junit.framework.TestCase;
+
+/**
+ * Unit Test the JASPIServerAuthenticationManager
+ * @author Anil.Saldhana at redhat.com
+ */
+public class JASPIServerAuthenticationManagerUnitTestCase extends TestCase
+{ 
+   AuthConfigFactory factory = null;
+
+   String layer = SecurityConstants.SERVLET_LAYER;
+
+   String appId = "localhost /petstore";
+
+   String configFile = "config/jaspi-config.xml";
+
+   @SuppressWarnings("unchecked")
+   protected void setUp() throws Exception
+   {
+      factory = AuthConfigFactory.getFactory();
+      factory.registerConfigProvider(new JBossAuthConfigProvider(new HashMap()), layer, appId, "Test Config Provider");
+
+      SecurityContext jsc = new JBossSecurityContext("conf-jaspi");
+      SecurityContextAssociation.setSecurityContext(jsc);
+
+      XMLLoginConfigImpl xli = XMLLoginConfigImpl.getInstance();
+      SecurityActions.setJAASConfiguration(xli);
+
+      URL configURL = Thread.currentThread().getContextClassLoader().getResource(configFile);
+      assertNotNull("Config URL", configURL);
+
+      xli.setConfigURL(configURL);
+      xli.loadConfig();
+   }
+   
+   public void testIsValid()
+   {
+      CallbackHandler cbh = new AppCallbackHandler("anil",
+            "anilpwd".toCharArray());
+      MessageInfo messageInfo = new GenericMessageInfo(new Object(), new Object());
+      JASPIServerAuthenticationManager jaspiManager = new JASPIServerAuthenticationManager();
+      boolean valid = jaspiManager.isValid(messageInfo, new Subject(), layer, 
+                                       cbh);
+      assertTrue(valid);
+   }
+   
+   public void testIsInValid()
+   {
+      CallbackHandler cbh = new AppCallbackHandler("anil",
+            "dead".toCharArray());
+      MessageInfo messageInfo = new GenericMessageInfo(new Object(), new Object());
+      JASPIServerAuthenticationManager jaspiManager = new JASPIServerAuthenticationManager();
+      boolean valid = jaspiManager.isValid(messageInfo, new Subject(), layer, 
+                                       cbh);
+      assertFalse(valid);
+   }
+}
\ No newline at end of file

Modified: projects/security/security-jboss-sx/trunk/pom.xml
===================================================================
--- projects/security/security-jboss-sx/trunk/pom.xml	2008-10-30 14:38:28 UTC (rev 80247)
+++ projects/security/security-jboss-sx/trunk/pom.xml	2008-10-30 14:43:34 UTC (rev 80248)
@@ -62,38 +62,6 @@
    </modules>
   
    <profiles>
-    <!--    mvn install -Psecurity-manager    -->
-    <profile>
-      <id>security-manager</id>
-      <activation>
-         <activeByDefault>false</activeByDefault>
-      </activation>
-      <properties>
-         <test.env>-Dtest.basedir=${basedir}/target/test-classes</test.env>
-         <policy.file>${basedir}/src/tests/resources/java.policy</policy.file>
-         <surefire.jvm.args>-Djava.security.manager -Djava.security.policy=${policy.file} ${test.env}</surefire.jvm.args>
-      </properties>
-      <modules>
-        <module>jbosssx</module>
-      </modules>
-    </profile>
-    <!--     mvn install -Psecurity-manager-debug   -->
-    <!-- Best Practice:    mvn install -Psecurity-manager-debug  2>&1 > logfile2>&1 > logfile -->
-    <profile>
-      <id>security-manager-debug</id>
-      <activation>
-         <activeByDefault>false</activeByDefault>
-      </activation>
-      <properties>
-         <test.env>-Dtest.basedir=${basedir}/target/test-classes</test.env>
-         <policy.file>${basedir}/src/tests/resources/java.policy</policy.file>
-         <surefire.jvm.args>-Djava.security.manager -Djava.security.policy=${policy.file} -Djava.security.debug=failure,access ${test.env}</surefire.jvm.args>
-      </properties>
-      <modules>
-        <module>jbosssx</module>
-      </modules>
-    </profile>
-
     <!-- Specify heap size for ACL tests -->
     <profile>
       <id>acl-heap-profile</id>
@@ -108,25 +76,6 @@
       </modules>
     </profile>
    </profiles>
-
-   <build>
-    <plugins>
-     <plugin>
-        <artifactId>maven-surefire-plugin</artifactId>
-        <configuration>
-          <printSummary>true</printSummary>
-          <testFailureIgnore>false</testFailureIgnore>
-          <redirectTestOutputToFile>true</redirectTestOutputToFile>
-          <includes>
-             <include>**/**TestCase.java</include>
-          </includes>
-          <forkMode>pertest</forkMode>
-          <argLine>${surefire.jvm.args}</argLine>
-          <trimStackTrace>false</trimStackTrace>
-        </configuration>
-      </plugin>
-    </plugins>
-   </build>
   
    <distributionManagement>
     <repository>




More information about the jboss-cvs-commits mailing list