use of ddf.security.samlp.impl.EntityInformation in project ddf by codice.
the class IdpEndpoint method parseServiceProviderMetadata.
private void parseServiceProviderMetadata(List<String> serviceProviderMetadata) {
if (serviceProviderMetadata != null) {
try {
MetadataConfigurationParser metadataConfigurationParser = new MetadataConfigurationParser(serviceProviderMetadata, ed -> {
EntityInformation entityInfo = new EntityInformation.Builder(ed, SUPPORTED_BINDINGS).build();
if (entityInfo != null) {
serviceProviders.put(ed.getEntityID(), entityInfo);
}
});
serviceProviders.putAll(metadataConfigurationParser.getEntryDescriptions().entrySet().stream().map(e -> Maps.immutableEntry(e.getKey(), new EntityInformation.Builder(e.getValue(), SUPPORTED_BINDINGS).build())).filter(e -> nonNull(e.getValue())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)));
} catch (IOException e) {
LOGGER.warn("Unable to parse SP metadata configuration. Check the configuration for SP metadata.", e);
}
}
}
use of ddf.security.samlp.impl.EntityInformation in project ddf by codice.
the class RedirectValidator method validateAuthnRequest.
@Override
public void validateAuthnRequest(AuthnRequest authnRequest, String samlRequest, String relayState, String signatureAlgorithm, String signature, boolean strictSignature) throws SimpleSign.SignatureException, ValidationException {
LOGGER.debug("Validating AuthnRequest required attributes and signature");
if (strictSignature) {
if (!StringUtils.isEmpty(signature) && !StringUtils.isEmpty(signatureAlgorithm)) {
String signedParts;
try {
signedParts = String.format("SAMLRequest=%s&RelayState=%s&SigAlg=%s", URLEncoder.encode(samlRequest, "UTF-8"), relayState, URLEncoder.encode(signatureAlgorithm, "UTF-8"));
} catch (UnsupportedEncodingException e) {
throw new SimpleSign.SignatureException("Unable to construct signed query parts.", e);
}
EntityInformation entityInformation = getServiceProviders().get(authnRequest.getIssuer().getValue());
if (entityInformation == null) {
throw new ValidationException(String.format("Unable to find metadata for %s", authnRequest.getIssuer().getValue()));
}
String encryptionCertificate = entityInformation.getEncryptionCertificate();
String signingCertificate = entityInformation.getSigningCertificate();
if (signingCertificate == null) {
throw new ValidationException("Unable to find signing certificate in metadata. Please check metadata.");
}
boolean result = getSimpleSign().validateSignature(signedParts, signature, signingCertificate);
if (!result) {
throw new ValidationException("Signature verification failed for redirect binding.");
}
} else {
throw new SimpleSign.SignatureException("No signature present for AuthnRequest.");
}
}
super.validateAuthnRequest(authnRequest, samlRequest, relayState, signatureAlgorithm, signature, strictSignature);
}
Aggregations