View Javadoc

1   package gov.bnl.gums.userGroup;
2   
3   import java.lang.ref.SoftReference;
4   
5   import gov.bnl.gums.configuration.Configuration;
6   import gov.bnl.gums.db.UserGroupDB;
7   
8   import org.apache.log4j.Logger;
9   
10  /** 
11   * Represents a VOMS server.  Contains the other parameters for access this server. 
12   * This is meant to be a shared reference for multiple user groups.  One specifies
13   * the base url here and provides the remainder url for each user group.
14   *
15   * @author Jay Packard
16   */
17  public class VomsServer {
18      private Logger log = Logger.getLogger(VOMSUserGroup.class);
19  	private String name = "";
20  	private String description = "";
21      private String baseUrl = "";
22      private String sslKey = "";
23      private String sslCertfile = "";
24      private String sslCAFiles = "";
25      private String sslKeyPasswd = "";
26      private UserGroupDB db = null;
27  	private String persistenceFactory;
28  	private SoftReference configurationRef = null;
29      
30  	/**
31  	 * Creates a new VomsServer object. This empty 
32  	 * constructor is needed by the XML Digestor.
33  	 */
34  	public VomsServer() {
35  	}
36  
37  	/**
38  	 * Creates a new VomsServer object with a configuration.
39  	 * 
40  	 * @param configuration
41  	 */
42  	public VomsServer(Configuration configuration) {
43  		this.configurationRef = new SoftReference(configuration);
44  	}
45  	
46  	/**
47  	 * Creates a new VomsServer object with a configuration and a name.
48  	 * 
49  	 * @param configuration
50  	 * @param name
51  	 */
52  	public VomsServer(Configuration configuration, String name) {
53  		this.configurationRef = new SoftReference(configuration);
54  		this.name = name;
55  	}
56  	 
57  	
58  	public VomsServer clone(Configuration configuration) {
59      	VomsServer vomsServer = new VomsServer(configuration, new String(name));
60      	vomsServer.setDescription(new String(getDescription()));
61      	vomsServer.setBaseUrl(new String(baseUrl));
62      	vomsServer.setSslKey(new String(sslKey));
63      	vomsServer.setSslCertfile(new String(sslCertfile));
64      	vomsServer.setSslKeyPasswd(new String(sslKeyPasswd));
65      	vomsServer.setSslCAFiles(new String(sslCAFiles));
66      	vomsServer.setPersistenceFactory(new String(persistenceFactory));
67      	return vomsServer;
68      }
69  
70  	/**
71       * Returns the address of the VOMS server to contact.
72       * @return The address of the VOMS server (i.e. https://voms.myste.org:8443/edg-voms-admin/myvo/services/VOMSAdmin)
73       */
74      public String getBaseUrl() {
75          return baseUrl;
76      }
77  	
78  	public Configuration getConfiguration() {
79  		if (configurationRef==null)
80  			return null;
81  		return (Configuration)configurationRef.get();
82  	}
83  	
84  	public String getDescription() {
85  		return description;
86  	}
87  	
88  	public UserGroupDB getDB(String userGroup) {
89      	return getConfiguration().getPersistenceFactory(persistenceFactory).retrieveUserGroupDB( userGroup );
90      }
91  	
92      public String getName() {
93  		return name;
94  	}
95      
96      public String getPersistenceFactory() {
97          return persistenceFactory;
98      }
99      
100     /**
101      * Returns the location of the Certificate Authority certificates used to connect to the VOMS server.
102      * @return The location of the CA certificates (i.e. /etc/grid-security/certificates/*.0)
103      */
104     public String getSslCAFiles() {
105         return this.sslCAFiles;
106     }
107     
108     /**
109      * Returns the location of the certificated used to connect to the VOMS server.
110      * @return The location of the certificate (i.e. /etc/grid-security/hostcert.pem)
111      */
112     public String getSslCertfile() {
113         return this.sslCertfile;
114     }
115     
116     /**
117      * Returns the location of the key to be used during the connection.
118      * @return The location of the key (i.e. /etc/grid-security/hostkey.pem)
119      */
120     public String getSslKey() {
121         return this.sslKey;
122     }
123     
124     /**
125      * Returns the private key password used to connect to the VOMS server.
126      * @return The password for the private key
127      */
128     public String getSslKeyPasswd() {
129         return this.sslKeyPasswd;
130     }
131     
132     /**
133      * Changes the base address of the VOMS server to contact. The address of the server
134      * is really the address of the Web service components. If you go to that address,
135      * the AXIS servlet has to reply.
136      * @param url The address of the VOMS server (i.e. https://voms.myste.org:8443/edg-voms-admin)
137      */
138     public void setBaseUrl(String baseUrl) {
139         this.baseUrl = baseUrl;
140     }
141     
142     public void setConfiguration(Configuration configuration) {
143 		this.configurationRef = new SoftReference(configuration);
144 	}
145     
146     public void setDescription(String description) {
147     	this.description = description;
148     }
149     
150     public void setName(String name) {
151 		this.name = name;
152 	}
153     
154     public void setPersistenceFactory(String persistenceFactory) {
155         this.persistenceFactory = persistenceFactory;
156     }
157     
158     /**
159      * Changes the location of the Certificate Authority certificates used to connect to the VOMS server.
160      * @param sslCAFiles The location of the CA certificates (i.e. /etc/grid-security/certificates/*.0)
161      */
162     public void setSslCAFiles(String sslCAFiles) {
163         this.sslCAFiles = sslCAFiles;
164     }
165     
166     /**
167      * Changes the location of the certificated used to connect to the VOMS server.
168      * @param sslCertfile The location of the certificate (i.e. /etc/grid-security/hostcert.pem)
169      */
170     public void setSslCertfile(String sslCertfile) {
171         this.sslCertfile = sslCertfile;
172     }
173     
174     /**
175      * Changes the location of the private key used to connect to the VOMS server.
176      * @param sslKey The location of the key (i.e. /etc/grid-security/hostkey.pem)
177      */
178     public void setSslKey(String sslKey) {
179         this.sslKey = sslKey;
180     }
181     
182     /**
183      * Changes the private key password used to connect to the VOMS server.
184      * @param sslKeyPasswd The password for the private key
185      */
186     public void setSslKeyPasswd(String sslKeyPasswd) {
187         this.sslKeyPasswd = sslKeyPasswd;
188     }
189 
190     public String toString() {
191         return "vomsServer: baseUrl='" + baseUrl + "' sslCertfile='" + getSslCertfile() + "' sslKey='" + getSslKey() + "' sslKeyPasswd set:" + (!getSslKeyPasswd().equals("")) + " - sslCAFiles='" + getSslCAFiles() + "'";
192     }
193     
194     public String toXML() {
195     	String retStr = "\t\t<vomsServer\n"+
196 		"\t\t\tname='"+name+"'\n"+
197 		"\t\t\tdescription='"+getDescription()+"'\n"+
198 		"\t\t\tpersistenceFactory='"+persistenceFactory+"'\n"+
199 		"\t\t\tbaseUrl='"+baseUrl+"'\n";
200     	if (sslKey != null)
201     		retStr += "\t\t\tsslKey='"+sslKey+"'\n";
202     	if (sslCertfile != null)
203     		retStr += "\t\t\tsslCertfile='"+sslCertfile+"'\n";
204     	if (sslKeyPasswd != null)
205     		retStr += "\t\t\tsslKeyPasswd='"+sslKeyPasswd+"'\n";
206     	if (sslCAFiles != null)
207     		retStr += "\t\t\tsslCAFiles='"+sslCAFiles+"'\n";
208 
209     	if (retStr.charAt(retStr.length()-1)=='\n')
210     		retStr = retStr.substring(0, retStr.length()-1);    
211 
212     	retStr += "/>\n\n";    	
213     	
214     	return retStr;
215     }
216     
217 }