use of org.jboss.security.client.SecurityClient in project wildfly by wildfly.
the class GetCallerPrincipalTestCase method login.
private SecurityClient login() throws Exception {
final SecurityClient client = SecurityClientFactory.getSecurityClient();
client.setSimple("user1", "password1");
client.login();
return client;
}
use of org.jboss.security.client.SecurityClient in project wildfly by wildfly.
the class GetCallerPrincipalTestCase method testStatefulLifecycle.
@Test
public void testStatefulLifecycle() throws Exception {
deployer.deploy("sfsb");
SecurityClient client = this.login();
ITestResultsSingleton results = this.getResultsSingleton();
try {
IBeanLifecycleCallback bean = (IBeanLifecycleCallback) initialContext.lookup("ejb:/sfsb//" + SFSBLifecycleCallback.class.getSimpleName() + "!" + IBeanLifecycleCallback.class.getName() + "?stateful");
log.trace("Stateful bean returns: " + bean.get());
Assert.assertEquals(ANONYMOUS + "start", results.getSfsb("postconstruct"));
bean.remove();
Assert.assertEquals(LOCAL_USER + "stop", results.getSfsb("predestroy"));
} finally {
deployer.undeploy("sfsb");
client.logout();
}
}
use of org.jboss.security.client.SecurityClient in project wildfly by wildfly.
the class SingletonSecurityTestCase method testInvocationOnSecuredMethodWithInCorrectRole.
/**
* Test a method invocation on a singleton bean with an incorrect role.
*
* @throws Exception
*/
@Test
public void testInvocationOnSecuredMethodWithInCorrectRole() throws Exception {
final SingletonSecurity securedSingleton = InitialContext.doLookup("java:module/" + SecuredSingletonBean.class.getSimpleName());
final SecurityClient securityClient = SecurityClientFactory.getSecurityClient();
securityClient.setSimple("user2", "password2");
try {
// login
securityClient.login();
try {
// expects role1, so should fail
securedSingleton.allowedForRole1();
Assert.fail("Call to secured method, with incorrect role, was expected to fail");
} catch (EJBAccessException ejbae) {
// expected
}
} finally {
securityClient.logout();
}
}
use of org.jboss.security.client.SecurityClient in project wildfly by wildfly.
the class SingletonSecurityTestCase method testInvocationOnSecuredMethodWithCorrectRole.
/**
* Test a method invocation on a singleton bean with the correct expected role.
*
* @throws Exception
*/
@Test
public void testInvocationOnSecuredMethodWithCorrectRole() throws Exception {
final SingletonSecurity securedSingleton = InitialContext.doLookup("java:module/" + SecuredSingletonBean.class.getSimpleName());
final SecurityClient securityClient = SecurityClientFactory.getSecurityClient();
securityClient.setSimple("user1", "password1");
try {
// login
securityClient.login();
// expects role1, so should succeed
securedSingleton.allowedForRole1();
} finally {
securityClient.logout();
}
}
use of org.jboss.security.client.SecurityClient in project wildfly by wildfly.
the class EJBServlet method processRequest.
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
SecurityClient client = null;
try {
InitialContext ctx = new InitialContext();
client = SecurityClientFactory.getSecurityClient();
client.setSimple("user1", "password1");
client.login();
injectedSession.hello();
injectedSession.goodbye();
injectedStateless.hello();
injectedStateless.goodbye();
String lookupString = "java:global/ejb3-servlet-ejbs/Session30!";
EJBServletHelper test = new EJBServletHelper();
test.processRequest(lookupString, ctx);
} catch (Exception e) {
log.error(e);
throw new ServletException("Failed to call EJBs/Session30 through remote and local interfaces", e);
} finally {
client.logout();
}
response.setContentType("text/plain");
PrintWriter out = response.getWriter();
out.print("EJBServlet OK");
out.close();
}
Aggregations