The client used to invoke the secure service will be almost identical to clients seen in the previous part of the tutorial (GT3 Core). In fact, to configure our client for a basic secure invocation we only need to add two lines!
((Stub)math)._setProperty(Constants.GSI_SEC_CONV,Constants.ENCRYPTION); ((Stub)math)._setProperty(Constants.AUTHORIZATION,NoAuthorization.getInstance());
What these two lines do is configure the stub class (a MathPortType object) to use security. More specifically, we're doing the following:
We're telling the stub to use full-blown encryption. GSI allows us to choose between different levels of security, and encryption is just one of them. For example, we could have chosen to guarantee message integrity using a digital signature (without encrypting the whole message). All the stub options are described in the Stub security options appendix.
We're telling the stub to use no client-side authorization. Remember that there is a difference in GSI between client-side and server-side authorization. Take a look at the GSI authorization page to refresh your memory.
As mentioned before, besides those two lines, the rest of the client is practically identical to the previous ones seen in the tutorial. The only difference is that we'll be putting the add, subtract, and getValue calls inside try...catch blocks to observe how certain exceptions are raised in certain circumstances (we'll see this in the following sections).
package org.globus.progtutorial.clients.MathService;
import org.globus.progtutorial.stubs.MathService.service.MathServiceGridLocator;
import org.globus.progtutorial.stubs.MathService.MathPortType;
import org.globus.ogsa.impl.security.Constants;
import org.globus.ogsa.impl.security.authorization.NoAuthorization;
import javax.xml.rpc.Stub;
import java.net.URL;
public class ClientGSIConvEncrypt
{
public static void main(String[] args)
{
try
{
// Get command-line arguments
URL GSH = new java.net.URL(args[0]);
int a = Integer.parseInt(args[1]);
// Get a reference to the MathService instance
MathServiceGridLocator mathLocator = new MathServiceGridLocator();
MathPortType math = mathLocator.getMathServicePort(GSH);
// Setup security options
((Stub)math)._setProperty(Constants.GSI_SEC_CONV,Constants.ENCRYPTION);
((Stub)math)._setProperty(Constants.AUTHORIZATION,NoAuthorization.getInstance());
// Call remote method 'add'
try{
math.add(a);
System.out.println("Added " + a);
} catch(Exception e)
{
System.out.println("ERROR: " + e.getMessage());
}
// Call remote method 'subtract'
try{
math.subtract(1);
System.out.println("Subtracted 1");
} catch(Exception e)
{
System.out.println("ERROR: " + e.getMessage());
}
// Get current value through remote method 'getValue'
try{
int value = math.getValue();
System.out.println("Current value: " + value);
} catch(Exception e)
{
System.out.println("ERROR: " + e.getMessage());
}
}catch(Exception e)
{
System.out.println("ERROR!");
e.printStackTrace();
}
}
}
This file is $TUTORIAL_DIR/org/globus/progtutorial/clients/MathService/ClientGSIConvEncrypt.java |