JAAS
silenius Oct 22, 2009 12:01 PMHello all,
I'm trying to make Embedded JBoss work without success.
Each time I try to call a protected EJB3 method I get the following error:
javax.ejb.EJBAccessException: Caller unauthorized at org.jboss.ejb3.security.RoleBasedAuthorizationInterceptorv2.invoke(RoleBasedAuthorizationInterceptorv2.java:184) at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) at org.jboss.ejb3.security.Ejb3AuthenticationInterceptorv2.invoke(Ejb3AuthenticationInterceptorv2.java:166) at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46) at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106) at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:249) at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.java:214) at org.jboss.ejb3.stateless.StatelessLocalProxy.invoke(StatelessLocalProxy.java:86) at $Proxy83.insertClient(Unknown Source) at my.package.business.ClientAdministrationServiceBeanTest.insertClient(ClientAdministrationServiceBeanTest.java:109)
My SessionBean looks like this:
@Stateless
@Local(ClientAdministrationService.class)
@LocalBinding(jndiBinding = "clientAdministrationService")
@SecurityDomain("MyRealm")
@RunAs("private")
public class ClientAdministrationServiceBean implements ClientAdministrationService {
@EJB
ClientDAO clientDAO;
@PermitAll
@TransactionAttribute(value = TransactionAttributeType.REQUIRED)
public Client insertClient(Client client){
client.setStatus(Status.ENABLE);
return clientDAO.insert(client);
}
...
}
My test class (using TestNG) looks like this:
public class ClientAdministrationServiceBeanTest {
private static final Logger LOGGER = LoggerFactory.getLogger(ClientAdministrationServiceBeanTest.class);
private static ClientAdministrationService service;
private SecurityClient securityClient;
@BeforeClass
public void setUp() throws Exception {
try {
if (!Bootstrap.getInstance().isStarted()) {
Bootstrap.getInstance().bootstrap();
Bootstrap.getInstance().scanClasspath("classes");
// Bootstrap.getInstance().deploy(makeURLForDir("target/classes"));
// String resource = "META-INF/persistence.xml";
// Bootstrap.getInstance().deployResourceBase(resource);
}
} catch (DeploymentException e) {
LOGGER.error(e.getMessage(), e);
// } catch (IOException e) {
// LOGGER.error(e.getMessage(), e);
}
securityClient = SecurityClientFactory.getSecurityClient();
securityClient.setSimple("admin", "test");
securityClient.login();
// SecurityAssociation.setPrincipal(new SimplePrincipal("admin"));
// SecurityAssociation.setCredential("test".toCharArray());
InitialContext ctx = new InitialContext();
service = (ClientAdministrationService) ctx.lookup("clientAdministrationService");
}
@AfterClass
public void tearDown() throws Exception {
securityClient.logout();
if (System.getProperty("shutdown.embedded.jboss") != null) {
Bootstrap.getInstance().shutdown();
}
}
...
}
If I remove the annotation @SecurityDomain("MyRealm") from my Session Bean the code works fine.
Is there a way to use a self defined JAAS domain policy inside my EJB3 with Embedded JBoss?
Thanks, kind regards,
Samuel Santos