use of org.jboss.ejb.client.EJBClientContext 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.jboss.ejb.client.EJBClientContext in project wildfly by wildfly.
the class SwitchIdentityTestCase method callUsingSecurityContextAssociation.
/**
* Perform the tests using the SecurityContextAssociation API to set the desired Principal.
*/
private void callUsingSecurityContextAssociation(String userName, boolean hasRole1, boolean hasRole2) throws Exception {
try {
final Properties ejbClientConfiguration = EJBUtil.createEjbClientConfiguration(Utils.getHost(mgmtClient), userName);
// register the client side interceptor
final EJBClientContext ejbClientContext = EJBClientContext.getCurrent().withAddedInterceptors(new org.jboss.as.test.integration.ejb.container.interceptor.security.ClientSecurityInterceptor());
SecurityContextAssociation.setPrincipal(new SimplePrincipal(userName));
ejbClientContext.runCallable(() -> {
final Manage targetBean = EJBUtil.lookupEJB(ejbClientConfiguration, TargetBean.class, Manage.class);
final Manage bridgeBean = EJBUtil.lookupEJB(ejbClientConfiguration, 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;
});
} finally {
SecurityContextAssociation.clearSecurityContext();
}
}
use of org.jboss.ejb.client.EJBClientContext in project wildfly by wildfly.
the class EJBClientInterceptorTestCase method testEJBClientInterceptionFromRemoteClient.
/**
* @throws Exception
*/
@Test
// run as a truly remote client
@RunAsClient
public void testEJBClientInterceptionFromRemoteClient() throws Exception {
// create some data that the client side interceptor will pass along during the EJB invocation
final Map<String, Object> interceptorData = new HashMap<String, Object>();
final String keyOne = "foo";
final Object valueOne = "bar";
final String keyTwo = "blah";
final Object valueTwo = new Integer("12");
interceptorData.put(keyOne, valueOne);
interceptorData.put(keyTwo, valueTwo);
final SimpleEJBClientInterceptor clientInterceptor = new SimpleEJBClientInterceptor(interceptorData);
// get hold of the EJBClientContext and register the client side interceptor
final EJBClientContext ejbClientContext = EJBClientContext.getCurrent().withAddedInterceptors(clientInterceptor);
final Hashtable props = new Hashtable();
props.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
final Context jndiContext = new InitialContext(props);
ejbClientContext.runCallable(() -> {
final RemoteSFSB remoteSFSB = (RemoteSFSB) jndiContext.lookup("ejb:" + APP_NAME + "/" + MODULE_NAME + "/" + DISTINCT_NAME + "/" + SimpleSFSB.class.getSimpleName() + "!" + RemoteSFSB.class.getName() + "?stateful");
// invoke the bean and ask it for the invocation data that it saw on the server side
final Map<String, Object> valuesSeenOnServerSide = remoteSFSB.getInvocationData(keyOne, keyTwo);
// make sure the server side bean was able to get the data which was passed on by the client side
// interceptor
Assert.assertNotNull("Server side context data was expected to be non-null", valuesSeenOnServerSide);
Assert.assertFalse("Server side context data was expected to be non-empty", valuesSeenOnServerSide.isEmpty());
for (final Map.Entry<String, Object> clientInterceptorDataEntry : interceptorData.entrySet()) {
final String key = clientInterceptorDataEntry.getKey();
final Object expectedValue = clientInterceptorDataEntry.getValue();
Assert.assertEquals("Unexpected value in bean, on server side, via InvocationContext.getContextData() for key " + key, expectedValue, valuesSeenOnServerSide.get(key));
}
return null;
});
}
use of org.jboss.ejb.client.EJBClientContext in project wildfly by wildfly.
the class ContainerInterceptorsTestCase method testDataPassingForContainerInterceptorsOnRemoteView.
/**
* Tests that the container-interceptor(s) have access to the data that's passed by a remote client via the
* {@link javax.interceptor.InvocationContext#getContextData()}
*/
@Test
// force real remote invocation so that the RemotingConnectionEJBReceiver is used instead of a LocalEJBReceiver
@RunAsClient
public void testDataPassingForContainerInterceptorsOnRemoteView() throws Exception {
// create some data that the client side interceptor will pass along during the EJB invocation
final Map<String, Object> interceptorData = new HashMap<String, Object>();
interceptorData.put(FlowTrackingBean.CONTEXT_DATA_KEY, ContainerInterceptorOne.class.getName());
final SimpleEJBClientInterceptor clientInterceptor = new SimpleEJBClientInterceptor(interceptorData);
// get hold of the EJBClientContext and register the client side interceptor
EJBClientContext ejbClientContext = EJBClientContext.getCurrent().withAddedInterceptors(clientInterceptor);
final Hashtable<String, Object> jndiProps = new Hashtable<String, Object>();
jndiProps.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
final Context jndiCtx = new InitialContext(jndiProps);
ejbClientContext.runCallable(() -> {
final FlowTracker bean = (FlowTracker) jndiCtx.lookup("ejb:/" + EJB_JAR_NAME + "/" + FlowTrackingBean.class.getSimpleName() + "!" + FlowTracker.class.getName());
final String message = "foo";
// we passed ContainerInterceptorOne as the value of the context data for the invocation, which means that we want the ContainerInterceptorOne
// to be skipped, so except that interceptor, the rest should be invoked.
final String expectedResultForFirstInvocation = NonContainerInterceptor.class.getName() + " " + FlowTrackingBean.class.getName() + " " + message;
final String firstResult = bean.echo(message);
Assert.assertEquals("Unexpected result invoking on bean when passing context data via EJB client interceptor", expectedResultForFirstInvocation, firstResult);
// Now try another invocation, this time skip a different interceptor
interceptorData.clear();
interceptorData.put(FlowTrackingBean.CONTEXT_DATA_KEY, NonContainerInterceptor.class.getName());
final String secondMessage = "bar";
// we passed NonContainerInterceptor as the value of the context data for the invocation, which means that we want the NonContainerInterceptor
// to be skipped, so except that interceptor, the rest should be invoked.
final String expectedResultForSecondInvocation = ContainerInterceptorOne.class.getName() + " " + FlowTrackingBean.class.getName() + " " + secondMessage;
final String secondResult = bean.echo(secondMessage);
Assert.assertEquals("Unexpected result invoking on bean when passing context data via EJB client interceptor", expectedResultForSecondInvocation, secondResult);
return null;
});
}
use of org.jboss.ejb.client.EJBClientContext in project wildfly by wildfly.
the class SwitchIdentityTestCase method callUsingSecurityContextAssociation.
/**
* Perform the tests using the SecurityContextAssociation API to set the desired Principal.
*/
private void callUsingSecurityContextAssociation(String userName, boolean hasRole1, boolean hasRole2) throws Exception {
try {
final Properties ejbClientConfiguration = EJBUtil.createEjbClientConfiguration(Utils.getHost(mgmtClient), userName);
// register the client side interceptor
final EJBClientContext ejbClientContext = EJBClientContext.getCurrent().withAddedInterceptors(new ClientSecurityInterceptor());
SecurityContextAssociation.setPrincipal(new SimplePrincipal(userName));
ejbClientContext.runCallable(() -> {
final Manage targetBean = EJBUtil.lookupEJB(ejbClientConfiguration, TargetBean.class, Manage.class);
final Manage bridgeBean = EJBUtil.lookupEJB(ejbClientConfiguration, 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;
});
} finally {
SecurityContextAssociation.clearSecurityContext();
}
}
Aggregations