View Javadoc

1   /*
2    * AbstractHostGroup.java
3    *
4    * Created on May 10, 2005, 3:44 PM
5    *
6    * To change this template, choose Tools | Options and locate the template under
7    * the Source Creation and Management node. Right-click the template and choose
8    * Open. You can then make changes to the template in the Source Editor.
9    */
10  
11  package gov.bnl.gums.hostToGroup;
12  
13  import gov.bnl.gums.configuration.Configuration;
14  
15  import java.util.*;
16  
17  /** It defines a a group of hosts that will be using the same mappings for user
18   * authorization. An object of this class links a series of hostnames to a list
19   * of group mappings.
20   * <p>
21   * This class does not return the list of hosts that will be affected since 
22   * the group of hosts can be defined by a rule, without knowledge of which
23   * systems exist. For example, all the machines in the 130.199.*.* subnet,
24   * or all machines in the usatlas.bnl.gov subdomain.
25   *
26   * @author Gabriele Carcassi, Jay Packard
27   */
28  public abstract class HostToGroupMapping {
29      private List groupToAccountMappers = new ArrayList();
30      private Configuration configuration = null;
31      private String name = "";
32  	private String description = "";
33      
34  	/**
35  	 * Create a nwe HostToGroupMapping object.
36  	 * 
37  	 * This empty constructor needed by XML Digestor
38  	 */
39      public HostToGroupMapping() {
40      }
41  
42      /**
43       * Create a new HostToGroupMapping object with a configuration.
44       * 
45       * @param configuration
46       */
47      public HostToGroupMapping(Configuration configuration) {
48      	this.configuration = configuration;
49      }
50      
51  	/**
52  	 * Create a new HostToGroupMapping object with a configuration and a name.
53  	 * 
54  	 * @param configuration
55  	 */
56      public HostToGroupMapping(Configuration configuration, String name) {
57      	this.configuration = configuration;
58      	this.name = name;
59      }
60  
61      /** Changes the list of group mapping associated with this mapping.
62       *
63       * @param groupMapper A list of GroupMapper objects.
64       */
65      public void addGroupToAccountMapping(String groupToAccountMapping) {
66          this.groupToAccountMappers.add(groupToAccountMapping);
67      }
68      
69  	/**
70  	 * Create a clone of itself for specified configuration.
71  	 * 
72  	 * @param configuration
73  	 * @return
74  	 */
75      public abstract HostToGroupMapping clone(Configuration configuration);
76      
77      /**
78       * Determines if this host to group mapping contains a group to account mapping.
79       * 
80       * @return returns true if group to account mapping is contained.
81       */
82      public boolean containsGroupToAccountMapping(String groupToAccountMappingQuery) {
83      	Iterator groupMapperIt = groupToAccountMappers.iterator();
84      	while(groupMapperIt.hasNext()) {
85      		String groupToAccountMapping = (String)groupMapperIt.next();
86      		if(groupToAccountMapping.equals(groupToAccountMappingQuery))
87      			return true;
88      	}
89      	return false;
90      }
91      
92      /**
93       * Getter for property configuration.
94       * 
95       * @return Configuration as string.
96       */
97      public Configuration getConfiguration() {
98      	return configuration;
99      }
100     
101     /**
102      * Getter for property description.
103      * 
104      * @return Description as string.
105      */
106 	public String getDescription() {
107 		return description;
108 	}
109     
110     /** Returns the list of group mapping associated with this mapping.
111      * @return A list of GroupMapper objects.
112      */
113     public List getGroupToAccountMappings() {
114         return Collections.unmodifiableList(groupToAccountMappers);
115     }
116     
117     /**
118      * Getter for property name.
119      * 
120      * @return Value of property name.
121      */
122     public String getName() {
123     	return name;
124     }
125     
126     /**
127      * Determines if hostname is matched within this host to group mapping.
128      * 
129      * @param hostname
130      * @return true if hostname matches
131      */
132     public abstract boolean isInGroup(String hostname);
133     
134     /**
135      * Setter for property configuration.
136      * 
137      * @param configuration.
138      */
139     public void setConfiguration(Configuration configuration) {
140 		this.configuration = configuration;
141 	}
142     
143     /**
144      * Setter for property description.
145      * 
146      * @param description.
147      */
148     public void setDescription(String description) {
149     	this.description = description;
150     }
151     
152     /**
153      * Setter for property name.
154      * 
155      * @param name.
156      */
157     public void setName(String name) {
158     	this.name = name;
159     }
160     
161     /**
162      * Get XML representation of this object for writing to gums.config
163      * 
164      * @return xml as string
165      */
166     public abstract String toXML();
167 }