当前位置: 首页>>代码示例>>Java>>正文


Java AuthenticationContext类代码示例

本文整理汇总了Java中org.wildfly.security.auth.client.AuthenticationContext的典型用法代码示例。如果您正苦于以下问题:Java AuthenticationContext类的具体用法?Java AuthenticationContext怎么用?Java AuthenticationContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


AuthenticationContext类属于org.wildfly.security.auth.client包,在下文中一共展示了AuthenticationContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: assertDefaultRealmWorks

import org.wildfly.security.auth.client.AuthenticationContext; //导入依赖的package包/类
/**
 * Tests if DIGEST-* mechanism with default realm used works correctly for both valid and invalid username/password
 * combinations.
 *
 * @param mechanism DIGEST mechanism name
 */
private void assertDefaultRealmWorks(String mechanism) throws Exception {
    try (CLIWrapper cli = new CLIWrapper(true)) {
        cli.sendLine(String.format(
                "/subsystem=elytron/sasl-authentication-factory=%s:write-attribute(name=mechanism-configurations, value=[{mechanism-name=%s}])",
                NAME, mechanism));
    }
    ServerReload.reloadIfRequired(TestSuiteEnvironment.getModelControllerClient());

    AuthenticationConfiguration authnCfg = AuthenticationConfiguration.empty()
            .setSaslMechanismSelector(SaslMechanismSelector.fromString(mechanism)).useName(USERNAME)
            .usePassword(USERNAME + PASSWORD_SFX);
    AuthenticationContext.empty().with(MatchRule.ALL, authnCfg).run(() -> assertWhoAmI(USERNAME));

    authnCfg = AuthenticationConfiguration.empty().setSaslMechanismSelector(SaslMechanismSelector.fromString(mechanism))
            .useName("noSuchUser").usePassword("aPassword");
    AuthenticationContext.empty().with(MatchRule.ALL, authnCfg).run(() -> assertAuthenticationFails(
            "Authentication should fail when the user doesn't exist in the security-realm"));
}
 
开发者ID:wildfly,项目名称:wildfly-core,代码行数:25,代码来源:DefaultRealmDigestMgmtSaslTestCase.java

示例2: assertKerberosSaslMechPasses

import org.wildfly.security.auth.client.AuthenticationContext; //导入依赖的package包/类
/**
 * Asserts that given user can authenticate with given Kerberos SASL mechanism.
 */
protected void assertKerberosSaslMechPasses(String mech, String user, String password, boolean withSsl)
        throws MalformedURLException, LoginException, Exception {
    // 1. Authenticate to Kerberos.
    final LoginContext lc = KerberosTestUtils.loginWithKerberos(KRB5_CONFIGURATION, user, password);
    try {
        AuthenticationConfiguration authCfg = AuthenticationConfiguration.empty()
                .setSaslMechanismSelector(SaslMechanismSelector.fromString(mech))
                .useGSSCredential(getGSSCredential(lc.getSubject()));

        AuthenticationContext authnCtx = AuthenticationContext.empty().with(MatchRule.ALL, authCfg);
        if (withSsl) {
            authnCtx = authnCtx.withSsl(MatchRule.ALL, sslFactory);
        }
        final AuthenticationContext authnCtxFinal = authnCtx;
        Subject.doAs(lc.getSubject(), (PrivilegedAction<Void>) () -> {
            authnCtxFinal.run(() -> assertWhoAmI(user + "@JBOSS.ORG", withSsl));
            return null;
        });
    } finally {
        lc.logout();
    }
}
 
开发者ID:wildfly,项目名称:wildfly-core,代码行数:26,代码来源:AbstractKerberosMgmtSaslTestBase.java

示例3: assertKerberosSaslMechFails

import org.wildfly.security.auth.client.AuthenticationContext; //导入依赖的package包/类
protected void assertKerberosSaslMechFails(String mech, String user, String password, boolean withSsl)
        throws MalformedURLException, LoginException, Exception {
    // 1. Authenticate to Kerberos.
    final LoginContext lc = KerberosTestUtils.loginWithKerberos(KRB5_CONFIGURATION, user, password);
    try {
        AuthenticationConfiguration authCfg = AuthenticationConfiguration.empty()
                .setSaslMechanismSelector(SaslMechanismSelector.fromString(mech))
                .useGSSCredential(getGSSCredential(lc.getSubject()));

        AuthenticationContext authnCtx = AuthenticationContext.empty().with(MatchRule.ALL, authCfg);
        if (withSsl) {
            authnCtx = authnCtx.withSsl(MatchRule.ALL, sslFactory);
        }
        final AuthenticationContext authnCtxFinal = authnCtx;
        Subject.doAs(lc.getSubject(), (PrivilegedAction<Void>) () -> {
            authnCtxFinal.run(() -> assertAuthenticationFails(null, null, withSsl));
            return null;
        });
    } finally {
        lc.logout();
    }
}
 
开发者ID:wildfly,项目名称:wildfly-core,代码行数:23,代码来源:AbstractKerberosMgmtSaslTestBase.java

示例4: testMatchingFilteringProperties

import org.wildfly.security.auth.client.AuthenticationContext; //导入依赖的package包/类
/**
 * Tests SASL mechanism filtering through policy properties which are matched by EXTERNAL mechanism.
 *
 * @see <a href="https://issues.jboss.org/browse/ELY-982">ELY-982</a>
 */
@Test
public void testMatchingFilteringProperties() throws Exception {
    Map<String, String> mechanismProperties = new HashMap<>();
    mechanismProperties.put(Sasl.POLICY_NOPLAINTEXT, "true");
    mechanismProperties.put(Sasl.POLICY_NOACTIVE, "true");
    mechanismProperties.put(Sasl.POLICY_NODICTIONARY, "true");
    AuthenticationConfiguration authCfg = AuthenticationConfiguration.empty()
            .setSaslMechanismSelector(SaslMechanismSelector.fromString(MECHANISM))
            .useMechanismProperties(mechanismProperties);

    SecurityFactory<SSLContext> ssl = new SSLContextBuilder().setClientMode(true)
            .setKeyManager(getKeyManager(CLIENT_KEYSTORE_FILE)).setTrustManager(getTrustManager()).build();
    AuthenticationContext.empty().with(MatchRule.ALL, authCfg).withSsl(MatchRule.ALL, ssl)
            .run(() -> assertWhoAmI("client"));
}
 
开发者ID:wildfly,项目名称:wildfly-core,代码行数:21,代码来源:ExternalMgmtSaslTestCase.java

示例5: testNullProvider

import org.wildfly.security.auth.client.AuthenticationContext; //导入依赖的package包/类
/**
 * Tests wrongly configured security Provider in the clients AuthenticationConfiguration.
 */
@Test
public void testNullProvider() throws Exception {
    String mechanismName = getMechanism();
    AuthenticationConfiguration authnCfg = AuthenticationConfiguration.empty()
            .setSaslMechanismSelector(SaslMechanismSelector.fromString(mechanismName))
            .useProviders(() -> new Provider[] { null });
    if ("ANONYMOUS".equals(mechanismName)) {
        authnCfg = authnCfg.useAnonymous();
    } else if ("OAUTHBEARER".equals(mechanismName)) {
        authnCfg = authnCfg.useBearerTokenCredential(new BearerTokenCredential(JWT_TOKEN));
    } else if (!"JBOSS-LOCAL-USER".equals(mechanismName)) {
        authnCfg = authnCfg.useName(USERNAME).usePassword(USERNAME + PASSWORD_SFX);
    }
    AuthenticationContext.empty().with(MatchRule.ALL, authnCfg).run(() -> assertAuthenticationFails());
}
 
开发者ID:wildfly,项目名称:wildfly-core,代码行数:19,代码来源:AbstractMgmtSaslTestBase.java

示例6: createDomainClient

import org.wildfly.security.auth.client.AuthenticationContext; //导入依赖的package包/类
/**
 * Create a new model controller client. The client can (and should) be closed without affecting other usages.
 *
 * @param authConfigUri the path to the {@code wildfly-config.xml} to use or {@code null}
 *
 * @return the domain client
 */
public DomainClient createDomainClient(final URI authConfigUri) {
    final DomainTestConnection connection = this.connection;
    if(connection == null) {
        throw new IllegalStateException();
    }
    if (authConfigUri == null) {
        return DomainClient.Factory.create(connection.createClient());
    }
    try {
        final AuthenticationContext context = ElytronXmlParser.parseAuthenticationClientConfiguration(authConfigUri).create();
        return DomainClient.Factory.create(new ContextualModelControllerClient(connection.createClient(), context));
    } catch (GeneralSecurityException | ConfigXMLParseException e) {
        throw new RuntimeException("Failed to parse authentication configuration: " + authConfigUri, e);
    }
}
 
开发者ID:wildfly,项目名称:wildfly-core,代码行数:23,代码来源:DomainLifecycleUtil.java

示例7: RemoteDomainConnection

import org.wildfly.security.auth.client.AuthenticationContext; //导入依赖的package包/类
RemoteDomainConnection(final String localHostName, final ProtocolConnectionConfiguration configuration, final AuthenticationContext authenticationContext,
                       final SecurityRealm realm,  final String username, final List<DiscoveryOption> discoveryOptions,
                       final ExecutorService executorService,
                       final ScheduledExecutorService scheduledExecutorService,
                       final HostRegistrationCallback callback,
                       final RunningMode runningMode) {
    this.callback = callback;
    this.localHostName = localHostName;
    this.configuration = configuration;
    this.authenticationContext = authenticationContext;
    this.username = username;
    this.realm = realm;
    this.discoveryOptions = discoveryOptions;
    this.executorService = executorService;
    this.channelHandler = new ManagementChannelHandler(this, executorService);
    this.scheduledExecutorService = scheduledExecutorService;
    this.runningMode = runningMode;
    this.connectionManager = ProtocolConnectionManager.create(new InitialConnectTask());
}
 
开发者ID:wildfly,项目名称:wildfly-core,代码行数:20,代码来源:RemoteDomainConnection.java

示例8: deploy

import org.wildfly.security.auth.client.AuthenticationContext; //导入依赖的package包/类
@Override
public void deploy(DeploymentPhaseContext context) throws DeploymentUnitProcessingException {
    AuthenticationContext authenticationContext = context.getAttachment(AUTHENTICATION_CONTEXT_KEY);
    if (authenticationContext != null) {
        AuthenticationContext.getContextManager().setClassLoaderDefault(
                context.getDeploymentUnit().getAttachment(MODULE).getClassLoader(), authenticationContext);
    }
}
 
开发者ID:wildfly,项目名称:wildfly-core,代码行数:9,代码来源:AuthenticationContextAssociationProcessor.java

示例9: performRuntime

import org.wildfly.security.auth.client.AuthenticationContext; //导入依赖的package包/类
protected void performRuntime(final OperationContext context, final ModelNode operation, final ModelNode model) throws OperationFailedException {

            RuntimeCapability<Void> runtimeCapability = DIR_CONTEXT_RUNTIME_CAPABILITY.fromBaseCapability(context.getCurrentAddressValue());
            ServiceName serviceName = runtimeCapability.getCapabilityServiceName(DirContextSupplier.class);

            final InjectedValue<ExceptionSupplier<CredentialSource, Exception>> credentialSourceSupplierInjector = new InjectedValue<>();
            final InjectedValue<AuthenticationContext> authenticationContextInjector = new InjectedValue<>();
            final InjectedValue<SSLContext> sslContextInjector = new InjectedValue<>();

            TrivialService<DirContextSupplier> service = new TrivialService<>(obtainDirContextSupplier(context, model, credentialSourceSupplierInjector, authenticationContextInjector, sslContextInjector));
            ServiceBuilder<DirContextSupplier> serviceBuilder = context.getServiceTarget().addService(serviceName, service);

            String sslContextName = SSL_CONTEXT.resolveModelAttribute(context, model).asStringOrNull();
            if (sslContextName != null) {
                String sslCapability = RuntimeCapability.buildDynamicCapabilityName(SSL_CONTEXT_CAPABILITY, sslContextName);
                ServiceName sslServiceName = context.getCapabilityServiceName(sslCapability, SSLContext.class);
                serviceBuilder.addDependency(sslServiceName, SSLContext.class, sslContextInjector);
            }

            if (CREDENTIAL_REFERENCE.resolveModelAttribute(context, model).isDefined()) {
                credentialSourceSupplierInjector.inject(CredentialReference.getCredentialSourceSupplier(context, CREDENTIAL_REFERENCE, model, serviceBuilder));
            }

            String authenticationContextName = AUTHENTICATION_CONTEXT.resolveModelAttribute(context, model).asStringOrNull();
            if (authenticationContextName != null) {
                String acCapability = RuntimeCapability.buildDynamicCapabilityName(AUTHENTICATION_CONTEXT_CAPABILITY, authenticationContextName);
                ServiceName acServiceName = context.getCapabilityServiceName(acCapability, AuthenticationContext.class);
                serviceBuilder.addDependency(acServiceName, AuthenticationContext.class, authenticationContextInjector);
            }

            serviceBuilder
                    .setInitialMode(ServiceController.Mode.ACTIVE)
                    .install();
        }
 
开发者ID:wildfly,项目名称:wildfly-core,代码行数:35,代码来源:DirContextDefinition.java

示例10: testCorrectMechanismPasses

import org.wildfly.security.auth.client.AuthenticationContext; //导入依赖的package包/类
/**
 * Tests that client is able to use mechanism when server allows it.
 */
@Test
public void testCorrectMechanismPasses() throws Exception {
    AuthenticationConfiguration authCfg = AuthenticationConfiguration.empty()
            .setSaslMechanismSelector(SaslMechanismSelector.fromString(MECHANISM));

    SecurityFactory<SSLContext> ssl = new SSLContextBuilder().setClientMode(true)
            .setKeyManager(getKeyManager(CLIENT_KEYSTORE_FILE)).setTrustManager(getTrustManager()).build();
    AuthenticationContext.empty().with(MatchRule.ALL, authCfg).withSsl(MatchRule.ALL, ssl)
            .run(() -> assertWhoAmI("client"));
}
 
开发者ID:wildfly,项目名称:wildfly-core,代码行数:14,代码来源:ExternalMgmtSaslTestCase.java

示例11: assertUnmatchingFilteringPropertyFails

import org.wildfly.security.auth.client.AuthenticationContext; //导入依赖的package包/类
/**
 * @param policyProperty
 * @throws Exception
 */
private void assertUnmatchingFilteringPropertyFails(String policyProperty) throws Exception {
    Map<String, String> mechanismProperties = new HashMap<>();
    mechanismProperties.put(policyProperty, "true");
    AuthenticationConfiguration authCfg = AuthenticationConfiguration.empty()
            .setSaslMechanismSelector(SaslMechanismSelector.fromString(MECHANISM))
            .useMechanismProperties(mechanismProperties);

    SecurityFactory<SSLContext> ssl = new SSLContextBuilder().setClientMode(true)
            .setKeyManager(getKeyManager(CLIENT_KEYSTORE_FILE)).setTrustManager(getTrustManager()).build();
    AuthenticationContext.empty().with(MatchRule.ALL, authCfg).withSsl(MatchRule.ALL, ssl)
            .run(() -> assertAuthenticationFails(
                    String.format("The EXTERNAL SASL mechanism should not be selected, when property %s is true.", policyProperty)));
}
 
开发者ID:wildfly,项目名称:wildfly-core,代码行数:18,代码来源:ExternalMgmtSaslTestCase.java

示例12: testUntrustedCertFails

import org.wildfly.security.auth.client.AuthenticationContext; //导入依赖的package包/类
/**
 * Tests that client with wrong (untrusted) certificate is not able to execute operation on server through the mechanism.
 */
@Test
public void testUntrustedCertFails() throws Exception {
    AuthenticationConfiguration authCfg = AuthenticationConfiguration.empty()
            .setSaslMechanismSelector(SaslMechanismSelector.fromString(MECHANISM));

    SecurityFactory<SSLContext> ssl = new SSLContextBuilder().setClientMode(true)
            .setKeyManager(getKeyManager(UNTRUSTED_STORE_FILE)).setTrustManager(getTrustManager()).build();
    AuthenticationContext.empty().with(MatchRule.ALL, authCfg).withSsl(MatchRule.ALL, ssl)
            .run(() -> assertCertAuthenticationFails(
                    "Client certificate authentication should fail for an untrusted certificate."));
}
 
开发者ID:wildfly,项目名称:wildfly-core,代码行数:15,代码来源:ExternalMgmtSaslTestCase.java

示例13: testWrongCredentialsFail

import org.wildfly.security.auth.client.AuthenticationContext; //导入依赖的package包/类
/**
 * Tests that invalid credentials results in authentication failure.
 */
@Test
public void testWrongCredentialsFail() throws Exception {
    String mechanismName = getMechanism();
    if ("ANONYMOUS".equals(mechanismName)) {
        LOGGER.info("We don't test ANONYMOUS mechanism with wrong user credentials.");
        return;
    }

    AuthenticationConfiguration authnCfg = AuthenticationConfiguration.empty()
            .setSaslMechanismSelector(SaslMechanismSelector.fromString(mechanismName)).useName(USERNAME)
            .usePassword("wrongPassword").useProviders(() -> new Provider[] { PROVIDER_ELYTRON });
    AuthenticationContext.empty().with(MatchRule.ALL, authnCfg).run(() -> assertAuthenticationFails());
}
 
开发者ID:wildfly,项目名称:wildfly-core,代码行数:17,代码来源:AbstractMgmtSaslTestBase.java

示例14: createValidConfigForMechanism

import org.wildfly.security.auth.client.AuthenticationContext; //导入依赖的package包/类
protected AuthenticationContext createValidConfigForMechanism(String mechanismName, String username) {
    AuthenticationConfiguration authnCfg = AuthenticationConfiguration.empty()
            .setSaslMechanismSelector(SaslMechanismSelector.fromString(mechanismName));
    if ("ANONYMOUS".equals(mechanismName)) {
        authnCfg = authnCfg.useAnonymous();
    } else if ("OAUTHBEARER".equals(mechanismName)) {
        authnCfg = authnCfg.useBearerTokenCredential(new BearerTokenCredential(JWT_TOKEN));
    } else if (!"JBOSS-LOCAL-USER".equals(mechanismName)) {
        authnCfg = authnCfg.useName(username).usePassword(username + PASSWORD_SFX);
    }
    return AuthenticationContext.empty().with(MatchRule.ALL, authnCfg);
}
 
开发者ID:wildfly,项目名称:wildfly-core,代码行数:13,代码来源:AbstractMgmtSaslTestBase.java

示例15: testExpiredToken

import org.wildfly.security.auth.client.AuthenticationContext; //导入依赖的package包/类
@Test
public void testExpiredToken() throws Exception {
    AuthenticationContext.empty()
            .with(MatchRule.ALL,
                    AuthenticationConfiguration.empty().setSaslMechanismSelector(SaslMechanismSelector.ALL)
                            .useBearerTokenCredential(new BearerTokenCredential(TOKEN_EXPIRED)))
            .run(() -> assertAuthenticationFails());
}
 
开发者ID:wildfly,项目名称:wildfly-core,代码行数:9,代码来源:OauthbearerMgmtSaslTestCase.java


注:本文中的org.wildfly.security.auth.client.AuthenticationContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。