chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fguilla...@apache.org
Subject svn commit: r926011 - /incubator/chemistry/trunk/chemistry/chemistry-soap-server/src/main/java/org/apache/chemistry/soap/server/AuthHandler.java
Date Mon, 22 Mar 2010 09:50:55 GMT
Author: fguillaume
Date: Mon Mar 22 09:50:55 2010
New Revision: 926011

URL: http://svn.apache.org/viewvc?rev=926011&view=rev
Log:
More robust SOAP wsse:UsernameToken parsing

Modified:
    incubator/chemistry/trunk/chemistry/chemistry-soap-server/src/main/java/org/apache/chemistry/soap/server/AuthHandler.java

Modified: incubator/chemistry/trunk/chemistry/chemistry-soap-server/src/main/java/org/apache/chemistry/soap/server/AuthHandler.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-soap-server/src/main/java/org/apache/chemistry/soap/server/AuthHandler.java?rev=926011&r1=926010&r2=926011&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-soap-server/src/main/java/org/apache/chemistry/soap/server/AuthHandler.java
(original)
+++ incubator/chemistry/trunk/chemistry/chemistry-soap-server/src/main/java/org/apache/chemistry/soap/server/AuthHandler.java
Mon Mar 22 09:50:55 2010
@@ -67,47 +67,51 @@ public class AuthHandler implements SOAP
     }
 
     protected boolean handleInboundMessage(SOAPMessageContext soapContext) {
-        CallContext callContext = new CallContext();
-        try {
-            extractUsernamePassword(soapContext, callContext);
-        } catch (NoSuchElementException e) {
-            // cannot get UsernameToken
-            callContext.setUsername("");
-            callContext.setPassword("");
-        }
+        CallContext callContext = extractUsernamePassword(soapContext);
         callContext.setInMessageContext(soapContext);
         return true; // continue processing
     }
 
     /**
      * Gets the username and password from the UsernameToken on the
-     * {@link SOAPMessageContext} and stores them in the {@link CallContext}.
-     *
-     * @throws NoSuchElementException if the token cannot be found
+     * {@link SOAPMessageContext} and returns a {@link CallContext}.
      */
-    protected void extractUsernamePassword(SOAPMessageContext soapContext,
-            CallContext callContext) throws NoSuchElementException {
+    protected CallContext extractUsernamePassword(SOAPMessageContext soapContext) {
         SOAPHeader sh;
         try {
             sh = soapContext.getMessage().getSOAPHeader();
         } catch (SOAPException e) {
             throw new RuntimeException("Cannot get SOAP header", e);
         }
-        // NoSuchElementException may be thrown by next()
-        SOAPElement security = (SOAPElement) sh.getChildElements(WSSE_SECURITY).next();
-        SOAPElement token = (SOAPElement) security.getChildElements(
-                WSSE_USERNAME_TOKEN).next();
-        SOAPElement usernameElement = (SOAPElement) token.getChildElements(
-                WSSE_USERNAME).next();
-        SOAPElement passwordElement = (SOAPElement) token.getChildElements(
-                WSSE_PASSWORD).next();
-        String username = usernameElement.getValue();
-        String password = passwordElement.getValue();
-        if (username == null || password == null) {
-            throw new NoSuchElementException();
+        String username = "";
+        String password = "";
+        try {
+            // NoSuchElementException may be thrown by next()
+            SOAPElement security = (SOAPElement) sh.getChildElements(
+                    WSSE_SECURITY).next();
+            SOAPElement token = (SOAPElement) security.getChildElements(
+                    WSSE_USERNAME_TOKEN).next();
+            try {
+                SOAPElement usernameElement = (SOAPElement) token.getChildElements(
+                        WSSE_USERNAME).next();
+                username = usernameElement.getTextContent();
+            } catch (NoSuchElementException e) {
+                // skip
+            }
+            try {
+                SOAPElement passwordElement = (SOAPElement) token.getChildElements(
+                        WSSE_PASSWORD).next();
+                password = passwordElement.getTextContent();
+            } catch (NoSuchElementException e) {
+                // skip
+            }
+        } catch (NoSuchElementException e) {
+            // no wsse:Security or wsse:UsernameToken
         }
+        CallContext callContext = new CallContext();
         callContext.setUsername(username);
         callContext.setPassword(password);
+        return callContext;
     }
 
     protected boolean handleOutboundMessage(SOAPMessageContext soapContext) {



Mime
View raw message