use of javax.ws.rs.core.Cookie in project keywhiz by square.
the class UserAuthFactoryTest method noSessionCookie.
@Test(expected = NotAuthorizedException.class)
public void noSessionCookie() throws Exception {
cookies.put("not-session", new Cookie("not-session", "value"));
factory.provide(request);
}
use of javax.ws.rs.core.Cookie in project keywhiz by square.
the class UserAuthFactoryTest method successfulAuth.
@Test
public void successfulAuth() throws Exception {
User user = User.named("username");
Cookie sessionCookie = new Cookie("session", "valid-session");
cookies.put(sessionCookie.getName(), sessionCookie);
when(cookieAuthenticator.authenticate(sessionCookie)).thenReturn(Optional.of(user));
assertThat(factory.provide(request)).isEqualTo(user);
}
use of javax.ws.rs.core.Cookie in project keywhiz by square.
the class UserAuthFactoryTest method invalidSessionCookie.
@Test(expected = NotAuthorizedException.class)
public void invalidSessionCookie() throws Exception {
Cookie badSessionCookie = new Cookie("session", "bad-value");
cookies.put(badSessionCookie.getName(), badSessionCookie);
when(cookieAuthenticator.authenticate(badSessionCookie)).thenReturn(Optional.empty());
factory.provide(request);
}
use of javax.ws.rs.core.Cookie in project OpenAM by OpenRock.
the class ListenerRestTest method setup.
@BeforeClass
public void setup() throws Exception {
try {
agent = IdRepoUtils.createAgent(REALM, AGENT_NAME);
SSOToken ssoToken = AuthUtils.authenticate(REALM, AGENT_NAME, AGENT_NAME);
String userTokenId = ssoToken.getTokenID().toString();
hashedTokenId = Hash.hash(userTokenId);
tokenIdHeader = RestServiceManager.SSOTOKEN_SUBJECT_PREFIX + RestServiceManager.SUBJECT_DELIMITER + userTokenId;
String cookieValue = userTokenId;
if (Boolean.parseBoolean(SystemProperties.get(Constants.AM_COOKIE_ENCODE, "false"))) {
cookieValue = URLEncoder.encode(userTokenId, "UTF-8");
}
cookie = new Cookie(SystemProperties.get(Constants.AM_COOKIE_NAME), cookieValue);
PrivilegeManager pm = PrivilegeManager.getInstance(REALM, adminSubject);
Privilege privilege = Privilege.getNewInstance();
privilege.setName(PRIVILEGE_NAME);
Map<String, Boolean> actions = new HashMap<String, Boolean>();
actions.put("GET", true);
Entitlement entitlement = new Entitlement(RESOURCE_NAME + "/*", actions);
privilege.setEntitlement(entitlement);
EntitlementSubject sbj = new AuthenticatedUsers();
privilege.setSubject(sbj);
pm.add(privilege);
listenerClient = Client.create().resource(SystemProperties.getServerInstanceName() + "/ws/1/entitlement/listener");
ENC_NOTIFICATION_URL = ESAPI.encoder().encodeForURL(NOTIFICATION_URL);
} catch (Exception e) {
UnittestLog.logError("ListenerRestTest.setup() failed:", e);
throw e;
}
}
use of javax.ws.rs.core.Cookie in project OpenAM by OpenRock.
the class ListenerRestTest method getListener.
private String getListener(String url) throws UnsupportedEncodingException, EncodingException {
String adminTokenId = adminToken.getTokenID().toString();
String adminHashedTokenId = Hash.hash(adminTokenId);
String adminTokenIdHeader = RestServiceManager.SSOTOKEN_SUBJECT_PREFIX + RestServiceManager.SUBJECT_DELIMITER + adminTokenId;
String cookieValue = adminTokenId;
if (Boolean.parseBoolean(SystemProperties.get(Constants.AM_COOKIE_ENCODE, "false"))) {
cookieValue = URLEncoder.encode(adminTokenId, "UTF-8");
}
cookie = new Cookie(SystemProperties.get(Constants.AM_COOKIE_NAME), cookieValue);
String encodedURL = ESAPI.encoder().encodeForURL(url);
String result = listenerClient.path(encodedURL).queryParam("subject", adminHashedTokenId).header(RestServiceManager.SUBJECT_HEADER_NAME, adminTokenIdHeader).cookie(cookie).get(String.class);
return result;
}
Aggregations