use of org.opensaml.xml.signature.SignatureException in project uaa by cloudfoundry.
the class IdpSamlAuthenticationSuccessHandler method onAuthenticationSuccess.
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws ServletException {
SAMLMessageContext context = ((UaaAuthentication) authentication).getSamlMessageContext();
IdpExtendedMetadata extendedMetadata = null;
try {
extendedMetadata = (IdpExtendedMetadata) metadataManager.getExtendedMetadata(context.getLocalEntityId());
} catch (MetadataProviderException e) {
throw new ServletException("Failed to obtain local SAML IdP extended metadata.", e);
}
try {
populatePeerContext(context);
} catch (MetadataProviderException e) {
throw new ServletException("Failed to populate peer SAML SP context.", e);
}
try {
IdpWebSSOProfileOptions options = new IdpWebSSOProfileOptions();
options.setAssertionsSigned(extendedMetadata.isAssertionsSigned());
options.setAssertionTimeToLiveSeconds(extendedMetadata.getAssertionTimeToLiveSeconds());
idpWebSsoProfile.sendResponse(authentication, context, options);
} catch (SAMLException e) {
LOGGER.debug("Incoming SAML message is invalid.", e);
throw new AuthenticationServiceException("Incoming SAML message is invalid.", e);
} catch (MetadataProviderException e) {
LOGGER.debug("Error determining metadata contracts.", e);
throw new AuthenticationServiceException("Error determining metadata contracts.", e);
} catch (MessageEncodingException e) {
LOGGER.debug("Error decoding incoming SAML message.", e);
throw new AuthenticationServiceException("Error encoding outgoing SAML message.", e);
} catch (MarshallingException | SecurityException | SignatureException e) {
LOGGER.debug("Error signing SAML assertion.", e);
throw new AuthenticationServiceException("Error signing SAML assertion.", e);
}
}
use of org.opensaml.xml.signature.SignatureException in project uaa by cloudfoundry.
the class IdpInitiatedLoginController method initiate.
@RequestMapping("/saml/idp/initiate")
public void initiate(@RequestParam(value = "sp", required = false) String sp, HttpServletRequest request, HttpServletResponse response) {
if (!hasText(sp)) {
throw new ProviderNotFoundException("Missing sp request parameter. sp parameter must be a valid and configured entity ID");
}
log.debug(String.format("IDP is initiating authentication request to SP[%s]", sp));
Optional<SamlServiceProviderHolder> holder = configurator.getSamlServiceProviders().stream().filter(serviceProvider -> sp.equals(serviceProvider.getSamlServiceProvider().getEntityId())).findFirst();
if (holder.isEmpty()) {
log.debug(String.format("SP[%s] was not found, aborting saml response", sp));
throw new ProviderNotFoundException("Invalid sp entity ID. sp parameter must be a valid and configured entity ID");
}
if (!holder.get().getSamlServiceProvider().isActive()) {
log.debug(String.format("SP[%s] is disabled, aborting saml response", sp));
throw new ProviderNotFoundException("Service provider is disabled.");
}
if (!holder.get().getSamlServiceProvider().getConfig().isEnableIdpInitiatedSso()) {
log.debug(String.format("SP[%s] initiated login is disabled, aborting saml response", sp));
throw new ProviderNotFoundException("IDP initiated login is disabled for this service provider.");
}
String nameId = "urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified";
try {
String assertionLocation = getAssertionConsumerURL(sp);
log.debug(String.format("IDP is sending assertion for SP[%s] to %s", sp, assertionLocation));
AuthnRequest authnRequest = idpWebSsoProfile.buildIdpInitiatedAuthnRequest(nameId, sp, assertionLocation);
SAMLMessageContext samlContext = getSamlContext(sp, authnRequest, request, response);
idpWebSsoProfile.sendResponse(SecurityContextHolder.getContext().getAuthentication(), samlContext, getIdpIniatedOptions());
log.debug(String.format("IDP initiated authentication and responded to SP[%s]", sp));
} catch (MetadataProviderException | SAMLException | SecurityException | MessageEncodingException | MarshallingException | SignatureException e) {
log.debug(String.format("IDP is unable to process assertion for SP[%s]", sp), e);
throw new ProviderNotFoundException("Unable to process SAML assertion. Response not sent.");
}
}
Aggregations