public class Client
{
public static void main(String[] args) throws Exception
{
// Establish the proxy with an incorrect security identity
SecurityClient securityClient = SecurityClientFactory.getSecurityClient();
securityClient.setSimple("kabir","invalidpassword");
securityClient.login();
InitialContext ctx = new InitialContext();
// let's use the bean whose proxy communicates via ssl
Calculator sslCalculator = (Calculator) ctx.lookup("CalculatorBean/remote");
System.out.println("Invoking bean methods on a proxy through sslsocket");
System.out.println("Kabir is a student.");
System.out.println("Kabir types in the wrong password");
try
{
System.out.println("1 + 1 = " + sslCalculator.add(1, 1));
throw new RuntimeException("ERROR - User with incorrect password allowed to operate on bean");
}
catch (EJBAccessException ex)
{
System.out.println("Saw expected SecurityException: " + ex.getMessage());
}
System.out.println("Kabir types in correct password.");
System.out.println("Kabir does unchecked addition.");
// Re-establish the proxy with the correct security identity
securityClient.logout();
securityClient.setSimple("kabir", "validpassword");
securityClient.login();
System.out.println("1 + 1 = " + sslCalculator.add(1, 1));
System.out.println("Kabir is not a teacher so he cannot do division");