use of org.jboss.as.naming.InitialContext in project wildfly by wildfly.
the class RunAsWithElytronEJBContextPropagationTestCase method initContext.
private InitialContext initContext() {
Properties props = new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY, WildFlyInitialContextFactory.class.getName());
props.put(Context.PROVIDER_URL, "remote+http://" + TestSuiteEnvironment.getServerAddress() + ":8080");
props.put(Context.SECURITY_PRINCIPAL, USERNAME);
props.put(Context.SECURITY_CREDENTIALS, PASSWORD);
try {
return new InitialContext(props);
} catch (NamingException e) {
throw new RuntimeException(e);
}
}
use of org.jboss.as.naming.InitialContext in project wildfly by wildfly.
the class ElytronRemoteOutboundConnectionTestCase method callIntermediateWhoAmI.
private String callIntermediateWhoAmI(boolean useRestrictedMethod) {
AuthenticationConfiguration common = AuthenticationConfiguration.empty().useProviders(() -> new Provider[] { new WildFlyElytronProvider() }).setSaslMechanismSelector(SaslMechanismSelector.ALL);
AuthenticationContext authCtxEmpty = AuthenticationContext.empty();
final AuthenticationContext authCtx = authCtxEmpty.with(MatchRule.ALL, common);
final EJBClientContext.Builder ejbClientBuilder = new EJBClientContext.Builder();
ejbClientBuilder.addTransportProvider(new RemoteTransportProvider());
final EJBClientConnection.Builder connBuilder = new EJBClientConnection.Builder();
connBuilder.setDestination(URI.create("remote+http://" + TestSuiteEnvironment.getServerAddressNode1() + ":8180"));
ejbClientBuilder.addClientConnection(connBuilder.build());
final EJBClientContext ejbCtx = ejbClientBuilder.build();
AuthenticationContext.getContextManager().setThreadDefault(authCtx);
EJBClientContext.getContextManager().setThreadDefault(ejbCtx);
Properties props = new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY, WildFlyInitialContextFactory.class.getName());
String result;
try {
InitialContext ctx = new InitialContext(props);
String lookupName = "ejb:/outbound-module/IntermediateWhoAmI!org.jboss.as.test.manualmode.ejb.client.outbound.connection.security.WhoAmI";
WhoAmI intermediate = (WhoAmI) ctx.lookup(lookupName);
if (useRestrictedMethod) {
result = intermediate.whoAmIRestricted();
} else {
result = intermediate.whoAmI();
}
ctx.close();
} catch (NamingException e) {
throw new RuntimeException(e);
}
return result;
}
use of org.jboss.as.naming.InitialContext in project wildfly by wildfly.
the class RunAsWithElytronEJBContextPropagationTestCase method testRunAsWithElytronEJBContextPropagation.
/**
* Test that checks the first EJB is called by admin role, same user is used to call the second EJB were the role does not
* change.
*
* The test uses http-remoting protocol.
*/
@Test
public void testRunAsWithElytronEJBContextPropagation() {
InitialContext context = initContext();
IntermediateCallerInRoleRemote intermediate;
try {
intermediate = (IntermediateCallerInRoleRemote) context.lookup("ejb:/ejb-security-context-propagation/IntermediateCallerInRole!" + IntermediateCallerInRoleRemote.class.getName());
} catch (NamingException e) {
throw new RuntimeException(e);
}
Assert.assertFalse(intermediate.isCallerInRole(ROLE));
Assert.assertTrue(intermediate.isServerCallerInRole(ROLE));
closeContext(context);
}
Aggregations