Search in sources :

Example 1 with CREDENTIAL

use of org.wildfly.extension.undertow.ApplicationSecurityDomainSingleSignOnDefinition.Attribute.CREDENTIAL 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)1 GeneralSecurityException (java.security.GeneralSecurityException)1 KeyPair (java.security.KeyPair)1 KeyStore (java.security.KeyStore)1 Optional (java.util.Optional)1 Consumer (java.util.function.Consumer)1 Function (java.util.function.Function)1 Supplier (java.util.function.Supplier)1 SSLContext (javax.net.ssl.SSLContext)1 CommonUnaryRequirement (org.jboss.as.clustering.controller.CommonUnaryRequirement)1 CredentialSourceDependency (org.jboss.as.clustering.controller.CredentialSourceDependency)1 ResourceServiceConfigurator (org.jboss.as.clustering.controller.ResourceServiceConfigurator)1 OperationContext (org.jboss.as.controller.OperationContext)1 OperationFailedException (org.jboss.as.controller.OperationFailedException)1 ModelNode (org.jboss.dmr.ModelNode)1 Service (org.jboss.msc.Service)1 ServiceBuilder (org.jboss.msc.service.ServiceBuilder)1 ServiceTarget (org.jboss.msc.service.ServiceTarget)1 CompositeDependency (org.wildfly.clustering.service.CompositeDependency)1 FunctionalService (org.wildfly.clustering.service.FunctionalService)1