cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1057393 [3/5] - in /cxf/trunk: common/common/src/main/java/org/apache/cxf/common/logging/ common/common/src/test/java/org/apache/cxf/staxutils/resources/ distribution/src/main/release/samples/aegis/testSrc/org/apache/cxf/sample/test/ distr...
Date Mon, 10 Jan 2011 22:07:13 GMT
Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Headers.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Headers.java?rev=1057393&r1=1057392&r2=1057393&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Headers.java (original)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Headers.java Mon Jan 10 22:07:10 2011
@@ -1,406 +1,406 @@
-/**
- * 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
- *
- * 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 org.apache.cxf.transport.http;
-
-import java.io.IOException;
-import java.net.HttpURLConnection;
-import java.net.URLConnection;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.helpers.CastUtils;
-import org.apache.cxf.helpers.HttpHeaderHelper;
-import org.apache.cxf.message.Message;
-import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
-import org.apache.cxf.transports.http.configuration.HTTPServerPolicy;
-import org.apache.cxf.version.Version;
-
-public class Headers {
-    /**
-     *  This constant is the Message(Map) key for the HttpURLConnection that
-     *  is used to get the response.
-     */
-    public static final String KEY_HTTP_CONNECTION = "http.connection";
-    public static final String PROTOCOL_HEADERS_CONTENT_TYPE = Message.CONTENT_TYPE.toLowerCase();
-    private static final String HTTP_HEADERS_SETCOOKIE = "Set-Cookie";
-
-    private static final Logger LOG = LogUtils.getL7dLogger(Headers.class);
-    private final Message message;
-    private final Map<String, List<String>> headers;
-
-    public Headers(Message message) {
-        this.message = message;
-        this.headers = getSetProtocolHeaders(message);
-    }
-
-    /**
-     * Write cookie header from given session cookies
-     * 
-     * @param sessionCookies
-     */
-    public void writeSessionCookies(Map<String, Cookie> sessionCookies) {
-        List<String> cookies = null;
-        for (String s : headers.keySet()) {
-            if (HttpHeaderHelper.COOKIE.equalsIgnoreCase(s)) {
-                cookies = headers.remove(s);
-                break;
-            }
-        }
-        if (cookies == null) {
-            cookies = new ArrayList<String>();
-        } else {
-            cookies = new ArrayList<String>(cookies);
-        }
-        headers.put(HttpHeaderHelper.COOKIE, cookies);
-        for (Cookie c : sessionCookies.values()) {
-            cookies.add(c.requestCookieHeader());
-        }
-    }
-
-    /**
-     * This call places HTTP Header strings into the headers that are relevant
-     * to the ClientPolicy that is set on this conduit by configuration.
-     * 
-     * REVISIT: A cookie is set statically from configuration? 
-     */
-    void setFromClientPolicy(HTTPClientPolicy policy) {
-        if (policy == null) {
-            return;
-        }
-        if (policy.isSetCacheControl()) {
-            headers.put("Cache-Control",
-                    createMutableList(policy.getCacheControl().value()));
-        }
-        if (policy.isSetHost()) {
-            headers.put("Host",
-                    createMutableList(policy.getHost()));
-        }
-        if (policy.isSetConnection()) {
-            headers.put("Connection",
-                    createMutableList(policy.getConnection().value()));
-        }
-        if (policy.isSetAccept()) {
-            headers.put("Accept",
-                    createMutableList(policy.getAccept()));
-        } else if (!headers.containsKey("Accept")) {
-            headers.put("Accept", createMutableList("*/*"));
-        }
-        if (policy.isSetAcceptEncoding()) {
-            headers.put("Accept-Encoding",
-                    createMutableList(policy.getAcceptEncoding()));
-        }
-        if (policy.isSetAcceptLanguage()) {
-            headers.put("Accept-Language",
-                    createMutableList(policy.getAcceptLanguage()));
-        }
-        if (policy.isSetContentType()) {
-            message.put(Message.CONTENT_TYPE, policy.getContentType());
-        }
-        if (policy.isSetCookie()) {
-            headers.put("Cookie",
-                    createMutableList(policy.getCookie()));
-        }
-        if (policy.isSetBrowserType()) {
-            headers.put("BrowserType",
-                    createMutableList(policy.getBrowserType()));
-        }
-        if (policy.isSetReferer()) {
-            headers.put("Referer",
-                    createMutableList(policy.getReferer()));
-        }
-    }
-    
-    void setFromServerPolicy(HTTPServerPolicy policy) {
-        if (policy.isSetCacheControl()) {
-            headers.put("Cache-Control",
-                        createMutableList(policy.getCacheControl().value()));
-        }
-        if (policy.isSetContentLocation()) {
-            headers.put("Content-Location",
-                        createMutableList(policy.getContentLocation()));
-        }
-        if (policy.isSetContentEncoding()) {
-            headers.put("Content-Encoding",
-                        createMutableList(policy.getContentEncoding()));
-        }
-        if (policy.isSetContentType()) {
-            headers.put(HttpHeaderHelper.CONTENT_TYPE,
-                        createMutableList(policy.getContentType()));
-        }
-        if (policy.isSetServerType()) {
-            headers.put("Server",
-                        createMutableList(policy.getServerType()));
-        }
-        if (policy.isSetHonorKeepAlive() && !policy.isHonorKeepAlive()) {
-            headers.put("Connection",
-                        createMutableList("close"));
-        } else if (policy.isSetKeepAliveParameters()) {
-            headers.put("Keep-Alive", createMutableList(policy.getKeepAliveParameters()));
-        }
-        
-    
-        
-    /*
-     * TODO - hook up these policies
-    <xs:attribute name="SuppressClientSendErrors" type="xs:boolean" use="optional" default="false">
-    <xs:attribute name="SuppressClientReceiveErrors" type="xs:boolean" use="optional" default="false">
-    */
-    }
-
-    public void removeAuthorizationHeaders() {
-        headers.remove("Authorization");
-        headers.remove("Proxy-Authorization");
-    }
-    
-    public void setAuthorization(String authorization) {
-        headers.put("Authorization",
-                createMutableList(authorization));
-    }
-    
-    public void setProxyAuthorization(String authorization) {
-        headers.put("Proxy-Authorization",
-                createMutableList(authorization));
-    }
-    
-    
-    /**
-     * While extracting the Message.PROTOCOL_HEADERS property from the Message,
-     * this call ensures that the Message.PROTOCOL_HEADERS property is
-     * set on the Message. If it is not set, an empty map is placed there, and
-     * then returned.
-     * 
-     * @param message The outbound message
-     * @return The PROTOCOL_HEADERS map
-     */
-    public static Map<String, List<String>> getSetProtocolHeaders(final Message message) {
-        Map<String, List<String>> headers =
-            CastUtils.cast((Map<?, ?>)message.get(Message.PROTOCOL_HEADERS));        
-        if (null == headers) {
-            headers = new LinkedHashMap<String, List<String>>();
-        } else if (headers instanceof HashMap) {
-            headers = new LinkedHashMap<String, List<String>>(headers);
-        }
-        message.put(Message.PROTOCOL_HEADERS, headers);
-        return headers;
-    }
-
-    public void readFromConnection(HttpURLConnection connection) {
-        Map<String, List<String>> origHeaders = connection.getHeaderFields();
-        headers.clear();
-        for (String key : connection.getHeaderFields().keySet()) {
-            if (key != null) {
-                headers.put(HttpHeaderHelper.getHeaderKey(key), 
-                    origHeaders.get(key));
-            }
-        }
-    }
-
-    private static List<String> createMutableList(String val) {
-        return new ArrayList<String>(Arrays.asList(new String[] {val}));
-    }
-    
-    /**
-     * This procedure logs the PROTOCOL_HEADERS from the 
-     * Message at the specified logging level.
-     * 
-     * @param level   The Logging Level.
-     * @param headers The Message protocol headers.
-     */
-    void logProtocolHeaders(Level level) {
-        for (String header : headers.keySet()) {
-            List<String> headerList = headers.get(header);
-            for (String value : headerList) {
-                LOG.log(level, header + ": " + value);
-            }
-        }
-    }
-    
-    /**
-     * Set content type and protocol headers (Message.PROTOCOL_HEADERS) headers into the URL
-     * connection. 
-     * Note, this does not mean they immediately get written to the output
-     * stream or the wire. They just just get set on the HTTP request.
-     * 
-     * @param connection 
-     * @throws IOException
-     */
-    public void setProtocolHeadersInConnection(HttpURLConnection connection) throws IOException {
-        String ct = determineContentType();
-        connection.setRequestProperty(HttpHeaderHelper.CONTENT_TYPE, ct);
-        transferProtocolHeadersToURLConnection(connection);
-        logProtocolHeaders(Level.FINE);
-    }
-
-    private String determineContentType() {
-        String ct  = (String)message.get(Message.CONTENT_TYPE);
-        String enc = (String)message.get(Message.ENCODING);
-
-        if (null != ct) {
-            if (enc != null 
-                && ct.indexOf("charset=") == -1
-                && !ct.toLowerCase().contains("multipart/related")) {
-                ct = ct + "; charset=" + enc;
-            }
-        } else if (enc != null) {
-            ct = "text/xml; charset=" + enc;
-        } else {
-            ct = "text/xml";
-        }
-        return ct;
-    }
-    
-    /**
-     * This procedure sets the URLConnection request properties
-     * from the PROTOCOL_HEADERS in the message.
-     */
-    private void transferProtocolHeadersToURLConnection(URLConnection connection) {
-        for (String header : headers.keySet()) {
-            List<String> headerList = headers.get(header);
-            if (HttpHeaderHelper.CONTENT_TYPE.equalsIgnoreCase(header)) {
-                continue;
-            }
-            if (HttpHeaderHelper.COOKIE.equalsIgnoreCase(header)) {
-                for (String s : headerList) {
-                    connection.addRequestProperty(HttpHeaderHelper.COOKIE, s);
-                }
-            } else {
-                StringBuilder b = new StringBuilder();
-                for (int i = 0; i < headerList.size(); i++) {
-                    b.append(headerList.get(i));
-                    if (i + 1 < headerList.size()) {
-                        b.append(',');
-                    }
-                }
-                connection.setRequestProperty(header, b.toString());
-            }
-        }
-        if (!connection.getRequestProperties().containsKey("User-Agent")) {
-            connection.addRequestProperty("User-Agent", Version.getCompleteVersionString());
-        }
-    }
-    
-    /**
-     * Copy the request headers into the message.
-     * 
-     * @param message the current message
-     * @param headers the current set of headers
-     */
-    protected void copyFromRequest(HttpServletRequest req) {
-
-        //TODO how to deal with the fields        
-        for (Enumeration<String> e = req.getHeaderNames(); e.hasMoreElements();) {
-            String fname = (String)e.nextElement();
-            String mappedName = HttpHeaderHelper.getHeaderKey(fname);
-            List<String> values;
-            if (headers.containsKey(mappedName)) {
-                values = headers.get(mappedName);
-            } else {
-                values = new ArrayList<String>();
-                headers.put(mappedName, values);
-            }
-            for (Enumeration<String> e2 = req.getHeaders(fname); e2.hasMoreElements();) {
-                String val = (String)e2.nextElement();
-                values.add(val);
-            }
-        }
-        headers.put(Message.CONTENT_TYPE, Collections.singletonList(req.getContentType()));
-        if (LOG.isLoggable(Level.FINE)) {
-            LOG.log(Level.FINE, "Request Headers: " + headers.toString());
-        }
-    }
-
-    private String getContentTypeFromMessage() {
-        final String ct  = (String)message.get(Message.CONTENT_TYPE);
-        final String enc = (String)message.get(Message.ENCODING);
-        
-        if (null != ct 
-            && null != enc
-            && ct.indexOf("charset=") == -1
-            && !ct.toLowerCase().contains("multipart/related")) {
-            return ct + "; charset=" + enc;
-        } else {
-            return ct;
-        }
-    }
-    
-    /**
-     * Copy the response headers into the response.
-     * 
-     * @param message the current message
-     * @param headers the current set of headers
-     */
-    protected void copyToResponse(HttpServletResponse response) {
-        String contentType = getContentTypeFromMessage();
- 
-        if (!headers.containsKey(Message.CONTENT_TYPE) && contentType != null) {
-            response.setContentType(contentType);
-        }
-
-        for (Iterator<?> iter = headers.keySet().iterator(); iter.hasNext();) {
-            String header = (String)iter.next();
-            List<?> headerList = (List<?>)headers.get(header);
-            StringBuilder sb = new StringBuilder();
-
-            if (HTTP_HEADERS_SETCOOKIE.equals(header)) {
-                for (int i = 0; i < headerList.size(); i++) {
-                    response.addHeader(header, headerList.get(i).toString());
-                }
-            } else {
-                for (int i = 0; i < headerList.size(); i++) {
-                    sb.append(headerList.get(i));
-                    if (i + 1 < headerList.size()) {
-                        sb.append(',');
-                    }
-                }
-            }
-
-            response.addHeader(header, sb.toString());
-        }
-    }
-    
-    void removeContentType() {
-        if (headers.containsKey(PROTOCOL_HEADERS_CONTENT_TYPE)) {
-            headers.remove(PROTOCOL_HEADERS_CONTENT_TYPE);
-        }
-    }
-
-    public String getAuthorization() {
-        if (headers.containsKey("Authorization")) {
-            List<String> authorizationLines = headers.get("Authorization"); 
-            return authorizationLines.get(0);
-        } else {
-            return null;
-        }
-    }
-
-}
+/**
+ * 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
+ *
+ * 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 org.apache.cxf.transport.http;
+
+import java.io.IOException;
+import java.net.HttpURLConnection;
+import java.net.URLConnection;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.helpers.CastUtils;
+import org.apache.cxf.helpers.HttpHeaderHelper;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
+import org.apache.cxf.transports.http.configuration.HTTPServerPolicy;
+import org.apache.cxf.version.Version;
+
+public class Headers {
+    /**
+     *  This constant is the Message(Map) key for the HttpURLConnection that
+     *  is used to get the response.
+     */
+    public static final String KEY_HTTP_CONNECTION = "http.connection";
+    public static final String PROTOCOL_HEADERS_CONTENT_TYPE = Message.CONTENT_TYPE.toLowerCase();
+    private static final String HTTP_HEADERS_SETCOOKIE = "Set-Cookie";
+
+    private static final Logger LOG = LogUtils.getL7dLogger(Headers.class);
+    private final Message message;
+    private final Map<String, List<String>> headers;
+
+    public Headers(Message message) {
+        this.message = message;
+        this.headers = getSetProtocolHeaders(message);
+    }
+
+    /**
+     * Write cookie header from given session cookies
+     * 
+     * @param sessionCookies
+     */
+    public void writeSessionCookies(Map<String, Cookie> sessionCookies) {
+        List<String> cookies = null;
+        for (String s : headers.keySet()) {
+            if (HttpHeaderHelper.COOKIE.equalsIgnoreCase(s)) {
+                cookies = headers.remove(s);
+                break;
+            }
+        }
+        if (cookies == null) {
+            cookies = new ArrayList<String>();
+        } else {
+            cookies = new ArrayList<String>(cookies);
+        }
+        headers.put(HttpHeaderHelper.COOKIE, cookies);
+        for (Cookie c : sessionCookies.values()) {
+            cookies.add(c.requestCookieHeader());
+        }
+    }
+
+    /**
+     * This call places HTTP Header strings into the headers that are relevant
+     * to the ClientPolicy that is set on this conduit by configuration.
+     * 
+     * REVISIT: A cookie is set statically from configuration? 
+     */
+    void setFromClientPolicy(HTTPClientPolicy policy) {
+        if (policy == null) {
+            return;
+        }
+        if (policy.isSetCacheControl()) {
+            headers.put("Cache-Control",
+                    createMutableList(policy.getCacheControl().value()));
+        }
+        if (policy.isSetHost()) {
+            headers.put("Host",
+                    createMutableList(policy.getHost()));
+        }
+        if (policy.isSetConnection()) {
+            headers.put("Connection",
+                    createMutableList(policy.getConnection().value()));
+        }
+        if (policy.isSetAccept()) {
+            headers.put("Accept",
+                    createMutableList(policy.getAccept()));
+        } else if (!headers.containsKey("Accept")) {
+            headers.put("Accept", createMutableList("*/*"));
+        }
+        if (policy.isSetAcceptEncoding()) {
+            headers.put("Accept-Encoding",
+                    createMutableList(policy.getAcceptEncoding()));
+        }
+        if (policy.isSetAcceptLanguage()) {
+            headers.put("Accept-Language",
+                    createMutableList(policy.getAcceptLanguage()));
+        }
+        if (policy.isSetContentType()) {
+            message.put(Message.CONTENT_TYPE, policy.getContentType());
+        }
+        if (policy.isSetCookie()) {
+            headers.put("Cookie",
+                    createMutableList(policy.getCookie()));
+        }
+        if (policy.isSetBrowserType()) {
+            headers.put("BrowserType",
+                    createMutableList(policy.getBrowserType()));
+        }
+        if (policy.isSetReferer()) {
+            headers.put("Referer",
+                    createMutableList(policy.getReferer()));
+        }
+    }
+    
+    void setFromServerPolicy(HTTPServerPolicy policy) {
+        if (policy.isSetCacheControl()) {
+            headers.put("Cache-Control",
+                        createMutableList(policy.getCacheControl().value()));
+        }
+        if (policy.isSetContentLocation()) {
+            headers.put("Content-Location",
+                        createMutableList(policy.getContentLocation()));
+        }
+        if (policy.isSetContentEncoding()) {
+            headers.put("Content-Encoding",
+                        createMutableList(policy.getContentEncoding()));
+        }
+        if (policy.isSetContentType()) {
+            headers.put(HttpHeaderHelper.CONTENT_TYPE,
+                        createMutableList(policy.getContentType()));
+        }
+        if (policy.isSetServerType()) {
+            headers.put("Server",
+                        createMutableList(policy.getServerType()));
+        }
+        if (policy.isSetHonorKeepAlive() && !policy.isHonorKeepAlive()) {
+            headers.put("Connection",
+                        createMutableList("close"));
+        } else if (policy.isSetKeepAliveParameters()) {
+            headers.put("Keep-Alive", createMutableList(policy.getKeepAliveParameters()));
+        }
+        
+    
+        
+    /*
+     * TODO - hook up these policies
+    <xs:attribute name="SuppressClientSendErrors" type="xs:boolean" use="optional" default="false">
+    <xs:attribute name="SuppressClientReceiveErrors" type="xs:boolean" use="optional" default="false">
+    */
+    }
+
+    public void removeAuthorizationHeaders() {
+        headers.remove("Authorization");
+        headers.remove("Proxy-Authorization");
+    }
+    
+    public void setAuthorization(String authorization) {
+        headers.put("Authorization",
+                createMutableList(authorization));
+    }
+    
+    public void setProxyAuthorization(String authorization) {
+        headers.put("Proxy-Authorization",
+                createMutableList(authorization));
+    }
+    
+    
+    /**
+     * While extracting the Message.PROTOCOL_HEADERS property from the Message,
+     * this call ensures that the Message.PROTOCOL_HEADERS property is
+     * set on the Message. If it is not set, an empty map is placed there, and
+     * then returned.
+     * 
+     * @param message The outbound message
+     * @return The PROTOCOL_HEADERS map
+     */
+    public static Map<String, List<String>> getSetProtocolHeaders(final Message message) {
+        Map<String, List<String>> headers =
+            CastUtils.cast((Map<?, ?>)message.get(Message.PROTOCOL_HEADERS));        
+        if (null == headers) {
+            headers = new LinkedHashMap<String, List<String>>();
+        } else if (headers instanceof HashMap) {
+            headers = new LinkedHashMap<String, List<String>>(headers);
+        }
+        message.put(Message.PROTOCOL_HEADERS, headers);
+        return headers;
+    }
+
+    public void readFromConnection(HttpURLConnection connection) {
+        Map<String, List<String>> origHeaders = connection.getHeaderFields();
+        headers.clear();
+        for (String key : connection.getHeaderFields().keySet()) {
+            if (key != null) {
+                headers.put(HttpHeaderHelper.getHeaderKey(key), 
+                    origHeaders.get(key));
+            }
+        }
+    }
+
+    private static List<String> createMutableList(String val) {
+        return new ArrayList<String>(Arrays.asList(new String[] {val}));
+    }
+    
+    /**
+     * This procedure logs the PROTOCOL_HEADERS from the 
+     * Message at the specified logging level.
+     * 
+     * @param level   The Logging Level.
+     * @param headers The Message protocol headers.
+     */
+    void logProtocolHeaders(Level level) {
+        for (String header : headers.keySet()) {
+            List<String> headerList = headers.get(header);
+            for (String value : headerList) {
+                LOG.log(level, header + ": " + value);
+            }
+        }
+    }
+    
+    /**
+     * Set content type and protocol headers (Message.PROTOCOL_HEADERS) headers into the URL
+     * connection. 
+     * Note, this does not mean they immediately get written to the output
+     * stream or the wire. They just just get set on the HTTP request.
+     * 
+     * @param connection 
+     * @throws IOException
+     */
+    public void setProtocolHeadersInConnection(HttpURLConnection connection) throws IOException {
+        String ct = determineContentType();
+        connection.setRequestProperty(HttpHeaderHelper.CONTENT_TYPE, ct);
+        transferProtocolHeadersToURLConnection(connection);
+        logProtocolHeaders(Level.FINE);
+    }
+
+    private String determineContentType() {
+        String ct  = (String)message.get(Message.CONTENT_TYPE);
+        String enc = (String)message.get(Message.ENCODING);
+
+        if (null != ct) {
+            if (enc != null 
+                && ct.indexOf("charset=") == -1
+                && !ct.toLowerCase().contains("multipart/related")) {
+                ct = ct + "; charset=" + enc;
+            }
+        } else if (enc != null) {
+            ct = "text/xml; charset=" + enc;
+        } else {
+            ct = "text/xml";
+        }
+        return ct;
+    }
+    
+    /**
+     * This procedure sets the URLConnection request properties
+     * from the PROTOCOL_HEADERS in the message.
+     */
+    private void transferProtocolHeadersToURLConnection(URLConnection connection) {
+        for (String header : headers.keySet()) {
+            List<String> headerList = headers.get(header);
+            if (HttpHeaderHelper.CONTENT_TYPE.equalsIgnoreCase(header)) {
+                continue;
+            }
+            if (HttpHeaderHelper.COOKIE.equalsIgnoreCase(header)) {
+                for (String s : headerList) {
+                    connection.addRequestProperty(HttpHeaderHelper.COOKIE, s);
+                }
+            } else {
+                StringBuilder b = new StringBuilder();
+                for (int i = 0; i < headerList.size(); i++) {
+                    b.append(headerList.get(i));
+                    if (i + 1 < headerList.size()) {
+                        b.append(',');
+                    }
+                }
+                connection.setRequestProperty(header, b.toString());
+            }
+        }
+        if (!connection.getRequestProperties().containsKey("User-Agent")) {
+            connection.addRequestProperty("User-Agent", Version.getCompleteVersionString());
+        }
+    }
+    
+    /**
+     * Copy the request headers into the message.
+     * 
+     * @param message the current message
+     * @param headers the current set of headers
+     */
+    protected void copyFromRequest(HttpServletRequest req) {
+
+        //TODO how to deal with the fields        
+        for (Enumeration<String> e = req.getHeaderNames(); e.hasMoreElements();) {
+            String fname = (String)e.nextElement();
+            String mappedName = HttpHeaderHelper.getHeaderKey(fname);
+            List<String> values;
+            if (headers.containsKey(mappedName)) {
+                values = headers.get(mappedName);
+            } else {
+                values = new ArrayList<String>();
+                headers.put(mappedName, values);
+            }
+            for (Enumeration<String> e2 = req.getHeaders(fname); e2.hasMoreElements();) {
+                String val = (String)e2.nextElement();
+                values.add(val);
+            }
+        }
+        headers.put(Message.CONTENT_TYPE, Collections.singletonList(req.getContentType()));
+        if (LOG.isLoggable(Level.FINE)) {
+            LOG.log(Level.FINE, "Request Headers: " + headers.toString());
+        }
+    }
+
+    private String getContentTypeFromMessage() {
+        final String ct  = (String)message.get(Message.CONTENT_TYPE);
+        final String enc = (String)message.get(Message.ENCODING);
+        
+        if (null != ct 
+            && null != enc
+            && ct.indexOf("charset=") == -1
+            && !ct.toLowerCase().contains("multipart/related")) {
+            return ct + "; charset=" + enc;
+        } else {
+            return ct;
+        }
+    }
+    
+    /**
+     * Copy the response headers into the response.
+     * 
+     * @param message the current message
+     * @param headers the current set of headers
+     */
+    protected void copyToResponse(HttpServletResponse response) {
+        String contentType = getContentTypeFromMessage();
+ 
+        if (!headers.containsKey(Message.CONTENT_TYPE) && contentType != null) {
+            response.setContentType(contentType);
+        }
+
+        for (Iterator<?> iter = headers.keySet().iterator(); iter.hasNext();) {
+            String header = (String)iter.next();
+            List<?> headerList = (List<?>)headers.get(header);
+            StringBuilder sb = new StringBuilder();
+
+            if (HTTP_HEADERS_SETCOOKIE.equals(header)) {
+                for (int i = 0; i < headerList.size(); i++) {
+                    response.addHeader(header, headerList.get(i).toString());
+                }
+            } else {
+                for (int i = 0; i < headerList.size(); i++) {
+                    sb.append(headerList.get(i));
+                    if (i + 1 < headerList.size()) {
+                        sb.append(',');
+                    }
+                }
+            }
+
+            response.addHeader(header, sb.toString());
+        }
+    }
+    
+    void removeContentType() {
+        if (headers.containsKey(PROTOCOL_HEADERS_CONTENT_TYPE)) {
+            headers.remove(PROTOCOL_HEADERS_CONTENT_TYPE);
+        }
+    }
+
+    public String getAuthorization() {
+        if (headers.containsKey("Authorization")) {
+            List<String> authorizationLines = headers.get("Authorization"); 
+            return authorizationLines.get(0);
+        } else {
+            return null;
+        }
+    }
+
+}

Propchange: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Headers.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Headers.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HttpServletRequestSnapshot.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HttpServletRequestSnapshot.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/ProxyFactory.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/ProxyFactory.java?rev=1057393&r1=1057392&r2=1057393&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/ProxyFactory.java (original)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/ProxyFactory.java Mon Jan 10 22:07:10 2011
@@ -1,145 +1,145 @@
-/**
- * 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
- *
- * 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 org.apache.cxf.transport.http;
-
-import java.net.InetSocketAddress;
-import java.net.Proxy;
-import java.net.URL;
-import java.util.regex.Pattern;
-
-import org.apache.cxf.common.util.StringUtils;
-import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
-import org.apache.cxf.transports.http.configuration.ProxyServerType;
-
-public class ProxyFactory {
-    /**
-     * JVM/System property name holding the hostname of the http proxy.
-     */
-    private static final String HTTP_PROXY_HOST = "http.proxyHost";
-
-    /**
-     * JVM/System property name holding the port of the http proxy.
-     */
-    private static final String HTTP_PROXY_PORT = "http.proxyPort";
-
-    /**
-     * JVM/System property name holding the list of hosts/patterns that
-     * should not use the proxy configuration.
-     */
-    private static final String HTTP_NON_PROXY_HOSTS = "http.nonProxyHosts";
-
-    /**
-     * This field holds ONLY the static System proxy configuration:
-     * + http.proxyHost
-     * + http.proxyPort (default 8080)
-     * + http.nonProxyHosts (default null)
-     * It is initialized at the instance creation (and may be null
-     * if there is no appropriate System properties)
-     */
-    private HTTPClientPolicy systemProxyConfiguration;
-    
-    public ProxyFactory() {
-        this.systemProxyConfiguration = createSystemProxyConfiguration();
-    }
-    
-    private static HTTPClientPolicy createSystemProxyConfiguration() {
-        // Retrieve system properties (if any)
-        HTTPClientPolicy systemProxyConfiguration = null;
-        String proxyHost = System.getProperty(HTTP_PROXY_HOST);
-        if (proxyHost != null) {
-            // System is configured with a proxy, use it
-
-            systemProxyConfiguration = new HTTPClientPolicy();
-            systemProxyConfiguration.setProxyServer(proxyHost);
-            systemProxyConfiguration.setProxyServerType(ProxyServerType.HTTP);
-
-            // 8080 is the default proxy port value as per some documentation
-            String proxyPort = System.getProperty(HTTP_PROXY_PORT, "8080");
-            systemProxyConfiguration.setProxyServerPort(Integer.valueOf(proxyPort));
-
-            // Load non proxy hosts
-            String nonProxyHosts = System.getProperty(HTTP_NON_PROXY_HOSTS);
-            if (!StringUtils.isEmpty(nonProxyHosts)) {
-                systemProxyConfiguration.setNonProxyHosts(nonProxyHosts);
-            }
-        }
-        return systemProxyConfiguration;
-    }
-    
-    /**
-     * This method returns the Proxy server should it be set on the 
-     * Client Side Policy.
-     * 
-     * @return The proxy server or null, if not set.
-     */
-    public Proxy createProxy(HTTPClientPolicy policy, URL currentUrl) {
-        if (policy != null) {
-            // Maybe the user has provided some proxy information
-            if (policy.isSetProxyServer()
-                && !StringUtils.isEmpty(policy.getProxyServer())) {
-                return getProxy(policy, currentUrl.getHost());
-            } else {
-                // There is a policy but no Proxy configuration,
-                // fallback on the system proxy configuration
-                return getSystemProxy(currentUrl.getHost());
-            }
-        } else {
-            // Use system proxy configuration
-            return getSystemProxy(currentUrl.getHost());
-        }
-    }
-
-    /**
-     * Get the system proxy (if any) for the given URL's host.
-     */
-    private Proxy getSystemProxy(String hostname) {
-        if (systemProxyConfiguration != null) {
-            return getProxy(systemProxyConfiguration, hostname);
-        }
-
-        // No proxy configured
-        return null;
-    }
-
-    /**
-     * Honor the nonProxyHosts property value (if set).
-     */
-    private Proxy getProxy(final HTTPClientPolicy policy, final String hostname) {
-        if (policy.isSetNonProxyHosts()) {
-
-            // Try to match the URL hostname with the exclusion pattern
-            Pattern pattern = PatternBuilder.build(policy.getNonProxyHosts());
-            if (pattern.matcher(hostname).matches()) {
-                // Excluded hostname -> no proxy
-                return null;
-            }
-        }
-        // Either nonProxyHosts is not set or the pattern did not match
-        return createProxy(policy);
-    }
-
-    /**
-     * Construct a new {@code Proxy} instance from the given policy.
-     */
-    private Proxy createProxy(final HTTPClientPolicy policy) {
-        return new Proxy(Proxy.Type.valueOf(policy.getProxyServerType().toString()),
-                         new InetSocketAddress(policy.getProxyServer(),
-                                               policy.getProxyServerPort()));
-    }
-}
+/**
+ * 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
+ *
+ * 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 org.apache.cxf.transport.http;
+
+import java.net.InetSocketAddress;
+import java.net.Proxy;
+import java.net.URL;
+import java.util.regex.Pattern;
+
+import org.apache.cxf.common.util.StringUtils;
+import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
+import org.apache.cxf.transports.http.configuration.ProxyServerType;
+
+public class ProxyFactory {
+    /**
+     * JVM/System property name holding the hostname of the http proxy.
+     */
+    private static final String HTTP_PROXY_HOST = "http.proxyHost";
+
+    /**
+     * JVM/System property name holding the port of the http proxy.
+     */
+    private static final String HTTP_PROXY_PORT = "http.proxyPort";
+
+    /**
+     * JVM/System property name holding the list of hosts/patterns that
+     * should not use the proxy configuration.
+     */
+    private static final String HTTP_NON_PROXY_HOSTS = "http.nonProxyHosts";
+
+    /**
+     * This field holds ONLY the static System proxy configuration:
+     * + http.proxyHost
+     * + http.proxyPort (default 8080)
+     * + http.nonProxyHosts (default null)
+     * It is initialized at the instance creation (and may be null
+     * if there is no appropriate System properties)
+     */
+    private HTTPClientPolicy systemProxyConfiguration;
+    
+    public ProxyFactory() {
+        this.systemProxyConfiguration = createSystemProxyConfiguration();
+    }
+    
+    private static HTTPClientPolicy createSystemProxyConfiguration() {
+        // Retrieve system properties (if any)
+        HTTPClientPolicy systemProxyConfiguration = null;
+        String proxyHost = System.getProperty(HTTP_PROXY_HOST);
+        if (proxyHost != null) {
+            // System is configured with a proxy, use it
+
+            systemProxyConfiguration = new HTTPClientPolicy();
+            systemProxyConfiguration.setProxyServer(proxyHost);
+            systemProxyConfiguration.setProxyServerType(ProxyServerType.HTTP);
+
+            // 8080 is the default proxy port value as per some documentation
+            String proxyPort = System.getProperty(HTTP_PROXY_PORT, "8080");
+            systemProxyConfiguration.setProxyServerPort(Integer.valueOf(proxyPort));
+
+            // Load non proxy hosts
+            String nonProxyHosts = System.getProperty(HTTP_NON_PROXY_HOSTS);
+            if (!StringUtils.isEmpty(nonProxyHosts)) {
+                systemProxyConfiguration.setNonProxyHosts(nonProxyHosts);
+            }
+        }
+        return systemProxyConfiguration;
+    }
+    
+    /**
+     * This method returns the Proxy server should it be set on the 
+     * Client Side Policy.
+     * 
+     * @return The proxy server or null, if not set.
+     */
+    public Proxy createProxy(HTTPClientPolicy policy, URL currentUrl) {
+        if (policy != null) {
+            // Maybe the user has provided some proxy information
+            if (policy.isSetProxyServer()
+                && !StringUtils.isEmpty(policy.getProxyServer())) {
+                return getProxy(policy, currentUrl.getHost());
+            } else {
+                // There is a policy but no Proxy configuration,
+                // fallback on the system proxy configuration
+                return getSystemProxy(currentUrl.getHost());
+            }
+        } else {
+            // Use system proxy configuration
+            return getSystemProxy(currentUrl.getHost());
+        }
+    }
+
+    /**
+     * Get the system proxy (if any) for the given URL's host.
+     */
+    private Proxy getSystemProxy(String hostname) {
+        if (systemProxyConfiguration != null) {
+            return getProxy(systemProxyConfiguration, hostname);
+        }
+
+        // No proxy configured
+        return null;
+    }
+
+    /**
+     * Honor the nonProxyHosts property value (if set).
+     */
+    private Proxy getProxy(final HTTPClientPolicy policy, final String hostname) {
+        if (policy.isSetNonProxyHosts()) {
+
+            // Try to match the URL hostname with the exclusion pattern
+            Pattern pattern = PatternBuilder.build(policy.getNonProxyHosts());
+            if (pattern.matcher(hostname).matches()) {
+                // Excluded hostname -> no proxy
+                return null;
+            }
+        }
+        // Either nonProxyHosts is not set or the pattern did not match
+        return createProxy(policy);
+    }
+
+    /**
+     * Construct a new {@code Proxy} instance from the given policy.
+     */
+    private Proxy createProxy(final HTTPClientPolicy policy) {
+        return new Proxy(Proxy.Type.valueOf(policy.getProxyServerType().toString()),
+                         new InetSocketAddress(policy.getProxyServer(),
+                                               policy.getProxyServerPort()));
+    }
+}

Propchange: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/ProxyFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/ProxyFactory.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/TrustDecisionUtil.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/TrustDecisionUtil.java?rev=1057393&r1=1057392&r2=1057393&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/TrustDecisionUtil.java (original)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/TrustDecisionUtil.java Mon Jan 10 22:07:10 2011
@@ -1,112 +1,112 @@
-/**
- * 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
- *
- * 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 org.apache.cxf.transport.http;
-
-import java.io.IOException;
-import java.net.HttpURLConnection;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.message.Message;
-import org.apache.cxf.transport.https.HttpsURLConnectionInfo;
-
-final class TrustDecisionUtil {
-    private static final Logger LOG = LogUtils.getL7dLogger(TrustDecisionUtil.class);
-    
-    private TrustDecisionUtil() {
-    }
-
-    /**
-     * This call must take place before anything is written to the 
-     * URLConnection. The URLConnection.connect() will be called in order 
-     * to get the connection information. 
-     * 
-     * This method is invoked just after setURLRequestHeaders() from the 
-     * WrappedOutputStream before it writes data to the URLConnection.
-     * 
-     * If trust cannot be established the Trust Decider implemenation
-     * throws an IOException.
-     * 
-     * @param message      The message being sent.
-     * @throws IOException This exception is thrown if trust cannot be
-     *                     established by the configured MessageTrustDecider.
-     * @see MessageTrustDecider
-     */
-    static void makeTrustDecision(
-            MessageTrustDecider trustDecider, 
-            Message message,
-            HttpURLConnection connection, 
-            String conduitName) throws IOException {
-    
-        MessageTrustDecider decider2 = message.get(MessageTrustDecider.class);
-        if (trustDecider != null || decider2 != null) {
-            try {
-                // We must connect or we will not get the credentials.
-                // The call is (said to be) ingored internally if
-                // already connected.
-                connection.connect();
-                HttpsURLConnectionInfo info = new HttpsURLConnectionInfo(connection);
-                if (trustDecider != null) {
-                    trustDecider.establishTrust(
-                            conduitName, 
-                        info,
-                        message);
-                    if (LOG.isLoggable(Level.FINE)) {
-                        LOG.log(Level.FINE, "Trust Decider "
-                            + trustDecider.getLogicalName()
-                            + " considers Conduit "
-                            + conduitName 
-                            + " trusted.");
-                    }
-                }
-                if (decider2 != null) {
-                    decider2.establishTrust(conduitName, 
-                                            info,
-                                            message);
-                    if (LOG.isLoggable(Level.FINE)) {
-                        LOG.log(Level.FINE, "Trust Decider "
-                            + decider2.getLogicalName()
-                            + " considers Conduit "
-                            + conduitName 
-                            + " trusted.");
-                    }
-                }
-            } catch (UntrustedURLConnectionIOException untrustedEx) {
-                connection.disconnect();
-                if (LOG.isLoggable(Level.FINE)) {
-                    LOG.log(Level.FINE, "Trust Decider "
-                        + trustDecider.getLogicalName()
-                        + " considers Conduit "
-                        + conduitName 
-                        + " untrusted.", untrustedEx);
-                }
-                throw untrustedEx;
-            }
-        } else {
-            // This case, when there is no trust decider, a trust
-            // decision should be a matter of policy.
-            if (LOG.isLoggable(Level.FINE)) {
-                LOG.log(Level.FINE, "No Trust Decider for Conduit '"
-                    + conduitName
-                    + "'. An afirmative Trust Decision is assumed.");
-            }
-        }
-    }
-}
+/**
+ * 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
+ *
+ * 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 org.apache.cxf.transport.http;
+
+import java.io.IOException;
+import java.net.HttpURLConnection;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.transport.https.HttpsURLConnectionInfo;
+
+final class TrustDecisionUtil {
+    private static final Logger LOG = LogUtils.getL7dLogger(TrustDecisionUtil.class);
+    
+    private TrustDecisionUtil() {
+    }
+
+    /**
+     * This call must take place before anything is written to the 
+     * URLConnection. The URLConnection.connect() will be called in order 
+     * to get the connection information. 
+     * 
+     * This method is invoked just after setURLRequestHeaders() from the 
+     * WrappedOutputStream before it writes data to the URLConnection.
+     * 
+     * If trust cannot be established the Trust Decider implemenation
+     * throws an IOException.
+     * 
+     * @param message      The message being sent.
+     * @throws IOException This exception is thrown if trust cannot be
+     *                     established by the configured MessageTrustDecider.
+     * @see MessageTrustDecider
+     */
+    static void makeTrustDecision(
+            MessageTrustDecider trustDecider, 
+            Message message,
+            HttpURLConnection connection, 
+            String conduitName) throws IOException {
+    
+        MessageTrustDecider decider2 = message.get(MessageTrustDecider.class);
+        if (trustDecider != null || decider2 != null) {
+            try {
+                // We must connect or we will not get the credentials.
+                // The call is (said to be) ingored internally if
+                // already connected.
+                connection.connect();
+                HttpsURLConnectionInfo info = new HttpsURLConnectionInfo(connection);
+                if (trustDecider != null) {
+                    trustDecider.establishTrust(
+                            conduitName, 
+                        info,
+                        message);
+                    if (LOG.isLoggable(Level.FINE)) {
+                        LOG.log(Level.FINE, "Trust Decider "
+                            + trustDecider.getLogicalName()
+                            + " considers Conduit "
+                            + conduitName 
+                            + " trusted.");
+                    }
+                }
+                if (decider2 != null) {
+                    decider2.establishTrust(conduitName, 
+                                            info,
+                                            message);
+                    if (LOG.isLoggable(Level.FINE)) {
+                        LOG.log(Level.FINE, "Trust Decider "
+                            + decider2.getLogicalName()
+                            + " considers Conduit "
+                            + conduitName 
+                            + " trusted.");
+                    }
+                }
+            } catch (UntrustedURLConnectionIOException untrustedEx) {
+                connection.disconnect();
+                if (LOG.isLoggable(Level.FINE)) {
+                    LOG.log(Level.FINE, "Trust Decider "
+                        + trustDecider.getLogicalName()
+                        + " considers Conduit "
+                        + conduitName 
+                        + " untrusted.", untrustedEx);
+                }
+                throw untrustedEx;
+            }
+        } else {
+            // This case, when there is no trust decider, a trust
+            // decision should be a matter of policy.
+            if (LOG.isLoggable(Level.FINE)) {
+                LOG.log(Level.FINE, "No Trust Decider for Conduit '"
+                    + conduitName
+                    + "'. An afirmative Trust Decision is assumed.");
+            }
+        }
+    }
+}

Propchange: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/TrustDecisionUtil.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/TrustDecisionUtil.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/auth/DefaultBasicAuthSupplier.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/auth/DefaultBasicAuthSupplier.java?rev=1057393&r1=1057392&r2=1057393&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/auth/DefaultBasicAuthSupplier.java (original)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/auth/DefaultBasicAuthSupplier.java Mon Jan 10 22:07:10 2011
@@ -1,53 +1,53 @@
-/**
- * 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
- *
- * 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 org.apache.cxf.transport.http.auth;
-
-import java.net.URL;
-
-import org.apache.cxf.common.util.Base64Utility;
-import org.apache.cxf.configuration.security.AuthorizationPolicy;
-import org.apache.cxf.message.Message;
-
-public final class DefaultBasicAuthSupplier implements HttpAuthSupplier {
-    public DefaultBasicAuthSupplier() {
-        super();
-    }
-
-    public boolean requiresRequestCaching() {
-        return false;
-    }
-    
-    public static String getBasicAuthHeader(String userName, String passwd) {
-        String userAndPass = userName + ":" + passwd;
-        return "Basic " + Base64Utility.encode(userAndPass.getBytes());
-    }
-
-    public String getAuthorization(AuthorizationPolicy  authPolicy,
-                                   URL currentURL,
-                                   Message message,
-                                   String fullHeader) {
-        if (authPolicy.getUserName() != null && authPolicy.getPassword() != null) {
-            return getBasicAuthHeader(authPolicy.getUserName(), 
-                                      authPolicy.getPassword());
-        } else {
-            return null;
-        }
-    }
-
+/**
+ * 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
+ *
+ * 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 org.apache.cxf.transport.http.auth;
+
+import java.net.URL;
+
+import org.apache.cxf.common.util.Base64Utility;
+import org.apache.cxf.configuration.security.AuthorizationPolicy;
+import org.apache.cxf.message.Message;
+
+public final class DefaultBasicAuthSupplier implements HttpAuthSupplier {
+    public DefaultBasicAuthSupplier() {
+        super();
+    }
+
+    public boolean requiresRequestCaching() {
+        return false;
+    }
+    
+    public static String getBasicAuthHeader(String userName, String passwd) {
+        String userAndPass = userName + ":" + passwd;
+        return "Basic " + Base64Utility.encode(userAndPass.getBytes());
+    }
+
+    public String getAuthorization(AuthorizationPolicy  authPolicy,
+                                   URL currentURL,
+                                   Message message,
+                                   String fullHeader) {
+        if (authPolicy.getUserName() != null && authPolicy.getPassword() != null) {
+            return getBasicAuthHeader(authPolicy.getUserName(), 
+                                      authPolicy.getPassword());
+        } else {
+            return null;
+        }
+    }
+
 }
\ No newline at end of file

Propchange: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/auth/DefaultBasicAuthSupplier.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/auth/DefaultBasicAuthSupplier.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/auth/HttpAuthHeader.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/auth/HttpAuthHeader.java?rev=1057393&r1=1057392&r2=1057393&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/auth/HttpAuthHeader.java (original)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/auth/HttpAuthHeader.java Mon Jan 10 22:07:10 2011
@@ -1,137 +1,137 @@
-/**
- * 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
- *
- * 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 org.apache.cxf.transport.http.auth;
-
-import java.io.IOException;
-import java.io.StreamTokenizer;
-import java.io.StringReader;
-import java.util.HashMap;
-import java.util.Map;
-
-public final class HttpAuthHeader {
-    public static final String AUTH_TYPE_BASIC = "Basic";
-    public static final String AUTH_TYPE_DIGEST = "Digest";
-    public static final String AUTH_TYPE_NEGOTIATE = "Negotiate";
-
-    private String fullHeader;
-    private String authType;
-    private String fullContent;
-    private Map<String, String> params;
-
-    public HttpAuthHeader(String fullHeader) {
-        this.fullHeader = (fullHeader == null) ? "" : fullHeader;
-        int spacePos = this.fullHeader.indexOf(' ');
-        if (spacePos == -1) {
-            this.authType = this.fullHeader;
-            this.fullContent = "";
-        } else {
-            this.authType = this.fullHeader.substring(0, spacePos);
-            this.fullContent = this.fullHeader.substring(spacePos + 1);
-        }
-        this.params = parseHeader();
-    }
-    
-    public HttpAuthHeader(String authType, Map<String, String> params) {
-        this.authType = authType;
-        this.params = params;
-        this.fullContent = paramsToString();
-        this.fullHeader = authType + " " + fullContent;
-    }
-    
-    private String paramsToString() {
-        StringBuilder builder = new StringBuilder();
-        boolean first = true;
-        for (String key : params.keySet()) {
-            String param = params.get(key);
-            if (param != null) {
-                if (!first) {
-                    builder.append(", ");
-                }
-                builder.append(key + "=\"" + param + "\"");
-                first = false;
-            }
-        }
-        return builder.toString();
-    }
-
-    private Map<String, String> parseHeader() {
-        Map<String, String> map = new HashMap<String, String>();
-        try {
-            StreamTokenizer tok = new StreamTokenizer(new StringReader(this.fullContent));
-            tok.quoteChar('"');
-            tok.quoteChar('\'');
-            tok.whitespaceChars('=', '=');
-            tok.whitespaceChars(',', ',');
-            
-            while (tok.nextToken() != StreamTokenizer.TT_EOF) {
-                String key = tok.sval;
-                if (tok.nextToken() == StreamTokenizer.TT_EOF) {
-                    map.put(key, null);
-                    return map;
-                }
-                String value = tok.sval;
-                map.put(key, value);
-            }
-        } catch (IOException ex) {
-            // ignore can´t happen for StringReader
-        }
-        return map;
-    }
-
-    /**
-     * Extracts the authorization realm from the 
-     * "WWW-Authenticate" Http response header.
-     * 
-     * @param authenticate content of the WWW-Authenticate header
-     * @return The realm, or null if it is non-existent.
-     */
-    public String getRealm() {
-        Map<String, String> map = parseHeader();
-        return map.get("realm");
-    }
-
-    public boolean authTypeIsDigest() {
-        return AUTH_TYPE_DIGEST.equals(this.authType);
-    }
-    
-    public boolean authTypeIsBasic() {
-        return AUTH_TYPE_BASIC.equals(this.authType);
-    }
-    
-    public boolean authTypeIsNegotiate() {
-        return AUTH_TYPE_DIGEST.equals(this.authType);
-    }
-    
-    public String getAuthType() {
-        return authType;
-    }
-
-    public String getFullContent() {
-        return fullContent;
-    }
-
-    public String getFullHeader() {
-        return this.fullHeader;
-    }
-
-    public Map<String, String> getParams() {
-        return params;
-    }
-
-}
+/**
+ * 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
+ *
+ * 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 org.apache.cxf.transport.http.auth;
+
+import java.io.IOException;
+import java.io.StreamTokenizer;
+import java.io.StringReader;
+import java.util.HashMap;
+import java.util.Map;
+
+public final class HttpAuthHeader {
+    public static final String AUTH_TYPE_BASIC = "Basic";
+    public static final String AUTH_TYPE_DIGEST = "Digest";
+    public static final String AUTH_TYPE_NEGOTIATE = "Negotiate";
+
+    private String fullHeader;
+    private String authType;
+    private String fullContent;
+    private Map<String, String> params;
+
+    public HttpAuthHeader(String fullHeader) {
+        this.fullHeader = (fullHeader == null) ? "" : fullHeader;
+        int spacePos = this.fullHeader.indexOf(' ');
+        if (spacePos == -1) {
+            this.authType = this.fullHeader;
+            this.fullContent = "";
+        } else {
+            this.authType = this.fullHeader.substring(0, spacePos);
+            this.fullContent = this.fullHeader.substring(spacePos + 1);
+        }
+        this.params = parseHeader();
+    }
+    
+    public HttpAuthHeader(String authType, Map<String, String> params) {
+        this.authType = authType;
+        this.params = params;
+        this.fullContent = paramsToString();
+        this.fullHeader = authType + " " + fullContent;
+    }
+    
+    private String paramsToString() {
+        StringBuilder builder = new StringBuilder();
+        boolean first = true;
+        for (String key : params.keySet()) {
+            String param = params.get(key);
+            if (param != null) {
+                if (!first) {
+                    builder.append(", ");
+                }
+                builder.append(key + "=\"" + param + "\"");
+                first = false;
+            }
+        }
+        return builder.toString();
+    }
+
+    private Map<String, String> parseHeader() {
+        Map<String, String> map = new HashMap<String, String>();
+        try {
+            StreamTokenizer tok = new StreamTokenizer(new StringReader(this.fullContent));
+            tok.quoteChar('"');
+            tok.quoteChar('\'');
+            tok.whitespaceChars('=', '=');
+            tok.whitespaceChars(',', ',');
+            
+            while (tok.nextToken() != StreamTokenizer.TT_EOF) {
+                String key = tok.sval;
+                if (tok.nextToken() == StreamTokenizer.TT_EOF) {
+                    map.put(key, null);
+                    return map;
+                }
+                String value = tok.sval;
+                map.put(key, value);
+            }
+        } catch (IOException ex) {
+            // ignore can´t happen for StringReader
+        }
+        return map;
+    }
+
+    /**
+     * Extracts the authorization realm from the 
+     * "WWW-Authenticate" Http response header.
+     * 
+     * @param authenticate content of the WWW-Authenticate header
+     * @return The realm, or null if it is non-existent.
+     */
+    public String getRealm() {
+        Map<String, String> map = parseHeader();
+        return map.get("realm");
+    }
+
+    public boolean authTypeIsDigest() {
+        return AUTH_TYPE_DIGEST.equals(this.authType);
+    }
+    
+    public boolean authTypeIsBasic() {
+        return AUTH_TYPE_BASIC.equals(this.authType);
+    }
+    
+    public boolean authTypeIsNegotiate() {
+        return AUTH_TYPE_DIGEST.equals(this.authType);
+    }
+    
+    public String getAuthType() {
+        return authType;
+    }
+
+    public String getFullContent() {
+        return fullContent;
+    }
+
+    public String getFullHeader() {
+        return this.fullHeader;
+    }
+
+    public Map<String, String> getParams() {
+        return params;
+    }
+
+}

Propchange: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/auth/HttpAuthHeader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/auth/HttpAuthHeader.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/auth/SpnegoAuthSupplier.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/auth/SpnegoAuthSupplier.java?rev=1057393&r1=1057392&r2=1057393&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/auth/SpnegoAuthSupplier.java (original)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/auth/SpnegoAuthSupplier.java Mon Jan 10 22:07:10 2011
@@ -1,172 +1,172 @@
-/**
- * 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
- *
- * 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 org.apache.cxf.transport.http.auth;
-
-import java.net.URL;
-import java.security.PrivilegedActionException;
-import java.security.PrivilegedExceptionAction;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import javax.security.auth.Subject;
-import javax.security.auth.callback.Callback;
-import javax.security.auth.callback.CallbackHandler;
-import javax.security.auth.callback.NameCallback;
-import javax.security.auth.callback.PasswordCallback;
-import javax.security.auth.login.LoginContext;
-import javax.security.auth.login.LoginException;
-
-import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.common.util.Base64Utility;
-import org.apache.cxf.configuration.security.AuthorizationPolicy;
-import org.apache.cxf.message.Message;
-import org.ietf.jgss.GSSContext;
-import org.ietf.jgss.GSSException;
-import org.ietf.jgss.GSSManager;
-import org.ietf.jgss.GSSName;
-import org.ietf.jgss.Oid;
-
-public class SpnegoAuthSupplier implements HttpAuthSupplier {
-    private static final String KERBEROS_OID = "1.2.840.113554.1.2.2";
-    //private static final String SPNEGO_OID = "1.3.6.1.5.5.2";
-
-    private static final Logger LOG = LogUtils.getL7dLogger(SpnegoAuthSupplier.class);
-
-    private LoginContext lc;
-    
-    public boolean requiresRequestCaching() {
-        return false;
-    }
-
-    public String getAuthorization(AuthorizationPolicy  authPolicy,
-                                    URL currentURL,
-                                    Message message,
-                                    String fullHeader) {
-        if (!HttpAuthHeader.AUTH_TYPE_NEGOTIATE.equals(authPolicy.getAuthorizationType())) {
-            return null;
-        }
-        try {
-            String spn = "HTTP/" + currentURL.getHost();
-            LOG.fine("Adding authorization service ticket for service principal name: " + spn);
-            byte[] token = getToken(authPolicy, spn);
-            return HttpAuthHeader.AUTH_TYPE_NEGOTIATE + " " + Base64Utility.encode(token);
-        } catch (LoginException e) {
-            throw new RuntimeException(e.getMessage(), e);
-        } catch (GSSException e) {
-            throw new RuntimeException(e.getMessage(), e);
-        }
-    }
-
-    /**
-     * Create and return service ticket token
-     * 
-     * @param authPolicy
-     * @param context
-     * @return
-     * @throws GSSException
-     * @throws LoginException
-     */
-    private byte[] getToken(AuthorizationPolicy authPolicy, final GSSContext context) throws GSSException,
-            LoginException {
-        final byte[] token = new byte[0];
-
-        if (authPolicy.getUserName() == null || authPolicy.getUserName().trim().length() == 0) {
-            return context.initSecContext(token, 0, token.length);
-        }
-
-        if (lc == null) {
-            lc = new LoginContext(authPolicy.getAuthorization(), getUsernamePasswordHandler(
-                authPolicy.getUserName(), authPolicy.getPassword()));
-            lc.login();
-        }
-
-        try {
-            return (byte[]) Subject.doAs(lc.getSubject(), new CreateServiceTicketAction(context, token));
-        } catch (PrivilegedActionException e) {
-            if (e.getCause() instanceof GSSException) {
-                throw (GSSException) e.getCause();
-            }
-            LOG.log(Level.SEVERE, "initSecContext", e);
-            return null;
-        }
-    }
-
-    /**
-     * Create and return a service ticket token for a given service principal
-     * name
-     * 
-     * @param proxyAuthPolicy
-     * @param spn
-     * @return service ticket token
-     * @throws GSSException
-     * @throws LoginException
-     */
-    private byte[] getToken(AuthorizationPolicy proxyAuthPolicy, String spn) throws GSSException, 
-        LoginException {
-        GSSManager manager = GSSManager.getInstance();
-        GSSName serverName = manager.createName(spn, null);
-
-        // TODO Is it correct to use kerberos oid instead of spnego here?
-        Oid oid = new Oid(KERBEROS_OID);
-        
-        GSSContext context = manager
-                .createContext(serverName.canonicalize(oid), oid, null, GSSContext.DEFAULT_LIFETIME);
-        // TODO Do we need mutual auth. Will the code we have really work with
-        // mutual auth?
-        context.requestMutualAuth(true);
-        // TODO Credential delegation could be a security hole if it was not
-        // intended. Both settings should be configurable
-        context.requestCredDeleg(true);
-
-        return getToken(proxyAuthPolicy, context);
-    }
-
-    private final class CreateServiceTicketAction implements PrivilegedExceptionAction<byte[]> {
-        private final GSSContext context;
-        private final byte[] token;
-
-        private CreateServiceTicketAction(GSSContext context, byte[] token) {
-            this.context = context;
-            this.token = token;
-        }
-
-        public byte[] run() throws GSSException {
-            return context.initSecContext(token, 0, token.length);
-        }
-    }
-    
-    public static CallbackHandler getUsernamePasswordHandler(final String username, final String password) {
-        final CallbackHandler handler = new CallbackHandler() {
-
-            public void handle(final Callback[] callback) {
-                for (int i = 0; i < callback.length; i++) {
-                    if (callback[i] instanceof NameCallback) {
-                        final NameCallback nameCallback = (NameCallback) callback[i];
-                        nameCallback.setName(username);
-                    } else if (callback[i] instanceof PasswordCallback) {
-                        final PasswordCallback passCallback = (PasswordCallback) callback[i];
-                        passCallback.setPassword(password.toCharArray());
-                    }
-                }
-            }
-        };
-        return handler;
-    }
-
-}
+/**
+ * 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
+ *
+ * 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 org.apache.cxf.transport.http.auth;
+
+import java.net.URL;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.security.auth.Subject;
+import javax.security.auth.callback.Callback;
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.callback.NameCallback;
+import javax.security.auth.callback.PasswordCallback;
+import javax.security.auth.login.LoginContext;
+import javax.security.auth.login.LoginException;
+
+import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.common.util.Base64Utility;
+import org.apache.cxf.configuration.security.AuthorizationPolicy;
+import org.apache.cxf.message.Message;
+import org.ietf.jgss.GSSContext;
+import org.ietf.jgss.GSSException;
+import org.ietf.jgss.GSSManager;
+import org.ietf.jgss.GSSName;
+import org.ietf.jgss.Oid;
+
+public class SpnegoAuthSupplier implements HttpAuthSupplier {
+    private static final String KERBEROS_OID = "1.2.840.113554.1.2.2";
+    //private static final String SPNEGO_OID = "1.3.6.1.5.5.2";
+
+    private static final Logger LOG = LogUtils.getL7dLogger(SpnegoAuthSupplier.class);
+
+    private LoginContext lc;
+    
+    public boolean requiresRequestCaching() {
+        return false;
+    }
+
+    public String getAuthorization(AuthorizationPolicy  authPolicy,
+                                    URL currentURL,
+                                    Message message,
+                                    String fullHeader) {
+        if (!HttpAuthHeader.AUTH_TYPE_NEGOTIATE.equals(authPolicy.getAuthorizationType())) {
+            return null;
+        }
+        try {
+            String spn = "HTTP/" + currentURL.getHost();
+            LOG.fine("Adding authorization service ticket for service principal name: " + spn);
+            byte[] token = getToken(authPolicy, spn);
+            return HttpAuthHeader.AUTH_TYPE_NEGOTIATE + " " + Base64Utility.encode(token);
+        } catch (LoginException e) {
+            throw new RuntimeException(e.getMessage(), e);
+        } catch (GSSException e) {
+            throw new RuntimeException(e.getMessage(), e);
+        }
+    }
+
+    /**
+     * Create and return service ticket token
+     * 
+     * @param authPolicy
+     * @param context
+     * @return
+     * @throws GSSException
+     * @throws LoginException
+     */
+    private byte[] getToken(AuthorizationPolicy authPolicy, final GSSContext context) throws GSSException,
+            LoginException {
+        final byte[] token = new byte[0];
+
+        if (authPolicy.getUserName() == null || authPolicy.getUserName().trim().length() == 0) {
+            return context.initSecContext(token, 0, token.length);
+        }
+
+        if (lc == null) {
+            lc = new LoginContext(authPolicy.getAuthorization(), getUsernamePasswordHandler(
+                authPolicy.getUserName(), authPolicy.getPassword()));
+            lc.login();
+        }
+
+        try {
+            return (byte[]) Subject.doAs(lc.getSubject(), new CreateServiceTicketAction(context, token));
+        } catch (PrivilegedActionException e) {
+            if (e.getCause() instanceof GSSException) {
+                throw (GSSException) e.getCause();
+            }
+            LOG.log(Level.SEVERE, "initSecContext", e);
+            return null;
+        }
+    }
+
+    /**
+     * Create and return a service ticket token for a given service principal
+     * name
+     * 
+     * @param proxyAuthPolicy
+     * @param spn
+     * @return service ticket token
+     * @throws GSSException
+     * @throws LoginException
+     */
+    private byte[] getToken(AuthorizationPolicy proxyAuthPolicy, String spn) throws GSSException, 
+        LoginException {
+        GSSManager manager = GSSManager.getInstance();
+        GSSName serverName = manager.createName(spn, null);
+
+        // TODO Is it correct to use kerberos oid instead of spnego here?
+        Oid oid = new Oid(KERBEROS_OID);
+        
+        GSSContext context = manager
+                .createContext(serverName.canonicalize(oid), oid, null, GSSContext.DEFAULT_LIFETIME);
+        // TODO Do we need mutual auth. Will the code we have really work with
+        // mutual auth?
+        context.requestMutualAuth(true);
+        // TODO Credential delegation could be a security hole if it was not
+        // intended. Both settings should be configurable
+        context.requestCredDeleg(true);
+
+        return getToken(proxyAuthPolicy, context);
+    }
+
+    private final class CreateServiceTicketAction implements PrivilegedExceptionAction<byte[]> {
+        private final GSSContext context;
+        private final byte[] token;
+
+        private CreateServiceTicketAction(GSSContext context, byte[] token) {
+            this.context = context;
+            this.token = token;
+        }
+
+        public byte[] run() throws GSSException {
+            return context.initSecContext(token, 0, token.length);
+        }
+    }
+    
+    public static CallbackHandler getUsernamePasswordHandler(final String username, final String password) {
+        final CallbackHandler handler = new CallbackHandler() {
+
+            public void handle(final Callback[] callback) {
+                for (int i = 0; i < callback.length; i++) {
+                    if (callback[i] instanceof NameCallback) {
+                        final NameCallback nameCallback = (NameCallback) callback[i];
+                        nameCallback.setName(username);
+                    } else if (callback[i] instanceof PasswordCallback) {
+                        final PasswordCallback passCallback = (PasswordCallback) callback[i];
+                        passCallback.setPassword(password.toCharArray());
+                    }
+                }
+            }
+        };
+        return handler;
+    }
+
+}

Propchange: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/auth/SpnegoAuthSupplier.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/auth/SpnegoAuthSupplier.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



Mime
View raw message