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:com.liusoft.dlog4j.UserLoginManager.java

/**
 *  Velocity?//from   ww w. j  av  a 2  s. co m
 * 
 * @param request
 * @param response
 * @param uuid
 * @param verify_host
 * @return
 * @see com.liusoft.dlog4j.velocity.DLOG_VelocityTool#verify_login_cookie(String,
 *      boolean)
 */
public static SessionUserObject getLoginUser(HttpServletRequest request, HttpServletResponse response,
        boolean verify_host) {
    // sessionsession?
    Cookie uuidCookie = null;
    HttpSession ssn = request.getSession(false);
    if (ssn != null) {
        SessionUserObject user = (SessionUserObject) ssn.getAttribute(SESSION_USER_KEY);
        if (user != null) {
            uuidCookie = getUuidCookie(request);
            //sessioncookie?
            //(?s1s2?)
            if (uuidCookie != null)
                return user;
            ssn.invalidate();
            return null;
        }
    }
    String uuid = null;
    if (uuidCookie == null)
        uuidCookie = getUuidCookie(request);
    if (uuidCookie != null)
        uuid = uuidCookie.getValue();
    if (StringUtils.isEmpty(uuid))
        return null;
    // session?
    try {
        UUID oUUID = new UUID(uuid);
        String new_host = request.getRemoteAddr();
        if (verify_host && !StringUtils.equals(new_host, oUUID.host))
            return null;
        UserBean user = UserDAO.getUserByID(oUUID.uid);
        // ?
        if (user == null || user.getStatus() != UserBean.STATUS_NORMAL
                || user.getPassword().hashCode() != oUUID.pwdCode) {
            RequestUtils.setCookie(request, response, COOKIE_UUID_KEY, "", 0);
            RequestUtils.setCookie(request, response, COOKIE_LASTLOGIN_KEY, "", 0);
            return null;
        }
        int keep_days = user.getKeepDays();
        if (keep_days < 1)
            keep_days = 365;
        return loginUser(request, response, user, keep_days);
    } catch (Exception e) {
        log.error("Exception occur when get current user.", e);
    }

    return null;
}

From source file:co.edu.utb.softeng.springtodos.config.security.CsrfHeaderFilter.java

@Override
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);//www.  ja v a2 s . c o  m
        }

    }
    filterChain.doFilter(request, response);

}

From source file:com.springsource.greenhouse.home.DateTimeZoneHandlerInterceptor.java

private Integer getMillisOffset(HttpServletRequest request) {
    Cookie cookie = WebUtils.getCookie(request, "Greenhouse.timeZoneOffset");
    if (cookie != null) {
        return Integer.valueOf(cookie.getValue());
    } else {//from w  w  w .  j  a v a 2 s.  c  o  m
        return null;
    }
}

From source file:gov.nih.nci.ncicb.cadsr.admintool.struts.action.BaseDispatchAction.java

protected ActionForward dispatchMethod(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response, String name) throws Exception {

    String user = null;//from  ww w .  j a  v a  2  s  .  c om
    Cookie[] cookieArray = request.getCookies();
    if (cookieArray != null) {
        for (int i = 0; i < cookieArray.length; i++) {
            Cookie c = cookieArray[i];
            if (c.getName().equals("ADMIN_TOOL_USER")) {
                user = c.getValue();
                System.out.println("Reading username from cookie :" + user);
                System.out.println("Domain: " + c.getDomain());
                System.out.println("Path: " + c.getPath());
            }
        }
    }
    if (user == null) {
        return mapping.findForward("login");
    }
    return super.dispatchMethod(mapping, form, request, response, name);
}

From source file:gov.nih.nci.ncicb.cadsr.admintool.struts.action.BaseAction.java

public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    String user = null;//from  w  w w. j a  v  a2  s. c om
    Cookie[] cookieArray = request.getCookies();
    if (cookieArray != null) {
        for (int i = 0; i < cookieArray.length; i++) {
            Cookie c = cookieArray[i];
            if (c.getName().equals("ADMIN_TOOL_USER")) {
                user = c.getValue();
                System.out.println("Reading username from cookie :" + user);
                System.out.println("Domain: " + c.getDomain());
                System.out.println("Path: " + c.getPath());
            }
        }
    }
    if (user == null) {
        return mapping.findForward("login");
    }

    return executeAction(mapping, form, request, response);
}

From source file:com.ar.dev.tierra.api.config.CsrfHeaderFilter.java

/**
 * Metodo para agregar cookie contra CRSF
 * @param request//from ww  w  .j  a va 2s  .c o  m
 * @param response
 * @param filterChain
 * @throws ServletException
 * @throws IOException 
 */
@Override
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);
        }
    }
    filterChain.doFilter(request, response);
}

From source file:name.cphillipson.experimental.gwt.server.interceptor.DateTimeZoneHandlerInterceptor.java

private Integer getMillisOffset(HttpServletRequest request) {
    final Cookie cookie = WebUtils.getCookie(request, "emkt.timeZoneOffset");
    if (cookie != null) {
        return Integer.valueOf(cookie.getValue());
    } else {//from   w  w  w. j  av a2 s.co  m
        return null;
    }
}

From source file:pl.szcze.userserviceproject.CsrfHeaderFilter.java

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
        FilterChain filterChain) throws ServletException, IOException {
    CsrfToken csrfToken = (CsrfToken) request.getAttribute(CsrfToken.class.getName());

    if (csrfToken != null) {
        Cookie cookie = WebUtils.getCookie(request, "XSRF-TOKEN");
        String token = csrfToken.getToken();

        if (cookie == null || token != null && !token.equals(cookie.getValue())) {
            cookie = new Cookie("XSRF-TOKEN", token);
            cookie.setPath("/");
            response.addCookie(cookie);/*from w  ww.  jav a 2 s  .  com*/
        }
    }

    filterChain.doFilter(request, response);
}

From source file:com.zextras.zimbradrive.BackendUtils.java

private String assertZmAuthTokenFromCookies(HttpServletRequest httpServletRequest) {
    Cookie[] cookies = httpServletRequest.getCookies();
    for (Cookie cookie : cookies) {
        if (cookie.getName().equals(AUTH_TOKEN)) {
            return cookie.getValue();
        }//from  ww  w  . ja va 2  s  .  co m
    }
    throw new NoZmAuthTokenCookieFoundException();
}

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

/**
 * Find the cookie in request and /*from  www. j a v  a2 s  . co m*/
 * @param request
 * @param cookieName
 * @return
 */

protected String getCookieValue(HttpServletRequest request, String cookieName) {
    String cookieValue = null;
    Cookie[] cookies = request.getCookies();
    if (cookies != null)
        for (Cookie cookie : cookies)
            if (cookie.getName().equals(cookieName)) {
                cookieValue = cookie.getValue();
                break;
            }
    return cookieValue;
}