[Swift-commit] cog r3437

swift at ci.uchicago.edu swift at ci.uchicago.edu
Thu Aug 2 01:35:04 CDT 2012


------------------------------------------------------------------------
r3437 | hategan | 2012-08-02 01:34:52 -0500 (Thu, 02 Aug 2012) | 1 line

changed security contexts to accept a host parameter (such that: credentials can be selected based on host name AND interactive credential dialogs can display the host name requesting credentials
------------------------------------------------------------------------
Index: modules/abstraction-common/src/org/globus/cog/abstraction/tools/execution/JobSubmission.java
===================================================================
--- modules/abstraction-common/src/org/globus/cog/abstraction/tools/execution/JobSubmission.java	(revision 3436)
+++ modules/abstraction-common/src/org/globus/cog/abstraction/tools/execution/JobSubmission.java	(working copy)
@@ -167,13 +167,11 @@
         ExecutionService service = new ExecutionServiceImpl();
         service.setProvider(this.provider.toLowerCase());
 
-        SecurityContext securityContext = AbstractionFactory
-                .newSecurityContext(provider);
-        securityContext.setCredentials(null);
-        service.setSecurityContext(securityContext);
-
         ServiceContact sc = new ServiceContactImpl(this.serviceContact);
         service.setServiceContact(sc);
+        
+        SecurityContext securityContext = AbstractionFactory.getSecurityContext(provider, sc);
+        service.setSecurityContext(securityContext);
 
         /*
          * This is an abstraction for the jobmanager. For example, the
Index: modules/abstraction-common/src/org/globus/cog/abstraction/tools/transfer/FileTransfer.java
===================================================================
--- modules/abstraction-common/src/org/globus/cog/abstraction/tools/transfer/FileTransfer.java	(revision 3436)
+++ modules/abstraction-common/src/org/globus/cog/abstraction/tools/transfer/FileTransfer.java	(working copy)
@@ -92,28 +92,23 @@
         this.task.setSpecification(spec);
 
         // create te source service
-        SecurityContext sourceSecurityContext = AbstractionFactory
-                .newSecurityContext(sourceURI.getScheme());
-        // selects the default credentials
-        sourceSecurityContext.setCredentials(null);
-
         ServiceContact sourceServiceContact = new ServiceContactImpl();
         sourceServiceContact.setHost(sourceURI.getHost());
         sourceServiceContact.setPort(sourceURI.getPort());
+        
+        SecurityContext sourceSecurityContext = 
+            AbstractionFactory.getSecurityContext(sourceURI.getScheme(), sourceServiceContact);
 
         Service sourceService = new ServiceImpl(sourceURI.getScheme(),
                 Service.FILE_TRANSFER, sourceServiceContact,
                 sourceSecurityContext);
 
-        // create te destination service
-        SecurityContext destinationSecurityContext = AbstractionFactory
-                .newSecurityContext(destinationURI.getScheme());
-        // selects the default credentials
-        destinationSecurityContext.setCredentials(null);
-
         ServiceContact destinationServiceContact = new ServiceContactImpl();
         destinationServiceContact.setHost(destinationURI.getHost());
         destinationServiceContact.setPort(destinationURI.getPort());
+        
+        SecurityContext destinationSecurityContext = 
+            AbstractionFactory.getSecurityContext(destinationURI.getScheme(), destinationServiceContact);
 
         Service destinationService = new ServiceImpl(
                 destinationURI.getScheme(), Service.FILE_TRANSFER,
Index: modules/abstraction-common/src/org/globus/cog/abstraction/xml/TaskUnmarshaller.java
===================================================================
--- modules/abstraction-common/src/org/globus/cog/abstraction/xml/TaskUnmarshaller.java	(revision 3436)
+++ modules/abstraction-common/src/org/globus/cog/abstraction/xml/TaskUnmarshaller.java	(working copy)
@@ -141,26 +141,27 @@
                 }
             }
             String provider = xmlService.getProvider();
+            // set the service contact
+            String serviceContact = xmlService.getServiceContact();
+            if (serviceContact != null && serviceContact.length() > 0) {
+                ServiceContact contact = new ServiceContactImpl(serviceContact
+                        .trim());
+                service.setServiceContact(contact);
+            }
+            
             if (provider != null && provider.length() > 0) {
                 service.setProvider(provider.trim());
 
                 try {
-                    service.setSecurityContext(AbstractionFactory
-                            .newSecurityContext(provider));
+                    service.setSecurityContext(AbstractionFactory.newSecurityContext(provider, service.getServiceContact()));
                 } catch (Exception e) {
                     throw new UnmarshalException(
                             "Cannot establish the appropriate security context",
                             e);
                 }
             }
-            // set the service contact
-            String serviceContact = xmlService.getServiceContact();
-            if (serviceContact != null && serviceContact.length() > 0) {
-                ServiceContact contact = new ServiceContactImpl(serviceContact
-                        .trim());
-                service.setServiceContact(contact);
-            }
 
+
             // set the service attributes
             AttributeList attrList = xmlService.getAttributeList();
             if (attrList != null) {
Index: modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/FileResourceCache.java
===================================================================
--- modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/FileResourceCache.java	(revision 3436)
+++ modules/abstraction-common/src/org/globus/cog/abstraction/impl/file/FileResourceCache.java	(working copy)
@@ -26,7 +26,6 @@
 import org.globus.cog.abstraction.impl.common.task.InvalidProviderException;
 import org.globus.cog.abstraction.impl.common.task.InvalidSecurityContextException;
 import org.globus.cog.abstraction.interfaces.FileResource;
-import org.globus.cog.abstraction.interfaces.SecurityContext;
 import org.globus.cog.abstraction.interfaces.Service;
 
 public class FileResourceCache {
@@ -115,7 +114,7 @@
             throw new InvalidProviderException("Provider is null");
         }
         if (service.getSecurityContext() == null) {
-            service.setSecurityContext(AbstractionFactory.newSecurityContext(provider));
+            service.setSecurityContext(AbstractionFactory.getSecurityContext(provider, service.getServiceContact()));
         }
         FileResource fileResource = AbstractionFactory
                 .newFileResource(provider);
Index: modules/abstraction-common/src/org/globus/cog/abstraction/impl/fileTransfer/DelegatedFileTransferHandler.java
===================================================================
--- modules/abstraction-common/src/org/globus/cog/abstraction/impl/fileTransfer/DelegatedFileTransferHandler.java	(revision 3436)
+++ modules/abstraction-common/src/org/globus/cog/abstraction/impl/fileTransfer/DelegatedFileTransferHandler.java	(working copy)
@@ -8,7 +8,6 @@
 
 import java.io.File;
 import java.io.IOException;
-import java.net.MalformedURLException;
 
 import org.apache.log4j.Logger;
 import org.globus.cog.abstraction.impl.common.AbstractDelegatedTaskHandler;
@@ -20,7 +19,6 @@
 import org.globus.cog.abstraction.impl.common.task.InvalidProviderException;
 import org.globus.cog.abstraction.impl.common.task.InvalidSecurityContextException;
 import org.globus.cog.abstraction.impl.common.task.InvalidServiceContactException;
-import org.globus.cog.abstraction.impl.common.task.SecurityContextImpl;
 import org.globus.cog.abstraction.impl.common.task.ServiceContactImpl;
 import org.globus.cog.abstraction.impl.common.task.ServiceImpl;
 import org.globus.cog.abstraction.impl.common.task.TaskImpl;
@@ -38,13 +36,7 @@
 import org.globus.cog.abstraction.interfaces.Status;
 import org.globus.cog.abstraction.interfaces.Task;
 import org.globus.cog.abstraction.interfaces.TaskHandler;
-import org.globus.gsi.gssapi.auth.Authorization;
-import org.globus.gsi.gssapi.auth.HostAuthorization;
-import org.globus.io.urlcopy.UrlCopy;
-import org.globus.io.urlcopy.UrlCopyException;
 import org.globus.io.urlcopy.UrlCopyListener;
-import org.globus.util.GlobusURL;
-import org.ietf.jgss.GSSCredential;
 
 public class DelegatedFileTransferHandler extends AbstractDelegatedTaskHandler implements 
         Runnable, UrlCopyListener {
@@ -628,12 +620,13 @@
         }
     }
 
-    private SecurityContext getSecurityContext(Service service) {
+    private SecurityContext getSecurityContext(Service service) throws InvalidProviderException, ProviderMethodException {
         SecurityContext securityContext = service.getSecurityContext();
         if (securityContext == null) {
-            // create default credentials
-            securityContext = new SecurityContextImpl();
+            return AbstractionFactory.getSecurityContext(service.getProvider(), service.getServiceContact());
         }
-        return securityContext;
+        else {
+            return securityContext;
+        }
     }
 }
\ No newline at end of file
Index: modules/abstraction-common/src/org/globus/cog/abstraction/impl/common/AbstractionFactory.java
===================================================================
--- modules/abstraction-common/src/org/globus/cog/abstraction/impl/common/AbstractionFactory.java	(revision 3436)
+++ modules/abstraction-common/src/org/globus/cog/abstraction/impl/common/AbstractionFactory.java	(working copy)
@@ -16,6 +16,7 @@
 import org.globus.cog.abstraction.impl.common.task.InvalidProviderException;
 import org.globus.cog.abstraction.interfaces.FileResource;
 import org.globus.cog.abstraction.interfaces.SecurityContext;
+import org.globus.cog.abstraction.interfaces.ServiceContact;
 import org.globus.cog.abstraction.interfaces.TaskHandler;
 
 /**
@@ -29,11 +30,11 @@
     private static final String PROVIDER_PROP = "cog-provider.properties";
 
     private static Logger logger = Logger.getLogger(AbstractionFactory.class);
-
-    private static Map<String, SecurityContext> defaultCredentials;
     
+    public static Map<String, Map<ServiceContact, SecurityContext>> cachedSecurityContexts;
+    
     static {
-    	defaultCredentials = new HashMap<String, SecurityContext>();
+        cachedSecurityContexts = new HashMap<String, Map<ServiceContact, SecurityContext>>();
     }
 
     public static TaskHandler newExecutionTaskHandler()
@@ -92,11 +93,47 @@
                 AbstractionProperties.TYPE_FILE_RESOURCE);
     }
 
+    /**
+     * @deprecated 
+     */
     public static SecurityContext newSecurityContext(String provider)
             throws InvalidProviderException, ProviderMethodException {
         return (SecurityContext) newObject(provider,
                 AbstractionProperties.TYPE_SECURITY_CONTEXT);
     }
+    
+    public static SecurityContext newSecurityContext(String provider, ServiceContact serviceContact)
+            throws InvalidProviderException, ProviderMethodException {
+        SecurityContext sc = (SecurityContext) newObject(provider,
+                AbstractionProperties.TYPE_SECURITY_CONTEXT);
+        sc.setServiceContact(serviceContact);
+        return sc;
+    }
+    
+    /**
+     * Return a possibly cached security context
+     */
+    public static SecurityContext getSecurityContext(String provider, ServiceContact serviceContact)
+            throws InvalidProviderException, ProviderMethodException {
+        Map<ServiceContact, SecurityContext> providerContexts;
+        synchronized(cachedSecurityContexts) {
+            providerContexts = cachedSecurityContexts.get(provider);
+            if (providerContexts == null) {
+                providerContexts = new HashMap<ServiceContact, SecurityContext>();
+                cachedSecurityContexts.put(provider, providerContexts);
+            }
+        }
+        
+        synchronized(providerContexts) {
+            SecurityContext sc = providerContexts.get(serviceContact);
+            if (sc == null) {
+                sc = newSecurityContext(provider, serviceContact);
+                providerContexts.put(serviceContact, sc);
+            }
+            
+            return sc;
+        }
+    }
 
     public static boolean hasObject(String provider, String role) {
         try {
@@ -134,9 +171,11 @@
             boolean useSandbox) throws InvalidProviderException,
             InvalidClassException {
         provider = provider.toLowerCase();
-        logger
+        if (logger.isDebugEnabled()) {
+            logger
                 .debug("Instantiating " + className + " for provider "
                         + provider);
+        }
         ClassLoader cl = AbstractionFactory.class.getClassLoader();
         try {
             return cl.loadClass(className).newInstance();
@@ -145,14 +184,4 @@
             throw new InvalidClassException(e);
         }
     }
-    
-    public synchronized static Object getDefaultCredentials(String provider) throws InvalidProviderException, ProviderMethodException {
-    	SecurityContext sc = defaultCredentials.get(provider);
-    	if (sc == null) {
-    	    sc = newSecurityContext(provider);
-            defaultCredentials.put(provider, sc);   
-    	}
-    	return sc.getDefaultCredentials();
-    }
-    
 }
\ No newline at end of file
Index: modules/abstraction-common/src/org/globus/cog/abstraction/impl/common/task/SecurityContextImpl.java
===================================================================
--- modules/abstraction-common/src/org/globus/cog/abstraction/impl/common/task/SecurityContextImpl.java	(revision 3436)
+++ modules/abstraction-common/src/org/globus/cog/abstraction/impl/common/task/SecurityContextImpl.java	(working copy)
@@ -9,11 +9,13 @@
 import java.util.HashMap;
 
 import org.globus.cog.abstraction.interfaces.SecurityContext;
+import org.globus.cog.abstraction.interfaces.ServiceContact;
 
 public class SecurityContextImpl implements SecurityContext {
     private HashMap<String, Object> attributes;
     private Object credentials;
     private String alias;
+    private ServiceContact serviceContact;
 
     public SecurityContextImpl() {
         this.attributes = new HashMap<String, Object>();
@@ -88,4 +90,12 @@
     public Object getDefaultCredentials() {
         return null;
     }
+
+    public ServiceContact getServiceContact() {
+        return serviceContact;
+    }
+
+    public void setServiceContact(ServiceContact serviceContact) {
+        this.serviceContact = serviceContact;
+    }
 }
\ No newline at end of file
Index: modules/abstraction-common/src/org/globus/cog/abstraction/impl/common/util/FileTransfer.java
===================================================================
--- modules/abstraction-common/src/org/globus/cog/abstraction/impl/common/util/FileTransfer.java	(revision 3436)
+++ modules/abstraction-common/src/org/globus/cog/abstraction/impl/common/util/FileTransfer.java	(working copy)
@@ -122,11 +122,11 @@
 		else {
 			if (protocol.equals("gsiftp")) {
 				service.setProvider("GridFTP");
-				securityContext = AbstractionFactory.newSecurityContext("GridFTP");
+				securityContext = AbstractionFactory.getSecurityContext("GridFTP", service.getServiceContact());
 			}
 			else if (protocol.equals("scp")) {
 				service.setProvider("ssh");
-				securityContext = AbstractionFactory.newSecurityContext("ssh");
+				securityContext = AbstractionFactory.getSecurityContext("ssh", service.getServiceContact());
 			}
 			else {
 				throw new Exception("unsupported protocol: " + protocol);
Index: modules/abstraction-common/src/org/globus/cog/abstraction/interfaces/SecurityContext.java
===================================================================
--- modules/abstraction-common/src/org/globus/cog/abstraction/interfaces/SecurityContext.java	(revision 3436)
+++ modules/abstraction-common/src/org/globus/cog/abstraction/interfaces/SecurityContext.java	(working copy)
@@ -6,6 +6,7 @@
 
 package org.globus.cog.abstraction.interfaces;
 
+import org.globus.cog.abstraction.impl.common.task.InvalidSecurityContextException;
 import org.ietf.jgss.GSSCredential;
 
 /**
@@ -40,4 +41,8 @@
      * else return <code>null</code>
      */
     public Object getDefaultCredentials();
+    
+    public void setServiceContact(ServiceContact serviceContact);
+    
+    public ServiceContact getServiceContact();
 }
\ No newline at end of file
Index: modules/abstraction-common/src/org/globus/cog/abstraction/examples/invocation/ServiceInvocation.java
===================================================================
--- modules/abstraction-common/src/org/globus/cog/abstraction/examples/invocation/ServiceInvocation.java	(revision 3436)
+++ modules/abstraction-common/src/org/globus/cog/abstraction/examples/invocation/ServiceInvocation.java	(working copy)
@@ -89,7 +89,7 @@
         service.setProvider(this.provider.toLowerCase());
 
         SecurityContext securityContext = AbstractionFactory
-                .newSecurityContext(provider);
+                .getSecurityContext(provider, new ServiceContactImpl(serviceContact));
         securityContext.setCredentials(null);
         service.setSecurityContext(securityContext);
 



More information about the Swift-commit mailing list