View Javadoc

1   /*
2    * AccountMapper.java
3    *
4    * Created on March 30, 2004, 5:56 PM
5    */
6   
7   package gov.bnl.gums.account;
8   
9   import java.lang.ref.SoftReference;
10  
11  import gov.bnl.gums.configuration.Configuration;
12  import gov.bnl.gums.GridUser;
13  
14  /** 
15   * Defines the logic with which a user will be mapped to a local account.
16   * As of now, the logic is a simple certificate subject mapped to a user
17   * account. In the future this interface will be extended to map the credential
18   * of a full proxy (DN, vo, role, group) to a user and group account.
19   *
20   * @author  Gabriele Carcassi, Jay Packard
21   */
22  public abstract class AccountMapper {
23      /**
24       * @return user friendly string representation of the property type called statically 
25       */
26  	static public String getTypeStatic() {
27  		return "abstract";
28  	}
29  	
30  	private String name = "";
31  	private String description = "";
32  	private SoftReference configurationRef = null;
33  	
34  	/**
35  	 * Create an account mapper object - empty constructor needed by XML Digestor
36  	 */
37  	public AccountMapper() {
38      }
39   
40  	/**
41  	 * Create an account mapper object with a given configuration
42  	 * 
43  	 * @param configuration
44  	 */
45  	public AccountMapper(Configuration configuration) {
46      	this.configurationRef = new SoftReference(configuration);
47      }
48  	
49  	/**
50  	 * Create an account mapper object with a given configuration and name
51  	 * 
52  	 * @param configuration
53  	 * @param name
54  	 */
55  	public AccountMapper(Configuration configuration, String name) {
56      	this.configurationRef = new SoftReference(configuration);
57      	this.name = name;
58      }
59      
60  	/**
61  	 * Create a clone of itself
62  	 * 
63  	 * @param configuration
64  	 * @return
65  	 */
66  	public abstract AccountMapper clone(Configuration configuration);
67  
68  	/**
69  	 * @return Configuration object
70  	 */
71  	public Configuration getConfiguration() {
72  		if (configurationRef==null)
73  			return null;
74  		return (Configuration)configurationRef.get();
75  	}
76  	
77  	/**
78  	 * @return description as string
79  	 */
80  	public String getDescription() {
81  		return description;
82  	}
83  	
84  	/**
85  	 * @return name as string
86  	 */
87  	public String getName() {
88  		return name;
89  	}
90  	
91  	/**
92  	 * @return string representation of type of account mapper
93  	 */
94  	public String getType() {
95  		return "abstract";
96  	}
97  	
98  	/**
99       * Maps a grid identity to a local account name.
100      * @param userDN the certificate DN (i.e. '/DC=org/DC=doegrids/OU=People/CN=John Smith').
101      * @return a user account (i.e. 'atlas').
102      */
103     public abstract String mapUser(GridUser user, boolean createNew);
104     
105     public String mapUser(String userDN, boolean createNew) {
106     	GridUser user = new GridUser();
107     	user.setCertificateDN(userDN);
108     	return mapUser(user, createNew);
109     }
110 
111     /**
112      * @param configuration
113      */
114     public void setConfiguration(Configuration configuration) {
115 		this.configurationRef = new SoftReference(configuration);
116 	}
117 	
118     /**
119      * @param name
120      */
121     public void setName(String name) {
122 		this.name = name;
123 	}
124     
125     /**
126      * @param description
127      */
128     public void setDescription(String description) {
129     	this.description = description;
130     }
131 
132     /**
133      * Get string representation of this object for displaying in the 
134      * diagnostic summary web page
135      * 
136      * @param bgColor back ground color
137      * @return
138      */
139     public abstract String toString(String bgColor);
140     
141     /**
142      * Get XML representation of this object for writing to gums.config
143      * 
144      * @return xml as string
145      */
146     public abstract String toXML();
147 }