use of org.opensaml.saml2.metadata.RoleDescriptor in project cas by apereo.
the class SamlIdPObjectSigner method prepareSecurityParametersContext.
/**
* Prepare security parameters context.
*
* @param <T> the type parameter
* @param adaptor the adaptor
* @param outboundContext the outbound context
* @param service the service
* @throws SAMLException the saml exception
*/
protected <T extends SAMLObject> void prepareSecurityParametersContext(final SamlRegisteredServiceServiceProviderMetadataFacade adaptor, final MessageContext<T> outboundContext, final SamlRegisteredService service) throws SAMLException {
@NonNull final SecurityParametersContext secParametersContext = outboundContext.getSubcontext(SecurityParametersContext.class, true);
final RoleDescriptor roleDesc = adaptor.getSsoDescriptor();
final SignatureSigningParameters signingParameters = buildSignatureSigningParameters(roleDesc, service);
secParametersContext.setSignatureSigningParameters(signingParameters);
}
use of org.opensaml.saml2.metadata.RoleDescriptor in project verify-hub by alphagov.
the class SamlEntityDescriptorValidator method validateRoleDescriptor.
private void validateRoleDescriptor(EntityDescriptor descriptor) {
if (descriptor.getRoleDescriptors().isEmpty()) {
SamlValidationSpecificationFailure failure = SamlTransformationErrorFactory.missingRoleDescriptor();
throw new SamlTransformationErrorException(failure.getErrorMessage(), failure.getLogLevel());
}
RoleDescriptor roleDescriptor = descriptor.getRoleDescriptors().get(0);
if (roleDescriptor.getKeyDescriptors().isEmpty()) {
SamlValidationSpecificationFailure failure = SamlTransformationErrorFactory.missingKeyDescriptor();
throw new SamlTransformationErrorException(failure.getErrorMessage(), failure.getLogLevel());
}
KeyInfo keyInfo = roleDescriptor.getKeyDescriptors().get(0).getKeyInfo();
if (keyInfo == null) {
SamlValidationSpecificationFailure failure = SamlTransformationErrorFactory.missingKeyInfo();
throw new SamlTransformationErrorException(failure.getErrorMessage(), failure.getLogLevel());
}
if (keyInfo.getX509Datas().isEmpty()) {
SamlValidationSpecificationFailure failure = SamlTransformationErrorFactory.missingX509Data();
throw new SamlTransformationErrorException(failure.getErrorMessage(), failure.getLogLevel());
}
X509Data x509Data = keyInfo.getX509Datas().get(0);
if (x509Data.getX509Certificates().isEmpty()) {
SamlValidationSpecificationFailure failure = SamlTransformationErrorFactory.missingX509Certificate();
throw new SamlTransformationErrorException(failure.getErrorMessage(), failure.getLogLevel());
}
X509Certificate x509Certificate = x509Data.getX509Certificates().get(0);
if (StringUtils.isEmpty(x509Certificate.getValue())) {
SamlValidationSpecificationFailure failure = SamlTransformationErrorFactory.emptyX509Certificiate();
throw new SamlTransformationErrorException(failure.getErrorMessage(), failure.getLogLevel());
}
}
use of org.opensaml.saml2.metadata.RoleDescriptor in project pac4j by pac4j.
the class SAML2ContextProvider method addContext.
protected final void addContext(final SAML2MetadataResolver metadata, final BaseContext parentContext, final QName elementName) {
final EntityDescriptor entityDescriptor;
final RoleDescriptor roleDescriptor;
try {
final var set = new CriteriaSet();
final var entityId = metadata.getEntityId();
set.add(new EntityIdCriterion(entityId));
entityDescriptor = SAML2Utils.buildChainingMetadataResolver(this.idpEntityId, this.spEntityId).resolveSingle(set);
if (entityDescriptor == null) {
throw new SAMLException("Cannot find entity " + entityId + " in metadata provider");
}
final var list = entityDescriptor.getRoleDescriptors(elementName, SAMLConstants.SAML20P_NS);
roleDescriptor = CommonHelper.isNotEmpty(list) ? list.get(0) : null;
if (roleDescriptor == null) {
throw new SAMLException("Cannot find entity " + entityId + " or role " + elementName + " in metadata provider");
}
} catch (final ResolverException e) {
throw new SAMLException("An error occurred while getting IDP descriptors", e);
}
final var mdCtx = parentContext.getSubcontext(SAMLMetadataContext.class, true);
mdCtx.setEntityDescriptor(entityDescriptor);
mdCtx.setRoleDescriptor(roleDescriptor);
}
use of org.opensaml.saml2.metadata.RoleDescriptor in project MaxKey by dromara.
the class MetadataGenerator method buildEntityDescriptor.
public EntityDescriptor buildEntityDescriptor(String entityId, RoleDescriptor roleDescriptor) {
EntityDescriptor entityDescriptor = new EntityDescriptorBuilder().buildObject();
entityDescriptor.setEntityID(entityId);
entityDescriptor.getRoleDescriptors().add(roleDescriptor);
return entityDescriptor;
}
use of org.opensaml.saml2.metadata.RoleDescriptor in project cloud-pipeline by epam.
the class SAMLContexProviderCustomSingKey method populateLocalEntity.
@Override
protected void populateLocalEntity(SAMLMessageContext samlContext) throws MetadataProviderException {
String localEntityId = samlContext.getLocalEntityId();
QName localEntityRole = samlContext.getLocalEntityRole();
if (localEntityId == null) {
throw new MetadataProviderException("No hosted service provider is configured and no alias was selected");
}
EntityDescriptor entityDescriptor = metadata.getEntityDescriptor(localEntityId);
RoleDescriptor roleDescriptor = metadata.getRole(localEntityId, localEntityRole, SAMLConstants.SAML20P_NS);
ExtendedMetadata extendedMetadata = metadata.getExtendedMetadata(localEntityId);
if (entityDescriptor == null || roleDescriptor == null) {
throw new MetadataProviderException("Metadata for entity " + localEntityId + " and role " + localEntityRole + " wasn't found");
}
samlContext.setLocalEntityMetadata(entityDescriptor);
samlContext.setLocalEntityRoleMetadata(roleDescriptor);
samlContext.setLocalExtendedMetadata(extendedMetadata);
if (extendedMetadata.getSigningKey() != null) {
samlContext.setLocalSigningCredential(keyManager.getCredential(extendedMetadata.getSigningKey()));
} else {
samlContext.setLocalSigningCredential(keyManager.getCredential(signingKey));
}
}
Aggregations