use of org.wildfly.security.auth.client.AuthenticationContext in project quickstart by wildfly.
the class RemoteClient method main.
public static void main(String[] args) throws Exception {
AuthenticationConfiguration common = AuthenticationConfiguration.empty().setSaslMechanismSelector(SaslMechanismSelector.NONE.addMechanism("DIGEST-MD5"));
AuthenticationConfiguration quickstartUser = common.useName("quickstartUser").usePassword("quickstartPwd1!");
final AuthenticationContext authCtx1 = AuthenticationContext.empty().with(MatchRule.ALL, quickstartUser);
System.out.println(authCtx1.runCallable(callable));
AuthenticationConfiguration superUser = common.useName("quickstartAdmin").usePassword("adminPwd1!");
final AuthenticationContext authCtx2 = AuthenticationContext.empty().with(MatchRule.ALL, superUser);
System.out.println(authCtx2.runCallable(callable));
}
use of org.wildfly.security.auth.client.AuthenticationContext in project wildfly by wildfly.
the class SwitchIdentityTestCase method setupAuthenticationContext.
private AuthenticationContext setupAuthenticationContext(final String username) {
OptionMap.Builder builder = OptionMap.builder().set(Options.SASL_POLICY_NOANONYMOUS, true);
builder.set(Options.SASL_POLICY_NOPLAINTEXT, false);
builder.set(Options.SASL_DISALLOWED_MECHANISMS, Sequence.of("JBOSS-LOCAL-USER"));
final AuthenticationContext authenticationContext = AuthenticationContext.empty().with(MatchRule.ALL, AuthenticationConfiguration.EMPTY.useName(username == null ? "$local" : username).useRealm(null).allowSaslMechanisms("DIGEST-MD5").useMechanismProperties(getSaslProperties(builder.getMap())).useProvidersFromClassLoader(SwitchIdentityTestCase.class.getClassLoader()));
return authenticationContext;
}
use of org.wildfly.security.auth.client.AuthenticationContext in project wildfly by wildfly.
the class SwitchIdentityTestCase method callUsingClientLoginModule.
// Private methods -------------------------------------------------------
/**
* Perform the tests using the ClientLoginModule and LoginContext API to set the desired Principal.
*/
private void callUsingClientLoginModule(String userName, boolean hasRole1, boolean hasRole2) throws Exception {
AuthenticationContext authenticationContext = setupAuthenticationContext(userName);
authenticationContext.runCallable(() -> {
// register the client side interceptor
final EJBClientContext ejbClientContext = EJBClientContext.getCurrent().withAddedInterceptors(new ClientSecurityInterceptor());
ejbClientContext.runCallable(() -> {
final Manage targetBean = EJBUtil.lookupEJB(TargetBean.class, Manage.class);
final Manage bridgeBean = EJBUtil.lookupEJB(BridgeBean.class, Manage.class);
//test direct access
testMethodAccess(targetBean, ManageMethodEnum.ALLROLES, true);
testMethodAccess(targetBean, ManageMethodEnum.ROLE1, hasRole1);
testMethodAccess(targetBean, ManageMethodEnum.ROLE2, hasRole2);
//test security context propagation
testMethodAccess(bridgeBean, ManageMethodEnum.ALLROLES, true);
testMethodAccess(bridgeBean, ManageMethodEnum.ROLE1, hasRole1);
testMethodAccess(bridgeBean, ManageMethodEnum.ROLE2, hasRole2);
return null;
});
return null;
});
}
use of org.wildfly.security.auth.client.AuthenticationContext in project wildfly by wildfly.
the class SwitchIdentityTestCase method setupAuthenticationContext.
private AuthenticationContext setupAuthenticationContext(final String username) {
OptionMap.Builder builder = OptionMap.builder().set(Options.SASL_POLICY_NOANONYMOUS, true);
builder.set(Options.SASL_POLICY_NOPLAINTEXT, false);
builder.set(Options.SASL_DISALLOWED_MECHANISMS, Sequence.of("JBOSS-LOCAL-USER"));
final AuthenticationContext authenticationContext = AuthenticationContext.empty().with(MatchRule.ALL, AuthenticationConfiguration.EMPTY.useName(username == null ? "$local" : username).useRealm(null).allowSaslMechanisms("DIGEST-MD5").useMechanismProperties(getSaslProperties(builder.getMap())).useProvidersFromClassLoader(org.jboss.as.test.integration.ejb.container.interceptor.security.SwitchIdentityTestCase.class.getClassLoader()));
return authenticationContext;
}
use of org.wildfly.security.auth.client.AuthenticationContext in project wildfly by wildfly.
the class UndertowSSLv2HelloTestCase method testTwoWayElytronClientServerSupportsSSLv2Hello.
/**
* Two way SSL - RESTEasy client sends SSLv2Hello message and server supports the protocol.
* Handshake should succeed.
*/
@Test
public void testTwoWayElytronClientServerSupportsSSLv2Hello() throws Exception {
configureSSLContext(SSLV2HELLO_CONTEXT);
AuthenticationContext context = doPrivileged((PrivilegedAction<AuthenticationContext>) () -> {
try {
URL config = getClass().getResource("wildfly-config-sslv2hello.xml");
return ElytronXmlParser.parseAuthenticationClientConfiguration(config.toURI()).create();
} catch (Throwable t) {
throw new InvalidAuthenticationConfigurationException(t);
}
});
context.run(() -> {
ClientBuilder clientBuilder = ClientBuilder.newBuilder().hostnameVerifier((s, sslSession) -> true);
Client client = clientBuilder.build();
Response response = client.target(String.valueOf(securedRootUrl)).request().get();
Assert.assertEquals(200, response.getStatus());
});
restoreConfiguration();
}
Aggregations