View Javadoc

1   package org.astrogrid.ogsa.echo;
2   
3   import java.net.URL;
4   import java.util.GregorianCalendar;
5   import javax.xml.rpc.Stub;
6   import org.astrogrid.ogsa.echo.EchoServiceLocator;
7   import org.astrogrid.ogsa.echo.EchoPortType;
8   import org.globus.axis.gsi.GSIConstants;
9   import org.globus.ogsa.impl.security.authentication.Constants;
10  import org.globus.ogsa.impl.security.authorization.NoAuthorization;
11  import org.globus.ogsa.utils.GridServiceFactory;
12  import org.gridforum.ogsi.Factory;
13  import org.gridforum.ogsi.LocatorType;
14  import org.gridforum.ogsi.OGSIServiceLocator;
15  
16  public class WhoAmIDelegate {
17    
18    private URL serviceFactory;
19  
20  
21    public WhoAmIDelegate (String factoryHandle) throws Exception {
22      this.serviceFactory = new URL(factoryHandle);
23    }
24  
25    
26    /***
27     * Returns the identity derived from the caller's
28     * security credentials, as reported by a 
29     * remote service, or null if the service
30     * cannot find the identity.
31     */
32    public String whoAmI () throws Exception {
33      System.out.println("Entering whoAmi");
34   
35      // Get access to the factory port.  Use the GridServiceFactory
36      // wrapper to the port to simplify the interface of the
37      // createService method.
38      OGSIServiceLocator factoryLocator = new OGSIServiceLocator();
39      Factory factory = factoryLocator.getFactoryPort(this.serviceFactory);
40      GridServiceFactory gridFactory = new GridServiceFactory(factory);
41          
42      // Create a service instance and locate its echo port.
43      // Set a 10-minute timeout.
44      GregorianCalendar timeout = new GregorianCalendar();
45      timeout.add(GregorianCalendar.MINUTE, 10);
46      LocatorType instanceLocator = gridFactory.createService(timeout);
47      EchoServiceGridLocator portLocator = new EchoServiceGridLocator();
48      EchoPortType port = portLocator.getEchoPortType(instanceLocator);
49      
50      // Set up authenticated access: make credentials available in
51      // calls to the service.
52      Stub portStub = (Stub)port;
53      portStub._setProperty(GSIConstants.GSI_MODE,
54                            GSIConstants.GSI_MODE_LIMITED_DELEG);
55      portStub._setProperty(Constants.MSG_SEC_TYPE,
56                            Constants.SIGNATURE);
57      portStub._setProperty(Constants.AUTHORIZATION,
58                            NoAuthorization.getInstance());
59                                   
60      // Invoke the echo port.
61      return port.whoAmI();
62    }
63  }