View Javadoc

1   /*
2    * ManualAccountMapper.java
3    *
4    * Created on May 25, 2004, 5:06 PM
5    */
6   
7   package gov.bnl.gums.account;
8   
9   import java.util.Map;
10  
11  import gov.bnl.gums.GridUser;
12  import gov.bnl.gums.configuration.Configuration;
13  import gov.bnl.gums.db.ManualAccountMapperDB;
14  
15  /** 
16   * An account mapping policy that looks at a stored table to determine the
17   * account. The database implementation is an abstract interface, which
18   * allows the mapping to be persistent on different mediums (i.e. database,
19   * LDAP, file, ...)
20   * <p>
21   * This class will provide also configurable data caching.
22   *
23   * @author Gabriele Carcassi, Jay Packard
24   */
25  public class ManualAccountMapper extends AccountMapper {
26      static public String getTypeStatic() {
27  		return "manual";
28  	}
29      
30      private ManualAccountMapperDB db;
31  	private String persistenceFactory = "";
32      
33      public ManualAccountMapper() {
34      	super();
35      }
36   
37      public ManualAccountMapper(Configuration configuration) {
38      	super(configuration);
39      }
40      
41      public ManualAccountMapper(Configuration configuration, String name) {
42      	super(configuration, name);
43      }
44      
45      public void addMapping(String userDN, String account) {
46      	getDB().createMapping(userDN, account);
47      }
48      
49      public AccountMapper clone(Configuration configuration) {
50      	ManualAccountMapper accountMapper = new ManualAccountMapper(configuration, new String(getName()));
51      	accountMapper.setDescription(new String(getDescription()));
52      	accountMapper.setPersistenceFactory(new String(persistenceFactory));
53      	return accountMapper;
54      }
55      
56      public void createMapping(String userDN, String account) {
57      	getDB().createMapping(userDN, account);
58      }
59      
60      public ManualAccountMapperDB getDB() {
61      	if (db==null)
62      		db = getConfiguration().getPersistenceFactory(persistenceFactory).retrieveManualAccountMapperDB( getName() );
63      	return db;
64      }
65      
66      public Map getAccountMap() {
67      	return getDB().retrieveAccountMap();
68      }
69      
70      public Map getReverseAccountMap() {
71      	return getDB().retrieveReverseAccountMap();
72      }
73      
74      public String getPersistenceFactory() {
75          return persistenceFactory;
76      }
77      
78      public String getType() {
79  		return "manual";
80  	}
81      
82      public String mapUser(GridUser user, boolean createIfDoesNotExist) {
83          return getDB().retrieveMapping(user.getCertificateDN());
84      }
85      
86      public boolean removeMapping(String userDN) {
87          return getDB().removeMapping(userDN);
88      }  
89      
90      public void setPersistenceFactory(String persistanceFactory) {
91          this.persistenceFactory = persistanceFactory;
92      }
93  
94      public String toString(String bgColor) {
95      	return "<td bgcolor=\""+bgColor+"\"><a href=\"accountMappers.jsp?command=edit&name=" + getName() + "\">" + getName() + "</a></td><td bgcolor=\""+bgColor+"\">" + getType() + "</td><td bgcolor=\""+bgColor+"\">&nbsp;</td>";
96      }      
97      
98      public String toXML() {
99      	return "\t\t<manualAccountMapper\n"+
100 			"\t\t\tname='"+getName()+"'\n"+
101 			"\t\t\tdescription='"+getDescription()+"'\n"+
102 			"\t\t\tpersistenceFactory='"+persistenceFactory+"'/>\n\n";
103     }
104 }