use of org.apereo.cas.configuration.CasConfigurationProperties in project cas by apereo.
the class AbstractRegisteredServiceAttributeReleasePolicy method getReleasedByDefaultAttributes.
/**
* Determines a default bundle of attributes that may be released to all services
* without the explicit mapping for each service.
*
* @param p the principal
* @param attributes the attributes
* @return the released by default attributes
*/
protected Map<String, Object> getReleasedByDefaultAttributes(final Principal p, final Map<String, Object> attributes) {
final ApplicationContext ctx = ApplicationContextProvider.getApplicationContext();
if (ctx != null) {
LOGGER.debug("Located application context. Retrieving default attributes for release, if any");
final CasConfigurationProperties props = ctx.getAutowireCapableBeanFactory().getBean(CasConfigurationProperties.class);
final Set<String> defaultAttrs = props.getAuthn().getAttributeRepository().getDefaultAttributesToRelease();
LOGGER.debug("Default attributes for release are: [{}]", defaultAttrs);
final Map<String, Object> defaultAttributesToRelease = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
defaultAttrs.stream().forEach(key -> {
if (attributes.containsKey(key)) {
LOGGER.debug("Found and added default attribute for release: [{}]", key);
defaultAttributesToRelease.put(key, attributes.get(key));
}
});
return defaultAttributesToRelease;
}
return new TreeMap<>();
}
use of org.apereo.cas.configuration.CasConfigurationProperties in project cas by apereo.
the class WSFederationMetadataWriter method produceMetadataDocument.
/**
* Produce metadata document.
*
* @param config the config
* @return the document
*/
public Document produceMetadataDocument(final CasConfigurationProperties config) {
try {
final WsFederationProperties.SecurityTokenService sts = config.getAuthn().getWsfedIdP().getSts();
final Properties prop = CryptoUtils.getSecurityProperties(sts.getRealm().getKeystoreFile(), sts.getRealm().getKeystorePassword(), sts.getRealm().getKeystoreAlias());
final Crypto crypto = CryptoFactory.getInstance(prop);
final W3CDOMStreamWriter writer = new W3CDOMStreamWriter();
writer.writeStartDocument(StandardCharsets.UTF_8.name(), "1.0");
final String referenceID = IDGenerator.generateID("_");
writer.writeStartElement("md", "EntityDescriptor", SAML2_METADATA_NS);
writer.writeAttribute("ID", referenceID);
final String idpEntityId = config.getServer().getPrefix().concat(WSFederationConstants.ENDPOINT_FEDERATION_REQUEST);
writer.writeAttribute("entityID", idpEntityId);
writer.writeNamespace("md", SAML2_METADATA_NS);
writer.writeNamespace("fed", WS_FEDERATION_NS);
writer.writeNamespace("wsa", WS_ADDRESSING_NS);
writer.writeNamespace("auth", WS_FEDERATION_NS);
writer.writeNamespace("xsi", SCHEMA_INSTANCE_NS);
final String stsUrl = config.getServer().getPrefix().concat(WSFederationConstants.ENDPOINT_STS).concat(config.getAuthn().getWsfedIdP().getIdp().getRealmName());
writeFederationMetadata(writer, idpEntityId, stsUrl, crypto);
writer.writeEndElement();
writer.writeEndDocument();
writer.close();
final String out = DOM2Writer.nodeToString(writer.getDocument());
LOGGER.debug("Produced unsigned metadata");
LOGGER.debug(out);
final Document result = SignatureUtils.signMetaInfo(crypto, null, config.getAuthn().getWsfedIdP().getSts().getRealm().getKeyPassword(), writer.getDocument(), referenceID);
if (result != null) {
return result;
}
throw new RuntimeException("Failed to sign the metadata document");
} catch (final Exception e) {
throw new RuntimeException("Error creating service metadata information: " + e.getMessage(), e);
}
}
Aggregations