Example usage for javax.servlet.http Cookie getValue

List of usage examples for javax.servlet.http Cookie getValue

Introduction

In this page you can find the example usage for javax.servlet.http Cookie getValue.

Prototype

public String getValue() 

Source Link

Document

Gets the current value of this Cookie.

Usage

From source file:hudson.plugins.timestamper.TimestampFormatter.java

/**
 * Create a new {@link TimestampFormatter}.
 * //  w w  w  . j  a  v  a  2s. com
 * @param systemTimeFormat
 *          the system clock time format
 * @param elapsedTimeFormat
 *          the elapsed time format
 * @param request
 *          the current HTTP request
 */
public TimestampFormatter(String systemTimeFormat, String elapsedTimeFormat, HttpServletRequest request) {
    String cookieValue = null;
    Cookie[] cookies = request.getCookies();
    if (cookies != null) {
        for (Cookie cookie : cookies) {
            if ("jenkins-timestamper".equals(cookie.getName())) {
                cookieValue = cookie.getValue();
                break;
            }
        }
    }

    if ("elapsed".equalsIgnoreCase(cookieValue)) {
        formatTimestamp = new ElapsedTimeFormatFunction(elapsedTimeFormat);
    } else if ("none".equalsIgnoreCase(cookieValue)) {
        formatTimestamp = new EmptyFormatFunction();
    } else {
        // "system", no cookie, or unrecognised cookie
        formatTimestamp = new SystemTimeFormatFunction(systemTimeFormat);
    }
}

From source file:com.glaf.core.util.RequestUtils.java

public static String getCookieValue(HttpServletRequest request, String name) {
    String value = null;/*from   w ww.j a  v  a  2  s  .c  o m*/
    Cookie[] cookies = request.getCookies();
    if (cookies != null && cookies.length > 0) {
        for (Cookie cookie : cookies) {
            if (StringUtils.equals(cookie.getName(), name)) {
                value = cookie.getValue();
            }
        }
    }
    return value;
}

From source file:com.sse.abtester.VariantSelectionFilter.java

/**
 * Gets the cookie value.//from   ww w  .  j  a  v a  2s .  co m
 *
 * @param request the request
 * @return cookie value attached to VSKEY, or empty String.
 */
private String getCookieValue(HttpServletRequest request) {
    Cookie[] cookies = request.getCookies();
    String cookieValue = "";
    if (cookies == null)
        return cookieValue;

    for (Cookie c : cookies) {
        if (c.getName() == VSKEY) {
            cookieValue = c.getValue();
            break;
        }
    }
    return cookieValue;
}

From source file:com.persistent.cloudninja.web.security.CNAuthenticationProcessingFilter.java

@Override
protected void successfulAuthentication(HttpServletRequest request, HttpServletResponse response,
        Authentication authResult) throws ServletException, IOException {
    User user = userDetailsService.getCurrentUser();
    String currentCookie = getCookie(request);
    Cookie newCookie = createCookie(user, currentCookie);

    String[] cookievalArray = newCookie.getValue().split("!");
    // get the tenant id
    String tenantId = cookievalArray[1];

    synchronized (userActivityQueue) {
        try {/*from w w  w.  j  av a  2  s. c o  m*/
            Calendar calendar = Calendar.getInstance();
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S z");
            dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
            String date = dateFormat.format(calendar.getTime());

            UserActivityQueueMessage message;

            message = new UserActivityQueueMessage(cookievalArray[1], cookievalArray[0],
                    dateFormat.parse(date));

            userActivityQueue.add(message);
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }

    // create Cookie containing logo url
    Cookie logoCookie = createLogoCookie(tenantId);

    response.addCookie(newCookie);
    response.addCookie(logoCookie);
    super.successfulAuthentication(request, response, authResult);
}

From source file:org.obiba.shiro.web.filter.AuthenticationFilter.java

private boolean isValid(Cookie cookie) {
    return cookie != null && cookie.getValue() != null;
}

From source file:com.xwiki.authentication.AbstractSSOAuthServiceImpl.java

protected XWikiUser checkAuthSSO(String username, String password, XWikiContext context) throws XWikiException {
    Cookie cookie;/*from w w  w  .j a  v a2  s  . c  o m*/

    LOG.debug("checkAuth");

    LOG.debug("Action: " + context.getAction());
    if (context.getAction().startsWith("logout")) {
        cookie = getCookie(COOKIE_NAME, 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(COOKIE_NAME, 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(COOKIE_NAME, 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());
    }

    return user;
}

From source file:org.craftercms.security.processors.impl.AddSecurityCookiesProcessorTest.java

@Test
public void testAddCookiesLoggedIn() throws Exception {
    String ticket = new ObjectId().toString();
    Date lastModified = new Date();

    Profile profile = new Profile();
    profile.setLastModified(lastModified);

    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
    RequestContext context = new RequestContext(request, response);
    RequestSecurityProcessor flushResponseProcessor = new RequestSecurityProcessor() {

        @Override/*  w  w w  .  j  a  va2 s  .c o m*/
        public void processRequest(RequestContext context, RequestSecurityProcessorChain processorChain)
                throws Exception {
            context.getResponse().getOutputStream().flush();
        }

    };

    RequestSecurityProcessorChain chain = new RequestSecurityProcessorChainImpl(
            Arrays.asList(processor, flushResponseProcessor).iterator());

    Authentication auth = new DefaultAuthentication(ticket, profile);
    SecurityUtils.setAuthentication(request, auth);

    processor.processRequest(context, chain);

    Cookie ticketCookie = response.getCookie(SecurityUtils.TICKET_COOKIE_NAME);

    assertNotNull(ticketCookie);
    assertEquals(ticket, ticketCookie.getValue());

    Cookie profileLastModifiedCookie = response.getCookie(SecurityUtils.PROFILE_LAST_MODIFIED_COOKIE_NAME);

    assertNotNull(profileLastModifiedCookie);
    assertEquals(profile.getLastModified().getTime(), Long.parseLong(profileLastModifiedCookie.getValue()));
}

From source file:com.baron.bm.controller.MemberController.java

@RequestMapping("/modify")
public String modifyidentity(String password, HttpServletRequest request) {
    String pass = null;//from   www .  ja v a2s . co m

    for (Cookie cookie : request.getCookies()) {
        if (cookie.getName().equals("bm_id")) {
            pass = joinService.identify(cookie.getValue());
        }
    }

    return (pass.equals(password)) ? "modifyidentity" : "identifyfail";
}

From source file:org.zaizi.sensefy.auth.LoginConfig.java

private Filter csrfHeaderFilter() {
    return new OncePerRequestFilter() {

        @Override// ww  w  .  j  a v a  2  s . c om
        protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
                FilterChain filterChain) throws ServletException, IOException {
            CsrfToken csrf = (CsrfToken) request.getAttribute(CsrfToken.class.getName());
            if (csrf != null) {

                Cookie cookie = WebUtils.getCookie(request, "XSRF-TOKEN");
                String token = csrf.getToken();
                if (cookie == null || token != null && !token.equals(cookie.getValue())) {
                    cookie = new Cookie("XSRF-TOKEN", token);
                    cookie.setPath("/");
                    response.addCookie(cookie);
                    // response.setHeader("Access-Control-Allow-Origin",
                    // "*");
                    // response.setHeader("Access-Control-Allow-Methods",
                    // "POST, GET, OPTIONS, DELETE");
                    // response.setHeader("Access-Control-Max-Age",
                    // "3600");
                    // response.setHeader("Access-Control-Allow-Headers",
                    // "x-requested-with");
                }

            }
            filterChain.doFilter(request, response);
        }
    };
}

From source file:fr.paris.lutece.plugins.mylutece.modules.wssodatabase.authentication.security.WSSOSessionTrackingFilter.java

/**
 * {@inheritDoc}/*from w w w  .j a v a 2  s  . c  o  m*/
 */
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    HttpServletRequest req = (HttpServletRequest) request;
    LuteceUser user = SecurityService.getInstance().getRegisteredUser(req);

    if (user != null) {
        Cookie[] cookies = req.getCookies();
        String strUserID = null;

        if (cookies != null) {
            for (int i = 0; i < cookies.length; i++) {
                Cookie cookie = cookies[i];

                if (cookie.getName().equals(AppPropertiesService.getProperty(PROPERTY_COOKIE_WSSOGUID))) {
                    strUserID = cookie.getValue();
                    if (!StringUtils.isEmpty(strUserID) && !strUserID.equals(user.getName())) {

                        SecurityService.getInstance().unregisterUser(req);

                    }

                    break;

                }
            }
        }
    }

    chain.doFilter(request, response);
}