boolean isRegistered = server.isRegistered(xmbean);
assertTrue(xmbean+" is registered", isRegistered);
// Lookup the Naming interface
InitialContext ctx = this.getInitialContext();
Naming naming = (Naming) ctx.lookup("secure/Naming");
getLog().info("Found Naming proxy: "+naming);
Name hello = ctx.getNameParser("").parse("Hello");
// Try to create a binding without security context
try
{
naming.bind(hello, "HelloBinding", "java.lang.String");
fail("Was able to invoke secretEcho");
}
catch(Exception e)
{
getLog().info("bind op failed as expected", e);
}
SimplePrincipal jduke = new SimplePrincipal("jduke");
SecurityAssociation.setPrincipal(jduke);
SecurityAssociation.setCredential("theduke".toCharArray());
naming.bind(hello, "HelloBinding", "java.lang.String");
getLog().info("Was able to create Hello binding");
SimplePrincipal guest = new SimplePrincipal("guest");
SecurityAssociation.setPrincipal(guest);
SecurityAssociation.setCredential("guest".toCharArray());
try
{
naming.bind(hello, "HelloBinding2", "java.lang.String");
fail("guest was able to create binding");
}
catch(Exception e)
{
getLog().info("guest bind op failed as expected", e);