use of org.apereo.cas.support.saml.SamlException in project cas by apereo.
the class SamlObjectSignatureValidator method validateSignatureOnProfileRequest.
private void validateSignatureOnProfileRequest(final RequestAbstractType profileRequest, final Signature signature, final RoleDescriptorResolver roleDescriptorResolver) throws Exception {
final SAMLSignatureProfileValidator validator = new SAMLSignatureProfileValidator();
LOGGER.debug("Validating profile signature for [{}] via [{}]...", profileRequest.getIssuer(), validator.getClass().getSimpleName());
validator.validate(signature);
LOGGER.debug("Successfully validated profile signature for [{}].", profileRequest.getIssuer());
final Credential credential = getSigningCredential(roleDescriptorResolver, profileRequest);
if (credential == null) {
throw new SamlException("Signing credential for validation could not be resolved");
}
LOGGER.debug("Validating signature using credentials for [{}]", credential.getEntityId());
SignatureValidator.validate(signature, credential);
LOGGER.info("Successfully validated the request signature.");
}
use of org.apereo.cas.support.saml.SamlException in project cas by apereo.
the class SamlProfileSaml2ResponseBuilder method encode.
@Override
protected Response encode(final SamlRegisteredService service, final Response samlResponse, final HttpServletResponse httpResponse, final SamlRegisteredServiceServiceProviderMetadataFacade adaptor, final String relayState) throws SamlException {
try {
final HTTPPostEncoder encoder = new HTTPPostEncoder();
encoder.setHttpServletResponse(httpResponse);
encoder.setVelocityEngine(this.velocityEngineFactory.createVelocityEngine());
final MessageContext outboundMessageContext = new MessageContext<>();
SamlIdPUtils.preparePeerEntitySamlEndpointContext(outboundMessageContext, adaptor);
outboundMessageContext.setMessage(samlResponse);
SAMLBindingSupport.setRelayState(outboundMessageContext, relayState);
encoder.setMessageContext(outboundMessageContext);
encoder.initialize();
encoder.encode();
return samlResponse;
} catch (final Exception e) {
throw Throwables.propagate(e);
}
}
use of org.apereo.cas.support.saml.SamlException in project cas by apereo.
the class ChainingMetadataResolverCacheLoader method load.
@Override
public ChainingMetadataResolver load(final SamlRegisteredService service) throws Exception {
try {
final ChainingMetadataResolver metadataResolver = new ChainingMetadataResolver();
final List<MetadataResolver> metadataResolvers = new ArrayList<>();
if (isDynamicMetadataQueryConfigured(service)) {
resolveMetadataDynamically(service, metadataResolvers);
} else {
resolveMetadataFromResource(service, metadataResolvers);
}
if (metadataResolvers.isEmpty()) {
throw new SamlException("No metadata resolvers could be configured for service " + service.getName() + " with metadata location " + service.getMetadataLocation());
}
synchronized (this.lock) {
metadataResolver.setId(ChainingMetadataResolver.class.getCanonicalName());
metadataResolver.setResolvers(metadataResolvers);
metadataResolver.initialize();
}
return metadataResolver;
} catch (final Exception e) {
throw new SamlException(e.getMessage(), e);
}
}
use of org.apereo.cas.support.saml.SamlException in project cas by apereo.
the class BaseWSFederationRequestController method constructServiceUrl.
/**
* Construct service url string.
*
* @param request the request
* @param response the response
* @param wsfedRequest the ws federation request
* @return the service url
*/
protected String constructServiceUrl(final HttpServletRequest request, final HttpServletResponse response, final WSFederationRequest wsfedRequest) {
try {
final URIBuilder builder = new URIBuilder(this.callbackService.getId());
builder.addParameter(WSFederationConstants.WA, wsfedRequest.getWa());
builder.addParameter(WSFederationConstants.WREPLY, wsfedRequest.getWreply());
builder.addParameter(WSFederationConstants.WTREALM, wsfedRequest.getWtrealm());
if (StringUtils.isNotBlank(wsfedRequest.getWctx())) {
builder.addParameter(WSFederationConstants.WCTX, wsfedRequest.getWctx());
}
if (StringUtils.isNotBlank(wsfedRequest.getWfresh())) {
builder.addParameter(WSFederationConstants.WREFRESH, wsfedRequest.getWfresh());
}
if (StringUtils.isNotBlank(wsfedRequest.getWhr())) {
builder.addParameter(WSFederationConstants.WHR, wsfedRequest.getWhr());
}
if (StringUtils.isNotBlank(wsfedRequest.getWreq())) {
builder.addParameter(WSFederationConstants.WREQ, wsfedRequest.getWreq());
}
final URI url = builder.build();
LOGGER.debug("Built service callback url [{}]", url);
return org.jasig.cas.client.util.CommonUtils.constructServiceUrl(request, response, url.toString(), casProperties.getServer().getName(), CasProtocolConstants.PARAMETER_SERVICE, CasProtocolConstants.PARAMETER_TICKET, false);
} catch (final Exception e) {
throw new SamlException(e.getMessage(), e);
}
}
Aggregations