View Javadoc

1   /*
2    * Group2AccountMapping.java
3    *
4    * Created on May 24, 2004, 2:36 PM
5    */
6   
7   package gov.bnl.gums.groupToAccount;
8   
9   import java.util.ArrayList;
10  import java.util.Iterator;
11  import java.util.List;
12  
13  import gov.bnl.gums.configuration.Configuration;
14  
15  /** This class defines which mapping policy should be used for the given group.
16   * It tells that a given user group (all the members of the 'usatlas'
17   * group in the 'atlas' LDAP vo) should be mapped using a given mapping policy
18   * (a composite made of a NISAccountMapper and GroupAccountMapper, meaning
19   * each user should be mapped to his account if exists, otherwise the generic
20   * group account should be used).
21   * <p>
22   * This class is used by the Hostname mapping to hold a series of group/accountmapping
23   * pairs.
24   *
25   * @author Gabriele Carcassi, Jay Packard
26   */
27  public class GroupToAccountMapping {
28      private ArrayList userGroups = new ArrayList();
29      private ArrayList accountMappers = new ArrayList();
30      private String name = "";
31  	private String description = "";
32      private String accountingVo = "";
33      private String accountingVoSubgroup = "";
34      private Configuration configuration = null;
35  
36  	/**
37  	 * Creates a GroupToAccountMapping object. This empty constructor is needed by the XML Digestor.
38  	 */
39  	public GroupToAccountMapping() {
40  	}    
41      
42  	/**
43  	 * Creates a GroupToAccountMapping object with a configuration.
44  	 * 
45  	 * @param configuration
46  	 */
47  	public GroupToAccountMapping(Configuration configuration) {
48  		this.configuration = configuration;
49  	}
50  	
51  	/**
52  	 * Creates a GroupToAccountMapping with a configuration and a name.
53  	 * 
54  	 * @param configuration
55  	 * @param name
56  	 */
57  	public GroupToAccountMapping(Configuration configuration, String name) {
58  		this.configuration = configuration;
59  		this.name = name;
60  	}
61  
62  	/**
63       * Setter for property mapper.
64       * 
65       * @param mapper New value of property mapper.
66       */
67      public void addAccountMapper(String accountMapper) {
68          accountMappers.add(accountMapper);
69      }
70  	
71  	/**
72       * Setter for property group.
73       * 
74       * @param group New value of property group.
75       */
76      public void addUserGroup(String userGroup) {
77      	userGroups.add(userGroup);
78      }
79  	
80  	/**
81  	 * Create a clone of itself for specified configuration.
82  	 * 
83  	 * @param configuration
84  	 * @return
85  	 */
86      public GroupToAccountMapping clone(Configuration configuration) {
87      	GroupToAccountMapping groupToAccountMapping = new GroupToAccountMapping(configuration, new String(name));
88      	groupToAccountMapping.setDescription(new String(getDescription()));
89      	groupToAccountMapping.setAccountingVoSubgroup(new String(accountingVoSubgroup));
90      	groupToAccountMapping.setAccountingVo(new String(accountingVo));
91      	Iterator it = getUserGroups().iterator();
92      	while (it.hasNext())
93      		groupToAccountMapping.addUserGroup( new String((String)it.next()) );
94      	it = getAccountMappers().iterator();
95      	while (it.hasNext())
96      		groupToAccountMapping.addAccountMapper( new String((String)it.next()) );
97      	return groupToAccountMapping;
98      }
99      
100 	/**
101      * @return returns true if userGroup is matched.
102      */
103     public boolean containsUserGroup(String userGroupQuery) {
104     	Iterator userGroupIt = userGroups.iterator();
105     	while(userGroupIt.hasNext()) {
106     		String userGroup = (String)userGroupIt.next();
107     		if(userGroup.equals(userGroupQuery))
108     			return true;
109     	}
110     	return false;
111     }
112     
113     /**
114      * Getter for property accountingVo.
115      * 
116      * @return Value of property accountingVo.
117      */
118     public String getAccountingVo() {
119 
120         return this.accountingVo;
121     }    
122     
123     /**
124      * Getter for property accountingVoSubgroup.
125      * 
126      * @return Value of property accountingVoSubgroup.
127      */
128     public String getAccountingVoSubgroup()  {
129 
130         return this.accountingVoSubgroup;
131     }    
132     
133     /**
134      * Getter for property mapper.
135      * 
136      * @return Value of property mapper.
137      */
138     public ArrayList getAccountMappers() {
139         return accountMappers;
140     }    
141     
142     /**
143      * Getter for property configuration.
144      * 
145      * @return Configuration object.
146      */
147     public Configuration getConfiguration() {
148 		return configuration;
149 	}
150     
151     /**
152      * Getter for property description.
153      * 
154      * @return Description as string.
155      */
156     public String getDescription() {
157 		return description;
158 	}
159 	
160     /**
161      * Getter for property name.
162      * 
163      * @return Value of property name.
164      */
165     public String getName() {
166         return (name!=null ? name : "");
167     }
168     
169     /**
170      * Getter for property group.
171      * 
172      * @return Value of property group.
173      */
174     public ArrayList getUserGroups() {
175         return this.userGroups;
176     }
177     
178     /**
179      * Setter for property accountingVo.
180      * @param accountingVo New value of property y.
181      */
182     public void setAccountingVo(String accountingVo) {
183 
184         this.accountingVo = accountingVo;
185     }
186 
187     /**
188      * Setter for property accountingVo.
189      * 
190      * @param accountingVo New value of property accountingVo.
191      */
192     public void setAccountingVoSubgroup(java.lang.String accountingVoSubgroup)  {
193 
194         this.accountingVoSubgroup = accountingVoSubgroup;
195     }
196 
197     /**
198      * Setter for property configuration.
199      * 
200      * @param configuration.
201      */
202     public void setConfiguration(Configuration configuration) {
203 		this.configuration = configuration;
204 	}
205     
206     /**
207      * Setter for property description.
208      * 
209      * @param description.
210      */
211     public void setDescription(String description) {
212     	this.description = description;
213     }
214     
215     /**
216      * Setter for property name.
217      * 
218      * @param name.
219      */
220     public void setName(String name) {
221 		this.name = name;
222 	}
223     
224     public String toString(String bgColor) {
225     	return "<td bgcolor=\""+bgColor+"\"><a href=\"groupToAccountMappings.jsp?command=edit&name=" + getName() + "\">" + getName() + "</a></td><td bgcolor=\""+bgColor+"\">" + getAccountingVoSubgroup() + "&nbsp;</td><td bgcolor=\""+bgColor+"\">" + getAccountingVo() + "&nbsp;</td>";
226     }
227     
228     /**
229      * Get XML representation of this object for writing to gums.config
230      * 
231      * @return xml as string
232      */
233     public String toXML() {
234     	String retStr = "\t\t<groupToAccountMapping\n"+
235 		"\t\t\tname='"+name+"'\n"+
236 		"\t\t\tdescription='"+getDescription()+"'\n"+
237 		"\t\t\taccountingVoSubgroup='"+accountingVoSubgroup+"'\n"+
238 		"\t\t\taccountingVo='"+accountingVo+"'\n"+
239 		"\t\t\tuserGroups='";
240 
241 	    List userGroups = getUserGroups();
242 		Iterator it = (Iterator)userGroups.iterator();
243 		while(it.hasNext()) {
244 			String userGroup = (String)it.next();
245 			retStr += userGroup + (it.hasNext()?", ":"");
246 		}
247 		
248 		retStr += "'\n";
249 		
250 		retStr += "\t\t\taccountMappers='";
251 	    
252 		List accountMappers = getAccountMappers();
253 		it = (Iterator)accountMappers.iterator();
254 		while(it.hasNext()) {
255 			String accountMapper = (String)it.next();
256 			retStr += accountMapper + (it.hasNext()?", ":"");
257 		}
258 		
259 		retStr += "'/>\n\n";
260 		
261 		return retStr;
262     }
263     
264 }