public void testSecurityDomain() throws Exception
{
log.info("+++ testSecurityDomain, domain=spec-test");
MBeanServerConnection conn = getServer();
ObjectName secMgrName = new ObjectName("jboss.security:service=JaasSecurityManager");
JaasSecurityManagerServiceMBean secMgr = (JaasSecurityManagerServiceMBean) MBeanServerInvocationHandler
.newProxyInstance(conn, secMgrName, JaasSecurityManagerServiceMBean.class, false);
// Test the spec-test security domain
String domain = "spec-test";
SimplePrincipal user = new SimplePrincipal("scott");
boolean isValid = secMgr.isValid(domain, user, password);
assertTrue("scott password is echoman", isValid);
HashSet testRole = new HashSet();
testRole.add(new SimplePrincipal("Echo"));
boolean hasRole = secMgr.doesUserHaveRole(domain, user, password, testRole);
assertTrue("scott has Echo role", hasRole);
testRole.clear();
testRole.add(new SimplePrincipal("EchoLocal"));
hasRole = secMgr.doesUserHaveRole(domain, user, password, testRole);
assertTrue("scott has EchoLocal role", hasRole);
testRole.clear();
testRole.add(new SimplePrincipal("ProjectUser"));
hasRole = secMgr.doesUserHaveRole(domain, user, password, testRole);
assertTrue("scott has ProjectUser role", hasRole);
isValid = secMgr.isValid(domain, user, "badpass".toCharArray());
assertTrue("badpass is an invalid password for scott", isValid == false);
// Test the spec-test-domain security domain
log.info("+++ testSecurityDomain, domain=spec-test-domain");
domain = "spec-test-domain";
isValid = secMgr.isValid(domain, user, password);
assertTrue("scott password is echoman", isValid);
hasRole = secMgr.doesUserHaveRole(domain, user, password, testRole);
assertTrue("scott has Echo role", hasRole);
testRole.clear();
SimplePrincipal echoLocal = new SimplePrincipal("EchoLocal");
testRole.add(echoLocal);
hasRole = secMgr.doesUserHaveRole(domain, user, password, testRole);
assertTrue("scott has EchoLocal role", hasRole);
testRole.clear();
SimplePrincipal projectUser = new SimplePrincipal("ProjectUser");
testRole.add(projectUser);
hasRole = secMgr.doesUserHaveRole(domain, user, password, testRole);
assertTrue("scott has ProjectUser role", hasRole);
Set roles = secMgr.getUserRoles(domain, user, password);
assertTrue(roles != null);
assertTrue("roles contains EchoLocal", roles.contains(echoLocal));
assertTrue("roles contains ProjectUser", roles.contains(projectUser));
isValid = secMgr.isValid(domain, user, "badpass".toCharArray());
assertTrue("badpass is an invalid password for scott", isValid == false);
}