View Javadoc

1   package fr.in2p3.jsaga.adaptor.security;
2   
3   import fr.in2p3.jsaga.adaptor.base.defaults.Default;
4   import fr.in2p3.jsaga.adaptor.base.defaults.EnvironmentVariables;
5   import fr.in2p3.jsaga.adaptor.base.usage.UAnd;
6   import fr.in2p3.jsaga.adaptor.base.usage.UFile;
7   import fr.in2p3.jsaga.adaptor.base.usage.UNoPrompt;
8   import fr.in2p3.jsaga.adaptor.base.usage.Usage;
9   import fr.in2p3.jsaga.adaptor.security.impl.GSSCredentialSecurityCredential;
10  import fr.in2p3.jsaga.adaptor.security.impl.InMemoryProxySecurityCredential;
11  import org.ogf.saga.context.Context;
12  import org.ogf.saga.error.IncorrectStateException;
13  import org.ogf.saga.error.NoSuccessException;
14  
15  import java.io.File;
16  import java.util.Map;
17  
18  /* ***************************************************
19  * *** Centre de Calcul de l'IN2P3 - Lyon (France) ***
20  * ***             http://cc.in2p3.fr/             ***
21  * ***************************************************
22  * File:   InMemoryProxySecurityAdaptor
23  * Author: Sylvain Reynaud (sreynaud@in2p3.fr)
24  * Date:   12 oct. 2007
25  * ***************************************************
26  * Description:                                      */
27  /**
28   *
29   */
30  public class InMemoryProxySecurityAdaptor implements SecurityAdaptor {
31      public String getType() {
32          return "InMemoryProxy";
33      }
34  
35      public Class getSecurityCredentialClass() {
36          return GSSCredentialSecurityCredential.class;
37      }
38  
39      public Usage getUsage() {
40          return new UAnd.Builder()
41                          .and(new UNoPrompt(Context.USERPROXY))
42                          .and(new UFile(Context.CERTREPOSITORY))
43                          .build();
44      }
45  
46      public Default[] getDefaults(Map attributes) throws IncorrectStateException {
47          EnvironmentVariables env = EnvironmentVariables.getInstance();
48          return new Default[]{
49                  new Default(Context.CERTREPOSITORY, new File[]{
50                          new File(env.getProperty("X509_CERT_DIR")+""),
51                          new File(System.getProperty("user.home")+"/.globus/certificates/"),
52                          new File("/etc/grid-security/certificates/")})
53          };
54      }
55  
56      public SecurityCredential createSecurityCredential(int usage, Map attributes, String contextId) throws IncorrectStateException, NoSuccessException {
57          String base64 = (String) attributes.get(Context.USERPROXY);
58          if (base64 != null) {
59              File certRepository = new File((String) attributes.get(Context.CERTREPOSITORY));
60              return new InMemoryProxySecurityCredential(base64, certRepository);
61          } else {
62              throw new NoSuccessException("Attribute is null: "+Context.USERPROXY);
63          }
64      }
65  }