use of javax.ws.rs.core.NewCookie in project jersey by jersey.
the class FormResource method getForm.
/**
* Produce a form from a static HTML file packaged with the compiled class
* @return a stream from which the HTML form can be read.
*/
@GET
public Response getForm() {
Date now = new Date();
InputStream entity = this.getClass().getClassLoader().getResourceAsStream("form.html");
return Response.ok(entity).cookie(new NewCookie("date", now.toString())).build();
}
use of javax.ws.rs.core.NewCookie in project keywhiz by square.
the class SessionLoginResourceTest method goodCredentialsSetsCookie.
@Test
public void goodCredentialsSetsCookie() throws Exception {
User user = User.named("goodUser");
when(ldapAuthenticator.authenticate(goodCredentials)).thenReturn(Optional.of(user));
Response response = sessionLoginResource.login(LoginRequest.from("good", "credentials".toCharArray()));
assertThat(response.getStatus()).isEqualTo(SEE_OTHER.getStatusCode());
Map<String, NewCookie> responseCookies = response.getCookies();
assertThat(responseCookies).hasSize(2).containsOnlyKeys("session", "XSRF-TOKEN");
User authUser = cookieAuthenticator.authenticate(responseCookies.get("session")).orElseThrow(RuntimeException::new);
assertThat(authUser).isEqualTo(user);
}
use of javax.ws.rs.core.NewCookie in project keywhiz by square.
the class SessionLogoutResourceIntegrationTest method sendsExpiredCookie.
@Test
public void sendsExpiredCookie() throws Exception {
Request request = new Request.Builder().post(RequestBody.create(MediaType.parse("text/plain"), "")).url(testUrl("/admin/logout")).build();
Response response = client.newCall(request).execute();
assertThat(response.code()).isEqualTo(303);
List<String> cookies = response.headers(HttpHeaders.SET_COOKIE);
assertThat(cookies).hasSize(1);
NewCookie cookie = NewCookie.valueOf(cookies.get(0));
assertThat(cookie.getName()).isEqualTo("session");
assertThat(cookie.getValue()).isEqualTo("expired");
assertThat(cookie.getVersion()).isEqualTo(1);
assertThat(cookie.getPath()).isEqualTo("/admin");
assertThat(cookie.isSecure()).isTrue();
assertThat(cookie.isHttpOnly()).isTrue();
assertThat(cookie.getExpiry()).isEqualTo(new Date(0));
}
use of javax.ws.rs.core.NewCookie in project ddf by codice.
the class IdpEndpoint method createCookie.
private NewCookie createCookie(HttpServletRequest request, org.opensaml.saml.saml2.core.Response response) {
LOGGER.debug("Creating cookie for user.");
if (response.getAssertions() != null && response.getAssertions().size() > 0) {
Assertion assertion = response.getAssertions().get(0);
if (assertion != null) {
UUID uuid = UUID.randomUUID();
cookieCache.cacheSamlAssertion(uuid.toString(), assertion.getDOM());
URL url;
try {
url = new URL(request.getRequestURL().toString());
LOGGER.debug("Returning new cookie for user.");
return new NewCookie(COOKIE, uuid.toString(), SERVICES_IDP_PATH, url.getHost(), NewCookie.DEFAULT_VERSION, null, -1, null, true, true);
} catch (MalformedURLException e) {
LOGGER.info("Unable to create session cookie. Client will need to log in again.", e);
}
}
}
return null;
}
use of javax.ws.rs.core.NewCookie in project dropwizard by dropwizard.
the class FlashFactoryTest method passesInHttpSessions.
@Test
public void passesInHttpSessions() throws Exception {
Response firstResponse = target("/flash").request(MediaType.TEXT_PLAIN).post(Entity.entity("Mr. Peeps", MediaType.TEXT_PLAIN));
final Map<String, NewCookie> cookies = firstResponse.getCookies();
firstResponse.close();
Invocation.Builder builder = target("/flash").request().accept(MediaType.TEXT_PLAIN);
for (NewCookie cookie : cookies.values()) {
builder = builder.cookie(cookie);
}
final String secondResponse = builder.get(String.class);
assertThat(secondResponse).isEqualTo("Mr. Peeps");
Invocation.Builder anotherBuilder = target("/flash").request().accept(MediaType.TEXT_PLAIN);
for (NewCookie cookie : cookies.values()) {
anotherBuilder = anotherBuilder.cookie(cookie);
}
final String thirdResponse = anotherBuilder.get(String.class);
assertThat(thirdResponse).isEqualTo("null");
}
Aggregations