use of javax.ws.rs.core.Cookie in project Payara by payara.
the class RestUtil method postRestRequestFromServlet.
public static void postRestRequestFromServlet(HttpServletRequest request, String endpoint, Map<String, Object> attrs, boolean quiet, boolean throwException) {
String token = (String) request.getSession().getAttribute(AdminConsoleAuthModule.REST_TOKEN);
WebTarget target = JERSEY_CLIENT.target(endpoint);
MultivaluedMap formData = buildMultivalueMap(attrs);
Response cr = target.request(RESPONSE_TYPE).cookie(new Cookie(REST_TOKEN_COOKIE, token)).post(Entity.entity(formData, MediaType.APPLICATION_FORM_URLENCODED), Response.class);
RestResponse rr = RestResponse.getRestResponse(cr);
parseResponse(rr, null, endpoint, attrs, quiet, throwException);
}
use of javax.ws.rs.core.Cookie in project Payara by payara.
the class RestUtil method delete.
public static RestResponse delete(String address, Map<String, Object> payload) {
WebTarget target = getJerseyClient().target(address);
Response cr = targetWithQueryParams(target, payload).request(RESPONSE_TYPE).cookie(new Cookie(REST_TOKEN_COOKIE, getRestToken())).delete(Response.class);
return RestResponse.getRestResponse(cr);
}
use of javax.ws.rs.core.Cookie in project Payara by payara.
the class TokenAuthenticationTest method testAuthRequired.
@Test
public void testAuthRequired() {
Map<String, String> newUser = new HashMap<String, String>() {
{
put("id", AUTH_USER_NAME);
put("groups", "asadmin");
put("authrealmname", "admin-realm");
put("AS_ADMIN_USERPASSWORD", AUTH_PASSWORD);
}
};
String token = null;
try {
// Delete the test user if it exists
deleteUserAuthTestUser(token);
// Verify that we can get unauthenticated access to the server
Response response = get("/domain");
assertTrue(isSuccess(response));
// Create the new user
response = post(URL_CREATE_USER, newUser);
assertTrue(isSuccess(response));
// Verify that we must now authentication (response.status = 401)
response = get("/domain");
assertFalse(isSuccess(response));
// Authenticate, get the token, then "clear" the authentication
authenticate();
token = getSessionToken();
resetClient();
// Build this request manually so we can pass the cookie
response = getClient().target(getAddress("/domain")).request().cookie(new Cookie(GF_REST_TOKEN_COOKIE_NAME, token)).get(Response.class);
assertTrue(isSuccess(response));
resetClient();
// Request again w/o the cookie. This should fail.
response = getClient().target(getAddress("/domain")).request().get(Response.class);
assertFalse(isSuccess(response));
authenticate();
} finally {
// Clean up after ourselves
deleteUserAuthTestUser(token);
}
}
use of javax.ws.rs.core.Cookie in project Payara by payara.
the class TokenAuthenticationTest method deleteUserAuthTestUser.
private void deleteUserAuthTestUser(String token) {
if (token != null) {
final String address = getAddress(URL_DELETE_USER);
Response response = getClient().target(address).queryParam("id", AUTH_USER_NAME).request().cookie(new Cookie(GF_REST_TOKEN_COOKIE_NAME, token)).delete(Response.class);
assertTrue(isSuccess(response));
resetClient();
} else {
Response response = delete(URL_DELETE_USER, new HashMap<String, String>() {
{
put("id", AUTH_USER_NAME);
}
});
if (response.getStatus() == 401) {
authenticate();
response = delete(URL_DELETE_USER, new HashMap<String, String>() {
{
put("id", AUTH_USER_NAME);
}
});
assertTrue(isSuccess(response));
resetClient();
}
}
}
use of javax.ws.rs.core.Cookie in project simba-os by cegeka.
the class SimbaRoleService method addRoleToUser.
public void addRoleToUser(String ssoToken, SimbaRoleR simbaRole, SimbaUserR simbaUser) {
checkRoleNotNull(simbaRole);
checkUserNotNull(simbaUser);
AddRoleToUsersR postEntity = new AddRoleToUsersR(simbaRole, simbaUser);
ClientResponse clientResponse = getSimbaResource().path("role").path("addUsers").header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).cookie(new Cookie(AuthenticationConstants.SIMBA_SSO_TOKEN, ssoToken)).post(ClientResponse.class, postEntity);
handleError("addRole", simbaRole.getName(), simbaUser.getUserName(), clientResponse, logger);
}
Aggregations