PhysicsService

We'll start by seeing the service and client that don't perform delegation. Later on, we'll see how using this same code, and adding just a couple of lines of code, delegation can be activated. All the code for the non-delegating example can be found here: $TUTORIAL_DIR/org/globus/progtutorial/services/security/delegation/

Service interface

The service interface of the PhysicsService is very simple, as it only has a single method. It can be found here: $TUTORIAL_DIR/schema/progtutorial/PhysicsService/Physics.gwsdl

Service implementation

The implementation is going to be pretty long, since this is the first time we have a service that invokes another service. You can find the code here: $TUTORIAL_DIR/org/globus/progtutorial/services/security/delegation/impl/PhysicsProviderNoDelegation.java

However, since this code is lengthy, we're going to take the time to take a look at it step-by-step. First of all, instead of fitting all the code into the getAnswerToLifeTheUniverseAndEverything method, we're going to divide everything into several private methods. The 'skeleton' of our implementation looks something like this:

package org.globus.progtutorial.services.security.delegation.impl;

// import statements

public class PhysicsProviderNoDelegation implements OperationProvider
{
  // Create this class's logger
  static Log logger = LogFactory.getLog(PhysicsProvider.class.getName());

  // Operation provider properties
  private static final String namespace = 
    "http://www.globus.org/namespaces/2004/02/progtutorial/PhysicsService";

  private static final QName[] operations = 
    new QName[]
      {new QName(namespace, "getAnswerToLifeTheUniverseAndEverything")};


  static final String mathFactoryURL =
  "http://127.0.0.1:8080/ogsa/services/progtutorial/security/gridmap/MathService";


  public int getAnswerToLifeTheUniverseAndEverything() throws RemoteException, SecurityException
  {
  }


  private void makeStubSecure(Object stub)
  {
  }

  private MathPortType getReferenceToMathService() throws RemoteException
  {
  }

  private void logSecurityInfo()
  {
  }
}

Let's take a look at what all these attributes and methods do.

mathFactoryURL attribute

static final String mathServiceGSH =
"http://127.0.0.1:8080/ogsa/services/progtutorial/security/gridmap/MathService";

Yes, this is a very big no-no. In the real world, a GSH should never be hard-coded into your service code, but obtained from an index service. However, we're using a hard-coded GSH for simplicity.

getAnswerToLifeTheUniverseAndEverything method

This is the only public remote method, and the one which will invoke the add method in MathService. Therefore, a lot of its code will be dedicated to communicating with MathService.

Before we start doing anything, we'll need a couple of variables:

MathPortType math;
int answer;

First of all, we're going to call the logSecurityInfo (which outputs the same data as in the previous examples) so we can check if delegation is working or not:

logSecurityInfo();

Next, we get a reference to the MathPortType.

math = getReferenceToMathService();

Now, we invoke the add method in MathService a couple times, thus obtaining The Answer.

for(int i=0; i<7; i++)
{
  logger.info("Invoking 'add' method...");
  math.add(6);
  logger.info("Invoked 'add' method");
}

Next, we call MathService's getValue to get the value of The Answer...

logger.info("Invoking 'getValue' method...");
answer = math.getValue();
logger.info("Invoked 'getValue' method");

Finally, we return The Answer:

return answer;

The whole thing would look something like this:

public int getAnswerToLifeTheUniverseAndEverything() throws RemoteException, SecurityException
{
  MathPortType math;
  int answer;

  logSecurityInfo();

  math = getReferenceToMathService();

  // Find the answer to life, the universe, and everything.
  // This is accomplished by invoking the 'add' method in the MathService!
  for(int i=0; i<7; i++)
  {
    logger.info("Invoking 'add' method...");
    math.add(6);
    logger.info("Invoked 'add' method");
  }

  logger.info("Invoking 'getValue' method...");
  answer = math.getValue();
  logger.info("Invoked 'getValue' method");

  return answer;
}

logSecurityInfo method

The logSecurityInfo method is very similar to the one we used in previous examples, with a couple minor modifications. We'll use it to write out the caller's identity, and the invocation, subject, and service subject.

Other private methods

The rest of the private methods perform operations which we've seen in many of the client applications (getting a reference to an instance, making a stub secure, etc.)

The getReferenceToMathInstance obtains a MathPortType stub from the locator.

private MathPortType getReferenceToMathService() throws RemoteException
{
  URL GSH = null;
  try{
   GSH = new java.net.URL(mathServiceGSH);
  } catch(Exception e){ }

  logger.info("Obtaining reference to MathService...");
  MathServiceGridLocator mathLocator =   new MathServiceGridLocator();
  MathPortType math = mathLocator.getMathServicePort(GSH);
  makeStubSecure(math);
  logger.info("Obtained reference to MathService");
  return math;
}

Notice getReferenceToMathService calls method makeStubSecure to set the stub's security properties.

private void makeStubSecure(Object stub)
{
  ((Stub)stub)._setProperty(Constants.GSI_SEC_CONV,Constants.ENCRYPTION);
  ((Stub)stub)._setProperty(Constants.AUTHORIZATION,NoAuthorization.getInstance());
}