org.opensaml.security.credential.impl.KeyStoreCredentialResolver Java Examples

The following examples show how to use org.opensaml.security.credential.impl.KeyStoreCredentialResolver. 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: KeyStoreCredentialResolverBuilder.java    From armeria with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new {@link KeyStoreCredentialResolver}.
 */
public CredentialResolver build() throws IOException, GeneralSecurityException {
    final KeyStore ks = KeyStore.getInstance(type);
    try (InputStream is = open()) {
        ks.load(is, password != null ? password.toCharArray() : null);
    }
    return new KeyStoreCredentialResolver(ks, keyPasswords);
}
 
Example #2
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;
    }
}