View Javadoc

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