• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Cookie类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中io.undertow.server.handlers.Cookie的典型用法代码示例。如果您正苦于以下问题:Java Cookie类的具体用法?Java Cookie怎么用?Java Cookie使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Cookie类属于io.undertow.server.handlers包,在下文中一共展示了Cookie类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: findStickyHost

import io.undertow.server.handlers.Cookie; //导入依赖的package包/类
protected Host findStickyHost(HttpServerExchange exchange) {
    Map<String, Cookie> cookies = exchange.getRequestCookies();
    for (String cookieName : sessionCookieNames) {
        Cookie sk = cookies.get(cookieName);
        if (sk != null) {
            int index = sk.getValue().indexOf('.');

            if (index == -1) {
                continue;
            }
            String route = sk.getValue().substring(index + 1);
            index = route.indexOf('.');
            if (index != -1) {
                route = route.substring(0, index);
            }
            return routes.get(route);
        }
    }
    return null;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:21,代码来源:LoadBalancingProxyClient.java


示例2: data

import io.undertow.server.handlers.Cookie; //导入依赖的package包/类
public void data(HttpServerExchange exchange) {
    exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "application/binary");

    // let's also update the cookie, if present. This place will get called frequent enough
    Cookie tokenCookie = exchange.getRequestCookies().get("pxls-token");
    if (tokenCookie != null) {
        setAuthCookie(exchange, tokenCookie.getValue(), 24);
    }

    exchange.getResponseSender().send(ByteBuffer.wrap(App.getBoardData()));
}
 
开发者ID:xSke,项目名称:Pxls,代码行数:12,代码来源:WebHandler.java


示例3: parseToken

import io.undertow.server.handlers.Cookie; //导入依赖的package包/类
private Optional<String> parseToken(HttpServerExchange exchange) {
    if (exchange.getRequestHeaders().contains("Authorization")) {
        String authorizationValue = exchange.getRequestHeaders().getFirst("Authorization");
        String[] tokens = authorizationValue.split("\\s+");
        if (Objects.equals(tokens[0], "Bearer")) {
            return Optional.of(tokens[1]);
        } else {
            return Optional.empty();
        }
    } else if (exchange.getRequestCookies().containsKey(config.getTokenName())) {
        Cookie tokenCookie = exchange.getRequestCookies().get(config.getTokenName());
        return Optional.of(tokenCookie.getValue());
    } else {
        return Optional.empty();
    }
}
 
开发者ID:kawasima,项目名称:bouncr,代码行数:17,代码来源:MultiAppProxyClient.java


示例4: build

import io.undertow.server.handlers.Cookie; //导入依赖的package包/类
public Cookie build() {
    Cookie cookie = new CookieImpl(this.cookieName)
            .setValue(this.cookieValue)
            .setDiscard(this.cookieDiscard)
            .setSecure(this.cookieSecure)
            .setHttpOnly(this.cookieHttpOnly)
            .setPath(this.cookiePath)
            .setExpires((this.cookieExpires == null) ?
                    Date.from(LocalDateTime.now().plusDays(1).atZone(ZoneId.systemDefault()).toInstant()) :
                    Date.from(this.cookieExpires.atZone(ZoneId.systemDefault()).toInstant()));

    if (this.cookieDomain != null) {
        cookie.setDomain(this.cookieDomain);
    }

    if (this.cookieMaxAge != null) {
        cookie.setMaxAge(this.cookieMaxAge);
    }

    return cookie;
}
 
开发者ID:svenkubiak,项目名称:mangooio,代码行数:22,代码来源:CookieBuilder.java


示例5: handleRequest

import io.undertow.server.handlers.Cookie; //导入依赖的package包/类
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
    Locale locale = Locale.forLanguageTag(this.config.getApplicationLanguage());
    Attachment attachment = exchange.getAttachment(RequestHelper.ATTACHMENT_KEY);

    Cookie i18nCookie = exchange.getRequestCookies().get(this.config.getI18nCookieName());
    if (i18nCookie == null) {
        final HeaderValues headerValues = exchange.getRequestHeaders().get(Header.ACCEPT_LANGUAGE.toHttpString());
        if (headerValues != null) {
            String acceptLanguage = headerValues.element();
            if (StringUtils.isNotBlank(acceptLanguage)) {
                locale = LocaleUtils.getLocaleFromString(acceptLanguage);
            }
        }
    } else {
        locale = LocaleUtils.getLocaleFromString(i18nCookie.getValue());
    }

    attachment.getMessages().reload(locale);
    attachment.withLocale(locale);
    
    exchange.putAttachment(RequestHelper.ATTACHMENT_KEY, attachment);
    nextHandler(exchange);
}
 
开发者ID:svenkubiak,项目名称:mangooio,代码行数:25,代码来源:LocaleHandler.java


示例6: readAttribute

import io.undertow.server.handlers.Cookie; //导入依赖的package包/类
@Override
public String readAttribute(final HttpServerExchange exchange) {
    Cookie cookie = exchange.getRequestCookies().get(cookieName);
    if (cookie == null) {
        return null;
    }
    return cookie.getValue();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:9,代码来源:CookieAttribute.java


示例7: flattenCookies

import io.undertow.server.handlers.Cookie; //导入依赖的package包/类
/**
 * Flattens the exchange cookie map into the response header map. This should be called by a
 * connector just before the response is started.
 *
 * @param exchange The server exchange
 */
public static void flattenCookies(final HttpServerExchange exchange) {
    Map<String, Cookie> cookies = exchange.getResponseCookiesInternal();
    if (cookies != null) {
        for (Map.Entry<String, Cookie> entry : cookies.entrySet()) {
            exchange.getResponseHeaders().add(Headers.SET_COOKIE, getCookieString(entry.getValue()));
        }
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:15,代码来源:Connectors.java


示例8: getCookieString

import io.undertow.server.handlers.Cookie; //导入依赖的package包/类
private static String getCookieString(final Cookie cookie) {
    switch (cookie.getVersion()) {
        case 0:
            return addVersion0ResponseCookieToExchange(cookie);
        case 1:
        default:
            return addVersion1ResponseCookieToExchange(cookie);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:10,代码来源:Connectors.java


示例9: addVersion1ResponseCookieToExchange

import io.undertow.server.handlers.Cookie; //导入依赖的package包/类
private static String addVersion1ResponseCookieToExchange(final Cookie cookie) {

        final StringBuilder header = new StringBuilder(cookie.getName());
        header.append("=");
        header.append(cookie.getValue());
        header.append("; Version=1");
        if (cookie.getPath() != null) {
            header.append("; Path=");
            header.append(cookie.getPath());
        }
        if (cookie.getDomain() != null) {
            header.append("; Domain=");
            header.append(cookie.getDomain());
        }
        if (cookie.isDiscard()) {
            header.append("; Discard");
        }
        if (cookie.isSecure()) {
            header.append("; Secure");
        }
        if (cookie.isHttpOnly()) {
            header.append("; HttpOnly");
        }
        if (cookie.getMaxAge() != null) {
            if (cookie.getMaxAge() >= 0) {
                header.append("; Max-Age=");
                header.append(cookie.getMaxAge());
            }
        }
        if (cookie.getExpires() != null) {
            header.append("; Expires=");
            header.append(DateUtils.toDateString(cookie.getExpires()));
        }
        return header.toString();
    }
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:36,代码来源:Connectors.java


示例10: setSessionId

import io.undertow.server.handlers.Cookie; //导入依赖的package包/类
@Override
public void setSessionId(final HttpServerExchange exchange, final String sessionId) {
    Cookie cookie = new CookieImpl(cookieName, sessionId)
            .setPath(path)
            .setDomain(domain)
            .setDiscard(discard)
            .setSecure(secure)
            .setHttpOnly(httpOnly)
            .setComment(comment);
    if (maxAge > 0) {
        cookie.setMaxAge(maxAge);
    }
    exchange.setResponseCookie(cookie);
    exchange.getRequestCookies().put(cookieName, cookie);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:16,代码来源:SessionCookieConfig.java


示例11: clearSession

import io.undertow.server.handlers.Cookie; //导入依赖的package包/类
@Override
public void clearSession(final HttpServerExchange exchange, final String sessionId) {
    Cookie cookie = new CookieImpl(cookieName, sessionId)
            .setPath(path)
            .setDomain(domain)
            .setDiscard(discard)
            .setSecure(secure)
            .setHttpOnly(httpOnly)
            .setMaxAge(0);
    exchange.setResponseCookie(cookie);
    exchange.getRequestCookies().remove(cookieName);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:13,代码来源:SessionCookieConfig.java


示例12: findSessionId

import io.undertow.server.handlers.Cookie; //导入依赖的package包/类
@Override
public String findSessionId(final HttpServerExchange exchange) {
    Map<String, Cookie> cookies = exchange.getRequestCookies();
    if (cookies != null) {
        Cookie sessionId = cookies.get(cookieName);
        if (sessionId != null) {
            return sessionId.getValue();
        }
    }
    return null;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:12,代码来源:SessionCookieConfig.java


示例13: handleRequest

import io.undertow.server.handlers.Cookie; //导入依赖的package包/类
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {

    Cookie sessionId = exchange.getRequestCookies().get(sessionCookieName);
    if (sessionId != null) {
        int part = sessionId.getValue().indexOf('.');
        if (part != -1) {
            sessionId.setValue(sessionId.getValue().substring(0, part));
        }
    }
    exchange.addResponseWrapper(wrapper);
    next.handleRequest(exchange);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:14,代码来源:JvmRouteHandler.java


示例14: wrap

import io.undertow.server.handlers.Cookie; //导入依赖的package包/类
@Override
public StreamSinkConduit wrap(ConduitFactory<StreamSinkConduit> factory, HttpServerExchange exchange) {

    Cookie sessionId = exchange.getResponseCookies().get(sessionCookieName);
    if (sessionId != null) {
        StringBuilder sb = new StringBuilder(sessionId.getValue());
        sb.append('.');
        sb.append(jvmRoute);
        sessionId.setValue(sb.toString());
    }
    return factory.create();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:13,代码来源:JvmRouteHandler.java


示例15: getRequestCookies

import io.undertow.server.handlers.Cookie; //导入依赖的package包/类
/**
 * @return A mutable map of request cookies
 */
public Map<String, Cookie> getRequestCookies() {
    if (requestCookies == null) {
        requestCookies = Cookies.parseRequestCookies(
                getConnection().getUndertowOptions().get(UndertowOptions.MAX_COOKIES, 200),
                getConnection().getUndertowOptions().get(UndertowOptions.ALLOW_EQUALS_IN_COOKIE_VALUE, false),
                requestHeaders.get(Headers.COOKIE));
    }
    return requestCookies;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:13,代码来源:HttpServerExchange.java


示例16: setResponseCookie

import io.undertow.server.handlers.Cookie; //导入依赖的package包/类
/**
 * Sets a response cookie
 *
 * @param cookie The cookie
 */
public HttpServerExchange setResponseCookie(final Cookie cookie) {
    if (responseCookies == null) {
        responseCookies = new TreeMap<>(); //hashmap is slow to allocate in JDK7
    }
    responseCookies.put(cookie.getName(), cookie);
    return this;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:13,代码来源:HttpServerExchange.java


示例17: getResponseCookies

import io.undertow.server.handlers.Cookie; //导入依赖的package包/类
/**
 * @return A mutable map of response cookies
 */
public Map<String, Cookie> getResponseCookies() {
    if (responseCookies == null) {
        responseCookies = new TreeMap<>();
    }
    return responseCookies;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:10,代码来源:HttpServerExchange.java


示例18: logout

import io.undertow.server.handlers.Cookie; //导入依赖的package包/类
public void logout(HttpServerExchange exchange) {
    Cookie tokenCookie = exchange.getRequestCookies().get("pxls-token");

    if (tokenCookie != null) {
        App.getUserManager().logOut(tokenCookie.getValue());
    }

    setAuthCookie(exchange, "", -1);
    respond(exchange, StatusCodes.OK, new EmptyResponse());
}
 
开发者ID:xSke,项目名称:Pxls,代码行数:11,代码来源:WebHandler.java


示例19: getCurrentSessionId

import io.undertow.server.handlers.Cookie; //导入依赖的package包/类
private String getCurrentSessionId(HttpServerExchange exchange) {
	if (exchange == null && ServletRequestContext.current() != null) {
		exchange = ServletRequestContext.current().getExchange();
	}
	if (exchange == null) return null;
	Cookie sessionCookie = exchange.getRequestCookies().get("JSESSIONID");
	if (sessionCookie == null) return null;
	return sessionCookie.getValue();
}
 
开发者ID:openanalytics,项目名称:shinyproxy,代码行数:10,代码来源:DockerService.java


示例20: hasValidAuthentication

import io.undertow.server.handlers.Cookie; //导入依赖的package包/类
/**
 * Checks if the given header contains a valid authentication
 *
 * @param cookieHeader The header to parse
 * @return True if the cookie contains a valid authentication, false otherwise
 */
public boolean hasValidAuthentication(String cookieHeader) {
    boolean validAuthentication = false;
    if (StringUtils.isNotBlank(cookieHeader)) {
        final Map<String, Cookie> cookies = Cookies.parseRequestCookies(1, false, Arrays.asList(cookieHeader));

        Config config = Application.getInstance(Config.class);
        String cookieValue = cookies.get(config.getAuthenticationCookieName()).getValue();
        if (StringUtils.isNotBlank(cookieValue) && !("null").equals(cookieValue)) {
            if (config.isAuthenticationCookieEncrypt()) {
                cookieValue = Application.getInstance(Crypto.class).decrypt(cookieValue);
            }

            String sign = null;
            String expires = null;
            String version = null;
            final String prefix = StringUtils.substringBefore(cookieValue, Default.DATA_DELIMITER.toString());

            if (StringUtils.isNotBlank(prefix)) {
                final String [] prefixes = prefix.split("\\" + Default.DELIMITER.toString());
                if (prefixes != null && prefixes.length == AUTH_PREFIX_LENGTH) {
                    sign = prefixes [INDEX_0];
                    expires = prefixes [INDEX_1];
                    version = prefixes [INDEX_2];
                }
            }

            if (StringUtils.isNotBlank(sign) && StringUtils.isNotBlank(expires)) {
                final String authenticatedUser = cookieValue.substring(cookieValue.indexOf(Default.DATA_DELIMITER.toString()) + 1, cookieValue.length());
                final LocalDateTime expiresDate = LocalDateTime.parse(expires);

                if (LocalDateTime.now().isBefore(expiresDate) && DigestUtils.sha512Hex(authenticatedUser + expires + version + config.getApplicationSecret()).equals(sign)) {
                    validAuthentication = true;
                }
            }
        }
    }

    return validAuthentication;
}
 
开发者ID:svenkubiak,项目名称:mangooio,代码行数:46,代码来源:RequestHelper.java



注:本文中的io.undertow.server.handlers.Cookie类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java AccessibleEditPart类代码示例发布时间:2022-05-22
下一篇:
Java HeaderValueParser类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap