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
36
37
38 OGSIServiceLocator factoryLocator = new OGSIServiceLocator();
39 Factory factory = factoryLocator.getFactoryPort(this.serviceFactory);
40 GridServiceFactory gridFactory = new GridServiceFactory(factory);
41
42
43
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
51
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
61 return port.whoAmI();
62 }
63 }