List of usage examples for javax.servlet.http Cookie getName
public String getName()
From source file:de.anycook.session.Session.java
private void loginWithCookies(javax.servlet.http.Cookie[] cookies) throws IOException, SQLException { if (cookies == null) { return;/* w w w .j av a 2s .c o m*/ } for (javax.servlet.http.Cookie cookie : cookies) { if (cookie.getName().equals("anycook")) { String cookieId = cookie.getValue(); try { login(cookieId); } catch (DBUser.CookieNotFoundException | DBUser.UserNotFoundException e) { logger.warn(e, e); } } String fbCookieKey = "fbsr_" + FacebookHandler.APP_ID; if (cookie.getName().equals(fbCookieKey)) { String cookieValue = cookie.getValue(); FacebookHandler.FacebookRequest request = FacebookHandler.decode(cookieValue); Long uid = Long.parseLong(request.user_id); try { facebookLogin(uid); } catch (User.LoginException | DBUser.UserNotFoundException e) { logger.warn(e, e); } } } }
From source file:com.itude.mobile.mobbl.server.http.HttpDelegate.java
private void prepareConnection(HttpMethod method, String userAgent, ArrayList<Cookie> cookies, Header[] requestHeaders, boolean acceptXml, boolean followRedirects) { logger.debug("HttpDelegate.prepareConnection()"); if (logger.isDebugEnabled()) HeaderUtil.printRequestHeaders(logger, method); if (acceptXml) method.addRequestHeader("Accept", "application/xml, */*"); if (cookies != null) { for (Cookie cookie : cookies) method.addRequestHeader("Cookie", cookie.getName() + "=" + cookie.getValue()); }/*from w ww. j av a 2 s . co m*/ if (userAgent != null) method.addRequestHeader(Constants.USER_AGENT, userAgent); method.setFollowRedirects(followRedirects); if (requestHeaders != null) for (Header h : requestHeaders) method.addRequestHeader(h); }
From source file:hudson.plugins.timestamper.format.TimestampFormatter.java
/** * Create a new {@link TimestampFormatter}. * /*www. j a v a 2 s .c o m*/ * @param systemTimeFormat * the system clock time format * @param elapsedTimeFormat * the elapsed time format * @param request * the current HTTP request * @param timeZoneId * the currently configured time zone */ TimestampFormatter(String systemTimeFormat, String elapsedTimeFormat, Optional<? extends HttpServletRequest> request, Optional<String> timeZoneId) { String mode = null; Boolean local = null; String offset = null; if (request.isPresent()) { Cookie[] cookies = request.get().getCookies(); if (cookies != null) { for (Cookie cookie : cookies) { if (mode == null && "jenkins-timestamper".equals(cookie.getName())) { mode = cookie.getValue(); } if (local == null && "jenkins-timestamper-local".equals(cookie.getName())) { local = Boolean.valueOf(cookie.getValue()); } if (offset == null && "jenkins-timestamper-offset".equals(cookie.getName())) { offset = cookie.getValue(); } } } } if ("elapsed".equalsIgnoreCase(mode)) { formatTimestamp = new ElapsedTimeFormatFunction(elapsedTimeFormat); } else if ("none".equalsIgnoreCase(mode)) { formatTimestamp = new EmptyFormatFunction(); } else { // "system", no mode cookie, or unrecognised mode cookie if (local != null && local.booleanValue()) { if (offset == null) { offset = "0"; } String localTimeZoneId = convertOffsetToTimeZoneId(offset); timeZoneId = Optional.of(localTimeZoneId); } formatTimestamp = new SystemTimeFormatFunction(systemTimeFormat, timeZoneId); } }
From source file:org.apache.jsp.fileUploader_jsp.java
public static String getBrowserInfiniteCookie(HttpServletRequest request) { Cookie[] cookieJar = request.getCookies(); if (cookieJar != null) { for (Cookie cookie : cookieJar) { if (cookie.getName().equals("infinitecookie")) { //System.out.println("Got Browser Cookie Line 109: " + cookie.getValue()); return cookie.getValue() + ";"; }//from ww w . j a v a2 s . c o m } } return null; }
From source file:net.ymate.platform.mvc.web.support.CookieHelper.java
private Cookie __doGetCookie(String cookieName) { Cookie _cookies[] = this.__request.getCookies(); if (_cookies == null) { return null; } else {//from w ww . j a v a2 s . co m for (int i = 0; i < _cookies.length; i++) { Cookie _cookie = _cookies[i]; String name = _cookie.getName(); if (name.equals(cookieName)) { return _cookie; } } return null; } }
From source file:com.vmware.demo.HomeController.java
@RequestMapping(value = "/sso", method = RequestMethod.GET) public String createForm(HttpServletRequest request, Locale locale, Model model) { if (null != request.getSession().getAttribute(ATTRIBUTE_SAML_CERTIFICATE)) { model.addAttribute(ATTRIBUTE_SAML_CERTIFICATE, request.getSession().getAttribute(ATTRIBUTE_SAML_CERTIFICATE)); }/*w ww .j a v a2s . c om*/ if (null != request.getSession().getAttribute(ATTRIBUTE_IDP_URI)) { model.addAttribute(ATTRIBUTE_IDP_URI, request.getSession().getAttribute(ATTRIBUTE_IDP_URI)); } else { String cookieValue = null; Cookie[] cookies = request.getCookies(); if (null != cookies) { for (Cookie cookie : cookies) { if (COOKIE_NAME.equals(cookie.getName())) { cookieValue = cookie.getValue(); } } } if (null != cookieValue) { } else { model.addAttribute(ATTRIBUTE_IDP_URI, DEFAULT_SAML_CONSUMER); } } model.addAttribute(ATTRIBUTE_META_DATA, generateMetaData(request)); model.addAttribute(ATTRIBUTE_RELAY_STATE, getURLWithContextPath(request)); model.addAttribute("action", "setup"); return "home"; }
From source file:net.ymate.platform.mvc.web.support.CookieHelper.java
/** * @return ?Cookie/*w w w . j av a2 s . co m*/ */ public Map<String, BlurObject> getCookies() { Map<String, BlurObject> _returnValue = new HashMap<String, BlurObject>(); Cookie[] _cookies = __request.getCookies(); if (_cookies != null) { String _cookiePre = WebMVC.getConfig().getCookiePrefix(); int _preLength = StringUtils.length(_cookiePre); for (Cookie _cookie : _cookies) { String _name = _cookie.getName(); if (_name.startsWith(_cookiePre)) { String _v = decodeValue(_cookie.getValue()); _returnValue.put(_name.substring(_preLength), new BlurObject(_v)); } } } return _returnValue; }
From source file:com.bradmcevoy.http.ServletRequest.java
@Override public Cookie getCookie(String name) { if (request.getCookies() != null) { for (javax.servlet.http.Cookie c : request.getCookies()) { if (c.getName().equals(name)) { return new ServletCookie(c); }//from w ww. j a va 2 s. c om } } return null; }
From source file:com.datatorrent.stram.security.StramWSFilter.java
@Override public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException { if (!(req instanceof HttpServletRequest)) { throw new ServletException("This filter only works for HTTP/HTTPS"); }/*from w w w .j a va 2 s .co m*/ HttpServletRequest httpReq = (HttpServletRequest) req; HttpServletResponse httpResp = (HttpServletResponse) resp; if (LOG.isDebugEnabled()) { LOG.debug("Remote address for request is: " + httpReq.getRemoteAddr()); } String requestURI = httpReq.getRequestURI(); if (LOG.isDebugEnabled()) { LOG.debug("Request path " + requestURI); } boolean authenticate = true; String user = null; if (getProxyAddresses().contains(httpReq.getRemoteAddr())) { if (httpReq.getCookies() != null) { for (Cookie c : httpReq.getCookies()) { if (WEBAPP_PROXY_USER.equals(c.getName())) { user = c.getValue(); break; } } } if (requestURI.equals(WebServices.PATH) && (user != null)) { String token = createClientToken(user, httpReq.getLocalAddr()); if (LOG.isDebugEnabled()) { LOG.debug("Create token " + token); } Cookie cookie = new Cookie(CLIENT_COOKIE, token); httpResp.addCookie(cookie); } authenticate = false; } if (authenticate) { Cookie cookie = null; if (httpReq.getCookies() != null) { for (Cookie c : httpReq.getCookies()) { if (c.getName().equals(CLIENT_COOKIE)) { cookie = c; break; } } } boolean valid = false; if (cookie != null) { if (LOG.isDebugEnabled()) { LOG.debug("Verifying token " + cookie.getValue()); } user = verifyClientToken(cookie.getValue()); valid = true; if (LOG.isDebugEnabled()) { LOG.debug("Token valid"); } } if (!valid) { httpResp.sendError(HttpServletResponse.SC_UNAUTHORIZED); return; } } if (user == null) { LOG.warn("Could not find " + WEBAPP_PROXY_USER + " cookie, so user will not be set"); chain.doFilter(req, resp); } else { final StramWSPrincipal principal = new StramWSPrincipal(user); ServletRequest requestWrapper = new StramWSServletRequestWrapper(httpReq, principal); chain.doFilter(requestWrapper, resp); } }
From source file:com.tenduke.example.scribeoauth.SessionManager.java
/** * Validates an authenticated session and will provide the logged in user's session information as validation result. * @param request Client HTTP request./* w w w. j a va 2 s . co m*/ * @param response HTTP response. * @return Session information or null if session is not valid. */ public SessionInformation validateSession(final HttpServletRequest request, final HttpServletResponse response) { // SessionInformation retValue = null; // String sessionId = null; final Cookie[] cookies = request.getCookies(); if (cookies != null && cookies.length > 0) { // for (Cookie cookie : cookies) { // if (SIGNED_SESSION_COOKIE_NAME.equals(cookie.getName())) { // sessionId = cookie.getValue().split("_")[0]; } } } // if (sessionId != null) { // retValue = getSessionInformation(sessionId); } // return retValue; }