Search in sources :

Example 1 with CasConfigurationProperties

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<>();
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) TreeMap(java.util.TreeMap)

Example 2 with CasConfigurationProperties

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);
    }
}
Also used : WsFederationProperties(org.apereo.cas.configuration.model.support.wsfed.WsFederationProperties) W3CDOMStreamWriter(org.apache.cxf.staxutils.W3CDOMStreamWriter) Crypto(org.apache.wss4j.common.crypto.Crypto) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) Properties(java.util.Properties) WsFederationProperties(org.apereo.cas.configuration.model.support.wsfed.WsFederationProperties) Document(org.w3c.dom.Document)

Aggregations

CasConfigurationProperties (org.apereo.cas.configuration.CasConfigurationProperties)2 Properties (java.util.Properties)1 TreeMap (java.util.TreeMap)1 W3CDOMStreamWriter (org.apache.cxf.staxutils.W3CDOMStreamWriter)1 Crypto (org.apache.wss4j.common.crypto.Crypto)1 WsFederationProperties (org.apereo.cas.configuration.model.support.wsfed.WsFederationProperties)1 ApplicationContext (org.springframework.context.ApplicationContext)1 Document (org.w3c.dom.Document)1