[jbossws-commits] JBossWS SVN: r18101 - in stack/cxf/branches/jaspi/modules/testsuite: test-utils/src/main/java/org/jboss/wsf/test and 1 other directory.

jbossws-commits at lists.jboss.org jbossws-commits at lists.jboss.org
Fri Nov 22 05:09:04 EST 2013


Author: jim.ma
Date: 2013-11-22 05:09:03 -0500 (Fri, 22 Nov 2013)
New Revision: 18101

Modified:
   stack/cxf/branches/jaspi/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/jaspi/JBWSJaspiTestCase.java
   stack/cxf/branches/jaspi/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/jaspi/usernametoken-soapmessage.xml
   stack/cxf/branches/jaspi/modules/testsuite/test-utils/src/main/java/org/jboss/wsf/test/JBossWSTestHelper.java
Log:
Add utility method to create jaspi security domain;improve test case

Modified: stack/cxf/branches/jaspi/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/jaspi/JBWSJaspiTestCase.java
===================================================================
--- stack/cxf/branches/jaspi/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/jaspi/JBWSJaspiTestCase.java	2013-11-22 08:24:57 UTC (rev 18100)
+++ stack/cxf/branches/jaspi/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/jaspi/JBWSJaspiTestCase.java	2013-11-22 10:09:03 UTC (rev 18101)
@@ -26,6 +26,8 @@
 import java.io.IOException;
 import java.net.URL;
 import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
 
 import javax.xml.namespace.QName;
 import javax.xml.soap.MessageFactory;
@@ -33,52 +35,88 @@
 import javax.xml.ws.Dispatch;
 import javax.xml.ws.Service;
 
+import junit.extensions.TestSetup;
 import junit.framework.Test;
 
 import org.apache.ws.security.util.XmlSchemaDateFormat;
 import org.jboss.wsf.test.JBossWSCXFTestSetup;
 import org.jboss.wsf.test.JBossWSTest;
+import org.jboss.wsf.test.JBossWSTestHelper;
 
 public class JBWSJaspiTestCase extends JBossWSTest
 {
    private String address = "http://" + getServerHost() + ":8080/jaxws-cxf-jaspi/JaspiEndpoint";
    private String wsdlURl = address + "?wsdl";
    private String targetNS = "http://org.jboss.ws.jaxws.cxf/jaspi";
+
    public static Test suite()
    {
-      return new JBossWSCXFTestSetup(JBWSJaspiTestCase.class, "jaxws-cxf-jaspi.war");
+      TestSetup testSetup = new JBossWSCXFTestSetup(JBWSJaspiTestCase.class, "jaxws-cxf-jaspi.war") {
+
+         public void setUp() throws Exception
+         {
+            Map<String, String> loginModuleOptions = new HashMap<String, String>();
+            String usersPropFile = System.getProperty("org.jboss.ws.testsuite.securityDomain.users.propfile");
+            String rolesPropFile = System.getProperty("org.jboss.ws.testsuite.securityDomain.roles.propfile");
+            if (usersPropFile != null)
+            {
+               loginModuleOptions.put("usersProperties", usersPropFile);
+            }
+            if (rolesPropFile != null)
+            {
+               loginModuleOptions.put("rolesProperties", rolesPropFile);
+            }
+
+            Map<String, String> authModuleOptions = new HashMap<String, String>();
+            authModuleOptions.put("action", "UsernameToken Timestamp");
+            JBossWSTestHelper.addJaspiSecurityDomain("jaspi", "jaas-lm-stack", loginModuleOptions, "org.jboss.wsf.stack.cxf.jaspi.module.SOAPServerAuthModule",
+                  authModuleOptions);
+
+            super.setUp();
+         }
+
+         public void tearDown() throws Exception
+         {
+            JBossWSTestHelper.removeSecurityDomain("jaspi");
+            super.tearDown();
+
+         }
+      };
+      return testSetup;
    }
-   
+
    public void testValidMessage() throws Exception
    {
-      
       Service service = Service.create(new URL(wsdlURl), new QName(targetNS, "JaspiService"));
       Dispatch<SOAPMessage> dispatch = service.createDispatch(new QName(targetNS, "JaspiEndpointPort"), SOAPMessage.class, Service.Mode.MESSAGE);
       SOAPMessage response = dispatch.invoke(prepareSOAPMessage("org/jboss/test/ws/jaxws/cxf/jaspi/usernametoken-soapmessage.xml"));
-      response.writeTo(System.out);
+      java.io.ByteArrayOutputStream bout = new java.io.ByteArrayOutputStream();
+      response.writeTo(bout);
+      assertTrue("Expected echoResponse replied", new String(bout.toByteArray()).indexOf("echoResponse") > -1);
    }
-  
-   private SOAPMessage prepareSOAPMessage(String messageFile) throws Exception {
+
+   private SOAPMessage prepareSOAPMessage(String messageFile) throws Exception
+   {
       MessageFactory factory = MessageFactory.newInstance();
-      URL fileURl = Thread.currentThread().getContextClassLoader()
-            .getResource(messageFile);
+      URL fileURl = Thread.currentThread().getContextClassLoader().getResource(messageFile);
       FileInputStream fins = new FileInputStream(fileURl.getFile());
       String content = readFile(fins);
       XmlSchemaDateFormat formater = new XmlSchemaDateFormat();
 
-      String replaced = content.replaceAll("\\$NOW", formater.format(new Date()));     
+      String replaced = content.replaceAll("\\$NOW", formater.format(new Date()));
       ByteArrayInputStream bin = new ByteArrayInputStream(replaced.getBytes());
       return factory.createMessage(null, bin);
    }
-   
-   private String readFile(FileInputStream in) throws IOException {
+
+   private String readFile(FileInputStream in) throws IOException
+   {
       StringBuilder sb = new StringBuilder(1024);
-      for (int i = in.read(); i != -1; i = in.read()) {
-         sb.append((char) i);
+      for (int i = in.read(); i != -1; i = in.read())
+      {
+         sb.append((char)i);
       }
       in.close();
       return sb.toString();
    }
 
-   
 }

Modified: stack/cxf/branches/jaspi/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/jaspi/usernametoken-soapmessage.xml
===================================================================
--- stack/cxf/branches/jaspi/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/jaspi/usernametoken-soapmessage.xml	2013-11-22 08:24:57 UTC (rev 18100)
+++ stack/cxf/branches/jaspi/modules/testsuite/cxf-tests/src/test/java/org/jboss/test/ws/jaxws/cxf/jaspi/usernametoken-soapmessage.xml	2013-11-22 10:09:03 UTC (rev 18101)
@@ -11,9 +11,9 @@
 			</wsu:Timestamp>
 			<wsse:UsernameToken
 				wsu:Id="UsernameToken-4313b55e-cbcd-438f-8408-c19f1016b208">
-				<wsse:Username>jbossws</wsse:Username>
+				<wsse:Username>kermit</wsse:Username>
 				<wsse:Password
-					Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">jbossws</wsse:Password>
+					Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">thefrog</wsse:Password>
 			</wsse:UsernameToken>
 		</wsse:Security>
 	</soap:Header>

Modified: stack/cxf/branches/jaspi/modules/testsuite/test-utils/src/main/java/org/jboss/wsf/test/JBossWSTestHelper.java
===================================================================
--- stack/cxf/branches/jaspi/modules/testsuite/test-utils/src/main/java/org/jboss/wsf/test/JBossWSTestHelper.java	2013-11-22 08:24:57 UTC (rev 18100)
+++ stack/cxf/branches/jaspi/modules/testsuite/test-utils/src/main/java/org/jboss/wsf/test/JBossWSTestHelper.java	2013-11-22 10:09:03 UTC (rev 18101)
@@ -403,6 +403,13 @@
       getDeployer().addSecurityDomain(name, authenticationOptions);
    }
    
+   public static void addJaspiSecurityDomain(String name, String loginModuleStackName, Map<String, String> loginModuleOptions, String authModuleName,
+         Map<String, String> authModuleOptions) throws Exception
+   {
+      getDeployer().addJaspiSecurityDomain(name, loginModuleStackName, loginModuleOptions, authModuleName, authModuleOptions);
+   }
+   
+   
    public static void removeSecurityDomain(String name) throws Exception
    {
       getDeployer().removeSecurityDomain(name);



More information about the jbossws-commits mailing list