List of usage examples for javax.servlet.http HttpServletRequest getHeaderNames
public Enumeration<String> getHeaderNames();
From source file:org.sakaiproject.mbm.servlet.SakaiToolServlet.java
@Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { if (log.isDebugEnabled()) { StringBuilder headers = new StringBuilder("Headers ["); StringBuilder params = new StringBuilder("Params ["); Enumeration<String> headerNames = req.getHeaderNames(); while (headerNames.hasMoreElements()) { String s = headerNames.nextElement(); headers.append(s).append("={") .append(StringUtils.isNotEmpty(req.getHeader(s)) ? req.getHeader(s) : "null").append("},"); }/*w w w . ja v a 2 s .c o m*/ headers.append("]"); Enumeration<String> paramNames = req.getParameterNames(); while (paramNames.hasMoreElements()) { String s = paramNames.nextElement(); params.append(s).append("={") .append(StringUtils.isNotEmpty(req.getParameter(s)) ? req.getParameter(s) : "null") .append("},"); } params.append("]"); log.debug(new StringBuilder() .append("SakaiToolServlet: service(HttpServletRequest, HttpServletResponse)\n") .append("context path = ").append(req.getContextPath()).append("\n").append("request path = ") .append(StringUtils.isNotEmpty(req.getPathInfo()) ? req.getPathInfo() : "null").append("\n") .append("headers = ").append(headers).append("\n").append("params = ").append(params) .append("\n").append("content type = ") .append(StringUtils.isNotEmpty(req.getContentType()) ? req.getContentType() : "null") .append("\n").append("method = ").append(req.getMethod()).append("\n") .append("query = ") .append(StringUtils.isNotEmpty(req.getQueryString()) ? req.getQueryString() : "null") .append("\n").append("request url = ").append(req.getRequestURL()).append("\n") .append("request uri = ").append(req.getRequestURI()).append("\n").append("locale = ") .append(req.getLocale()).append("\n")); } final String startPage = StringUtils.isNotEmpty(getInitParameter("index")) ? getInitParameter("index") : "/"; final String contextPath = req.getContextPath(); req.setAttribute(Tool.NATIVE_URL, Tool.NATIVE_URL); HttpServletRequest wrappedReq = new HttpServletRequestWrapper(req) { public String getContextPath() { return contextPath; } }; if (StringUtils.isEmpty(req.getPathInfo())) { resp.sendRedirect(contextPath + startPage); } else { RequestDispatcher dispatcher; if (StringUtils.isEmpty(req.getPathInfo())) { dispatcher = req.getRequestDispatcher("/"); } else { dispatcher = req.getRequestDispatcher(req.getPathInfo()); } dispatcher.forward(wrappedReq, resp); } }
From source file:pdl.web.filter.RestAuthenticationFilter.java
@Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { List<String> headerKeys = Arrays.asList(USER_NAME_PARAM, USER_PASS_PARAM); Map<String, String> headerAndParms = new HashMap<String, String>(); // load header values we care about Enumeration e = request.getHeaderNames(); while (e.hasMoreElements()) { String key = (String) e.nextElement(); if (headerKeys.contains(key)) { headerAndParms.put(key, request.getHeader(key)); }//w w w.j a va 2 s . co m } // load parameters for (Object key : request.getParameterMap().keySet()) { String[] o = (String[]) request.getParameterMap().get(key); headerAndParms.put((String) key, o[0]); } String userName = headerAndParms.get(USER_NAME_PARAM); String userPasswd = headerAndParms.get(USER_PASS_PARAM); if (userName == null || userPasswd == null) { response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "REST signature failed validation."); return; } /*catch (Exception e) { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "The REST Security Server experienced an internal error."); return; }*/ filterChain.doFilter(request, response); }
From source file:org.yes.cart.shoppingcart.support.headerdriven.impl.RequestHeaderTuplizerImpl.java
private Map<String, List<String>> createHeadersMap(final HttpServletRequest httpRequest) { final Map<String, List<String>> headers = new HashMap<String, List<String>>(); final Enumeration headerNames = httpRequest.getHeaderNames(); while (headerNames.hasMoreElements()) { final String nextKey = (String) headerNames.nextElement(); if (!headers.containsKey(nextKey)) { headers.put(nextKey, new ArrayList<String>()); }/*from w w w . j ava2 s .c om*/ final List<String> values = headers.get(nextKey); final Enumeration headerValues = httpRequest.getHeaders(nextKey); while (headerValues.hasMoreElements()) { final String nextValue = (String) headerValues.nextElement(); values.add(nextValue); } } return headers; }
From source file:org.springframework.cloud.netflix.zuul.filters.ProxyRequestHelper.java
public MultiValueMap<String, String> buildZuulRequestHeaders(HttpServletRequest request) { RequestContext context = RequestContext.getCurrentContext(); MultiValueMap<String, String> headers = new LinkedMultiValueMap<>(); Enumeration<?> headerNames = request.getHeaderNames(); if (headerNames != null) { while (headerNames.hasMoreElements()) { String name = (String) headerNames.nextElement(); String value = request.getHeader(name); if (isIncludedHeader(name)) headers.set(name, value); }/*from w w w . j av a2 s. com*/ } Map<String, String> zuulRequestHeaders = context.getZuulRequestHeaders(); for (String header : zuulRequestHeaders.keySet()) { headers.set(header, zuulRequestHeaders.get(header)); } headers.set("accept-encoding", "deflate, gzip"); return headers; }
From source file:org.owasp.benchmark.testcode.BenchmarkTest01141.java
@Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); String param = ""; boolean flag = true; java.util.Enumeration<String> names = request.getHeaderNames(); while (names.hasMoreElements() && flag) { String name = (String) names.nextElement(); java.util.Enumeration<String> values = request.getHeaders(name); if (values != null) { while (values.hasMoreElements() && flag) { String value = (String) values.nextElement(); if (value.equals("vector")) { param = name;//from w w w . ja v a 2 s .c om flag = false; } } } } String bar = new Test().doSomething(param); try { java.util.Properties benchmarkprops = new java.util.Properties(); benchmarkprops.load(this.getClass().getClassLoader().getResourceAsStream("benchmark.properties")); String algorithm = benchmarkprops.getProperty("cryptoAlg1", "DESede/ECB/PKCS5Padding"); javax.crypto.Cipher c = javax.crypto.Cipher.getInstance(algorithm); // Prepare the cipher to encrypt javax.crypto.SecretKey key = javax.crypto.KeyGenerator.getInstance("DES").generateKey(); c.init(javax.crypto.Cipher.ENCRYPT_MODE, key); // encrypt and store the results byte[] input = { (byte) '?' }; Object inputParam = bar; if (inputParam instanceof String) input = ((String) inputParam).getBytes(); if (inputParam instanceof java.io.InputStream) { byte[] strInput = new byte[1000]; int i = ((java.io.InputStream) inputParam).read(strInput); if (i == -1) { response.getWriter().println( "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); return; } input = java.util.Arrays.copyOf(strInput, i); } byte[] result = c.doFinal(input); java.io.File fileTarget = new java.io.File( new java.io.File(org.owasp.benchmark.helpers.Utils.testfileDir), "passwordFile.txt"); java.io.FileWriter fw = new java.io.FileWriter(fileTarget, true); //the true will append the new data fw.write("secret_value=" + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + "\n"); fw.close(); response.getWriter() .println("Sensitive value: '" + org.owasp.esapi.ESAPI.encoder().encodeForHTML(new String(input)) + "' encrypted and stored<br/>"); } catch (java.security.NoSuchAlgorithmException e) { response.getWriter().println( "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); e.printStackTrace(response.getWriter()); throw new ServletException(e); } catch (javax.crypto.NoSuchPaddingException e) { response.getWriter().println( "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); e.printStackTrace(response.getWriter()); throw new ServletException(e); } catch (javax.crypto.IllegalBlockSizeException e) { response.getWriter().println( "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); e.printStackTrace(response.getWriter()); throw new ServletException(e); } catch (javax.crypto.BadPaddingException e) { response.getWriter().println( "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); e.printStackTrace(response.getWriter()); throw new ServletException(e); } catch (java.security.InvalidKeyException e) { response.getWriter().println( "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); e.printStackTrace(response.getWriter()); throw new ServletException(e); } response.getWriter().println("Crypto Test javax.crypto.Cipher.getInstance(java.lang.String) executed"); }
From source file:org.holistic.ws_proxy.WSProxyHelper.java
public void set_headers2urlconn(HttpServletRequest req, URLConnection objURLConn) throws Exception { String m_strName;/* w ww. jav a 2 s .com*/ String m_strValue; for (Enumeration m_objElement = req.getHeaderNames(); m_objElement.hasMoreElements(); log .debug("ClientToEndPoint HEADER[" + m_strName + "] - VALUE[" + m_strValue + "]")) { m_strName = (String) m_objElement.nextElement(); m_strValue = req.getHeader(m_strName); if (m_strName.toUpperCase().equals("COOKIE") && m_strValue.indexOf(COOKIE_SESSION + "=") > 0) m_strValue = m_strValue.replaceAll(COOKIE_SESSION + "=", COOKIE_SESSION + "_PROXY="); if (m_strName.toUpperCase().equals("COOKIE") && m_strValue.indexOf(EXTRA_COOKIE) > 0) m_strValue = m_strValue.replaceAll(EXTRA_COOKIE, ""); objURLConn.setRequestProperty(m_strName, m_strValue); } String m_RemoteAddr = req.getRemoteAddr(); objURLConn.setRequestProperty("x-forwarded-for", m_RemoteAddr); log.debug("Client IP x-forwarded-for (" + m_RemoteAddr + ")."); String cipherSuite = (String) req.getAttribute("javax.net.ssl.cipher_suite"); if (cipherSuite != null && req.getAttribute("javax.net.ssl.peer_certificates") != null) { java.security.cert.X509Certificate certChain[] = (java.security.cert.X509Certificate[]) req .getAttribute("javax.net.ssl.peer_certificates"); java.security.cert.X509Certificate certStandar = certChain[0]; m_strName = "entrust-client-certificate"; String m_strTemp = (new BASE64Encoder()).encode(certStandar.getEncoded()); m_strValue = m_strTemp.replaceAll("\r\n", "").replaceAll("\n", ""); objURLConn.setRequestProperty(m_strName, m_strValue); log.debug("HEADER[" + m_strName + "] - VALUE[" + m_strValue + "]"); } }
From source file:org.owasp.benchmark.testcode.BenchmarkTest01139.java
@Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); String param = ""; boolean flag = true; java.util.Enumeration<String> names = request.getHeaderNames(); while (names.hasMoreElements() && flag) { String name = (String) names.nextElement(); java.util.Enumeration<String> values = request.getHeaders(name); if (values != null) { while (values.hasMoreElements() && flag) { String value = (String) values.nextElement(); if (value.equals("vector")) { param = name;/*from w ww. j a v a2 s . c om*/ flag = false; } } } } String bar = new Test().doSomething(param); // Code based on example from: // http://examples.javacodegeeks.com/core-java/crypto/encrypt-decrypt-file-stream-with-des/ try { javax.crypto.Cipher c = javax.crypto.Cipher.getInstance("RSA/ECB/PKCS1Padding", "SunJCE"); // Prepare the cipher to encrypt java.security.KeyPairGenerator keyGen = java.security.KeyPairGenerator.getInstance("RSA"); keyGen.initialize(1024); java.security.PublicKey publicKey = keyGen.genKeyPair().getPublic(); c.init(javax.crypto.Cipher.ENCRYPT_MODE, publicKey); // encrypt and store the results byte[] input = { (byte) '?' }; Object inputParam = bar; if (inputParam instanceof String) input = ((String) inputParam).getBytes(); if (inputParam instanceof java.io.InputStream) { byte[] strInput = new byte[1000]; int i = ((java.io.InputStream) inputParam).read(strInput); if (i == -1) { response.getWriter().println( "This input source requires a POST, not a GET. Incompatible UI for the InputStream source."); return; } input = java.util.Arrays.copyOf(strInput, i); } byte[] result = c.doFinal(input); java.io.File fileTarget = new java.io.File( new java.io.File(org.owasp.benchmark.helpers.Utils.testfileDir), "passwordFile.txt"); java.io.FileWriter fw = new java.io.FileWriter(fileTarget, true); //the true will append the new data fw.write("secret_value=" + org.owasp.esapi.ESAPI.encoder().encodeForBase64(result, true) + "\n"); fw.close(); response.getWriter() .println("Sensitive value: '" + org.owasp.esapi.ESAPI.encoder().encodeForHTML(new String(input)) + "' encrypted and stored<br/>"); } catch (java.security.NoSuchAlgorithmException e) { response.getWriter().println( "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); e.printStackTrace(response.getWriter()); throw new ServletException(e); } catch (java.security.NoSuchProviderException e) { response.getWriter().println( "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); e.printStackTrace(response.getWriter()); throw new ServletException(e); } catch (javax.crypto.NoSuchPaddingException e) { response.getWriter().println( "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); e.printStackTrace(response.getWriter()); throw new ServletException(e); } catch (javax.crypto.IllegalBlockSizeException e) { response.getWriter().println( "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); e.printStackTrace(response.getWriter()); throw new ServletException(e); } catch (javax.crypto.BadPaddingException e) { response.getWriter().println( "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); e.printStackTrace(response.getWriter()); throw new ServletException(e); } catch (java.security.InvalidKeyException e) { response.getWriter().println( "Problem executing crypto - javax.crypto.Cipher.getInstance(java.lang.String,java.security.Provider) Test Case"); e.printStackTrace(response.getWriter()); throw new ServletException(e); } response.getWriter() .println("Crypto Test javax.crypto.Cipher.getInstance(java.lang.String,java.lang.String) executed"); }
From source file:org.wso2.carbon.identity.oidc.dcr.factory.OIDCRegistrationRequestFactoryTest.java
@Test(dataProvider = "OIDCRequestBuilderCreationData") public void testCreate(String request, String sectorIdUrl, String subjectType, String tokenSignAlg, String tokenEncrAlg, String tokenEncrEnc, String userInfoRespSignAlg, String userInfoRespEncrAlg, String userInfoRespEnceEnc, String reqObjSignAlg, String reqObjEncrAlg, String reqObjEncrEnc, String tokenEPAuthSignAlg, String defaultMaxAge, String requireAuthTime, String defaultAcrValues, String initLoginUrl, List<String> requestUris) throws Exception { HttpServletRequest mockRequest = mock(HttpServletRequest.class); HttpServletResponse mockResponse = mock(HttpServletResponse.class); when(mockRequest.getReader()).thenReturn(new BufferedReader(new StringReader(request))); when(mockRequest.getHeaderNames()).thenReturn(Collections.<String>emptyEnumeration()); when(mockRequest.getAttributeNames()).thenReturn(Collections.<String>emptyEnumeration()); OIDCRegistrationRequest.OIDCRegistrationRequestBuilder requestBuilder = testedRegistrationRequestFactory .create(mockRequest, mockResponse); RegistrationRequest registrationRequest = requestBuilder.build(); RegistrationRequestProfile requestProfile = registrationRequest.getRegistrationRequestProfile(); assertTrue(requestProfile instanceof OIDCRegistrationRequestProfile, "Request profile should be an instance " + "of OIDCRegistrationRequestProfile"); OIDCRegistrationRequestProfile oidcRegRequestProfile = (OIDCRegistrationRequestProfile) requestProfile; assertEquals(requestBuilder.getRequest(), mockRequest, "Builder should have the provided request."); assertEquals(requestBuilder.getResponse(), mockResponse, "Builder should have the provided response."); assertEquals(oidcRegRequestProfile.getSectorIdentifierUri(), sectorIdUrl, "Invalid Sector Id URL"); assertEquals(oidcRegRequestProfile.getSubjectType(), subjectType, "Invalid subject type"); assertEquals(oidcRegRequestProfile.getIdTokenSignedResponseAlg(), tokenSignAlg, "Invalid token sign " + "algorithm"); assertEquals(oidcRegRequestProfile.getIdTokenEncryptedResponseAlg(), tokenEncrAlg, "Invalid token encryption" + " alg"); assertEquals(oidcRegRequestProfile.getIdTokenEncryptedResponseEnc(), tokenEncrEnc, "Invalid token encryption" + " enc"); assertEquals(oidcRegRequestProfile.getUserinfoSignedResponseAlg(), userInfoRespSignAlg, "Invalid userinfo " + "response sign alg"); assertEquals(oidcRegRequestProfile.getUserinfoencryptedResponseAlg(), userInfoRespEncrAlg, "Invalid userinfo " + "response encr alg"); assertEquals(oidcRegRequestProfile.getUserinfoEncryptedResponseEnc(), userInfoRespEnceEnc, "Invalid userinfo " + "response encr enc"); assertEquals(oidcRegRequestProfile.getRequestObjectSigningAlg(), reqObjSignAlg, "Invalid request obj sign " + "alg"); assertEquals(oidcRegRequestProfile.getRequestObjectEncryptionAlg(), reqObjEncrAlg, "Invalid request obj encr" + " alg"); assertEquals(oidcRegRequestProfile.getRequestObjectEncryptionEnc(), reqObjEncrEnc, "Invalid request obj encr" + " enc"); assertEquals(oidcRegRequestProfile.getTokenEndpointAuthSigningAlg(), tokenEPAuthSignAlg, "Invalid token " + "endpoint auth response alg."); assertEquals(oidcRegRequestProfile.getDefaultMaxAge(), defaultMaxAge, "Invalid default max age"); assertEquals(oidcRegRequestProfile.getRequireAuthTime(), requireAuthTime, "Invalid require auth time"); assertEquals(oidcRegRequestProfile.getDefaultAcrValues(), defaultAcrValues, "Invalid default acr values"); assertEquals(oidcRegRequestProfile.getInitiateLoginUri(), initLoginUrl, "Invalid initiate login uri"); assertTrue(CollectionUtils.isEqualCollection(oidcRegRequestProfile.getRequestUris(), requestUris), "Invalid " + "request URLs "); }
From source file:mobi.jenkinsci.ci.JenkinsCIPlugin.java
private void copyHeaders(final HttpPost post, final HttpServletRequest req) { for (final Enumeration<String> headerNames = req.getHeaderNames(); headerNames.hasMoreElements();) { final String headerName = headerNames.nextElement(); if (HEADERS_BLACKLIST.contains(headerName)) { continue; }/* w ww .j a va 2 s .c o m*/ post.setHeader(headerName, req.getHeader(headerName)); } }
From source file:PrintHeader.java
/** * Prints client header information that is available * /* w ww. j a v a 2 s. co m*/ * @param request * @param response * @throws IOException * @throws ServletException * */ public void printHeader(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { String headers = null; String htmlHeader = "<HTML><HEAD><TITLE> Request Headers</TITLE></HEAD><BODY>"; String htmlFooter = "</BODY></HTML>"; response.setContentType("text/html"); PrintWriter out = response.getWriter(); Enumeration e = request.getHeaderNames(); out.println(htmlHeader); out.println("<TABLE ALIGN=CENTER BORDER=1>"); out.println("<tr><th> Header </th><th> Value </th>"); while (e.hasMoreElements()) { headers = (String) e.nextElement(); if (headers != null) { out.println("<tr><td align=center><b>" + headers + "</td>"); out.println("<td align=center>" + request.getHeader(headers) + "</td></tr>"); } } out.println("</TABLE><BR>"); out.println(htmlFooter); }