1 10 package org.mmbase.security.classsecurity; 11 12 import java.util.*; 13 14 import org.mmbase.security.*; 15 import org.mmbase.security.SecurityException; 16 import org.mmbase.util.*; 17 import org.mmbase.util.logging.*; 18 import org.mmbase.util.xml.DocumentReader; 19 import org.w3c.dom.*; 20 import org.xml.sax.InputSource ; 21 import org.xml.sax.SAXException ; 22 23 24 34 public class ClassAuthenticationWrapper extends Authentication { 35 private static final Logger log = Logging.getLoggerInstance(ClassAuthenticationWrapper.class); 36 37 private Authentication wrappedAuthentication; 38 39 42 private Authentication getAuthenticationInstance(String className) throws SecurityException { 43 Authentication result; 44 try { 45 Class classType = Class.forName(className); 46 Object o = classType.newInstance(); 47 result = (Authentication) o; 48 } catch(ClassNotFoundException cnfe) { 49 throw new SecurityException (cnfe); 50 } catch(IllegalAccessException iae) { 51 throw new SecurityException (iae); 52 } catch(InstantiationException ie) { 53 throw new SecurityException (ie); 54 } 55 return result; 56 } 57 58 62 protected void load() throws SecurityException { 63 try { 64 InputSource in = MMBaseCopConfig.securityLoader.getInputSource(configResource); 65 Document document = DocumentReader.getDocumentBuilder( 66 true, new XMLErrorHandler(false, 0), new XMLEntityResolver(true, getClass()) ).parse(in); 70 71 72 Node authentication = document.getElementsByTagName("authentication").item(0); 73 74 String wrappedClass = authentication.getAttributes().getNamedItem("class").getNodeValue(); 75 String wrappedUrl = authentication.getAttributes().getNamedItem("url").getNodeValue(); 76 77 wrappedAuthentication = getAuthenticationInstance(wrappedClass); 78 wrappedAuthentication.load(manager, configWatcher, wrappedUrl); 79 ClassAuthentication.stopWatching(); 80 ClassAuthentication.load(configResource); 81 82 } catch (java.io.IOException ioe) { 83 throw new SecurityException (ioe); 84 } catch (SAXException se) { 85 throw new SecurityException (se); 86 } 87 88 } 89 90 96 protected UserContext login(Map loginInfo, Object [] parameters) throws SecurityException { 97 ClassAuthentication.Login l = ClassAuthentication.classCheck(null); 98 if (l != null) { 99 if (loginInfo == null) loginInfo = new HashMap(); 100 loginInfo.putAll(l.map); 101 return wrappedAuthentication.login(l.application, loginInfo, parameters); 102 } 103 return null; 104 } 105 106 109 public UserContext login(String application, Map loginInfo, Object [] parameters) throws SecurityException { 110 111 try { 113 return wrappedAuthentication.login(application, loginInfo, parameters); 114 } catch (UnknownAuthenticationMethodException uam) { return login(loginInfo, parameters); 116 } catch (SecurityException se) { log.warn("Authentication did not succeed " + se.getMessage() + " trying self"); 118 return login(loginInfo, parameters); 119 } 120 } 121 122 125 public boolean isValid(UserContext userContext) throws SecurityException { 126 return wrappedAuthentication.isValid(userContext); 127 } 128 129 130 } 131 | Popular Tags |