1 16 package org.apache.cocoon.webapps.authentication.configuration; 17 18 import java.io.Serializable ; 19 import java.util.HashMap ; 20 import java.util.Hashtable ; 21 import java.util.Map ; 22 23 import org.apache.avalon.framework.configuration.Configuration; 24 import org.apache.avalon.framework.configuration.ConfigurationException; 25 import org.apache.cocoon.ProcessingException; 26 import org.apache.cocoon.environment.Request; 27 import org.apache.cocoon.webapps.authentication.components.PipelineAuthenticator; 28 import org.apache.excalibur.source.SourceParameters; 29 30 36 public final class HandlerConfiguration implements Serializable { 37 38 39 private final String name; 40 41 42 private String redirectURI; 43 44 45 private SourceParameters redirectParameters; 46 47 48 private String authenticationResource; 49 50 51 private String logoutResource; 52 53 54 private String authenticatorClass; 55 56 57 private SourceParameters authenticationResourceParameters; 58 59 60 private String loadResource; 61 62 63 private SourceParameters loadResourceParameters; 64 65 66 private String saveResource; 67 68 69 private SourceParameters saveResourceParameters; 70 71 72 private Map applications = new Hashtable (3, 2); 73 74 75 private Map configurations; 76 77 78 private boolean saveOnLogout = false; 79 80 83 public HandlerConfiguration(String name) { 84 this.name = name; 85 this.configurations = new HashMap (3, 2); 86 } 87 88 91 public void configure(Request request, 92 Configuration conf) 93 throws ProcessingException, ConfigurationException { 94 Configuration child = conf.getChild("redirect-to", false); 96 if (child == null) 97 throw new ConfigurationException("Handler '"+this.name+"' needs a redirect-to URI."); 98 this.redirectURI = child.getAttribute("uri"); 99 if ( this.redirectURI.startsWith("cocoon:") ) { 100 final int pos = this.redirectURI.indexOf('/'); 101 if ( pos != -1 && this.redirectURI.length() > pos) { 102 if (this.redirectURI.charAt(pos+1) == '/') { 103 this.redirectURI = this.redirectURI.substring(pos+2).trim(); 104 this.redirectURI = request.getContextPath()+"/"+this.redirectURI; 105 } else { 106 this.redirectURI = this.redirectURI.substring(pos+1).trim(); 107 } 108 } 109 } 110 111 this.redirectParameters = SourceParameters.create(child); 112 113 child = conf.getChild("authentication", false); 115 if (child == null) { 116 throw new ConfigurationException("Handler '"+this.name+"' needs authentication configuration"); 117 } 118 this.authenticatorClass = child.getAttribute("authenticator", PipelineAuthenticator.class.getName()); 119 if ( PipelineAuthenticator.class.getName().equals(authenticatorClass)) { 120 this.authenticationResource = child.getAttribute("uri"); 121 } else { 122 this.authenticationResource = child.getAttribute("uri", null); 124 } 125 this.logoutResource = child.getAttribute("logout-uri", null); 127 this.authenticationResourceParameters = SourceParameters.create(child); 128 129 child = conf.getChild("load", false); 131 if (child != null) { 132 this.loadResource = child.getAttribute("uri"); 133 this.loadResourceParameters = SourceParameters.create(child); 134 } 135 136 child = conf.getChild("save", false); 138 if (child != null) { 139 this.saveResource = child.getAttribute("uri"); 140 this.saveResourceParameters = SourceParameters.create(child); 141 this.saveOnLogout = child.getAttributeAsBoolean("saveOnLogout", false); 142 } 143 144 child = conf.getChild("applications", false); 146 if (child != null) { 147 Configuration[] appConfs = child.getChildren("application"); 148 Configuration appconf; 149 150 if (appConfs != null) { 151 for(int i = 0; i < appConfs.length; i++) { 152 appconf = appConfs[i]; 153 154 String appName = appconf.getAttribute("name"); 156 157 if (this.applications.get(appName) != null) { 159 throw new ConfigurationException("Application names must be unique: " + appName); 160 } 161 162 ApplicationConfiguration apphandler = new ApplicationConfiguration(this, appName); 164 165 this.applications.put(appName, apphandler); 167 168 apphandler.configure(appconf); 170 } 171 } 172 } 173 174 Configuration[] configurations = conf.getChildren("configuration"); 176 if (configurations != null) { 177 for(int i = 0; i < configurations.length; i++) { 178 child = configurations[i]; 179 String value = child.getAttribute("name"); 180 if (this.getConfiguration(value) != null) { 181 throw new ConfigurationException("Configuration names must be unique for application " + this.name + ": " + value); 182 } 183 this.configurations.put(value, child); 184 } 185 } 186 187 } 188 189 190 193 public String getName() { return name; } 194 195 198 public String getRedirectURI() { 199 return this.redirectURI; 200 } 201 202 205 public SourceParameters getRedirectParameters() { 206 return this.redirectParameters; 207 } 208 209 212 public String getAuthenticationResource() { 213 return this.authenticationResource; 214 } 215 216 219 public SourceParameters getAuthenticationResourceParameters() { 220 return this.authenticationResourceParameters; 221 } 222 223 226 public String getLogoutResource() { 227 return this.logoutResource; 228 } 229 230 231 public String getSaveResource() { 232 return this.saveResource; } 233 234 235 236 public String getLoadResource() { 237 return this.loadResource; 238 } 239 240 241 public boolean saveOnLogout() { 242 return this.saveOnLogout; 243 } 244 245 246 public SourceParameters getSaveResourceParameters() { 247 return this.saveResourceParameters; 248 } 249 250 251 public SourceParameters getLoadResourceParameters() { 252 return this.loadResourceParameters; 253 } 254 255 258 public Map getApplications() { 259 return applications; 260 } 261 262 265 public Configuration getConfiguration(String name) { 266 return (Configuration)this.configurations.get(name); 267 } 268 269 272 public String toString() { 273 return "authentication handler '" + this.name + "' (" + super.toString() + ')'; 274 } 275 276 279 public String getAuthenticatorClassName() { 280 return this.authenticatorClass; 281 } 282 } 283 | Popular Tags |