You are viewing a plain text version of this content. The canonical link for it is here.
Posted to wss4j-dev@ws.apache.org by co...@apache.org on 2010/05/28 14:00:20 UTC

svn commit: r949154 - /webservices/wss4j/branches/1_5_x-fixes/test/wssec/TestWSSecurityNew5.java

Author: coheigea
Date: Fri May 28 12:00:20 2010
New Revision: 949154

URL: http://svn.apache.org/viewvc?rev=949154&view=rev
Log:
[WSS-219] - Added tests for adding a UsernameToken with an empty (not null) password.

Modified:
    webservices/wss4j/branches/1_5_x-fixes/test/wssec/TestWSSecurityNew5.java

Modified: webservices/wss4j/branches/1_5_x-fixes/test/wssec/TestWSSecurityNew5.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/1_5_x-fixes/test/wssec/TestWSSecurityNew5.java?rev=949154&r1=949153&r2=949154&view=diff
==============================================================================
--- webservices/wss4j/branches/1_5_x-fixes/test/wssec/TestWSSecurityNew5.java (original)
+++ webservices/wss4j/branches/1_5_x-fixes/test/wssec/TestWSSecurityNew5.java Fri May 28 12:00:20 2010
@@ -1,18 +1,20 @@
-/*
- * Copyright  2003-2004 The Apache Software Foundation.
- *
- *  Licensed under the Apache License, Version 2.0 (the "License");
- *  you may not use this file except in compliance with the License.
- *  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
  *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
+ * http://www.apache.org/licenses/LICENSE-2.0
  *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
  */
 
 package wssec;
@@ -32,6 +34,8 @@ import org.apache.ws.security.WSPassword
 import org.apache.ws.security.WSSecurityEngine;
 import org.apache.ws.security.WSConstants;
 import org.apache.ws.security.WSSConfig;
+import org.apache.ws.security.handler.RequestData;
+import org.apache.ws.security.handler.WSHandlerConstants;
 import org.apache.ws.security.message.WSSecUsernameToken;
 import org.apache.ws.security.message.WSSecHeader;
 import org.apache.ws.security.util.Base64;
@@ -335,6 +339,32 @@ public class TestWSSecurityNew5 extends 
     }
     
     /**
+     * Test that adds a UserNameToken with an empty password
+     */
+    public void testUsernameTokenEmptyPassword() throws Exception {
+        WSSecUsernameToken builder = new WSSecUsernameToken();
+        builder.setPasswordType(WSConstants.PASSWORD_TEXT);
+        builder.setUserInfo("wernerd", "");
+        LOG.info("Before adding UsernameToken with an empty password....");
+        Document doc = unsignedEnvelope.getAsDocument();
+        WSSecHeader secHeader = new WSSecHeader();
+        secHeader.insertSecurityHeader(doc);
+        Document signedDoc = builder.build(doc, secHeader);
+        if (LOG.isDebugEnabled()) {
+            String outputString = 
+                org.apache.ws.security.util.XMLUtils.PrettyDocumentToString(signedDoc);
+            LOG.debug(outputString);
+        }
+        try {
+            verify(signedDoc);
+            throw new Exception("Failure expected on an password");
+        } catch (WSSecurityException ex) {
+            assertTrue(ex.getErrorCode() == WSSecurityException.FAILED_AUTHENTICATION);
+            // expected
+        }
+    }
+    
+    /**
      * Test with a null token type. This will fail as the default is to reject custom
      * token types.
      */
@@ -501,6 +531,60 @@ public class TestWSSecurityNew5 extends 
     }
     
     /**
+     * Test that adds a UserNameToken via WSHandler
+     */
+    public void testUsernameTokenWSHandler() throws Exception {
+        MyHandler handler = new MyHandler();
+        Document doc = unsignedEnvelope.getAsDocument();
+        
+        RequestData reqData = new RequestData();
+        java.util.Map config = new java.util.TreeMap();
+        config.put("password", "verySecret");
+        config.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT);
+        reqData.setUsername("wernerd");
+        reqData.setMsgContext(config);
+        
+        java.util.Vector actions = new java.util.Vector();
+        actions.add(new Integer(WSConstants.UT));
+        
+        handler.send(WSConstants.UT, doc, reqData, actions, true);
+        
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Username Token via WSHandler");
+            String outputString = 
+                org.apache.ws.security.util.XMLUtils.PrettyDocumentToString(doc);
+            LOG.debug(outputString);
+        }
+    }
+    
+    /**
+     * Test that adds a UserNameToken with an empty password via WSHandler
+     */
+    public void testUsernameTokenWSHandlerEmptyPassword() throws Exception {
+        MyHandler handler = new MyHandler();
+        Document doc = unsignedEnvelope.getAsDocument();
+        
+        RequestData reqData = new RequestData();
+        java.util.Map config = new java.util.TreeMap();
+        config.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT);
+        config.put(WSHandlerConstants.PW_CALLBACK_REF, this);
+        reqData.setUsername("emptyuser");
+        reqData.setMsgContext(config);
+        
+        java.util.Vector actions = new java.util.Vector();
+        actions.add(new Integer(WSConstants.UT));
+        
+        handler.send(WSConstants.UT, doc, reqData, actions, true);
+        
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Username Token with an empty password via WSHandler");
+            String outputString = 
+                org.apache.ws.security.util.XMLUtils.PrettyDocumentToString(doc);
+            LOG.debug(outputString);
+        }
+    }
+    
+    /**
      * Verifies the soap envelope
      * 
      * @param env soap envelope
@@ -520,7 +604,11 @@ public class TestWSSecurityNew5 extends 
                 if (pc.getUsage() == WSPasswordCallback.USERNAME_TOKEN
                     && "wernerd".equals(pc.getIdentifier())) {
                     pc.setPassword("verySecret");
-                } else if (
+                } else if (pc.getUsage() == WSPasswordCallback.USERNAME_TOKEN
+                    && "emptyuser".equals(pc.getIdentifier())) {
+                    pc.setPassword("");
+                }  
+                else if (
                     pc.getUsage() == WSPasswordCallback.USERNAME_TOKEN_UNKNOWN
                 ) {
                     if ("wernerd".equals(pc.getIdentifier())



---------------------------------------------------------------------
To unsubscribe, e-mail: wss4j-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: wss4j-dev-help@ws.apache.org