[jboss-svn-commits] JBossWS SVN: r787 - in branches/jbossws-1.0/src: main/java/org/jboss/ws/wsse test/java/org/jboss/test/ws/wsse

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Sun Aug 20 15:11:21 EDT 2006


Author: darran.lofthouse at jboss.com
Date: 2006-08-20 15:11:16 -0400 (Sun, 20 Aug 2006)
New Revision: 787

Modified:
   branches/jbossws-1.0/src/main/java/org/jboss/ws/wsse/SecurityStore.java
   branches/jbossws-1.0/src/test/java/org/jboss/test/ws/wsse/SimpleSignEncryptTestCase.java
   branches/jbossws-1.0/src/test/java/org/jboss/test/ws/wsse/UsernameTestCase.java
Log:
JBWS-1097 - Do not attempt to initialise the keyStore or trustStore if the URL is not set.
For the profiles that do require the keyStore or trustStore log an appropriate error if they have not been set.


Modified: branches/jbossws-1.0/src/main/java/org/jboss/ws/wsse/SecurityStore.java
===================================================================
--- branches/jbossws-1.0/src/main/java/org/jboss/ws/wsse/SecurityStore.java	2006-08-19 07:59:15 UTC (rev 786)
+++ branches/jbossws-1.0/src/main/java/org/jboss/ws/wsse/SecurityStore.java	2006-08-20 19:11:16 UTC (rev 787)
@@ -23,11 +23,11 @@
 
 import java.io.BufferedReader;
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Method;
+import java.net.MalformedURLException;
 import java.net.URL;
 import java.security.InvalidAlgorithmParameterException;
 import java.security.KeyStore;
@@ -104,6 +104,25 @@
 
    private KeyStore loadStore(String property, String type, URL storeURL, String storeType, String storePassword) throws WSSecurityException
    {
+      if (storeURL==null)
+      {
+         String defaultStore = System.getProperty(property);
+         if (defaultStore==null)
+         {
+            return null;
+         }
+         
+         File storeFile = new File(defaultStore);
+         try
+         {
+            storeURL = storeFile.toURL();
+         }
+         catch (MalformedURLException e)
+         {
+            throw new WSSecurityException("Problems loading " + type + ": " + e.getMessage(), e);
+         }
+      }
+      
       if (storeType == null)
          storeType = System.getProperty(property + "Type");
       if (storeType == null)
@@ -240,6 +259,11 @@
 
    public X509Certificate getCertificate(String alias) throws WSSecurityException
    {
+      if (keyStore == null)
+      {
+         throw new WSSecurityException("KeyStore not set.");
+      }
+      
       X509Certificate cert;
       try
       {
@@ -262,6 +286,11 @@
       if (identifier == null)
          return null;
 
+      if (keyStore == null)
+      {
+         throw new WSSecurityException("KeyStore not set.");
+      }
+      
       try
       {
          Enumeration i = keyStore.aliases();
@@ -291,6 +320,11 @@
 
    public X509Certificate getCertificateByIssuerSerial(String issuer, String serial) throws WSSecurityException
    {
+      if (keyStore == null)
+      {
+         throw new WSSecurityException("KeyStore not set.");
+      }
+      
       try
       {
          Enumeration i = keyStore.aliases();
@@ -317,6 +351,11 @@
 
    public PrivateKey getPrivateKey(String alias) throws WSSecurityException
    {
+      if (keyStore == null)
+      {
+         throw new WSSecurityException("KeyStore not set.");
+      }
+      
       PrivateKey key;
       try
       {
@@ -335,6 +374,11 @@
 
    public PrivateKey getPrivateKey(X509Certificate cert) throws WSSecurityException
    {
+      if (keyStore == null)
+      {
+         throw new WSSecurityException("KeyStore not set.");
+      }
+      
       try
       {
          String alias = keyStore.getCertificateAlias(cert);
@@ -358,6 +402,11 @@
          throw new FailedAuthenticationException();
       }
 
+      if (keyStore == null)
+      {
+         throw new WSSecurityException("TrustStore not set.");
+      }
+      
       // Check for the exact entry in the truststore first, then fallback to a CA check
       try
       {

Modified: branches/jbossws-1.0/src/test/java/org/jboss/test/ws/wsse/SimpleSignEncryptTestCase.java
===================================================================
--- branches/jbossws-1.0/src/test/java/org/jboss/test/ws/wsse/SimpleSignEncryptTestCase.java	2006-08-19 07:59:15 UTC (rev 786)
+++ branches/jbossws-1.0/src/test/java/org/jboss/test/ws/wsse/SimpleSignEncryptTestCase.java	2006-08-20 19:11:16 UTC (rev 787)
@@ -1,29 +1,30 @@
 /*
-  * 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.
-  */
+ * 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.test.ws.wsse;
 
+import java.rmi.RemoteException;
+
 import javax.naming.InitialContext;
 import javax.xml.rpc.Service;
-import javax.xml.rpc.Stub;
 
 import junit.framework.Test;
 
@@ -38,6 +39,7 @@
  */
 public class SimpleSignEncryptTestCase extends JBossWSTest
 {
+
    /** Construct the test case with a given name
     */
 
@@ -60,4 +62,33 @@
       UserType retObj = hello.echoUserType(in0);
       assertEquals(in0, retObj);
    }
+
+   /**
+    * Test JSE endpoint
+    */
+   public void testEndpointNoProperties() throws Exception
+   {
+      System.clearProperty("org.jboss.ws.wsse.keyStore");
+      System.clearProperty("org.jboss.ws.wsse.trustStore");
+      System.clearProperty("org.jboss.ws.wsse.keyStorePassword");
+      System.clearProperty("org.jboss.ws.wsse.trustStorePassword");
+      System.clearProperty("org.jboss.ws.wsse.keyStoreType");
+      System.clearProperty("org.jboss.ws.wsse.trustStoreType");
+
+      InitialContext iniCtx = getInitialContext();
+      Service service = (Service)iniCtx.lookup("java:comp/env/service/HelloService");
+      Hello hello = (Hello)service.getPort(Hello.class);
+
+      UserType in0 = new UserType("Kermit");
+
+      try
+      {
+         hello.echoUserType(in0);
+         fail("Expected exception not thrown");
+      }
+      catch (RemoteException e)
+      {
+      }
+
+   }
 }

Modified: branches/jbossws-1.0/src/test/java/org/jboss/test/ws/wsse/UsernameTestCase.java
===================================================================
--- branches/jbossws-1.0/src/test/java/org/jboss/test/ws/wsse/UsernameTestCase.java	2006-08-19 07:59:15 UTC (rev 786)
+++ branches/jbossws-1.0/src/test/java/org/jboss/test/ws/wsse/UsernameTestCase.java	2006-08-20 19:11:16 UTC (rev 787)
@@ -39,7 +39,7 @@
 public class UsernameTestCase extends JBossWSTest
 {
    private static JaxRpcTestService endpoint;
-
+  
    public static Test suite()
    {
       return JBossWSTestSetup.newTestSetup(UsernameTestCase.class, "jbossws-wsse-username.jar, jbossws-wsse-username-client.jar");
@@ -57,8 +57,15 @@
          ((Stub)endpoint)._setProperty(Stub.USERNAME_PROPERTY, "kermit");
          ((Stub)endpoint)._setProperty(Stub.PASSWORD_PROPERTY, "thefrog");
       }
+            
+      System.clearProperty("org.jboss.ws.wsse.keyStore");
+      System.clearProperty("org.jboss.ws.wsse.trustStore");
+      System.clearProperty("org.jboss.ws.wsse.keyStorePassword");
+      System.clearProperty("org.jboss.ws.wsse.trustStorePassword");
+      System.clearProperty("org.jboss.ws.wsse.keyStoreType");
+      System.clearProperty("org.jboss.ws.wsse.trustStoreType");
    }
-
+   
    public void testEchoString() throws Exception
    {
       String hello = "Hello";




More information about the jboss-svn-commits mailing list