Search in sources :

Example 1 with DefaultSingleSignOnSessionFactory

use of org.wildfly.security.http.util.sso.DefaultSingleSignOnSessionFactory 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 DefaultSingleSignOnSessionFactory

use of org.wildfly.security.http.util.sso.DefaultSingleSignOnSessionFactory 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

IOException (java.io.IOException)2 GeneralSecurityException (java.security.GeneralSecurityException)2 KeyPair (java.security.KeyPair)2 KeyStore (java.security.KeyStore)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 PasswordCredential (org.wildfly.security.credential.PasswordCredential)2 CredentialSource (org.wildfly.security.credential.source.CredentialSource)2 DefaultSingleSignOnSessionFactory (org.wildfly.security.http.util.sso.DefaultSingleSignOnSessionFactory)2 SingleSignOnManager (org.wildfly.security.http.util.sso.SingleSignOnManager)2 SingleSignOnSessionFactory (org.wildfly.security.http.util.sso.SingleSignOnSessionFactory)2 ClearPassword (org.wildfly.security.password.interfaces.ClearPassword)2