1 19 20 package com.sslexplorer.security; 21 22 import java.util.Iterator ; 23 import java.util.List ; 24 import java.util.TreeMap ; 25 26 import org.apache.commons.logging.Log; 27 import org.apache.commons.logging.LogFactory; 28 29 import com.sslexplorer.core.CoreServlet; 30 31 47 public class AuthenticationModuleManager { 48 49 final static Log log = LogFactory.getLog(AuthenticationModuleManager.class); 50 51 private static AuthenticationModuleManager instance; 52 private TreeMap modules; 53 54 57 private AuthenticationModuleManager() { 58 super(); 59 modules = new TreeMap (); 60 } 61 62 72 public void registerModule(String name, Class moduleClass, String messageResourcesKey, boolean primary, boolean secondary, boolean system) { 73 modules.put(name, new AuthenticationModuleDefinition(name, moduleClass, messageResourcesKey, primary, secondary, system)); 74 } 75 76 87 public void registerModule(String name, Class moduleClass, String messageResourcesKey, boolean primary, boolean secondary, boolean system, boolean primaryIfSecondaryExists) { 88 modules.put(name, new AuthenticationModuleDefinition(name, moduleClass, messageResourcesKey, primary, secondary, system, primaryIfSecondaryExists)); 89 } 90 95 public void deregisterModule(String module) { 96 modules.remove(module); 97 } 98 99 106 public AuthenticationModuleDefinition getModuleDefinition(String module) { 107 return (AuthenticationModuleDefinition)modules.get(module); 108 } 109 110 120 public AuthenticationModule createModule(String module) throws InstantiationException , IllegalAccessException { 121 AuthenticationModuleDefinition def = getModuleDefinition(module); 122 if(def == null) { 123 throw new IllegalArgumentException ("No module named " + module); 124 } 125 return (AuthenticationModule)def.getModuleClass().newInstance(); 126 } 127 128 133 public Iterator authenticationModuleDefinitions() { 134 return modules.values().iterator(); 135 } 136 137 142 public static AuthenticationModuleManager getInstance() { 143 if(instance == null) { 144 instance = new AuthenticationModuleManager(); 145 } 146 return instance; 147 } 148 149 155 public boolean isRegistered(String module) { 156 return modules.containsKey(module); 157 } 158 159 166 public boolean isAuthenticationModuleInUse(String module) { 167 boolean available = true; 168 try { 169 boolean found = false; 170 List schemes = SystemDatabaseFactory.getInstance().getAuthenticationSchemeSequences(); 171 for(Iterator i = schemes.iterator(); i.hasNext() && !found; ) { 172 AuthenticationScheme seq = (DefaultAuthenticationScheme)i.next(); 173 if(seq.hasModule(module)) { 174 found = true; 175 } 176 } 177 if(!found) { 178 available = false; 179 } 180 } catch (Exception e) { 181 available = false; 182 } 183 return available; 184 } 185 186 194 public AuthenticationScheme getSchemeForAuthenticationModuleInUse(String module) { 195 try { 196 List schemes = SystemDatabaseFactory.getInstance().getAuthenticationSchemeSequences(); 197 for(Iterator i = schemes.iterator(); i.hasNext(); ) { 198 AuthenticationScheme seq = (DefaultAuthenticationScheme)i.next(); 199 if(seq.hasModule(module)) { 200 return seq; 201 } 202 } 203 } catch (Exception e) { 204 } 205 return null; 206 } 207 208 } 209 | Popular Tags |