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();
}
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;
}
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;
}
Aggregations