List of usage examples for javax.servlet.http Cookie getName
public String getName()
From source file:org.apache.atlas.web.filters.AtlasKnoxSSOAuthenticationFilter.java
/** * Encapsulate the acquisition of the JWT token from HTTP cookies within the * request./*from w w w . j a va 2s . co m*/ * * @param req servlet request to get the JWT token from * @return serialized JWT token */ protected String getJWTFromCookie(HttpServletRequest req) { String serializedJWT = null; Cookie[] cookies = req.getCookies(); if (cookieName != null && cookies != null) { for (Cookie cookie : cookies) { if (cookieName.equals(cookie.getName())) { if (LOG.isDebugEnabled()) { LOG.debug("{} cookie has been found and is being processed", cookieName); } serializedJWT = cookie.getValue(); break; } } } return serializedJWT; }
From source file:com.microsoft.azure.oidc.filter.helper.impl.SimpleAuthenticationHelper.java
private Cookie getCookie(final HttpServletRequest httpRequest, final String cookieName) { if (httpRequest == null || cookieName == null) { throw new PreconditionException("Required parameter is null"); }//from w w w .ja va 2s. co m if (httpRequest.getCookies() == null) { return null; } if (httpRequest.getCookies() != null) { for (final Cookie cookie : httpRequest.getCookies()) { if (cookie == null || cookie.getName() == null) { continue; } if (cookie.getName().equals(cookieName)) { return cookie; } } } return null; }
From source file:com.qut.middleware.spep.servlet.AuthenticationServletTest.java
/** * @throws Exception/*from w ww .j a v a2s .c om*/ */ @Test public void testPost2a() throws Exception { final LineVectorOutputStream outputStream = new LineVectorOutputStream(); final String sessionID = "9809283409182304981234-923-501209348091234"; final String base64RequestURL = new String(Base64.encodeBase64(this.defaultRequestURL.getBytes("UTF-8"))); Modify<AuthnProcessorData> modifyAuthnProcessorData = new ModifyAuthnProcessorData(sessionID, null, null); Capture<Cookie> captureCookie = new Capture<Cookie>(); this.authnProcessor.processAuthnResponse(modify(modifyAuthnProcessorData), (Response) notNull()); expectLastCall().anyTimes(); startMock(); this.authenticationServlet.init(this.servletConfig); String samlResponse = new String(Base64.encodeBase64("some response document".getBytes("UTF-8"))); ServletOutputStream out = new OutputStreamServletOutputStream(outputStream); HttpServletRequest request = createMock(HttpServletRequest.class); expect(request.getParameter("SAMLResponse")).andReturn(samlResponse).anyTimes(); HttpServletResponse response = createMock(HttpServletResponse.class); response.addCookie(capture(captureCookie)); expectLastCall().once(); // Make sure we get redirected to the default URL response.sendRedirect(this.defaultRequestURL); expectLastCall().once(); replay(request); replay(response); this.authenticationServlet.doPost(request, response); verify(request); verify(response); Cookie spepCookie = null; for (Cookie cookie : captureCookie.getCaptured()) { if (cookie.getName().equals(this.tokenName)) { spepCookie = cookie; break; } } assertNotNull(spepCookie); assertEquals(this.tokenName, spepCookie.getName()); assertEquals(sessionID, spepCookie.getValue()); endMock(); }
From source file:org.cateproject.test.functional.mockmvc.HtmlUnitRequestBuilder.java
private void processCookie(MockHttpServletRequest result, List<Cookie> cookies, Cookie cookie) { cookies.add(cookie);//from www . j av a2 s. c o m if ("JSESSIONID".equals(cookie.getName())) { result.setRequestedSessionId(cookie.getValue()); result.setSession(httpSession(result, cookie.getValue())); } }
From source file:org.apache.hive.service.cli.thrift.ThriftHttpServlet.java
/** * Convert cookie array to human readable cookie string * @param cookies Cookie Array//from w w w . j a v a2 s .co m * @return String containing all the cookies separated by a newline character. * Each cookie is of the format [key]=[value] */ private String toCookieStr(Cookie[] cookies) { String cookieStr = ""; for (Cookie c : cookies) { cookieStr += c.getName() + "=" + c.getValue() + " ;\n"; } return cookieStr; }
From source file:com.qut.middleware.spep.servlet.AuthenticationServletTest.java
/** * @throws Exception/*from ww w . j a va2s . co m*/ */ @Test public void testPost2b() throws Exception { final LineVectorOutputStream outputStream = new LineVectorOutputStream(); final String sessionID = "9809283409182304981234-923-501209348091234"; final String requestURL = "http://lol.request.url/somepage.jsp"; final String base64RequestURL = new String(Base64.encodeBase64(requestURL.getBytes("UTF-8"))); Modify<AuthnProcessorData> modifyAuthnProcessorData = new ModifyAuthnProcessorData(sessionID, base64RequestURL, null); Capture<Cookie> captureCookie = new Capture<Cookie>(); this.authnProcessor.processAuthnResponse(modify(modifyAuthnProcessorData), (Response) notNull()); expectLastCall().anyTimes(); startMock(); this.authenticationServlet.init(this.servletConfig); String samlResponse = new String(Base64.encodeBase64("some response document".getBytes("UTF-8"))); ServletOutputStream out = new OutputStreamServletOutputStream(outputStream); HttpServletRequest request = createMock(HttpServletRequest.class); expect(request.getParameter("SAMLResponse")).andReturn(samlResponse).anyTimes(); HttpServletResponse response = createMock(HttpServletResponse.class); response.addCookie(capture(captureCookie)); expectLastCall().once(); // Make sure we get redirected to the session URL response.sendRedirect(requestURL); expectLastCall().once(); replay(request); replay(response); this.authenticationServlet.doPost(request, response); verify(request); verify(response); Cookie spepCookie = null; for (Cookie cookie : captureCookie.getCaptured()) { if (cookie.getName().equals(this.tokenName)) { spepCookie = cookie; break; } } assertNotNull(spepCookie); assertEquals(this.tokenName, spepCookie.getName()); assertEquals(sessionID, spepCookie.getValue()); endMock(); }
From source file:com.haulmont.cuba.web.sys.CubaApplicationServlet.java
protected String getCookieValue(HttpServletRequest req, String cookieName) { if (req.getCookies() == null) { return null; }/* w ww . j av a2 s.com*/ for (Cookie cookie : req.getCookies()) { if (Objects.equals(cookieName, cookie.getName())) { return cookie.getValue(); } } return null; }
From source file:com.maydesk.base.PDUserSession.java
public String getCookie(String cookieName) { ContainerContext ctx = (ContainerContext) ApplicationInstance.getActive() .getContextProperty(ContainerContext.CONTEXT_PROPERTY_NAME); Cookie[] cookies = ctx.getCookies(); for (Cookie cookie : cookies) { if (StringUtils.equals(cookie.getName(), cookieName)) { return cookie.getValue(); }/*www. ja va 2 s.c om*/ } return null; }
From source file:com.netspective.sparx.security.HttpLoginManager.java
public String getRememberedUserId(HttpServletValueContext vc) { Cookie[] cookies = vc.getHttpRequest().getCookies(); if (cookies != null) { for (int i = 0; i < cookies.length; i++) { Cookie cookie = cookies[i]; if (cookie.getName().equals(getRememberUserIdCookieName())) return cookie.getValue(); }/*from www.j a v a 2s .c om*/ } return null; }
From source file:com.netspective.sparx.security.HttpLoginManager.java
public String getRememberedEncryptedPassword(HttpServletValueContext vc) { Cookie[] cookies = vc.getHttpRequest().getCookies(); if (cookies != null) { for (int i = 0; i < cookies.length; i++) { Cookie cookie = cookies[i]; if (cookie.getName().equals(getRememberPasswordCookieName())) return cookie.getValue(); }//from ww w .jav a 2 s. c o m } return null; }