All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.lsn.spring.auth.transport.cookie.CookieAuthHelper Maven / Gradle / Ivy

There is a newer version: 2.2.0
Show newest version
package io.lsn.spring.auth.transport.cookie;

import io.lsn.spring.auth.entity.User;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

public class CookieAuthHelper {

    /**
     * build cookie object
     *
     * @param request
     * @param user
     * @param toRemove
     * @return
     */
    public static Cookie buildCookie(HttpServletRequest request, User user, boolean toRemove) {
        Cookie cookie = new Cookie("X-Auth-Token", toRemove ? null : user.getApiToken().getToken());
        cookie.setHttpOnly(true);
        cookie.setSecure(request.isSecure());
        cookie.setPath("/");
        cookie.setMaxAge(toRemove ? 0 : -1);

        return cookie;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy