Search in sources :

Example 71 with Cookie

use of javax.ws.rs.core.Cookie in project cxf by apache.

the class AbstractServiceProviderFilter method checkSecurityContext.

protected boolean checkSecurityContext(Message m) {
    HttpHeaders headers = new HttpHeadersImpl(m);
    Map<String, Cookie> cookies = headers.getCookies();
    Cookie securityContextCookie = cookies.get(SSOConstants.SECURITY_CONTEXT_TOKEN);
    ResponseState responseState = getValidResponseState(securityContextCookie, m);
    if (responseState == null) {
        return false;
    }
    if (!isSupportUnsolicited()) {
        Cookie relayStateCookie = cookies.get(SSOConstants.RELAY_STATE);
        if (relayStateCookie == null) {
            reportError("MISSING_RELAY_COOKIE");
            return false;
        }
        String originalRelayState = responseState.getRelayState();
        if (!originalRelayState.equals(relayStateCookie.getValue())) {
            // perhaps the response state should also be removed
            reportError("INVALID_RELAY_STATE");
            return false;
        }
    }
    try {
        String assertion = responseState.getAssertion();
        SamlAssertionWrapper assertionWrapper = new SamlAssertionWrapper(StaxUtils.read(new StringReader(assertion)).getDocumentElement());
        setSecurityContext(m, assertionWrapper);
    } catch (Exception ex) {
        reportError("INVALID_RESPONSE_STATE");
        return false;
    }
    return true;
}
Also used : Cookie(javax.ws.rs.core.Cookie) HttpHeaders(javax.ws.rs.core.HttpHeaders) ResponseState(org.apache.cxf.rs.security.saml.sso.state.ResponseState) StringReader(java.io.StringReader) SamlAssertionWrapper(org.apache.wss4j.common.saml.SamlAssertionWrapper) IOException(java.io.IOException) HttpHeadersImpl(org.apache.cxf.jaxrs.impl.HttpHeadersImpl)

Example 72 with Cookie

use of javax.ws.rs.core.Cookie in project carbon-apimgt by wso2.

the class AuthUtilTestCase method testGetHttpOnlyCookieHeader.

@Test
public void testGetHttpOnlyCookieHeader() {
    Cookie cookie = new Cookie("WSO2_AM_REFRESH_TOKEN_1_Development", "xxx-refresh-token-1-xxx");
    String httpOnlyCookieHeader = AuthUtil.getHttpOnlyCookieHeader(cookie);
    Assert.assertEquals("WSO2_AM_REFRESH_TOKEN_1_Development=xxx-refresh-token-1-xxx; HttpOnly", httpOnlyCookieHeader);
}
Also used : NewCookie(javax.ws.rs.core.NewCookie) Cookie(javax.ws.rs.core.Cookie) Test(org.junit.Test)

Example 73 with Cookie

use of javax.ws.rs.core.Cookie in project Payara by payara.

the class RestUtil2 method sendRequestToCollectionResource.

@Handler(id = "rest.list", input = { @HandlerInput(name = "endpoint", type = String.class, required = true), @HandlerInput(name = "attrs", type = Map.class, required = false) }, output = { @HandlerOutput(name = "result", type = List.class) })
public static void sendRequestToCollectionResource(HandlerContext handlerCtx) {
    // Map<String, Object> attrs = (Map<String, Object>) handlerCtx.getInputValue("attrs");
    String endpoint = fixEndpoint((String) handlerCtx.getInputValue("endpoint"));
    Response resp = RestUtil.getJerseyClient().target(endpoint).request(RestUtil.RESPONSE_TYPE).cookie(new Cookie(RestUtil.REST_TOKEN_COOKIE, RestUtil.getRestToken())).get(Response.class);
    if (!isSuccess(resp.getStatus())) {
        throw new RuntimeException(resp.readEntity(String.class));
    }
    List list = resp.readEntity(List.class);
    handlerCtx.setOutputValue("result", list);
}
Also used : Response(javax.ws.rs.core.Response) Cookie(javax.ws.rs.core.Cookie) List(java.util.List) Handler(com.sun.jsftemplating.annotation.Handler)

Example 74 with Cookie

use of javax.ws.rs.core.Cookie in project Payara by payara.

the class RestUtil method post.

public static RestResponse post(String address, Map<String, Object> payload) {
    WebTarget target = getJerseyClient().target(address);
    MultivaluedMap formData = buildMultivalueMap(payload);
    Response cr = target.request(RESPONSE_TYPE).cookie(new Cookie(REST_TOKEN_COOKIE, getRestToken())).post(Entity.entity(formData, MediaType.APPLICATION_FORM_URLENCODED), Response.class);
    RestResponse rr = RestResponse.getRestResponse(cr);
    return rr;
}
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 75 with Cookie

use of javax.ws.rs.core.Cookie in project Payara by payara.

the class RestUtil method put.

public static RestResponse put(String address, Map<String, Object> payload) {
    WebTarget target = getJerseyClient().target(address);
    MultivaluedMap formData = buildMultivalueMap(payload);
    Response cr = target.request(RESPONSE_TYPE).cookie(new Cookie(REST_TOKEN_COOKIE, getRestToken())).put(Entity.entity(formData, MediaType.APPLICATION_FORM_URLENCODED), Response.class);
    RestResponse rr = RestResponse.getRestResponse(cr);
    return rr;
}
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)

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