org.opensaml.core.criterion.EntityIdCriterion Java Examples

The following examples show how to use org.opensaml.core.criterion.EntityIdCriterion. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Saml2SettingsProvider.java    From deprecated-security-advanced-modules with Apache License 2.0 5 votes vote down vote up
Saml2Settings get() throws SamlConfigException {
    try {
        HashMap<String, Object> configProperties = new HashMap<>();

        EntityDescriptor entityDescriptor = this.metadataResolver
                .resolveSingle(new CriteriaSet(new EntityIdCriterion(this.idpEntityId)));

        if (entityDescriptor == null) {
            throw new SamlConfigException("Could not find entity descriptor for " + this.idpEntityId);
        }

        IDPSSODescriptor idpSsoDescriptor = entityDescriptor
                .getIDPSSODescriptor("urn:oasis:names:tc:SAML:2.0:protocol");

        if (idpSsoDescriptor == null) {
            throw new SamlConfigException("Could not find IDPSSODescriptor supporting SAML 2.0 in "
                    + this.idpEntityId + "; role descriptors: " + entityDescriptor.getRoleDescriptors());
        }

        initIdpEndpoints(idpSsoDescriptor, configProperties);
        initIdpCerts(idpSsoDescriptor, configProperties);

        initSpEndpoints(configProperties);

        initMisc(configProperties);

        SettingsBuilder settingsBuilder = new SettingsBuilder();

        // TODO allow overriding of IdP metadata?
        settingsBuilder.fromValues(configProperties);
        settingsBuilder.fromValues(new SamlSettingsMap(this.esSettings));

        return settingsBuilder.build();
    } catch (ResolverException e) {
        throw new AuthenticatorUnavailableException(e);
    }
}
 
Example #2
Source File: AbstractMetadataResolverAdapter.java    From springboot-shiro-cas-mybatis with MIT License 5 votes vote down vote up
@Override
public EntityDescriptor getEntityDescriptorForEntityId(final String entityId) {
    try {
        final CriteriaSet criterions = new CriteriaSet(new EntityIdCriterion(entityId));
        if (this.metadataResolver != null) {
            return metadataResolver.resolveSingle(criterions);
        }
    } catch (final Exception ex) {
        throw new RuntimeException(ex.getMessage(), ex);
    }
    return null;

}
 
Example #3
Source File: MetadataHealthCheck.java    From verify-service-provider with MIT License 5 votes vote down vote up
@Override
protected Result check() throws Exception {
    try {
        CriteriaSet criteria = new CriteriaSet(new EntityIdCriterion(expectedEntityId));
        EntityDescriptor entityDescriptor = metadataResolver.resolveSingle(criteria);
        if (entityDescriptor != null) {
            return healthy();
        }
        return unhealthy(getMessage("No exception was thrown"));
    } catch (Exception e) {
        return unhealthy(getMessage(e.getMessage()));
    }
}
 
Example #4
Source File: SamlServiceProviderBuilder.java    From armeria with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public Credential apply(String keyName) {
    final CriteriaSet cs = new CriteriaSet();
    cs.add(new EntityIdCriterion(keyName));
    try {
        return resolver.resolveSingle(cs);
    } catch (Throwable cause) {
        return Exceptions.throwUnsafely(cause);
    }
}
 
Example #5
Source File: SAML2SPLoader.java    From syncope with Apache License 2.0 4 votes vote down vote up
@Override
public void load() {
    EntitlementsHolder.getInstance().addAll(SAML2SPEntitlement.values());
    ImplementationTypesHolder.getInstance().putAll(SAML2SPImplementationType.values());

    Properties props = PropertyUtils.read(getClass(), SAML2SP_LOGIC_PROPERTIES, "conf.directory");
    String confDirectory = props.getProperty("conf.directory");

    assertNotNull(confDirectory, "<conf.directory>");

    String name = props.getProperty("keystore.name");
    assertNotNull(name, "<keystore.name>");
    String type = props.getProperty("keystore.type");
    assertNotNull(type, "<keystore.type>");
    String storePass = props.getProperty("keystore.storepass");
    assertNotNull(storePass, "<keystore.storepass>");
    keyPass = props.getProperty("keystore.keypass");
    assertNotNull(keyPass, "<keystore.keypass>");
    String certAlias = props.getProperty("sp.cert.alias");
    assertNotNull(certAlias, "<sp.cert.alias>");
    signatureAlgorithm = props.getProperty("signature.algorithm");

    LOG.debug("Attempting to load the provided keystore...");
    try {
        ResourceWithFallbackLoader loader = new ResourceWithFallbackLoader();
        loader.setResourceLoader(ApplicationContextProvider.getApplicationContext());
        loader.setPrimary(StringUtils.appendIfMissing("file:" + confDirectory, "/") + name);
        loader.setFallback("classpath:" + name);

        keystore = KeyStore.getInstance(type);
        try (InputStream inputStream = loader.getResource().getInputStream()) {
            keystore.load(inputStream, storePass.toCharArray());
            LOG.debug("Keystore loaded");
        }

        Map<String, String> passwordMap = new HashMap<>();
        passwordMap.put(certAlias, keyPass);
        KeyStoreCredentialResolver resolver = new KeyStoreCredentialResolver(keystore, passwordMap);

        this.credential = resolver.resolveSingle(new CriteriaSet(new EntityIdCriterion(certAlias)));
        LOG.debug("SAML 2.0 Service Provider certificate loaded");

        saml2rw.init();

        inited = true;
    } catch (Exception e) {
        LOG.error("Could not initialize the SAML 2.0 Service Provider certificate", e);
        inited = false;
    }
}