use of org.opensaml.ws.transport.http.HTTPInTransport in project uaa by cloudfoundry.
the class SamlAssertionDecoder method doDecode.
/**
* {@inheritDoc}
*/
protected void doDecode(MessageContext messageContext) throws MessageDecodingException {
if (!(messageContext instanceof SAMLMessageContext)) {
log.error("Invalid message context type, this decoder only support SAMLMessageContext");
throw new MessageDecodingException("Invalid message context type, this decoder only support SAMLMessageContext");
}
if (!(messageContext.getInboundMessageTransport() instanceof HTTPInTransport)) {
log.error("Invalid inbound message transport type, this decoder only support HTTPInTransport");
throw new MessageDecodingException("Invalid inbound message transport type, this decoder only support HTTPInTransport");
}
SAMLMessageContext samlMsgCtx = (SAMLMessageContext) messageContext;
HTTPInTransport inTransport = (HTTPInTransport) samlMsgCtx.getInboundMessageTransport();
if (!inTransport.getHTTPMethod().equalsIgnoreCase("POST")) {
throw new MessageDecodingException("This message decoder only supports the HTTP POST method");
}
String relayState = inTransport.getParameterValue("RelayState");
samlMsgCtx.setRelayState(relayState);
log.debug("Decoded SAML relay state of: {}", relayState);
InputStream base64DecodedMessage = getBase64DecodedMessage(inTransport);
Assertion inboundMessage = (Assertion) unmarshallMessage(base64DecodedMessage);
Response response = SamlRedirectUtils.wrapAssertionIntoResponse(inboundMessage, inboundMessage.getIssuer().getValue());
samlMsgCtx.setInboundMessage(response);
samlMsgCtx.setInboundSAMLMessage(response);
log.debug("Decoded SAML message");
populateMessageContext(samlMsgCtx);
}
use of org.opensaml.ws.transport.http.HTTPInTransport in project uaa by cloudfoundry.
the class SamlAssertionBindingTests method supports.
@Test
public void supports() {
HTTPInTransport transport = mock(HTTPInTransport.class);
assertFalse(binding.supports(transport));
when(transport.getHTTPMethod()).thenReturn("POST");
assertFalse(binding.supports(transport));
when(transport.getParameterValue("assertion")).thenReturn("some assertion");
assertTrue(binding.supports(transport));
}
use of org.opensaml.ws.transport.http.HTTPInTransport in project uaa by cloudfoundry.
the class IdpSamlContextProviderImpl method populateLocalEntityId.
/**
* Method tries to load localEntityAlias and localEntityRole from the request path. Path is supposed to be in format:
* https(s)://server:port/application/saml/filterName/alias/aliasName/idp|sp. In case alias is missing from
* the path defaults are used. Otherwise localEntityId and sp or idp localEntityRole is entered into the context.
* <p>
* In case alias entity id isn't found an exception is raised.
*
* @param context context to populate fields localEntityId and localEntityRole for
* @param requestURI context path to parse entityId and entityRole from
* @throws MetadataProviderException in case entityId can't be populated
*/
@Override
protected void populateLocalEntityId(SAMLMessageContext context, String requestURI) throws MetadataProviderException {
String entityId;
HTTPInTransport inTransport = (HTTPInTransport) context.getInboundMessageTransport();
// Pre-configured entity Id
entityId = (String) inTransport.getAttribute(org.springframework.security.saml.SAMLConstants.LOCAL_ENTITY_ID);
if (entityId != null) {
log.debug("Using protocol specified IdP {}", entityId);
context.setLocalEntityId(entityId);
context.setLocalEntityRole(IDPSSODescriptor.DEFAULT_ELEMENT_NAME);
return;
}
if (requestURI == null) {
requestURI = "";
}
int filterIndex = requestURI.indexOf("/alias/");
if (filterIndex != -1) {
// EntityId from URL alias
String localAlias = requestURI.substring(filterIndex + 7);
QName localEntityRole;
int entityTypePosition = localAlias.lastIndexOf('/');
if (entityTypePosition != -1) {
String entityRole = localAlias.substring(entityTypePosition + 1);
if ("sp".equalsIgnoreCase(entityRole)) {
localEntityRole = SPSSODescriptor.DEFAULT_ELEMENT_NAME;
} else {
localEntityRole = IDPSSODescriptor.DEFAULT_ELEMENT_NAME;
}
localAlias = localAlias.substring(0, entityTypePosition);
} else {
localEntityRole = IDPSSODescriptor.DEFAULT_ELEMENT_NAME;
}
// Populate entityId
entityId = metadata.getEntityIdForAlias(localAlias);
if (entityId == null) {
throw new MetadataProviderException("No local entity found for alias " + localAlias + ", verify your configuration.");
} else {
log.debug("Using IdP {} specified in request with alias {}", entityId, localAlias);
}
context.setLocalEntityId(entityId);
context.setLocalEntityRole(localEntityRole);
} else {
// Defaults
context.setLocalEntityId(metadata.getDefaultIDP());
context.setLocalEntityRole(IDPSSODescriptor.DEFAULT_ELEMENT_NAME);
}
}
Aggregations