001: /**
002: * @author <a href="mailto:novotny@gridsphere.org">Jason Novotny</a>
003: * @version $Id: AuthModuleDefinition.java 6385 2007-10-25 14:02:26Z wehrens $
004: */package org.gridsphere.services.core.security.auth.modules.impl.descriptor;
005:
006: import org.gridsphere.portlet.service.spi.impl.descriptor.ConfigParam;
007:
008: import java.util.*;
009:
010: /**
011: * The <code>AuthModuleDefinition</code> defines
012: */
013: public class AuthModuleDefinition {
014:
015: protected AuthModulesDescriptor authDescriptor = null;
016: private String oid = null;
017: protected String moduleName = "";
018: private List moduleDescriptions = new Vector();
019: private List moduleErrors = new Vector();
020:
021: protected int priority = 100;
022: protected String moduleImplementation = "";
023: protected boolean moduleActive = false;
024:
025: protected List configParamList = new Vector();
026: protected Map attributes = new HashMap();
027: protected Properties configProps = null;
028:
029: public String getOid() {
030: return oid;
031: }
032:
033: public void setOid(String oid) {
034: this .oid = oid;
035: }
036:
037: /**
038: * Sets the auth module descriptor
039: *
040: * @param descriptor the auth module descriptor
041: */
042: public void setDescriptor(AuthModulesDescriptor descriptor) {
043: this .authDescriptor = descriptor;
044: }
045:
046: /**
047: * Returns the auth module descriptor
048: *
049: * @return descriptor the auth module descriptor
050: */
051: public AuthModulesDescriptor getDescriptor() {
052: return authDescriptor;
053: }
054:
055: /**
056: * Sets the portlet service name
057: *
058: * @param moduleName the portlet service name
059: */
060: public void setModuleName(String moduleName) {
061: this .moduleName = moduleName;
062: }
063:
064: /**
065: * Returns the portlet service name
066: *
067: * @return the portlet service name
068: */
069: public String getModuleName() {
070: return this .moduleName;
071: }
072:
073: /**
074: * Sets the list of module descriptions
075: *
076: * @param moduleDescriptions the list of module descriptions
077: */
078: public void setModuleDescriptions(List moduleDescriptions) {
079: this .moduleDescriptions = moduleDescriptions;
080: }
081:
082: /**
083: * Returns the module descriptions
084: *
085: * @return the module descriptions
086: */
087: public List getModuleDescriptions() {
088: return this .moduleDescriptions;
089: }
090:
091: /**
092: * Sets the list of module errors
093: *
094: * @param moduleErrors the list of module errors
095: */
096: public void setModuleErrors(List moduleErrors) {
097: this .moduleErrors = moduleErrors;
098: }
099:
100: /**
101: * Returns the module errors
102: *
103: * @return the module errors
104: */
105: public List getModuleErrors() {
106: return this .moduleErrors;
107: }
108:
109: /**
110: * Returns the portlet service implementation
111: *
112: * @return the portlet service implementation
113: */
114: public String getModuleImplementation() {
115: return this .moduleImplementation;
116: }
117:
118: /**
119: * Sets the portlet service implementation
120: *
121: * @param moduleImplementation the portlet service implementation
122: */
123: public void setModuleImplementation(String moduleImplementation) {
124: this .moduleImplementation = moduleImplementation;
125: }
126:
127: /**
128: * Returns the module priority
129: *
130: * @return the module priority
131: */
132: public int getModulePriority() {
133: return priority;
134: }
135:
136: /**
137: * Sets the module priority
138: *
139: * @param priority
140: */
141: public void setModulePriority(int priority) {
142: this .priority = priority;
143: }
144:
145: /**
146: * Returns true of this module is turned on for all users
147: *
148: * @return true of this module is turned on for all users
149: */
150: public boolean getModuleActive() {
151: return moduleActive;
152: }
153:
154: /**
155: * If true, this module will be active for all users
156: *
157: * @param moduleActive if true, this module will be active for all users
158: */
159: public void setModuleActive(boolean moduleActive) {
160: this .moduleActive = moduleActive;
161: }
162:
163: /**
164: * Sets the service configuration parameter list
165: *
166: * @param configParamList the configuration parameter list
167: */
168: public void setConfigParamList(List configParamList) {
169: this .configParamList = configParamList;
170: }
171:
172: /**
173: * Returns the service configuration parameter list
174: *
175: * @return the configuration parameter list
176: */
177: public List getConfigParamList() {
178: return this .configParamList;
179: }
180:
181: public String getAttribute(String name) {
182: return (String) attributes.get(name);
183: }
184:
185: public Map getAttributes() {
186: return attributes;
187: }
188:
189: public void setAttributes(Map attributes) {
190: this .attributes = attributes;
191: }
192:
193: /**
194: * Creates a properties from the ConfigParamList
195: *
196: * @see #getConfigParamList
197: */
198: private void createProperties() {
199: configProps = new Properties();
200: Iterator it = this .configParamList.iterator();
201: ConfigParam param;
202: while (it.hasNext()) {
203: param = (ConfigParam) it.next();
204: configProps.setProperty(param.getParamName(), param
205: .getParamValue());
206: }
207: }
208:
209: /**
210: * Return the configuration properties
211: *
212: * @return the configuration properties
213: */
214: public Properties getConfigProperties() {
215: if (configProps == null)
216: createProperties();
217: return configProps;
218: }
219:
220: /**
221: * Sets the configuration properties
222: *
223: * @param props the configuration properties
224: */
225: public void setConfigProperties(Properties props) {
226: Enumeration e = props.keys();
227: if (!props.isEmpty()) {
228: configParamList = new Vector();
229: }
230: while (e.hasMoreElements()) {
231: String key = (String) e.nextElement();
232: ConfigParam param = new ConfigParam(key, props
233: .getProperty(key));
234: configParamList.add(param);
235: }
236: }
237:
238: /**
239: * Returns a <code>String</code> representation if this auth module
240: * definition
241: *
242: * @return the auth module definition as a <code>String</code>
243: */
244: public String toString() {
245: StringBuffer sb = new StringBuffer("\n");
246: sb.append("auth module name: " + this .moduleName + "\n");
247: sb.append("auth module description: "
248: + this .moduleDescriptions.get(0) + "\n");
249: //sb.append("auth module error: " + this.moduleErrors.get(0) + "\n");
250: sb.append("auth module implementation: "
251: + this .moduleImplementation + "\n");
252: sb.append("auth module priority: " + this .priority + "\n");
253: sb.append("config properties: ");
254: Iterator it = this .configParamList.iterator();
255: ConfigParam c;
256: while (it.hasNext()) {
257: c = (ConfigParam) it.next();
258: sb.append("\tname: " + c.getParamName() + "\tvalue: "
259: + c.getParamValue());
260: }
261: return sb.toString();
262: }
263:
264: }
|