Search in sources :

Example 1 with ClearPassword

use of org.wildfly.security.password.interfaces.ClearPassword in project wildfly by wildfly.

the class SingleSignOnSessionFactoryBuilder method getValue.

@Override
public SingleSignOnSessionFactory getValue() {
    KeyStore store = this.keyStore.getValue();
    String alias = this.keyAlias;
    CredentialSource source = this.credentialSource.getValue();
    try {
        if (!store.containsAlias(alias)) {
            UndertowLogger.ROOT_LOGGER.missingKeyStoreEntry(alias);
        }
        if (!store.entryInstanceOf(alias, KeyStore.PrivateKeyEntry.class)) {
            UndertowLogger.ROOT_LOGGER.keyStoreEntryNotPrivate(alias);
        }
        PasswordCredential credential = source.getCredential(PasswordCredential.class);
        if (credential == null) {
            UndertowLogger.ROOT_LOGGER.missingCredential(source.toString());
        }
        ClearPassword password = credential.getPassword(ClearPassword.class);
        if (password == null) {
            UndertowLogger.ROOT_LOGGER.credentialNotClearPassword(credential.toString());
        }
        KeyStore.PrivateKeyEntry entry = (KeyStore.PrivateKeyEntry) store.getEntry(alias, new KeyStore.PasswordProtection(password.getPassword()));
        KeyPair keyPair = new KeyPair(entry.getCertificate().getPublicKey(), entry.getPrivateKey());
        Optional<SSLContext> context = Optional.ofNullable(this.sslContext).map(dependency -> dependency.getValue());
        return new DefaultSingleSignOnSessionFactory(this.manager.getValue(), keyPair, connection -> context.ifPresent(ctx -> connection.setSSLSocketFactory(ctx.getSocketFactory())));
    } catch (GeneralSecurityException | IOException e) {
        throw new IllegalArgumentException(e);
    }
}
Also used : ClearPassword(org.wildfly.security.password.interfaces.ClearPassword) KeyPair(java.security.KeyPair) ValueDependency(org.wildfly.clustering.service.ValueDependency) SSLContext(javax.net.ssl.SSLContext) Value(org.jboss.msc.value.Value) CredentialSource(org.wildfly.security.credential.source.CredentialSource) OperationContext(org.jboss.as.controller.OperationContext) DefaultSingleSignOnSessionFactory(org.wildfly.security.http.util.sso.DefaultSingleSignOnSessionFactory) GeneralSecurityException(java.security.GeneralSecurityException) CredentialSourceDependency(org.jboss.as.clustering.controller.CredentialSourceDependency) PasswordCredential(org.wildfly.security.credential.PasswordCredential) InjectedValueDependency(org.wildfly.clustering.service.InjectedValueDependency) ServiceTarget(org.jboss.msc.service.ServiceTarget) UndertowLogger(org.wildfly.extension.undertow.logging.UndertowLogger) SingleSignOnSessionFactory(org.wildfly.security.http.util.sso.SingleSignOnSessionFactory) CommonUnaryRequirement(org.jboss.as.clustering.controller.CommonUnaryRequirement) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) IOException(java.io.IOException) KeyStore(java.security.KeyStore) ResourceServiceBuilder(org.jboss.as.clustering.controller.ResourceServiceBuilder) Objects(java.util.Objects) ModelNodes(org.jboss.as.clustering.dmr.ModelNodes) ValueService(org.jboss.msc.service.ValueService) Stream(java.util.stream.Stream) OperationFailedException(org.jboss.as.controller.OperationFailedException) SingleSignOnManager(org.wildfly.security.http.util.sso.SingleSignOnManager) Optional(java.util.Optional) ClearPassword(org.wildfly.security.password.interfaces.ClearPassword) ModelNode(org.jboss.dmr.ModelNode) Attribute(org.wildfly.extension.undertow.ApplicationSecurityDomainSingleSignOnDefinition.Attribute) Builder(org.wildfly.clustering.service.Builder) KeyPair(java.security.KeyPair) GeneralSecurityException(java.security.GeneralSecurityException) PasswordCredential(org.wildfly.security.credential.PasswordCredential) SSLContext(javax.net.ssl.SSLContext) IOException(java.io.IOException) KeyStore(java.security.KeyStore) DefaultSingleSignOnSessionFactory(org.wildfly.security.http.util.sso.DefaultSingleSignOnSessionFactory) CredentialSource(org.wildfly.security.credential.source.CredentialSource)

Example 2 with ClearPassword

use of org.wildfly.security.password.interfaces.ClearPassword in project wildfly by wildfly.

the class EncryptProtocolConfigurationBuilder method accept.

@Override
public void accept(P protocol) {
    KeyStore store = this.keyStore.getValue();
    String alias = this.keyAlias;
    try {
        if (!store.containsAlias(alias)) {
            throw JGroupsLogger.ROOT_LOGGER.keyEntryNotFound(alias);
        }
        PasswordCredential credential = this.credentialSource.getValue().getCredential(PasswordCredential.class);
        if (credential == null) {
            throw JGroupsLogger.ROOT_LOGGER.unexpectedCredentialSource();
        }
        ClearPassword password = credential.getPassword(ClearPassword.class);
        if (password == null) {
            throw JGroupsLogger.ROOT_LOGGER.unexpectedCredentialSource();
        }
        protocol.setKeyStore(this.keyStore.getValue());
        protocol.setKeyAlias(this.keyAlias);
        protocol.setKeyPassword(new KeyStore.PasswordProtection(password.getPassword()));
    } catch (KeyStoreException | IOException e) {
        throw new IllegalArgumentException(e);
    }
}
Also used : ClearPassword(org.wildfly.security.password.interfaces.ClearPassword) PasswordCredential(org.wildfly.security.credential.PasswordCredential) KeyStoreException(java.security.KeyStoreException) IOException(java.io.IOException) KeyStore(java.security.KeyStore)

Example 3 with ClearPassword

use of org.wildfly.security.password.interfaces.ClearPassword in project fuse-karaf by jboss-fuse.

the class Activator method replaced.

/**
 * Replaces any value that is given in Credential Store reference format with the value from the Credential Store by
 * using {@link System#setProperty(String, String)}.
 *
 * @param credentialStore
 *            {@link CredentialStore} containing the secret values
 * @param key
 *            property key
 * @param value
 *            property value, expected to be in Credential store reference format
 * @return true if any replacement was done
 */
boolean replaced(final CredentialStore credentialStore, final String key, final String value) {
    if (!CredentialStoreHelper.couldBeCredentialStoreAlias(value)) {
        return false;
    }
    final String alias = CredentialStoreHelper.toCredentialStoreAlias(value);
    final PasswordCredential passwordCredential;
    try {
        passwordCredential = credentialStore.retrieve(alias, PasswordCredential.class);
    } catch (final CredentialStoreException e) {
        return false;
    }
    if (passwordCredential == null) {
        return false;
    }
    final Password password = passwordCredential.getPassword();
    final ClearPassword clearPassword = password.castAs(ClearPassword.class);
    final char[] rawClearPassword = clearPassword.getPassword();
    System.setProperty(key, String.valueOf(rawClearPassword));
    return true;
}
Also used : ClearPassword(org.wildfly.security.password.interfaces.ClearPassword) PasswordCredential(org.wildfly.security.credential.PasswordCredential) CredentialStoreException(org.wildfly.security.credential.store.CredentialStoreException) Password(org.wildfly.security.password.Password) ClearPassword(org.wildfly.security.password.interfaces.ClearPassword)

Example 4 with ClearPassword

use of org.wildfly.security.password.interfaces.ClearPassword in project wildfly by wildfly.

the class CipherAuthTokenServiceConfigurator method apply.

@Override
public CipherAuthToken apply(String authValue) {
    KeyStore store = this.keyStore.get();
    String alias = this.keyAlias;
    try {
        if (!store.containsAlias(alias)) {
            throw JGroupsLogger.ROOT_LOGGER.keyEntryNotFound(alias);
        }
        if (!store.entryInstanceOf(alias, KeyStore.PrivateKeyEntry.class)) {
            throw JGroupsLogger.ROOT_LOGGER.unexpectedKeyStoreEntryType(alias, KeyStore.PrivateKeyEntry.class.getSimpleName());
        }
        PasswordCredential credential = this.keyCredentialSource.get().getCredential(PasswordCredential.class);
        if (credential == null) {
            throw JGroupsLogger.ROOT_LOGGER.unexpectedCredentialSource();
        }
        ClearPassword password = credential.getPassword(ClearPassword.class);
        if (password == null) {
            throw JGroupsLogger.ROOT_LOGGER.unexpectedCredentialSource();
        }
        KeyStore.PrivateKeyEntry entry = (KeyStore.PrivateKeyEntry) store.getEntry(alias, new KeyStore.PasswordProtection(password.getPassword()));
        KeyPair pair = new KeyPair(entry.getCertificate().getPublicKey(), entry.getPrivateKey());
        Cipher cipher = Cipher.getInstance(this.transformation);
        return new CipherAuthToken(cipher, pair, authValue.getBytes(StandardCharsets.UTF_8));
    } catch (GeneralSecurityException | IOException e) {
        throw new IllegalArgumentException(e);
    }
}
Also used : ClearPassword(org.wildfly.security.password.interfaces.ClearPassword) KeyPair(java.security.KeyPair) GeneralSecurityException(java.security.GeneralSecurityException) PasswordCredential(org.wildfly.security.credential.PasswordCredential) IOException(java.io.IOException) KeyStore(java.security.KeyStore) Cipher(javax.crypto.Cipher) CipherAuthToken(org.jboss.as.clustering.jgroups.auth.CipherAuthToken)

Example 5 with ClearPassword

use of org.wildfly.security.password.interfaces.ClearPassword in project wildfly by wildfly.

the class SingleSignOnSessionFactoryServiceConfigurator method get.

@Override
public SingleSignOnSessionFactory get() {
    KeyStore store = this.keyStore.get();
    String alias = this.keyAlias;
    CredentialSource source = this.credentialSource.get();
    try {
        if (!store.containsAlias(alias)) {
            throw UndertowLogger.ROOT_LOGGER.missingKeyStoreEntry(alias);
        }
        if (!store.entryInstanceOf(alias, KeyStore.PrivateKeyEntry.class)) {
            throw UndertowLogger.ROOT_LOGGER.keyStoreEntryNotPrivate(alias);
        }
        PasswordCredential credential = source.getCredential(PasswordCredential.class);
        if (credential == null) {
            throw UndertowLogger.ROOT_LOGGER.missingCredential(source.toString());
        }
        ClearPassword password = credential.getPassword(ClearPassword.class);
        if (password == null) {
            throw UndertowLogger.ROOT_LOGGER.credentialNotClearPassword(credential.toString());
        }
        KeyStore.PrivateKeyEntry entry = (KeyStore.PrivateKeyEntry) store.getEntry(alias, new KeyStore.PasswordProtection(password.getPassword()));
        KeyPair keyPair = new KeyPair(entry.getCertificate().getPublicKey(), entry.getPrivateKey());
        Optional<SSLContext> context = Optional.ofNullable(this.sslContext).map(dependency -> dependency.get());
        return new DefaultSingleSignOnSessionFactory(this.manager.get(), keyPair, connection -> context.ifPresent(ctx -> connection.setSSLSocketFactory(ctx.getSocketFactory())));
    } catch (GeneralSecurityException | IOException e) {
        throw new IllegalArgumentException(e);
    }
}
Also used : ClearPassword(org.wildfly.security.password.interfaces.ClearPassword) KEY_ALIAS(org.wildfly.extension.undertow.ApplicationSecurityDomainSingleSignOnDefinition.Attribute.KEY_ALIAS) KeyPair(java.security.KeyPair) SSLContext(javax.net.ssl.SSLContext) FunctionalService(org.wildfly.clustering.service.FunctionalService) CredentialSource(org.wildfly.security.credential.source.CredentialSource) Function(java.util.function.Function) Supplier(java.util.function.Supplier) CREDENTIAL(org.wildfly.extension.undertow.ApplicationSecurityDomainSingleSignOnDefinition.Attribute.CREDENTIAL) OperationContext(org.jboss.as.controller.OperationContext) CompositeDependency(org.wildfly.clustering.service.CompositeDependency) DefaultSingleSignOnSessionFactory(org.wildfly.security.http.util.sso.DefaultSingleSignOnSessionFactory) GeneralSecurityException(java.security.GeneralSecurityException) CredentialSourceDependency(org.jboss.as.clustering.controller.CredentialSourceDependency) ServiceConfigurator(org.wildfly.clustering.service.ServiceConfigurator) PasswordCredential(org.wildfly.security.credential.PasswordCredential) ServiceTarget(org.jboss.msc.service.ServiceTarget) SupplierDependency(org.wildfly.clustering.service.SupplierDependency) UndertowLogger(org.wildfly.extension.undertow.logging.UndertowLogger) SingleSignOnSessionFactory(org.wildfly.security.http.util.sso.SingleSignOnSessionFactory) CommonUnaryRequirement(org.jboss.as.clustering.controller.CommonUnaryRequirement) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) IOException(java.io.IOException) KeyStore(java.security.KeyStore) Service(org.jboss.msc.Service) SSL_CONTEXT(org.wildfly.extension.undertow.ApplicationSecurityDomainSingleSignOnDefinition.Attribute.SSL_CONTEXT) ServiceSupplierDependency(org.wildfly.clustering.service.ServiceSupplierDependency) KEY_STORE(org.wildfly.extension.undertow.ApplicationSecurityDomainSingleSignOnDefinition.Attribute.KEY_STORE) Consumer(java.util.function.Consumer) ResourceServiceConfigurator(org.jboss.as.clustering.controller.ResourceServiceConfigurator) OperationFailedException(org.jboss.as.controller.OperationFailedException) SingleSignOnManager(org.wildfly.security.http.util.sso.SingleSignOnManager) Optional(java.util.Optional) ClearPassword(org.wildfly.security.password.interfaces.ClearPassword) ModelNode(org.jboss.dmr.ModelNode) KeyPair(java.security.KeyPair) GeneralSecurityException(java.security.GeneralSecurityException) PasswordCredential(org.wildfly.security.credential.PasswordCredential) SSLContext(javax.net.ssl.SSLContext) IOException(java.io.IOException) KeyStore(java.security.KeyStore) DefaultSingleSignOnSessionFactory(org.wildfly.security.http.util.sso.DefaultSingleSignOnSessionFactory) CredentialSource(org.wildfly.security.credential.source.CredentialSource)

Aggregations

PasswordCredential (org.wildfly.security.credential.PasswordCredential)8 ClearPassword (org.wildfly.security.password.interfaces.ClearPassword)8 IOException (java.io.IOException)5 KeyStore (java.security.KeyStore)5 GeneralSecurityException (java.security.GeneralSecurityException)3 KeyPair (java.security.KeyPair)3 CredentialSource (org.wildfly.security.credential.source.CredentialSource)3 KeyStoreException (java.security.KeyStoreException)2 Optional (java.util.Optional)2 SSLContext (javax.net.ssl.SSLContext)2 CommonUnaryRequirement (org.jboss.as.clustering.controller.CommonUnaryRequirement)2 CredentialSourceDependency (org.jboss.as.clustering.controller.CredentialSourceDependency)2 OperationContext (org.jboss.as.controller.OperationContext)2 OperationFailedException (org.jboss.as.controller.OperationFailedException)2 ModelNode (org.jboss.dmr.ModelNode)2 ServiceBuilder (org.jboss.msc.service.ServiceBuilder)2 ServiceTarget (org.jboss.msc.service.ServiceTarget)2 UndertowLogger (org.wildfly.extension.undertow.logging.UndertowLogger)2 CredentialStore (org.wildfly.security.credential.store.CredentialStore)2 DefaultSingleSignOnSessionFactory (org.wildfly.security.http.util.sso.DefaultSingleSignOnSessionFactory)2