11.3. A secure client

The client used to invoke the secure service will be almost identical to all the clients seen so far. The only difference is that we will be instructing the client to use GSI Secure Conversation with encryption and no client-side authorization. Believe it or not, this requires two simple lines of code:

1
((Stub)math)._setProperty(Constants.GSI_SEC_CONV,Constants.ENCRYPTION);
2
((Stub)math)._setProperty(Constants.AUTHORIZATION,NoAuthorization.getInstance());
1

We're telling the stub to use GSI Secure Conversation with encryption.

2

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 Section 10.4, “Authorization”.

Besides those two lines, the rest of the client is practically identical to the ones we've already seen. The only difference is that we will be putting the calls to the remote operations inside try...catch blocks to observe how certain exceptions are raised in certain circumstances (we'll see this in the following chapters).

package org.globus.examples.clients.MathService_instance_4op;

import javax.xml.rpc.Stub;

import org.apache.axis.message.addressing.Address;
import org.apache.axis.message.addressing.EndpointReferenceType;

import org.globus.axis.util.Util;
import org.globus.examples.services.security.first.impl.MathQNames;
import org.globus.examples.stubs.MathService_instance_4op.MathPortType;
import org.globus.examples.stubs.MathService_instance_4op.service.MathServiceAddressingLocator;
import org.globus.wsrf.impl.security.authorization.NoAuthorization;
import org.globus.wsrf.security.Constants;
import org.oasis.wsrf.properties.GetResourcePropertyResponse;

public class Client_GSISecConv_Encrypt {

	public static void main(String[] args) {
		MathServiceAddressingLocator locator = new MathServiceAddressingLocator();
		GetResourcePropertyResponse valueRP;
		String value;

		try {
			String serviceURI = args[0];

			// Create endpoint reference to service
			EndpointReferenceType endpoint = new EndpointReferenceType();
			endpoint.setAddress(new Address(serviceURI));
			MathPortType math = locator.getMathPortTypePort(endpoint);

			// Get PortType
			math = locator.getMathPortTypePort(endpoint);

			// Setup security options
			((Stub)math)._setProperty(Constants.GSI_SEC_CONV,Constants.ENCRYPTION);
			((Stub)math)._setProperty(Constants.AUTHORIZATION,NoAuthorization.getInstance());

			// Perform an addition
			try {
				math.add(60);
				System.out.println("Addition was successful");
			} catch (Exception e) {
				System.out.println("[add]      ERROR: " + e.getMessage());
			}

			/* Similar calls to subtract(), multiply(), divide(), and getResourceProperty */

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
[Note]

This file is $EXAMPLES_DIR/org/globus/examples/clients/MathService_instance_4op/Client_GSISecConv_Encrypt.java