Bug 485466 - [http whiteboard] HttpContext attributes are not used
correctly for getAuthType or getRemoteUser

Change-Id: I70c78a5bb4610a3fd4c4958e523b8a217a52bd00
Signed-off-by: Thomas Watson <tjwatson@us.ibm.com>
diff --git a/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/ServletTest.java b/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/ServletTest.java
index ac45f1e..b2eb491 100644
--- a/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/ServletTest.java
+++ b/bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/ServletTest.java
@@ -21,7 +21,8 @@
 import java.net.CookieHandler;
 import java.net.CookieManager;
 import java.net.CookiePolicy;
-
+import java.net.HttpRetryException;
+import java.net.URL;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -2900,6 +2901,45 @@
 		}
 	}
 
+	public void testHttpContextSetUser() throws ServletException, NamespaceException, IOException {
+		ExtendedHttpService extendedHttpService = (ExtendedHttpService)getHttpService();
+
+		HttpContext testContext = new HttpContext() {
+			
+			@Override
+			public boolean handleSecurity(HttpServletRequest request, HttpServletResponse response) throws IOException {
+				request.setAttribute(HttpContext.REMOTE_USER, "TEST");
+				request.setAttribute(HttpContext.AUTHENTICATION_TYPE, "Basic");
+				return true;
+			}
+			
+			@Override
+			public URL getResource(String name) {
+				return null;
+			}
+			
+			@Override
+			public String getMimeType(String name) {
+				return null;
+			}
+		};
+		HttpServlet testServlet = new HttpServlet() {
+			@Override
+			protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+					throws ServletException, IOException {
+				resp.setContentType("text/html");
+				PrintWriter out = resp.getWriter();
+				out.print("USER: " + req.getRemoteUser() + " AUTH_TYPE: " + req.getAuthType());
+			}
+			
+		};
+		extendedHttpService.registerServlet("/" + getName(), testServlet, null, testContext);
+
+		String expected = "USER: TEST AUTH_TYPE: Basic";
+		String actual = requestAdvisor.request(getName());
+		Assert.assertEquals(expected, actual);
+	}
+
 	private String doRequest(String action, Map<String, String> params) throws IOException {
 		return doRequestGetResponse(action, params).get("responseBody").get(0);
 	}
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/HttpServletRequestWrapperImpl.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/HttpServletRequestWrapperImpl.java
index dd98b26..c7b88d0 100644
--- a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/HttpServletRequestWrapperImpl.java
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/HttpServletRequestWrapperImpl.java
@@ -1,5 +1,5 @@
 /*******************************************************************************
- * Copyright (c) 2005, 2015 Cognos Incorporated, IBM Corporation and others.
+ * Copyright (c) 2005, 2016 Cognos Incorporated, IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -166,7 +166,7 @@
 	}
 
 	public String getAuthType() {
-		String authType = (String)request.getAttribute(HttpContext.AUTHENTICATION_TYPE);
+		String authType = (String) this.getAttribute(HttpContext.AUTHENTICATION_TYPE);
 		if (authType != null)
 			return authType;
 
@@ -174,7 +174,7 @@
 	}
 
 	public String getRemoteUser() {
-		String remoteUser = (String) request.getAttribute(HttpContext.REMOTE_USER);
+		String remoteUser = (String) this.getAttribute(HttpContext.REMOTE_USER);
 		if (remoteUser != null)
 			return remoteUser;