Methods Summary |
---|
public static javax.naming.InitialContext | getInitialContext(java.lang.String username, java.lang.String password)
Properties env = new Properties();
env.setProperty(Context.SECURITY_PRINCIPAL, username);
env.setProperty(Context.SECURITY_CREDENTIALS, password);
env.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.security.jndi.JndiLoginInitialContextFactory");
return new InitialContext(env);
|
public static void | main(java.lang.String[] args)
testAllEntity();
testSomeEntity();
testStarEntity();
|
public static void | testAllEntity()
InitialContext ctx = getInitialContext("somebody", "password");
Stateless stateless = (Stateless)ctx.lookup("StatelessBean/remote");
System.out.println("Good role");
System.out.println("Inserting...");
AllEntity e = stateless.insertAllEntity();
System.out.println("Reading...");
e = stateless.readAllEntity(e.id);
e.val += "y";
System.out.println("Updating...");
stateless.updateAllEntity(e);
System.out.println("Deleting...");
stateless.deleteAllEntity(e);
System.out.println("Inserting...");
e = stateless.insertAllEntity();
System.out.println("Bad role");
getInitialContext("rolefail", "password");
AllEntity ae2 = null;
try
{
System.out.println("Inserting...");
ae2 = stateless.insertAllEntity();
throw new RuntimeException("security exception should have been thrown!");
}
catch(Exception ex)
{
System.out.println("Expected failure: " + ex.getMessage());
}
try
{
System.out.println("Reading...");
ae2 = stateless.readAllEntity(e.id);
throw new RuntimeException("security exception should have been thrown!");
}
catch(Exception ex)
{
System.out.println("Expected failure: " + ex.getMessage());
}
try
{
e.val += "y";
stateless.updateAllEntity(e);
throw new RuntimeException("security exception should have been thrown!");
}
catch(Exception ex)
{
System.out.println("Expected failure: " + ex.getMessage());
}
try
{
stateless.deleteAllEntity(e);
throw new RuntimeException("security exception should have been thrown!");
}
catch(Exception ex)
{
System.out.println("Expected failure: " + ex.getMessage());
}
try
{
e = stateless.insertAllEntity();
throw new RuntimeException("security exception should have been thrown!");
}
catch(Exception ex)
{
System.out.println("Expected failure: " + ex.getMessage());
}
|
public static void | testSomeEntity()
InitialContext ctx = getInitialContext("somebody", "password");
Stateless stateless = (Stateless)ctx.lookup("StatelessBean/remote");
System.out.println("Good role");
System.out.println("Inserting...");
SomeEntity e = stateless.insertSomeEntity();
try
{
System.out.println("Reading...");
e = stateless.readSomeEntity(e.id);
throw new RuntimeException("security exception should have been thrown!");
}
catch(Exception ex)
{
System.out.println("Expected failure: " + ex.getMessage());
}
try
{
e.val += "y";
System.out.println("Updating...");
stateless.updateSomeEntity(e);
throw new RuntimeException("security exception should have been thrown!");
}
catch(Exception ex)
{
System.out.println("Expected failure: " + ex.getMessage());
}
System.out.println("Deleting...");
stateless.deleteSomeEntity(e);
System.out.println("Inserting...");
e = stateless.insertSomeEntity();
System.out.println("Bad role");
getInitialContext("rolefail", "password");
SomeEntity ae2 = null;
try
{
System.out.println("Inserting...");
ae2 = stateless.insertSomeEntity();
throw new RuntimeException("security exception should have been thrown!");
}
catch(Exception ex)
{
System.out.println("Expected failure: " + ex.getMessage());
}
try
{
stateless.deleteSomeEntity(e);
throw new RuntimeException("security exception should have been thrown!");
}
catch(Exception ex)
{
System.out.println("Expected failure: " + ex.getMessage());
}
try
{
e = stateless.insertSomeEntity();
throw new RuntimeException("security exception should have been thrown!");
}
catch(Exception ex)
{
System.out.println("Expected failure: " + ex.getMessage());
}
|
public static void | testStarEntity()
InitialContext ctx = getInitialContext("somebody", "password");
Stateless stateless = (Stateless)ctx.lookup("StatelessBean/remote");
System.out.println("Good role");
System.out.println("Inserting...");
StarEntity e = stateless.insertStarEntity();
System.out.println("Reading...");
e = stateless.readStarEntity(e.id);
e.val += "y";
System.out.println("Updating...");
stateless.updateStarEntity(e);
System.out.println("Deleting...");
stateless.deleteStarEntity(e);
System.out.println("Inserting...");
e = stateless.insertStarEntity();
System.out.println("Bad role");
getInitialContext("rolefail", "password");
StarEntity ae2 = null;
try
{
System.out.println("Inserting...");
ae2 = stateless.insertStarEntity();
throw new RuntimeException("security exception should have been thrown!");
}
catch(Exception ex)
{
System.out.println("Expected failure: " + ex.getMessage());
}
try
{
System.out.println("Reading...");
ae2 = stateless.readStarEntity(e.id);
throw new RuntimeException("security exception should have been thrown!");
}
catch(Exception ex)
{
System.out.println("Expected failure: " + ex.getMessage());
}
try
{
e.val += "y";
stateless.updateStarEntity(e);
throw new RuntimeException("security exception should have been thrown!");
}
catch(Exception ex)
{
System.out.println("Expected failure: " + ex.getMessage());
}
try
{
stateless.deleteStarEntity(e);
throw new RuntimeException("security exception should have been thrown!");
}
catch(Exception ex)
{
System.out.println("Expected failure: " + ex.getMessage());
}
try
{
e = stateless.insertStarEntity();
throw new RuntimeException("security exception should have been thrown!");
}
catch(Exception ex)
{
System.out.println("Expected failure: " + ex.getMessage());
}
|