List of usage examples for javax.servlet.http Cookie getValue
public String getValue()
From source file:com.microsoft.azure.oidc.filter.helper.impl.SimpleAuthenticationHelper.java
@Override public String getTokenString(final HttpServletRequest httpRequest, final HttpServletResponse httpResponse, final String tokenName) { if (httpRequest == null || httpResponse == null || tokenName == null) { throw new PreconditionException("Required parameter is null"); }/* w w w . j a va2s. c om*/ final String tokenString = httpRequest.getParameter(tokenName); if (tokenString != null) { return addCookie(httpRequest, httpResponse, tokenName, tokenString); } final Cookie cookieToken = getCookie(httpRequest, tokenName); if (cookieToken != null) { return addCookie(httpRequest, httpResponse, tokenName, cookieToken.getValue()); } return null; }
From source file:com.jolira.testing.CachingRESTProxy.java
private boolean cacheResponse(final String query, final File queryDir, final HttpServletRequest request) throws IOException { if (backend == null) { return false; }// w w w. ja v a2s . c o m final String protocol = ssl ? "https" : "http"; final String _url = protocol + "://" + backend + query; final URL url = new URL(_url); final HttpURLConnection connection = (HttpURLConnection) url.openConnection(); final Cookie[] cookies = request.getCookies(); if (cookies != null) { final StringBuilder cookieVal = new StringBuilder(); for (final Cookie cookie : cookies) { final String value = cookie.getValue(); final String name = cookie.getName(); cookieVal.append(name); cookieVal.append('='); cookieVal.append(value); cookieVal.append(';'); } connection.setRequestProperty("Cookie", cookieVal.toString()); } final InputStream in = connection.getInputStream(); try { cacheResponse(queryDir, connection, in); } finally { in.close(); } return true; }
From source file:com.googlesource.gerrit.plugins.github.oauth.OAuthGitFilter.java
private String generateRandomGerritPassword(String username, HttpServletRequest httpRequest, HttpServletResponse httpResponse, FilterChain chain) throws IOException, ServletException { log.warn("User " + username + " has not a Gerrit HTTP password: " + "generating a random one in order to be able to use Git over HTTP"); Cookie gerritCookie = getGerritLoginCookie(username, httpRequest, httpResponse, chain); String xGerritAuthValue = xGerritAuth.getAuthValue(gerritCookie); HttpPut putRequest = new HttpPut( getRequestUrlWithAlternatePath(httpRequest, "/accounts/self/password.http")); putRequest.setHeader("Cookie", gerritCookie.getName() + "=" + gerritCookie.getValue()); putRequest.setHeader(XGerritAuth.X_GERRIT_AUTH, xGerritAuthValue); putRequest.setEntity(new StringEntity("{\"generate\":true}", ContentType.APPLICATION_JSON)); HttpResponse putResponse = httpClientProvider.get().execute(putRequest); if (putResponse.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { throw new ServletException("Cannot generate HTTP password for authenticating user " + username); }/*from ww w . ja v a 2s. c o m*/ return accountCache.getByUsername(username).getPassword(username); }
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 w w w. java 2 s.c o m*/ } return null; }
From source file:org.cateproject.test.functional.mockmvc.HtmlUnitRequestBuilder.java
private void cookies(MockHttpServletRequest result) { String cookieHeaderValue = header("Cookie"); Cookie[] parentCookies = result.getCookies(); List<Cookie> cookies = new ArrayList<Cookie>(); if (cookieHeaderValue != null) { StringTokenizer tokens = new StringTokenizer(cookieHeaderValue, "=;"); while (tokens.hasMoreTokens()) { String cookieName = tokens.nextToken().trim(); if (!tokens.hasMoreTokens()) { throw new IllegalArgumentException("Expected value for cookie name " + cookieName + ". Full cookie was " + cookieHeaderValue); }//w w w .j a v a2 s . c om String cookieValue = tokens.nextToken().trim(); processCookie(result, cookies, new Cookie(cookieName, cookieValue)); } } Set<com.gargoylesoftware.htmlunit.util.Cookie> managedCookies = cookieManager .getCookies(webRequest.getUrl()); for (com.gargoylesoftware.htmlunit.util.Cookie cookie : managedCookies) { processCookie(result, cookies, new Cookie(cookie.getName(), cookie.getValue())); } if (parentCookies != null) { for (Cookie cookie : parentCookies) { cookies.add(cookie); } } if (!cookies.isEmpty()) { result.setCookies(cookies.toArray(new Cookie[0])); } }
From source file:com.google.identitytoolkit.GitkitClient.java
private String lookupCookie(HttpServletRequest request, String cookieName) { Cookie[] cookies = request.getCookies(); if (cookies == null) { return null; }//from w ww . ja va2 s. c o m for (Cookie cookie : cookies) { if (cookieName.equals(cookie.getName())) { return cookie.getValue(); } } 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(); }/*w w w . j a v a 2s . c om*/ } return null; }
From source file:fi.hoski.web.forms.RaceEntryServlet.java
private JSONObject fromCookie(HttpServletRequest request) throws JSONException { if (useCookies) { Cookie[] cookies = request.getCookies(); if (cookies != null) { for (Cookie cookie : cookies) { if (COOKIENAME.equals(cookie.getName())) { Base64 decoder = new Base64(); try { return new JSONObject(new String(decoder.decode(cookie.getValue()), "UTF-8")); } catch (UnsupportedEncodingException ex) { log(ex.getMessage(), ex); return new JSONObject(); }/* w ww . j av a 2 s. co m*/ } } } } return new JSONObject(); }
From source file:com.xpn.xwiki.stats.impl.StatsUtil.java
/** * Create a new visit cookie and return it. * //from ww w.java 2 s.c om * @param context the XWiki context. * @return the newly created cookie. * @since 1.4M1 */ protected static Cookie addCookie(XWikiContext context) { Cookie cookie = new Cookie(COOKPROP_VISITID, RandomStringUtils.randomAlphanumeric(32).toUpperCase()); cookie.setPath("/"); int time = (int) (getCookieExpirationDate().getTime() - (new Date()).getTime()) / 1000; cookie.setMaxAge(time); String cookieDomain = null; getCookieDomains(context); if (cookieDomains != null) { String servername = context.getRequest().getServerName(); for (int i = 0; i < cookieDomains.length; i++) { if (servername.indexOf(cookieDomains[i]) != -1) { cookieDomain = cookieDomains[i]; break; } } } if (cookieDomain != null) { cookie.setDomain(cookieDomain); } if (LOGGER.isDebugEnabled()) { LOGGER.debug("Setting cookie " + cookie.getValue() + " for name " + cookie.getName() + " with domain " + cookie.getDomain() + " and path " + cookie.getPath() + " and maxage " + cookie.getMaxAge()); } context.getResponse().addCookie(cookie); return cookie; }
From source file:com.xwiki.authentication.trustedldap.TrustedLDAPAuthServiceImpl.java
public XWikiUser checkAuthSSO(String username, String password, XWikiContext context) throws XWikiException { Cookie cookie;//from w w w. j a v a 2 s . c om LOG.debug("checkAuth"); LOG.debug("Action: " + context.getAction()); if (context.getAction().startsWith("logout")) { cookie = getCookie("XWIKISSOAUTHINFO", context); if (cookie != null) { cookie.setMaxAge(0); context.getResponse().addCookie(cookie); } return null; } Principal principal = null; if (LOG.isDebugEnabled()) { Cookie[] cookies = context.getRequest().getCookies(); if (cookies != null) { for (Cookie c : cookies) { LOG.debug("CookieList: " + c.getName() + " => " + c.getValue()); } } } cookie = getCookie("XWIKISSOAUTHINFO", context); if (cookie != null) { LOG.debug("Found Cookie"); String uname = decryptText(cookie.getValue(), context); if (uname != null) { principal = new SimplePrincipal(uname); } } XWikiUser user; // Authenticate if (principal == null) { principal = authenticate(username, password, context); if (principal == null) { return null; } LOG.debug("Saving auth cookie"); String encuname = encryptText(principal.getName().contains(":") ? principal.getName() : context.getDatabase() + ":" + principal.getName(), context); Cookie usernameCookie = new Cookie("XWIKISSOAUTHINFO", encuname); usernameCookie.setMaxAge(-1); usernameCookie.setPath("/"); context.getResponse().addCookie(usernameCookie); user = new XWikiUser(principal.getName()); } else { user = new XWikiUser(principal.getName().startsWith(context.getDatabase()) ? principal.getName().substring(context.getDatabase().length() + 1) : principal.getName()); } LOG.debug("XWikiUser=" + user); return user; }