List of usage examples for javax.servlet.http Cookie getValue
public String getValue()
From source file:nl.surfnet.mujina.saml.SSOSuccessAuthnResponder.java
@Override public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { AuthnRequestInfo info = (AuthnRequestInfo) request.getSession() .getAttribute(AuthnRequestInfo.class.getName()); if (info == null) { logger.warn("Could not find AuthnRequest on the request. Responding with SC_FORBIDDEN."); response.sendError(HttpServletResponse.SC_FORBIDDEN); return;//from w w w.ja va 2 s .c o m } logger.debug("AuthnRequestInfo: {}", info); SimpleAuthentication authToken = (SimpleAuthentication) SecurityContextHolder.getContext() .getAuthentication(); DateTime authnInstant = new DateTime(request.getSession().getCreationTime()); CriteriaSet criteriaSet = new CriteriaSet(); criteriaSet.add(new EntityIDCriteria(idpConfiguration.getEntityID())); criteriaSet.add(new UsageCriteria(UsageType.SIGNING)); Credential signingCredential = null; try { signingCredential = credentialResolver.resolveSingle(criteriaSet); } catch (org.opensaml.xml.security.SecurityException e) { logger.warn("Unable to resolve EntityID while signing", e); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; } Validate.notNull(signingCredential); AuthnResponseGenerator authnResponseGenerator = new AuthnResponseGenerator(signingCredential, idpConfiguration.getEntityID(), timeService, idService, idpConfiguration); EndpointGenerator endpointGenerator = new EndpointGenerator(); final String remoteIP = request.getRemoteAddr(); String attributeJson = null; if (null != request.getCookies()) { for (Cookie current : request.getCookies()) { if (current.getName().equalsIgnoreCase("mujina-attr")) { logger.info("Found a attribute cookie, this is used for the assertion response"); attributeJson = URLDecoder.decode(current.getValue(), "UTF-8"); } } } String acsEndpointURL = info.getAssertionConsumerURL(); if (idpConfiguration.getAcsEndpoint() != null) { acsEndpointURL = idpConfiguration.getAcsEndpoint().getUrl(); } Response authResponse = authnResponseGenerator.generateAuthnResponse(remoteIP, authToken, acsEndpointURL, responseValidityTimeInSeconds, info.getAuthnRequestID(), authnInstant, attributeJson, info.getEntityId()); Endpoint endpoint = endpointGenerator.generateEndpoint( org.opensaml.saml2.metadata.AssertionConsumerService.DEFAULT_ELEMENT_NAME, acsEndpointURL, null); request.getSession().removeAttribute(AuthnRequestInfo.class.getName()); String relayState = request.getParameter("RelayState"); //we could use a different adapter to send the response based on request issuer... try { adapter.sendSAMLMessage(authResponse, endpoint, response, relayState, signingCredential); } catch (MessageEncodingException mee) { logger.error("Exception encoding SAML message", mee); response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE); } }
From source file:com.shenit.commons.utils.HttpUtils.java
/** * ?cookie// ww w .j av a 2s. co m * * @param resp * @param copyToSession * ??session * @param cookies */ public static void save(HttpServletRequest req, HttpServletResponse resp, boolean copyToSession, Cookie... cookies) { HttpSession session = req.getSession(true); for (Cookie cookie : cookies) { resp.addCookie(cookie); if (copyToSession) session.setAttribute(cookie.getName(), cookie.getValue()); } }
From source file:org.sakaiproject.hybrid.util.NakamuraAuthenticationHelper.java
/** * Gets the authentication key from SAKAI-TRACKING cookie. * // w w w . ja va 2 s. c o m * @param request * @return null if no secret can be found. */ protected String getSecret(final HttpServletRequest request) { LOG.debug("getSecret(HttpServletRequest request)"); if (request == null) { throw new IllegalArgumentException("HttpServletRequest == null"); } @SuppressWarnings("PMD.DataflowAnomalyAnalysis") String secret = null; final Cookie[] cookies = request.getCookies(); if (cookies != null) { for (Cookie cookie : cookies) { if (cookieName.equals(cookie.getName())) { secret = cookie.getValue(); } } } return secret; }
From source file:com.pureinfo.tgirls.servlet.TestServlet.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { System.out.println("=================parameter from request===================="); Enumeration ereq = request.getParameterNames(); while (ereq.hasMoreElements()) { String name = (String) ereq.nextElement(); System.out.println(name + "[" + request.getParameter(name) + "]"); }/*w w w . ja va2s . co m*/ System.out.println("=================end===================="); String userTabaoId = request.getParameter("id"); if (StringUtils.isEmpty(userTabaoId)) { userTabaoId = "1"; } try { IUserMgr mgr = (IUserMgr) ArkContentHelper.getContentMgrOf(User.class); User _loginUser = mgr.getUserByTaobaoId(userTabaoId); addCookie(_loginUser, request, response); Cookie[] cookies = request.getCookies(); if (cookies == null) { System.out.println("=====cookie is null======="); } else { for (int i = 0; i < cookies.length; i++) { Cookie cookie = cookies[i]; System.out.println("cookie[" + i + "]:[" + cookie.getName() + ":" + cookie.getValue() + "(" + cookie.getMaxAge() + ")]"); } } //request.getSession().setAttribute(ArkHelper.ATTR_LOGIN_USER, _loginUser); System.out.println("loginuser:" + _loginUser); response.sendRedirect(request.getContextPath()); return; } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(System.err); } }
From source file:com.hangum.tadpole.preference.ui.GeneralPreferencePage.java
/** * initialize locale/* w w w . ja v a 2 s . c om*/ */ private void initLocale() { // ? ? ? .. HttpServletRequest request = RWT.getRequest(); Cookie[] cookies = request.getCookies(); boolean isExist = false; if (cookies != null) { for (Cookie cookie : cookies) { if (PublicTadpoleDefine.TDB_COOKIE_USER_LANGUAGE.equals(cookie.getName())) { comboLanguage.setText(cookie.getValue()); changeUILocale(comboLanguage.getText()); isExist = true; break; } } } // ? ?? ? . if (!isExist) comboLanguage.setText(Locale.ENGLISH.getDisplayLanguage(Locale.ENGLISH)); }
From source file:gr.abiss.calipso.web.filters.RestRequestNormalizerFilter.java
protected String getCookieToken(HttpServletRequest httpRequest) { String authToken = null;//from w w w . j a v a2 s .c o m Cookie[] cookies = httpRequest.getCookies(); String ssoCookieName = userDetailsConfig.getCookiesBasicAuthTokenName(); if (cookies != null) { for (int i = 0; i < cookies.length; i++) { Cookie cookie = cookies[i]; if (LOGGER.isDebugEnabled()) { LOGGER.debug("Found cookie '" + cookie.getName() + "', secure: " + cookie.getSecure() + ", comment: " + cookie.getComment() + ", domain: " + cookie.getDomain() + ", value: " + cookie.getValue()); } if (cookie.getName().equalsIgnoreCase(ssoCookieName)) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Matched calipso SSO cookie'" + cookie.getName() + "', secure: " + cookie.getSecure() + ", comment: " + cookie.getComment() + ", domain: " + cookie.getDomain() + ", value: " + cookie.getValue()); } authToken = cookie.getValue(); break; } } if (LOGGER.isDebugEnabled() && authToken == null) { LOGGER.debug("Found no calipso SSO cookie with name: " + ssoCookieName); } } return authToken; }
From source file:com.xpn.xwiki.stats.impl.StatsUtil.java
/** * Create and initialize a new visit statistics object. * /*w ww . j a v a 2s. co m*/ * @param context the XWiki context. * @return the new visit statistics object. * @since 1.4M1 */ private static VisitStats createNewVisit(XWikiContext context) { VisitStats visitStats = null; XWikiRequest request = context.getRequest(); Date nowDate = new Date(); Cookie cookie = (Cookie) context.get(CONTPROP_STATS_COOKIE); boolean newcookie = ((Boolean) context.get(CONTPROP_STATS_NEWCOOKIE)).booleanValue(); // we need to create the session String ip = request.getRemoteAddr(); String ua = request.getHeader(REQPROP_USERAGENT); if (ua == null) { ua = ""; } String uniqueID; if (newcookie) { // We cannot yet ID the user using the cookie // we need to use the IP and UA uniqueID = ip + ua; } else { // In this case we got the cookie from the request // so we id the user using the cookie uniqueID = cookie.getValue(); } visitStats = new VisitStats(context.getUser(), uniqueID, cookie.getValue(), ip, ua, nowDate, PeriodType.MONTH); visitStats.setEndDate(nowDate); return visitStats; }
From source file:m.c.m.proxyma.resource.ProxymaResponseDataBeanTest.java
/** * Test of getCookies method, of class ProxymaResponseDataBean. *///from ww w . j a v a 2 s . co m public void testGetCookies() { System.out.println("getCookies"); ProxymaResponseDataBean instance = new ProxymaResponseDataBean(); instance.addCookie(new Cookie("name1", "value1")); instance.addCookie(new Cookie("name2", "value2")); instance.addCookie(new Cookie("name1", "value3")); Collection<Cookie> result = instance.getCookies(); assertEquals(2, result.size()); //Test multi values header Iterator<Cookie> iter = result.iterator(); Cookie cookie = iter.next(); if ("name1".equals(cookie.getName())) { assertEquals("value3", cookie.getValue()); assertEquals("value2", iter.next().getValue()); } else { assertEquals("name2", cookie.getName()); assertEquals("value2", cookie.getValue()); assertEquals("value3", iter.next().getValue()); } instance = new ProxymaResponseDataBean(); result = instance.getCookies(); assertEquals(0, result.size()); }
From source file:org.tsm.concharto.web.filter.LoginFilter.java
/** * Returns true if the user is not in the session but the remember me cookie is correct * Also puts the user in the session. /*w ww . j a v a 2s. co m*/ * @param request * @return */ private boolean handleRememberMeCookie(HttpServletRequest request) { if (!AuthHelper.isUserInSession(request)) { Cookie cookie = WebUtils.getCookie(request, AuthHelper.COOKIE_REMEMBER_ME); if (null != cookie) { //if the cookie is there, get the user for that cookie User user = userDao.getUserFromRememberMeKey(cookie.getValue()); if (user != null) { //ok, they are authenticated sessionHelper.setUserInSession(request, user); return true; } } //The user is anonymous sessionHelper.setUserInSession(request, null); } return false; }
From source file:com.wavemaker.tools.security.CloudFoundrySecurityFilter.java
private void checkAuthenticationCookie(HttpServletRequest request) throws TransportTokenDigestMismatchException { Cookie[] allCookies = request.getCookies(); Assert.state(allCookies.length < 12, "Way too many auth cookies."); Cookie[] authCookies = new Cookie[allCookies.length]; int num = 0;//from w w w . j a v a 2 s .com for (Cookie cookie : allCookies) { if (cookie.getName().equals("wavemaker_authentication_token")) { authCookies[num++] = cookie; } } for (Cookie cookie : authCookies) { try { Assert.state(cookie != null, "This is no cookie"); Assert.state(StringUtils.hasLength(cookie.getValue()), "This cookie has no value"); log.debug("Trying = " + cookie.getValue()); SharedSecret sharedSecret = this.propagation.getForSelf(true); sharedSecret.decrypt(TransportToken.decode(cookie.getValue())); return; } catch (TransportTokenDigestMismatchException ttdme) { log.debug("Invalid cookie"); } } log.warn("NO valid cookie - redirecting " + request.getRequestURI() + " to spinup app"); throw (new TransportTokenDigestMismatchException("Unable to find valid secret token")); }