Search in sources :

Example 31 with Cookie

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);
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(javax.ws.rs.core.Response) Cookie(javax.ws.rs.core.Cookie) WebTarget(javax.ws.rs.client.WebTarget) MultivaluedMap(javax.ws.rs.core.MultivaluedMap)

Example 32 with Cookie

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);
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(javax.ws.rs.core.Response) Cookie(javax.ws.rs.core.Cookie) WebTarget(javax.ws.rs.client.WebTarget)

Example 33 with Cookie

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);
    }
}
Also used : Response(javax.ws.rs.core.Response) Cookie(javax.ws.rs.core.Cookie) HashMap(java.util.HashMap) Test(org.testng.annotations.Test)

Example 34 with Cookie

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();
        }
    }
}
Also used : Response(javax.ws.rs.core.Response) Cookie(javax.ws.rs.core.Cookie) HashMap(java.util.HashMap)

Example 35 with Cookie

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);
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) Cookie(javax.ws.rs.core.Cookie) AddRoleToUsersR(org.simbasecurity.dwclient.gateway.representations.AddRoleToUsersR)

Aggregations

Cookie (javax.ws.rs.core.Cookie)80 Test (org.junit.Test)40 Response (javax.ws.rs.core.Response)18 HashMap (java.util.HashMap)12 WebTarget (javax.ws.rs.client.WebTarget)12 HttpServletResponse (javax.servlet.http.HttpServletResponse)10 MultivaluedMap (javax.ws.rs.core.MultivaluedMap)8 NewCookie (javax.ws.rs.core.NewCookie)7 ContainerResponse (org.glassfish.jersey.server.ContainerResponse)7 Map (java.util.Map)5 Message (org.apache.cxf.message.Message)5 Entitlement (com.sun.identity.entitlement.Entitlement)4 EntitlementSubject (com.sun.identity.entitlement.EntitlementSubject)4 Privilege (com.sun.identity.entitlement.Privilege)4 PrivilegeManager (com.sun.identity.entitlement.PrivilegeManager)4 ClientResponse (com.sun.jersey.api.client.ClientResponse)4 HttpHeaders (javax.ws.rs.core.HttpHeaders)4 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)4 BeforeClass (org.testng.annotations.BeforeClass)4 SSOToken (com.iplanet.sso.SSOToken)3