Search in sources :

Example 1 with RequestState

use of org.apache.cxf.rs.security.saml.sso.state.RequestState in project cxf by apache.

the class AbstractRequestAssertionConsumerHandler method doProcessSamlResponse.

protected Response doProcessSamlResponse(String encodedSamlResponse, String relayState, boolean postBinding) {
    RequestState requestState = processRelayState(relayState);
    String contextCookie = createSecurityContext(requestState, encodedSamlResponse, relayState, postBinding);
    // Finally, redirect to the service provider endpoint
    URI targetURI = getTargetURI(requestState.getTargetAddress());
    return Response.seeOther(targetURI).header("Set-Cookie", contextCookie).build();
}
Also used : RequestState(org.apache.cxf.rs.security.saml.sso.state.RequestState) URI(java.net.URI)

Example 2 with RequestState

use of org.apache.cxf.rs.security.saml.sso.state.RequestState in project cxf by apache.

the class AbstractRequestAssertionConsumerHandler method processRelayState.

protected RequestState processRelayState(String relayState) {
    if (isSupportUnsolicited()) {
        String urlToForwardTo = applicationURL;
        if (relayState != null && relayState.getBytes().length > 0 && relayState.getBytes().length < 80) {
            // First see if we have a valid RequestState
            RequestState requestState = getStateProvider().removeRequestState(relayState);
            if (requestState != null && !isStateExpired(requestState.getCreatedAt(), 0)) {
                return requestState;
            }
            // Otherwise get the application URL from the RelayState if supported
            if (parseApplicationURLFromRelayState) {
                urlToForwardTo = relayState;
            }
        }
        // Otherwise create a new one for the IdP initiated case
        Instant now = Instant.now();
        return new RequestState(urlToForwardTo, getIdpServiceAddress(), null, getIssuerId(JAXRSUtils.getCurrentMessage()), "/", null, now.toEpochMilli());
    }
    if (relayState == null) {
        reportError("MISSING_RELAY_STATE");
        throw ExceptionUtils.toBadRequestException(null, null);
    }
    if (relayState.getBytes().length == 0 || relayState.getBytes().length > 80) {
        reportError("INVALID_RELAY_STATE");
        throw ExceptionUtils.toBadRequestException(null, null);
    }
    RequestState requestState = getStateProvider().removeRequestState(relayState);
    if (requestState == null) {
        reportError("MISSING_REQUEST_STATE");
        throw ExceptionUtils.toBadRequestException(null, null);
    }
    if (isStateExpired(requestState.getCreatedAt(), 0)) {
        reportError("EXPIRED_REQUEST_STATE");
        throw ExceptionUtils.toBadRequestException(null, null);
    }
    return requestState;
}
Also used : RequestState(org.apache.cxf.rs.security.saml.sso.state.RequestState) Instant(java.time.Instant)

Example 3 with RequestState

use of org.apache.cxf.rs.security.saml.sso.state.RequestState in project cxf by apache.

the class AbstractServiceProviderFilter method createSamlRequestInfo.

protected SamlRequestInfo createSamlRequestInfo(Message m) throws Exception {
    Document doc = DOMUtils.createDocument();
    doc.appendChild(doc.createElement("root"));
    // Create the AuthnRequest
    AuthnRequest authnRequest = authnRequestBuilder.createAuthnRequest(m, getIssuerId(m), getAbsoluteAssertionServiceAddress(m));
    if (isSignRequest()) {
        authnRequest.setDestination(getIdpServiceAddress());
        signAuthnRequest(authnRequest);
    }
    Element authnRequestElement = OpenSAMLUtil.toDom(authnRequest, doc);
    String authnRequestEncoded = encodeAuthnRequest(authnRequestElement);
    SamlRequestInfo info = new SamlRequestInfo();
    info.setSamlRequest(authnRequestEncoded);
    String webAppContext = getWebAppContext(m);
    String originalRequestURI = new UriInfoImpl(m).getRequestUri().toString();
    RequestState requestState = new RequestState(originalRequestURI, getIdpServiceAddress(), authnRequest.getID(), getIssuerId(m), webAppContext, getWebAppDomain(), System.currentTimeMillis());
    String relayState = URLEncoder.encode(UUID.randomUUID().toString(), StandardCharsets.UTF_8.name());
    getStateProvider().setRequestState(relayState, requestState);
    info.setRelayState(relayState);
    info.setWebAppContext(webAppContext);
    info.setWebAppDomain(getWebAppDomain());
    return info;
}
Also used : RequestState(org.apache.cxf.rs.security.saml.sso.state.RequestState) AuthnRequest(org.opensaml.saml.saml2.core.AuthnRequest) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) UriInfoImpl(org.apache.cxf.jaxrs.impl.UriInfoImpl)

Aggregations

RequestState (org.apache.cxf.rs.security.saml.sso.state.RequestState)3 URI (java.net.URI)1 Instant (java.time.Instant)1 UriInfoImpl (org.apache.cxf.jaxrs.impl.UriInfoImpl)1 AuthnRequest (org.opensaml.saml.saml2.core.AuthnRequest)1 Document (org.w3c.dom.Document)1 Element (org.w3c.dom.Element)1