本文整理汇总了Java中javax.ws.rs.core.Cookie.getValue方法的典型用法代码示例。如果您正苦于以下问题:Java Cookie.getValue方法的具体用法?Java Cookie.getValue怎么用?Java Cookie.getValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.ws.rs.core.Cookie
的用法示例。
在下文中一共展示了Cookie.getValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: provideValue
import javax.ws.rs.core.Cookie; //导入方法依赖的package包/类
@Override
public Object provideValue(Parameter parameter, ContainerRequestContext requestContext, ObjectMapper objectMapper) {
Object returnValue;
String cookieName = parameter.getAnnotation(CookieParam.class).value();
Cookie cookie = requestContext.getCookies().get(cookieName);
if (cookie == null) {
return null;
} else {
if (Cookie.class.isAssignableFrom(parameter.getType())) {
returnValue = cookie;
} else if (String.class.isAssignableFrom(parameter.getType())) {
returnValue = cookie.getValue();
} else {
try {
returnValue = objectMapper.readValue(cookie.getValue(), parameter.getType());
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
}
return returnValue;
}
示例2: provideValue
import javax.ws.rs.core.Cookie; //导入方法依赖的package包/类
@Override
public Object provideValue(Parameter parameter, ContainerRequestContext requestContext, ObjectMapper objectMapper) {
Object returnValue;
String cookieName = parameter.getAnnotation(CookieParam.class).value();
Cookie cookie = requestContext.getCookies().get(cookieName);
if (cookie == null) {
return null;
} else {
if (Cookie.class.isAssignableFrom(parameter.getType())) {
returnValue = cookie;
} else if (String.class.isAssignableFrom(parameter.getType())) {
returnValue = cookie.getValue();
} else {
try {
returnValue = objectMapper.readValue(cookie.getValue(), parameter.getType());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
return returnValue;
}
示例3: logout
import javax.ws.rs.core.Cookie; //导入方法依赖的package包/类
/**
* Perform logout for the given token.
*
* @param token - authentication token
* @param tokenAccessCookie - old session-based cookie with token.
*/
public Response logout(String token, Cookie tokenAccessCookie, UriInfo uriInfo) {
Response.ResponseBuilder response;
String accessToken = token;
if (accessToken == null && tokenAccessCookie != null) {
accessToken = tokenAccessCookie.getValue();
}
boolean secure = uriInfo.getRequestUri().getScheme().equals("https");
if (accessToken != null) {
response = Response.ok();
AccessTicket accessTicket = ticketManager.removeTicket(accessToken);
if (accessTicket != null) {
LOG.info("EVENT#user-sso-logged-out# USER#{}#", accessTicket.getUserId());
} else {
LOG.warn("AccessTicket not found. Nothing to do.");
}
} else {
response = Response.status(Response.Status.BAD_REQUEST);
LOG.warn("Token not found in request.");
}
if (cookieBuilder != null) {
cookieBuilder.clearCookies(response, accessToken, secure);
}
return response.build();
}
示例4: startServices
import javax.ws.rs.core.Cookie; //导入方法依赖的package包/类
public static void startServices() throws Exception {
//System.setProperty("bdb.log.level", "trace");
startAdminServer();
ctx = startCacheServer("0");
//URI baseURI = new URI("https://localhost:3443");
URI baseURI = new URI("http://localhost:3030");
ClientConfig clientConfig = new ClientConfig();
Client client = ClientBuilder.newClient(clientConfig);
target = client.target(baseURI);
LoginParams params = new LoginParams("default", "guest", "password");
Response response = target.path("access/login").request()
.header("Content-Type", "application/json")
.post(Entity.json(params), Response.class);
assertEquals(Status.OK.getStatusCode(), response.getStatus());
Cookie cc = response.getCookies().get(bg_cookie);
assertNotNull(cc);
assertEquals(bg_cookie, cc.getName());
cuid = cc.getValue();
}
示例5: getValue
import javax.ws.rs.core.Cookie; //导入方法依赖的package包/类
@Override
public T getValue(HttpContext httpContext) {
final Cookie cookie = httpContext.getRequest().getCookies().get(this.cookie);
if (cookie != null) {
final String value = cookie.getValue();
try {
final Optional<T> result = authenticator.authenticate(value);
if (result.isPresent()) {
return result.get();
}
} catch (AuthenticationException e) {
e.printStackTrace();
}
}
if (required) {
throw new WebApplicationException(
Response.status(Response.Status.UNAUTHORIZED)
.entity("Credentials are required to access this resource")
.type(MediaType.TEXT_PLAIN_TYPE)
.build());
}
return null;
}
示例6: getRememberedSerializedIdentity
import javax.ws.rs.core.Cookie; //导入方法依赖的package包/类
@Override
protected byte[] getRememberedSerializedIdentity(SubjectContext subjectContext) {
if (isIdentityRemoved()) {
return null;
}
Cookie cookie = Requests.getCookies().get(getCookie().getName());
//no cookie set - new site visitor?
if (cookie == null) return null;
String base64 = cookie.getValue();
if (Cookies.DELETED_COOKIE_VALUE.equals(base64)) return null;
if (base64 != null) {
base64 = ensurePadding(base64);
logger.trace("Acquired Base64 encoded identity [" + base64 + "]");
byte[] decoded = Base64.decode(base64);
logger.trace("Base64 decoded byte array length: " + (decoded != null ? decoded.length : 0) + " bytes.");
return decoded;
} else {
//no cookie set - new site visitor?
return null;
}
}
示例7: extractCookie
import javax.ws.rs.core.Cookie; //导入方法依赖的package包/类
public static Function<ContainerRequestContext,String> extractCookie(final String cookieName) {
return new Function<ContainerRequestContext, String>() {
@Nullable
@Override
public String apply(@Nullable ContainerRequestContext request) {
if (request == null) {
return null;
} else {
Cookie cookie = request.getCookies().get(cookieName);
if (cookie == null) {
return null;
} else {
return cookie.getValue();
}
}
}
};
}
示例8: restoreWithTimestamp
import javax.ws.rs.core.Cookie; //导入方法依赖的package包/类
<T> TimestampedState<T> restoreWithTimestamp(final Cookie cookie, final Class<T> type) {
final String value = cookie.getValue();
final String[] parts = value.split("\\|", 5);
final byte[] atime = DECODER.decode(parts[1]);
final long atimeLong = atime(atime);
if (atimeLong + timeout < timeSource.getAsLong()) {
throw new IllegalArgumentException("Given value has timed out at: " + Instant.ofEpochSecond(atimeLong));
}
final byte[] tid = DECODER.decode(parts[2]);
if (!MessageDigest.isEqual(tid, edition.tid)) {
throw new IllegalArgumentException(String.format("Given TID `%s`, mismatches current TID `%s`",
new BigInteger(tid).toString(16), new BigInteger(edition.tid).toString(16)));
}
final KeySource keySource = edition.keySource();
final int lastSeparatorIdx = value.lastIndexOf('|');
final byte[] mac = DECODER.decode(parts[4]);
final byte[] calculated = mac(edition.authenticationAlgorithm, value.substring(0, lastSeparatorIdx),
keySource.authenticationKey());
if (!MessageDigest.isEqual(mac, calculated)) {
throw new IllegalArgumentException("Cookie value fails authenticity check");
}
final byte[] iv = DECODER.decode(parts[3]);
final byte[] encrypted = DECODER.decode(parts[0]);
final byte[] clear = decrypt(edition.encryptionAlgorithm, iv, encrypted, keySource.encryptionKey());
@SuppressWarnings("unchecked")
final T ret = (T) deserialization.apply(type, clear);
return new TimestampedState<>(ret, atimeLong);
}
示例9: toString
import javax.ws.rs.core.Cookie; //导入方法依赖的package包/类
@Override
public String toString(final Cookie cookie) {
final HttpCookie httpCookie = new HttpCookie(cookie.getName(), cookie.getValue());
httpCookie.setDomain(cookie.getDomain());
httpCookie.setPath(cookie.getPath());
return httpCookie.toString();
}
示例10: get
import javax.ws.rs.core.Cookie; //导入方法依赖的package包/类
@Override
public T get() {
final MinijaxRequestContext context = MinijaxRequestContext.getThreadLocal();
final Cookie cookie = context.getCookies().get(key.getName());
final String cookieValue = cookie == null ? null : cookie.getValue();
return context.getApplication().convertParamToType(cookieValue, key.getType(), key.getAnnotations());
}
示例11: filter
import javax.ws.rs.core.Cookie; //导入方法依赖的package包/类
@Override
public void filter(ClientRequestContext clientRequestContext) throws IOException {
String query = clientRequestContext.getUri().getQuery();
Cookie cookie = clientRequestContext.getCookies().get("cookie");
String cookieValue = cookie==null?"null":cookie.getValue();
String header = clientRequestContext.getHeaderString("MyHeader");
clientRequestContext.abortWith(Response.ok(query + " " + cookieValue + " " + header).build());
}
示例12: filter
import javax.ws.rs.core.Cookie; //导入方法依赖的package包/类
@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
boolean useAuthentication = AccessServices.useAuthentication();
if(useAuthentication) {
Cookie sessionCookie = requestContext.getCookies().get("sessionid");
if(sessionCookie!=null) {
String token = sessionCookie.getValue();
try {
Session session = validateToken(token);
requestContext.setProperty("session", session);
Secured annotation = extendendUriInfo.getMatchedResourceMethod().getInvocable().getHandlingMethod().getAnnotation(Secured.class);
String right = annotation.right();
if(right.length()>0) {
Profile profile = session.getProfile();
boolean hasRight = profile.getRights().contains(right);
if(!hasRight) {
requestContext.abortWith(Response.status(Response.Status.UNAUTHORIZED).build());
}
}
} catch (Exception e) {
requestContext.abortWith(Response.status(Response.Status.UNAUTHORIZED).build());
}
} else {
requestContext.abortWith(Response.status(Response.Status.UNAUTHORIZED).build());
}
} else {
requestContext.setProperty("session", AccessServices.ANONYMOUS_SESSION);
}
}
示例13: authenticate
import javax.ws.rs.core.Cookie; //导入方法依赖的package包/类
@Override
public Optional<User> authenticate(final Cookie cookie) throws AuthenticationException {
final String token = cookie.getValue();
final Optional<Map<String, Object>> maybeClaims = getClaims(token);
try {
return maybeClaims.transform(jwtTokenManager::fromJWTClaim);
} catch (final IllegalArgumentException e) {
LOGGER.warn("Unable to read User from JWT claim", e);
return Optional.absent();
}
}
示例14: getLoginCookie
import javax.ws.rs.core.Cookie; //导入方法依赖的package包/类
/**
* Get the LoginCookie for a specific client
*
* @param client to find the login cookie for
* @return the login cookie
*/
public static LoginCookie getLoginCookie(
final EntityManager em,
final ContainerRequestContext req,
final Client client
) {
final Cookie cookie = getCookie(req, client);
if (cookie == null) {
return null;
}
// the cookie value is the login cookie secret
final String secret = cookie.getValue();
return getLoginCookie(em, secret, client);
}
示例15: getUserToken
import javax.ws.rs.core.Cookie; //导入方法依赖的package包/类
public String getUserToken(String reefssid) throws Exception {
WebTarget target = client.target(IElementsUserApi.CLOUD_URL);
// create a new client proxy for the BooksResource
IElementsUserApi elementsCloud = WebResourceFactory.newResource(IElementsUserApi.class, target);
Response response = elementsCloud.connect("gigaset", reefssid);
Cookie usercookie = response.getCookies().get("usertoken");
return usercookie.getValue();
}