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.List;
11  
12  import javax.persistence.DiscriminatorColumn;
13  import javax.persistence.DiscriminatorType;
14  import javax.persistence.Entity;
15  import javax.persistence.Inheritance;
16  import javax.persistence.InheritanceType;
17  import javax.persistence.Transient;
18  
19  import gov.bnl.gums.configuration.ConfigElement;
20  import gov.bnl.gums.configuration.Configuration;
21  import gov.bnl.gums.util.StringUtil;
22  
23  /** This class defines which mapping policy should be used for the given group.
24   * It tells that a given user group (all the members of the 'usatlas'
25   * group in the 'atlas' LDAP vo) should be mapped using a given mapping policy
26   * (a composite made of a NISAccountMapper and GroupAccountMapper, meaning
27   * each user should be mapped to his account if exists, otherwise the generic
28   * group account should be used).
29   * <p>
30   * This class is used by the Hostname mapping to hold a series of group/accountmapping
31   * pairs.
32   * 
33   * Two ways to build the userGroups and accountMappers - one with the add/remove methods, and the other with
34   * set and get methods, which Hibernate will use.
35   *
36   * @author Gabriele Carcassi, Jay Packard
37   */
38  @Entity
39  @Inheritance(strategy=InheritanceType.SINGLE_TABLE)
40  @DiscriminatorColumn(
41      name="type",
42      discriminatorType=DiscriminatorType.STRING
43  )
44  public class GroupToAccountMapping extends ConfigElement {
45      protected List<String> userGroupsList = new ArrayList<String>();
46      protected List<String> accountMappersList = new ArrayList<String>();
47  	
48  	// persistent variables
49      protected String accountingVo;
50      protected String accountingVoSubgroup;
51      protected String userGroups;
52      protected String accountMappers;
53      
54  	/**
55  	 * Creates a GroupToAccountMapping object. This empty constructor is needed by the XML Digestor.
56  	 */
57  	public GroupToAccountMapping() {
58  	}    
59  	
60  	/**
61  	 * Creates a GroupToAccountMapping with a configuration and a name.
62  	 * 
63  	 * @param configuration
64  	 * @param name
65  	 */
66  	public GroupToAccountMapping(Configuration configuration, String name) {
67  		super(configuration, name);
68  	}
69  
70  	/**
71       * Setter for property mapper.
72       * 
73       * @param mapper New value of property mapper.
74       */
75      public void addAccountMapper(int index, String accountMapper) {
76      	if (accountMappers!=null)
77      		throw new RuntimeException("Cannot call removeAccountMapper when setAccountMappers has been called");
78  		accountMappersList.add(index, accountMapper);
79      }
80      
81  	/**
82       * Setter for property mapper.
83       * 
84       * @param mapper New value of property mapper.
85       */
86      public void addAccountMapper(String accountMapper) {
87      	if (accountMappers!=null)
88      		throw new RuntimeException("Cannot call removeAccountMapper when setAccountMappers has been called");
89  		accountMappersList.add(accountMapper);
90      }
91  
92  	/**
93       * Setter for property mapper.
94       * 
95       * @param mapper New value of property mapper.
96       */
97      public void addUserGroup(int index, String userGroup) {
98      	if (userGroups!=null)
99      		throw new RuntimeException("Cannot call removeUserGroup when setUserGroups has been called");
100     	userGroupsList.add(index, userGroup);
101     }
102     
103 	/**
104      * Setter for property group.
105      * 
106      * @param group New value of property group.
107      */
108     public void addUserGroup(String userGroup) {
109     	if (userGroups!=null)
110     		throw new RuntimeException("Cannot call removeUserGroup when setUserGroups has been called");
111 		userGroupsList.add(userGroup);
112     }
113     
114     /**
115      * Getter for property accountingVo.
116      * 
117      * @return Value of property accountingVo.
118      */
119     public String getAccountingVo() {
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         return this.accountingVoSubgroup;
130     }    
131     
132     /**
133      * Getter for property mapper.
134      * 
135      * @return Value of property mapper.
136      */
137     public String getAccountMappers() {
138     	// Prefer string object since Hibernate requires the getter return the actual object set
139     	if (accountMappers!=null)
140     		return accountMappers;
141     	else
142     		return StringUtil.toCommaSeparatedList(accountMappersList);
143     } 
144     
145     /**
146      * Getter for property group.
147      * 
148      * @return Value of property group.
149      */
150     public String getUserGroups() {
151     	// Prefer string object since Hibernate requires the getter return the actual object set
152     	if (userGroups!=null)
153     		return userGroups;
154     	else
155     		return StringUtil.toCommaSeparatedList(userGroupsList);
156     }
157     
158     public boolean removeAccountMapper(int index) {
159     	if (accountMappers!=null)
160     		throw new RuntimeException("Cannot call removeAccountMapper when setAccountMappers has been called");
161 		return accountMappersList.remove(index)!=null;
162     }
163     
164     public boolean removeAccountMapper(String accountMapperName) {
165     	if (userGroups!=null)
166     		throw new RuntimeException("Cannot call removeAccountMapper when setAccountMappers has been called");
167 		return accountMappersList.remove(accountMapperName);
168     }
169     
170     public boolean removeUserGroup(int index) {
171     	if (userGroups!=null)
172     		throw new RuntimeException("Cannot call removeUserGroup when setUserGroups has been called");
173 		return userGroupsList.remove(index)!=null;
174     }
175     
176     public boolean removeUserGroup(String userGroupName) {
177     	if (userGroups!=null)
178     		throw new RuntimeException("Cannot call removeUserGroup when setUserGroups has been called");
179 		return userGroupsList.remove(userGroupName);
180     }
181     
182     /**
183      * Setter for property accountingVo.
184      * @param accountingVo New value of property y.
185      */
186     @ConfigFieldAnnotation(label="Accounting VO", help="to be included in OSG-user-VO-map")
187     public void setAccountingVo(String accountingVo) {
188         this.accountingVo = accountingVo;
189     }
190 
191     /**
192      * Setter for property accountingVo.
193      * 
194      * @param accountingVo New value of property accountingVo.
195      */
196     @ConfigFieldAnnotation(label="Accounting VO Subgroup", help="to be included in OSG-user-VO-map")
197     public void setAccountingVoSubgroup(java.lang.String accountingVoSubgroup)  {
198         this.accountingVoSubgroup = accountingVoSubgroup;
199     }
200     
201     @ConfigFieldAnnotation (label="Account Mapper(s)", help="map using first successful account mapper", orderedList=true)
202     public void setAccountMappers(String accountMappers) {
203     	this.accountMappers = accountMappers;
204 	}
205     
206     @ConfigFieldAnnotation(label="User Group(s)", help="validate membership from first successful user group", orderedList=true)
207     public void setUserGroups(String userGroups) {
208 		this.userGroups = userGroups;
209 	}
210     
211 }