diff options
author | Thomas Watson | 2016-01-08 21:24:55 +0000 |
---|---|---|
committer | Thomas Watson | 2016-01-08 21:24:55 +0000 |
commit | 0bc9249ac4efc3d8626fc05afee0ee9931f0f1c9 (patch) | |
tree | 7aa9c5d2428c2355e49a0a33d7c45f250757cc1c /bundles/org.eclipse.equinox.http.servlet.tests | |
parent | df2a054cc06a51e28c328c560193efb2cab6e559 (diff) | |
download | rt.equinox.bundles-0bc9249ac4efc3d8626fc05afee0ee9931f0f1c9.tar.gz rt.equinox.bundles-0bc9249ac4efc3d8626fc05afee0ee9931f0f1c9.tar.xz rt.equinox.bundles-0bc9249ac4efc3d8626fc05afee0ee9931f0f1c9.zip |
Bug 485466 - [http whiteboard] HttpContext attributes are not usedI20160112-0800
correctly for getAuthType or getRemoteUser
Change-Id: I70c78a5bb4610a3fd4c4958e523b8a217a52bd00
Signed-off-by: Thomas Watson <tjwatson@us.ibm.com>
Diffstat (limited to 'bundles/org.eclipse.equinox.http.servlet.tests')
-rw-r--r-- | bundles/org.eclipse.equinox.http.servlet.tests/src/org/eclipse/equinox/http/servlet/tests/ServletTest.java | 42 |
1 files changed, 41 insertions, 1 deletions
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 ac45f1e6e..b2eb491e9 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.lang.reflect.Method; 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 class ServletTest extends TestCase { } } + 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); } |