You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lenya.apache.org by an...@apache.org on 2004/09/16 16:20:13 UTC
svn commit: rev 46180 - in incubator/lenya/trunk/src/java/org/apache/lenya/ac: . file impl ldap
Author: andreas
Date: Thu Sep 16 07:20:12 2004
New Revision: 46180
Modified:
incubator/lenya/trunk/src/java/org/apache/lenya/ac/Identity.java
incubator/lenya/trunk/src/java/org/apache/lenya/ac/Item.java
incubator/lenya/trunk/src/java/org/apache/lenya/ac/Password.java
incubator/lenya/trunk/src/java/org/apache/lenya/ac/file/FileAccreditableManager.java
incubator/lenya/trunk/src/java/org/apache/lenya/ac/file/FileGroup.java
incubator/lenya/trunk/src/java/org/apache/lenya/ac/file/FileGroupManager.java
incubator/lenya/trunk/src/java/org/apache/lenya/ac/file/FileIPRange.java
incubator/lenya/trunk/src/java/org/apache/lenya/ac/file/FileIPRangeManager.java
incubator/lenya/trunk/src/java/org/apache/lenya/ac/file/FileItemManager.java
incubator/lenya/trunk/src/java/org/apache/lenya/ac/file/FileRole.java
incubator/lenya/trunk/src/java/org/apache/lenya/ac/file/FileRoleManager.java
incubator/lenya/trunk/src/java/org/apache/lenya/ac/file/FileUser.java
incubator/lenya/trunk/src/java/org/apache/lenya/ac/file/FileUserManager.java
incubator/lenya/trunk/src/java/org/apache/lenya/ac/impl/AbstractGroup.java
incubator/lenya/trunk/src/java/org/apache/lenya/ac/impl/AbstractGroupable.java
incubator/lenya/trunk/src/java/org/apache/lenya/ac/impl/AbstractIPRange.java
incubator/lenya/trunk/src/java/org/apache/lenya/ac/impl/AbstractItem.java
incubator/lenya/trunk/src/java/org/apache/lenya/ac/impl/AbstractRole.java
incubator/lenya/trunk/src/java/org/apache/lenya/ac/impl/AbstractUser.java
incubator/lenya/trunk/src/java/org/apache/lenya/ac/impl/DefaultAccessController.java
incubator/lenya/trunk/src/java/org/apache/lenya/ac/ldap/LDAPUser.java
Log:
get rid of log4j
Modified: incubator/lenya/trunk/src/java/org/apache/lenya/ac/Identity.java
==============================================================================
--- incubator/lenya/trunk/src/java/org/apache/lenya/ac/Identity.java (original)
+++ incubator/lenya/trunk/src/java/org/apache/lenya/ac/Identity.java Thu Sep 16 07:20:12 2004
@@ -15,7 +15,7 @@
*
*/
-/* $Id: Identity.java,v 1.4 2004/08/16 08:02:38 andreas Exp $ */
+/* $Id$ */
package org.apache.lenya.ac;
@@ -23,21 +23,25 @@
import java.util.HashSet;
import java.util.Set;
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.cocoon.environment.Session;
-import org.apache.log4j.Category;
/**
* Identity object. Used to store the authenticated accreditables in the session.
*/
-public class Identity implements Identifiable {
+public class Identity extends AbstractLogEnabled implements Identifiable {
private Set identifiables = new HashSet();
-
- private static final Category log = Category.getInstance(Identity.class);
-
+
/**
* Ctor.
*/
public Identity() {
+ }
+
+ /**
+ * Initializes this identity.
+ */
+ public void initialize() {
addIdentifiable(World.getInstance());
}
@@ -57,11 +61,11 @@
assert identifiable != null;
assert identifiable != this;
assert !identifiables.contains(identifiable);
-
- if (log.isDebugEnabled()) {
- log.debug("Adding identifiable: [" + identifiable + "]");
+
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Adding identifiable: [" + identifiable + "]");
}
-
+
identifiables.add(identifiable);
}
@@ -95,7 +99,7 @@
return string;
}
-
+
/**
* Checks if this identity belongs to a certain accreditable manager.
* @param manager The accreditable manager to check for.
@@ -104,9 +108,9 @@
* @throws AccessControlException if an error occurs
*/
public boolean belongsTo(AccreditableManager manager) throws AccessControlException {
-
+
boolean belongs = true;
-
+
Identifiable identifiables[] = getIdentifiables();
int i = 0;
while (belongs && i < identifiables.length) {
@@ -117,7 +121,7 @@
}
i++;
}
-
+
return belongs;
}
@@ -136,7 +140,7 @@
i++;
}
return user;
- }
+ }
/**
* Returns the machine of this identity.
@@ -153,34 +157,34 @@
i++;
}
return machine;
- }
-
- /**
- * Checks if this identity contains a certain identifiable.
- * @param identifiable The identifiable to look for.
- * @return A boolean value.
- */
- public boolean contains(Identifiable identifiable) {
- return identifiables.contains(identifiable);
- }
-
- /**
- * Fetches the identity from a session.
- * @param session The session.
- * @return An identity.
- */
- public static Identity getIdentity(Session session) {
- Identity identity = (Identity) session.getAttribute(Identity.class.getName());
- return identity;
- }
-
- /**
- * Removes a certain identifiable from the idenity.
- * @param identifiable An identifiable.
- */
- public void removeIdentifiable(Identifiable identifiable) {
- assert identifiables.contains(identifiable);
- identifiables.remove(identifiable);
- }
+ }
+
+ /**
+ * Checks if this identity contains a certain identifiable.
+ * @param identifiable The identifiable to look for.
+ * @return A boolean value.
+ */
+ public boolean contains(Identifiable identifiable) {
+ return identifiables.contains(identifiable);
+ }
+
+ /**
+ * Fetches the identity from a session.
+ * @param session The session.
+ * @return An identity.
+ */
+ public static Identity getIdentity(Session session) {
+ Identity identity = (Identity) session.getAttribute(Identity.class.getName());
+ return identity;
+ }
+
+ /**
+ * Removes a certain identifiable from the idenity.
+ * @param identifiable An identifiable.
+ */
+ public void removeIdentifiable(Identifiable identifiable) {
+ assert identifiables.contains(identifiable);
+ identifiables.remove(identifiable);
+ }
-}
+}
\ No newline at end of file
Modified: incubator/lenya/trunk/src/java/org/apache/lenya/ac/Item.java
==============================================================================
--- incubator/lenya/trunk/src/java/org/apache/lenya/ac/Item.java (original)
+++ incubator/lenya/trunk/src/java/org/apache/lenya/ac/Item.java Thu Sep 16 07:20:12 2004
@@ -15,7 +15,7 @@
*
*/
-/* $Id: Item.java,v 1.3 2004/03/03 12:56:31 gregor Exp $ */
+/* $Id$ */
package org.apache.lenya.ac;
@@ -23,12 +23,13 @@
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.logger.LogEnabled;
/**
* An item can be initialized from a configuration.
*/
-public interface Item {
+public interface Item extends LogEnabled {
/**
* Returns the ID.
Modified: incubator/lenya/trunk/src/java/org/apache/lenya/ac/Password.java
==============================================================================
--- incubator/lenya/trunk/src/java/org/apache/lenya/ac/Password.java (original)
+++ incubator/lenya/trunk/src/java/org/apache/lenya/ac/Password.java Thu Sep 16 07:20:12 2004
@@ -15,39 +15,17 @@
*
*/
-/* $Id: Password.java,v 1.4 2004/08/16 16:21:22 andreas Exp $ */
+/* $Id$ */
package org.apache.lenya.ac;
import java.security.MessageDigest;
-import org.apache.log4j.Category;
-
/**
* Encrypt plain text password
* Example: "message digest" becomes "f96b697d7cb7938d525a2f31aaf161d0" (hexadecimal notation (32 characters))
*/
public class Password {
- private static Category log = Category.getInstance(Password.class);
-
- /**
- * CLI
- *
- * @param args plain text password
- */
- public static void main(String[] args) {
- if (args.length != 1) {
- System.out.println("Usage: plain-text-password");
-
- return;
- }
-
- try {
- System.out.println(Password.encrypt(args[0]));
- } catch (Exception e) {
- System.err.println(e);
- }
- }
/**
* Encrypt plain text password
@@ -69,7 +47,7 @@
try {
md = MessageDigest.getInstance("MD5");
} catch (java.security.NoSuchAlgorithmException e) {
- log.error(e);
+ throw new RuntimeException(e);
}
return stringify(md.digest(plain.getBytes()));
}
Modified: incubator/lenya/trunk/src/java/org/apache/lenya/ac/file/FileAccreditableManager.java
==============================================================================
--- incubator/lenya/trunk/src/java/org/apache/lenya/ac/file/FileAccreditableManager.java (original)
+++ incubator/lenya/trunk/src/java/org/apache/lenya/ac/file/FileAccreditableManager.java Thu Sep 16 07:20:12 2004
@@ -236,28 +236,33 @@
* @see org.apache.lenya.ac.impl.AbstractAccreditableManager#initializeGroupManager()
*/
protected GroupManager initializeGroupManager() throws AccessControlException {
- return FileGroupManager.instance(getConfigurationDirectory());
+ FileGroupManager manager = FileGroupManager.instance(getConfigurationDirectory(), getLogger());
+ return manager;
}
/**
* @see org.apache.lenya.ac.impl.AbstractAccreditableManager#initializeIPRangeManager()
*/
protected IPRangeManager initializeIPRangeManager() throws AccessControlException {
- return FileIPRangeManager.instance(getConfigurationDirectory());
+ FileIPRangeManager manager = FileIPRangeManager.instance(getConfigurationDirectory(), getLogger());
+ return manager;
}
/**
* @see org.apache.lenya.ac.impl.AbstractAccreditableManager#initializeRoleManager()
*/
protected RoleManager initializeRoleManager() throws AccessControlException {
- return FileRoleManager.instance(getConfigurationDirectory());
+ FileRoleManager manager = FileRoleManager.instance(getConfigurationDirectory(), getLogger());
+ return manager;
}
/**
* @see org.apache.lenya.ac.impl.AbstractAccreditableManager#initializeUserManager()
*/
protected UserManager initializeUserManager() throws AccessControlException {
- return FileUserManager.instance(getConfigurationDirectory(), getUserTypes());
+ FileUserManager manager = FileUserManager.instance(getConfigurationDirectory(),
+ getUserTypes(), getLogger());
+ return manager;
}
}
Modified: incubator/lenya/trunk/src/java/org/apache/lenya/ac/file/FileGroup.java
==============================================================================
--- incubator/lenya/trunk/src/java/org/apache/lenya/ac/file/FileGroup.java (original)
+++ incubator/lenya/trunk/src/java/org/apache/lenya/ac/file/FileGroup.java Thu Sep 16 07:20:12 2004
@@ -15,7 +15,7 @@
*
*/
-/* $Id: FileGroup.java,v 1.4 2004/08/16 15:59:51 andreas Exp $ */
+/* $Id$ */
package org.apache.lenya.ac.file;
@@ -34,7 +34,7 @@
* File-based group implementation.
*/
public class FileGroup extends AbstractGroup implements Item {
-
+
/**
* @see org.apache.lenya.ac.Group#delete()
*/
@@ -53,7 +53,7 @@
* Create a new instance of <code>FileGroup</code>
* @param configurationDirectory to which the group will be attached to
* @param id the ID of the group
- */
+ */
public FileGroup(File configurationDirectory, String id) {
super(id);
setConfigurationDirectory(configurationDirectory);
@@ -67,7 +67,7 @@
public void configure(Configuration config) throws ConfigurationException {
new ItemConfiguration().configure(this, config);
}
-
+
/**
* Returns the configuration file.
* @return A file object.
@@ -80,7 +80,7 @@
/**
* Save this group
- *
+ *
* @throws AccessControlException if the save failed
*/
public void save() throws AccessControlException {
@@ -102,7 +102,7 @@
/**
* Create a configuration containing the group details
- *
+ *
* @return a <code>Configuration</code>
*/
private Configuration createConfiguration() {
@@ -129,4 +129,4 @@
assert (configurationDirectory != null) && configurationDirectory.isDirectory();
this.configurationDirectory = configurationDirectory;
}
-}
+}
\ No newline at end of file
Modified: incubator/lenya/trunk/src/java/org/apache/lenya/ac/file/FileGroupManager.java
==============================================================================
--- incubator/lenya/trunk/src/java/org/apache/lenya/ac/file/FileGroupManager.java (original)
+++ incubator/lenya/trunk/src/java/org/apache/lenya/ac/file/FileGroupManager.java Thu Sep 16 07:20:12 2004
@@ -15,7 +15,7 @@
*
*/
-/* $Id: FileGroupManager.java,v 1.4 2004/08/16 15:59:51 andreas Exp $ */
+/* $Id$ */
package org.apache.lenya.ac.file;
@@ -23,6 +23,7 @@
import java.util.HashMap;
import java.util.Map;
+import org.apache.avalon.framework.logger.Logger;
import org.apache.lenya.ac.AccessControlException;
import org.apache.lenya.ac.Group;
import org.apache.lenya.ac.GroupManager;
@@ -36,29 +37,30 @@
private static Map instances = new HashMap();
/**
- * Create a GroupManager
- *
- * @param configurationDirectory for which the GroupManager is to be created
- * @throws AccessControlException if no GroupManager could be instanciated
+ * Ctor.
*/
- private FileGroupManager(File configurationDirectory) throws AccessControlException {
- super(configurationDirectory);
+ private FileGroupManager() {
+ super();
}
-
+
/**
* Return the <code>GroupManager</code> for the given publication.
* The <code>GroupManager</code> is a singleton.
*
* @param configurationDirectory for which the GroupManager is requested
+ * @param logger The logger.
* @return a <code>GroupManager</code>
* @throws AccessControlException if no GroupManager could be instanciated
*/
- public static FileGroupManager instance(File configurationDirectory)
+ public static FileGroupManager instance(File configurationDirectory, Logger logger)
throws AccessControlException {
assert configurationDirectory != null;
if (!instances.containsKey(configurationDirectory)) {
- instances.put(configurationDirectory, new FileGroupManager(configurationDirectory));
+ FileGroupManager manager = new FileGroupManager();
+ manager.enableLogging(logger);
+ manager.configure(configurationDirectory);
+ instances.put(configurationDirectory, manager);
}
return (FileGroupManager) instances.get(configurationDirectory);
Modified: incubator/lenya/trunk/src/java/org/apache/lenya/ac/file/FileIPRange.java
==============================================================================
--- incubator/lenya/trunk/src/java/org/apache/lenya/ac/file/FileIPRange.java (original)
+++ incubator/lenya/trunk/src/java/org/apache/lenya/ac/file/FileIPRange.java Thu Sep 16 07:20:12 2004
@@ -20,133 +20,131 @@
package org.apache.lenya.ac.file;
import java.io.File;
+import java.net.InetAddress;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.configuration.DefaultConfiguration;
import org.apache.avalon.framework.configuration.DefaultConfigurationSerializer;
import org.apache.lenya.ac.AccessControlException;
-import org.apache.lenya.ac.IPRange;
import org.apache.lenya.ac.Machine;
import org.apache.lenya.ac.impl.AbstractIPRange;
import org.apache.lenya.ac.impl.ItemConfiguration;
+import org.apache.lenya.net.InetAddressUtil;
/**
* IP range that is stored in a file.
*/
public class FileIPRange extends AbstractIPRange {
- /**
- * Main method.
- *
- * @param args
- * The command-line arguments.
- * @deprecated This should bemoved to a JUnit test.
- */
- public static void main(String[] args) {
- if (args.length == 0) {
- System.out.println(
- "Usage: network, netmask, ip (e.g. 192.168.0.64 255.255.255.240 192.168.0.70)");
- return;
- }
- IPRange ipr = new FileIPRange();
- try {
- ipr.setNetworkAddress(args[0]);
- ipr.setSubnetMask(args[1]);
- if (ipr.contains(new Machine(args[2]))) {
- System.out.println("true");
- } else {
- System.out.println("false");
- }
- } catch (Exception e) {
- System.err.println(e);
- }
- }
-
- /**
- * Ctor.
- */
- public FileIPRange() {
- }
-
- /**
- * Ctor.
- *
- * @param configurationDirectory
- * The configuration directory.
- * @param id
- * The IP range ID.
- */
- public FileIPRange(File configurationDirectory, String id) {
- super(id);
- setConfigurationDirectory(configurationDirectory);
- }
-
- /**
- * @see org.apache.lenya.ac.impl.AbstractIPRange#save()
- */
- public void save() throws AccessControlException {
- DefaultConfigurationSerializer serializer = new DefaultConfigurationSerializer();
- Configuration config = createConfiguration();
-
- try {
- serializer.serializeToFile(getFile(), config);
- } catch (Exception e) {
- throw new AccessControlException(e);
- }
- }
-
- /**
- * Returns the configuration file.
- *
- * @return A file object.
- */
- protected File getFile() {
- File xmlPath = getConfigurationDirectory();
- File xmlFile = new File(xmlPath, getId() + FileIPRangeManager.SUFFIX);
- return xmlFile;
- }
-
- /**
- * @see org.apache.lenya.ac.Item#configure(org.apache.avalon.framework.configuration.Configuration)
- */
- public void configure(Configuration config) throws ConfigurationException {
- new ItemConfiguration().configure(this, config);
-
- String networkAddress = config.getChild(ELEMENT_NETWORK_ADDRESS).getValue();
- String subnetMask = config.getChild(ELEMENT_SUBNET_MASK).getValue();
-
- try {
- setNetworkAddress(networkAddress);
- setSubnetMask(subnetMask);
- } catch (AccessControlException e) {
- throw new ConfigurationException("Configuring IP range [" + getId() + "] failed: ", e);
- }
-
- }
-
- protected static final String IP_RANGE = "ip-range";
- protected static final String ELEMENT_NETWORK_ADDRESS = "network-address";
- protected static final String ELEMENT_SUBNET_MASK = "subnet-mask";
-
- /**
- * Create a configuration from the current user details. Can be used for saving.
- *
- * @return a <code>Configuration</code>
- */
- protected Configuration createConfiguration() {
- DefaultConfiguration config = new DefaultConfiguration(IP_RANGE);
- new ItemConfiguration().save(this, config);
-
- DefaultConfiguration networkAddressConfig =
- new DefaultConfiguration(ELEMENT_NETWORK_ADDRESS);
- networkAddressConfig.setValue(getNetworkAddress().getHostAddress());
- config.addChild(networkAddressConfig);
-
- DefaultConfiguration subnetMaskConfig = new DefaultConfiguration(ELEMENT_SUBNET_MASK);
- subnetMaskConfig.setValue(getSubnetMask().getHostAddress());
- config.addChild(subnetMaskConfig);
-
- return config;
- }
-}
+ /**
+ * Main method.
+ *
+ * @param args The command-line arguments.
+ * @deprecated This should bemoved to a JUnit test.
+ */
+ public static void main(String[] args) {
+ if (args.length == 0) {
+ System.out
+ .println("Usage: network, netmask, ip (e.g. 192.168.0.64 255.255.255.240 192.168.0.70)");
+ return;
+ }
+ try {
+ InetAddress networkAddress = InetAddress.getByName(args[0]);
+ InetAddress subnetMask = InetAddress.getByName(args[1]);
+ Machine machine = new Machine(args[2]);
+
+ if (InetAddressUtil.contains(networkAddress, subnetMask, machine.getAddress())) {
+ System.out.println("true");
+ } else {
+ System.out.println("false");
+ }
+ } catch (Exception e) {
+ System.err.println(e);
+ }
+ }
+
+ /**
+ * Ctor.
+ */
+ public FileIPRange() {
+ }
+
+ /**
+ * Ctor.
+ *
+ * @param configurationDirectory The configuration directory.
+ * @param id The IP range ID.
+ */
+ public FileIPRange(File configurationDirectory, String id) {
+ setConfigurationDirectory(configurationDirectory);
+ }
+
+ /**
+ * @see org.apache.lenya.ac.impl.AbstractIPRange#save()
+ */
+ public void save() throws AccessControlException {
+ DefaultConfigurationSerializer serializer = new DefaultConfigurationSerializer();
+ Configuration config = createConfiguration();
+
+ try {
+ serializer.serializeToFile(getFile(), config);
+ } catch (Exception e) {
+ throw new AccessControlException(e);
+ }
+ }
+
+ /**
+ * Returns the configuration file.
+ *
+ * @return A file object.
+ */
+ protected File getFile() {
+ File xmlPath = getConfigurationDirectory();
+ File xmlFile = new File(xmlPath, getId() + FileIPRangeManager.SUFFIX);
+ return xmlFile;
+ }
+
+ /**
+ * @see org.apache.lenya.ac.Item#configure(org.apache.avalon.framework.configuration.Configuration)
+ */
+ public void configure(Configuration config) throws ConfigurationException {
+ new ItemConfiguration().configure(this, config);
+
+ String networkAddress = config.getChild(ELEMENT_NETWORK_ADDRESS).getValue();
+ String subnetMask = config.getChild(ELEMENT_SUBNET_MASK).getValue();
+
+ try {
+ setNetworkAddress(networkAddress);
+ setSubnetMask(subnetMask);
+ } catch (AccessControlException e) {
+ throw new ConfigurationException("Configuring IP range [" + getId() + "] failed: ", e);
+ }
+
+ }
+
+ protected static final String IP_RANGE = "ip-range";
+ protected static final String ELEMENT_NETWORK_ADDRESS = "network-address";
+ protected static final String ELEMENT_SUBNET_MASK = "subnet-mask";
+
+ /**
+ * Create a configuration from the current user details. Can be used for saving.
+ *
+ * @return a <code>Configuration</code>
+ */
+ protected Configuration createConfiguration() {
+ DefaultConfiguration config = new DefaultConfiguration(IP_RANGE);
+ new ItemConfiguration().save(this, config);
+
+ DefaultConfiguration networkAddressConfig = new DefaultConfiguration(
+ ELEMENT_NETWORK_ADDRESS);
+ networkAddressConfig.setValue(getNetworkAddress().getHostAddress());
+ config.addChild(networkAddressConfig);
+
+ DefaultConfiguration subnetMaskConfig = new DefaultConfiguration(ELEMENT_SUBNET_MASK);
+ subnetMaskConfig.setValue(getSubnetMask().getHostAddress());
+ config.addChild(subnetMaskConfig);
+
+ return config;
+ }
+}
\ No newline at end of file
Modified: incubator/lenya/trunk/src/java/org/apache/lenya/ac/file/FileIPRangeManager.java
==============================================================================
--- incubator/lenya/trunk/src/java/org/apache/lenya/ac/file/FileIPRangeManager.java (original)
+++ incubator/lenya/trunk/src/java/org/apache/lenya/ac/file/FileIPRangeManager.java Thu Sep 16 07:20:12 2004
@@ -15,7 +15,7 @@
*
*/
-/* $Id: FileIPRangeManager.java,v 1.5 2004/08/16 15:59:51 andreas Exp $ */
+/* $Id$ */
package org.apache.lenya.ac.file;
@@ -23,6 +23,7 @@
import java.util.HashMap;
import java.util.Map;
+import org.apache.avalon.framework.logger.Logger;
import org.apache.lenya.ac.AccessControlException;
import org.apache.lenya.ac.IPRange;
import org.apache.lenya.ac.IPRangeManager;
@@ -35,13 +36,10 @@
/**
* Ctor.
- * @param configurationDirectory The configuration directory.
- * @throws AccessControlException when something went wrong.
*/
- protected FileIPRangeManager(File configurationDirectory) throws AccessControlException {
- super(configurationDirectory);
+ private FileIPRangeManager() {
}
-
+
protected static final String SUFFIX = ".ipml";
/**
@@ -52,24 +50,29 @@
}
private static Map instances = new HashMap();
-
+
/**
* Describe <code>instance</code> method here.
- *
+ *
* @param configurationDirectory a directory
+ * @param logger The logger.
* @return an <code>IPRangeManager</code> value
* @exception AccessControlException if an error occurs
*/
- public static FileIPRangeManager instance(File configurationDirectory) throws AccessControlException {
+ public static FileIPRangeManager instance(File configurationDirectory, Logger logger)
+ throws AccessControlException {
assert configurationDirectory != null;
if (!configurationDirectory.isDirectory()) {
- throw new AccessControlException(
- "Configuration directory [" + configurationDirectory + "] does not exist!");
+ throw new AccessControlException("Configuration directory [" + configurationDirectory
+ + "] does not exist!");
}
if (!instances.containsKey(configurationDirectory)) {
- instances.put(configurationDirectory, new FileIPRangeManager(configurationDirectory));
+ FileIPRangeManager manager = new FileIPRangeManager();
+ manager.enableLogging(logger);
+ manager.configure(configurationDirectory);
+ instances.put(configurationDirectory, manager);
}
return (FileIPRangeManager) instances.get(configurationDirectory);
@@ -77,7 +80,7 @@
/**
* Get all IP ranges.
- *
+ *
* @return an array of IP ranges.
*/
public IPRange[] getIPRanges() {
@@ -91,7 +94,7 @@
/**
* Add the given IP range
- *
+ *
* @param range IP range that is to be added
* @throws AccessControlException when the notification failed.
*/
@@ -101,7 +104,7 @@
/**
* Remove the given IP range
- *
+ *
* @param range IP range that is to be removed
* @throws AccessControlException when the notification failed.
*/
@@ -111,13 +114,12 @@
/**
* Get the IPRange with the given id.
- *
+ *
* @param rangeId user id of requested IP range
- * @return the requested IP range or null if there is
- * no IP range with the given id
+ * @return the requested IP range or null if there is no IP range with the given id
*/
public IPRange getIPRange(String rangeId) {
return (IPRange) getItem(rangeId);
}
-}
+}
\ No newline at end of file
Modified: incubator/lenya/trunk/src/java/org/apache/lenya/ac/file/FileItemManager.java
==============================================================================
--- incubator/lenya/trunk/src/java/org/apache/lenya/ac/file/FileItemManager.java (original)
+++ incubator/lenya/trunk/src/java/org/apache/lenya/ac/file/FileItemManager.java Thu Sep 16 07:20:12 2004
@@ -33,42 +33,48 @@
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.lenya.ac.AccessControlException;
import org.apache.lenya.ac.Group;
import org.apache.lenya.ac.Groupable;
import org.apache.lenya.ac.Item;
import org.apache.lenya.ac.ItemManagerListener;
import org.apache.lenya.ac.impl.ItemConfiguration;
-import org.apache.log4j.Category;
/**
* Abstract superclass for classes that manage items loaded from configuration files.
*/
-public abstract class FileItemManager {
- private static final Category log = Category.getInstance(FileItemManager.class);
+public abstract class FileItemManager extends AbstractLogEnabled {
+
+ protected static final String PATH = "config" + File.separator + "ac" + File.separator
+ + "passwd";
- protected static final String PATH = "config" + File.separator + "ac" + File.separator + "passwd";
-
private Map items = new HashMap();
private File configurationDirectory;
private DirectoryChangeNotifier notifier;
/**
- * Create a new ItemManager
- *
+ * Create a new ItemManager.
+ */
+ protected FileItemManager() {
+ }
+
+ /**
+ * Configures the item manager.
* @param configurationDirectory where the items are fetched from
* @throws AccessControlException if the item manager cannot be instantiated
*/
- protected FileItemManager(File configurationDirectory) throws AccessControlException {
+ public void configure(File configurationDirectory) throws AccessControlException {
assert configurationDirectory != null;
if (!configurationDirectory.exists() || !configurationDirectory.isDirectory()) {
- throw new AccessControlException(
- "The directory [" + configurationDirectory.getAbsolutePath() + "] does not exist!");
+ throw new AccessControlException("The directory ["
+ + configurationDirectory.getAbsolutePath() + "] does not exist!");
}
this.configurationDirectory = configurationDirectory;
- notifier = new DirectoryChangeNotifier(configurationDirectory, getFileFilter());
+ this.notifier = new DirectoryChangeNotifier(configurationDirectory, getFileFilter());
+ this.notifier.enableLogging(getLogger());
loadItems();
}
@@ -87,8 +93,8 @@
if (changed) {
- if (log.isDebugEnabled()) {
- log.debug("Item configuration has changed - reloading.");
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Item configuration has changed - reloading.");
}
File[] addedFiles = notifier.getAddedFiles();
@@ -145,16 +151,14 @@
if (item == null) {
try {
item = (Item) Class.forName(klass).newInstance();
+ item.enableLogging(getLogger());
} catch (Exception e) {
- String errorMsg =
- "Exception when trying to instanciate: "
- + klass
- + " with exception: "
- + e.fillInStackTrace();
+ String errorMsg = "Exception when trying to instanciate: " + klass
+ + " with exception: " + e.fillInStackTrace();
// an exception occured when trying to instanciate
// a user.
- log.error(errorMsg);
+ getLogger().error(errorMsg);
throw new AccessControlException(errorMsg, e);
}
item.setConfigurationDirectory(configurationDirectory);
@@ -183,12 +187,12 @@
assert file.exists();
config = builder.buildFromFile(file);
} catch (Exception e) {
- String errorMsg =
- "Exception when reading the configuration from file: " + file.getName();
+ String errorMsg = "Exception when reading the configuration from file: "
+ + file.getName();
// an exception occured when trying to read the configuration
// from the identity file.
- log.error(errorMsg);
+ getLogger().error(errorMsg);
throw new AccessControlException(errorMsg, e);
}
return config;
@@ -213,7 +217,7 @@
/**
* get all items
- *
+ *
* @return an array of items
*/
public Item[] getItems() {
@@ -227,15 +231,15 @@
/**
* Add an Item to this manager
- *
+ *
* @param item to be added
* @throws AccessControlException when the notification threw this exception.
*/
public void add(Item item) throws AccessControlException {
assert item != null;
items.put(item.getId(), item);
- if (log.isDebugEnabled()) {
- log.debug("Item [" + item + "] added.");
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Item [" + item + "] added.");
}
notifyAdded(item);
}
@@ -247,8 +251,8 @@
*/
public void remove(Item item) throws AccessControlException {
items.remove(item.getId());
- if (log.isDebugEnabled()) {
- log.debug("Item [" + item + "] removed.");
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Item [" + item + "] removed.");
}
notifyRemoved(item);
}
@@ -261,8 +265,8 @@
public void update(Item newItem) throws AccessControlException {
items.remove(newItem.getId());
items.put(newItem.getId(), newItem);
- if (log.isDebugEnabled()) {
- log.debug("Item [" + newItem + "] updated.");
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Item [" + newItem + "] updated.");
}
}
@@ -282,7 +286,7 @@
/**
* Get the directory where the items are located.
- *
+ *
* @return a <code>File</code>
*/
public File getConfigurationDirectory() {
@@ -316,7 +320,9 @@
* @param listener An item manager listener.
*/
public void addItemManagerListener(ItemManagerListener listener) {
- log.debug("Adding listener: [" + listener + "]");
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Adding listener: [" + listener + "]");
+ }
if (!itemManagerListeners.contains(listener)) {
itemManagerListeners.add(listener);
}
@@ -327,7 +333,9 @@
* @param listener An item manager listener.
*/
public void removeItemManagerListener(ItemManagerListener listener) {
- log.debug("Removing listener: [" + listener + "]");
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Removing listener: [" + listener + "]");
+ }
itemManagerListeners.remove(listener);
}
@@ -337,7 +345,9 @@
* @throws AccessControlException if an error occurs.
*/
protected void notifyAdded(Item item) throws AccessControlException {
- log.debug("Item was added: [" + item + "]");
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Item was added: [" + item + "]");
+ }
List clone = new ArrayList(itemManagerListeners);
for (Iterator i = clone.iterator(); i.hasNext();) {
ItemManagerListener listener = (ItemManagerListener) i.next();
@@ -351,11 +361,15 @@
* @throws AccessControlException if an error occurs.
*/
protected void notifyRemoved(Item item) throws AccessControlException {
- log.debug("Item was removed: [" + item + "]");
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Item was removed: [" + item + "]");
+ }
List clone = new ArrayList(itemManagerListeners);
for (Iterator i = clone.iterator(); i.hasNext();) {
ItemManagerListener listener = (ItemManagerListener) i.next();
- log.debug("Notifying listener: [" + listener + "]");
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Notifying listener: [" + listener + "]");
+ }
listener.itemRemoved(item);
}
}
@@ -363,7 +377,7 @@
/**
* Helper class to observe a directory for changes.
*/
- public static class DirectoryChangeNotifier {
+ public static class DirectoryChangeNotifier extends AbstractLogEnabled {
/**
* Ctor.
@@ -378,14 +392,14 @@
private File directory;
private FileFilter filter;
private Map canonicalPath2LastModified = new HashMap();
- private static final Category log = Category.getInstance(DirectoryChangeNotifier.class);
private Set addedFiles = new HashSet();
private Set removedFiles = new HashSet();
private Set changedFiles = new HashSet();
/**
- * Checks if the directory has changed (a new file was added, a file was removed, a file has changed).
+ * Checks if the directory has changed (a new file was added, a file was removed, a file has
+ * changed).
* @return A boolean value.
* @throws IOException when something went wrong.
*/
@@ -406,8 +420,8 @@
if (!canonicalPath2LastModified.containsKey(canonicalPath)) {
addedFiles.add(new File(canonicalPath));
- if (log.isDebugEnabled()) {
- log.debug("New file: [" + canonicalPath + "]");
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("New file: [" + canonicalPath + "]");
}
} else {
@@ -415,8 +429,8 @@
long lastModified = lastModifiedObject.longValue();
if (lastModified < files[i].lastModified()) {
changedFiles.add(files[i]);
- if (log.isDebugEnabled()) {
- log.debug("File has changed: [" + canonicalPath + "]");
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("File has changed: [" + canonicalPath + "]");
}
}
}
@@ -430,8 +444,8 @@
if (!newPathSet.contains(oldPaths[i])) {
removedFiles.add(new File(oldPaths[i]));
canonicalPath2LastModified.remove(oldPaths[i]);
- if (log.isDebugEnabled()) {
- log.debug("File removed: [" + oldPaths[i] + "]");
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("File removed: [" + oldPaths[i] + "]");
}
}
}
@@ -465,4 +479,4 @@
}
-}
+}
\ No newline at end of file
Modified: incubator/lenya/trunk/src/java/org/apache/lenya/ac/file/FileRole.java
==============================================================================
--- incubator/lenya/trunk/src/java/org/apache/lenya/ac/file/FileRole.java (original)
+++ incubator/lenya/trunk/src/java/org/apache/lenya/ac/file/FileRole.java Thu Sep 16 07:20:12 2004
@@ -33,12 +33,12 @@
* @version $Id$
*/
public class FileRole extends AbstractRole implements Item {
-
+
/**
- * Creates a new file role.
- * @param configurationDirectory The configuration directory.
- * @param id The role ID.
- */
+ * Creates a new file role.
+ * @param configurationDirectory The configuration directory.
+ * @param id The role ID.
+ */
public FileRole(File configurationDirectory, String id) {
setId(id);
setConfigurationDirectory(configurationDirectory);
@@ -54,7 +54,7 @@
/**
* Configure this instance of <code>FileRole</code>
- *
+ *
* @param config containing the role details
* @throws ConfigurationException if the <code>FileRole</code> could not be configured
*/
@@ -64,7 +64,7 @@
/**
* Save the role
- *
+ *
* @throws AccessControlException if the save fails
*/
public void save() throws AccessControlException {
@@ -82,7 +82,7 @@
/**
* Create a configuration containing the role details
- *
+ *
* @return a <code>Configuration</code>
*/
private Configuration createConfiguration() {
@@ -107,4 +107,4 @@
public void setConfigurationDirectory(File file) {
configurationDirectory = file;
}
-}
+}
\ No newline at end of file
Modified: incubator/lenya/trunk/src/java/org/apache/lenya/ac/file/FileRoleManager.java
==============================================================================
--- incubator/lenya/trunk/src/java/org/apache/lenya/ac/file/FileRoleManager.java (original)
+++ incubator/lenya/trunk/src/java/org/apache/lenya/ac/file/FileRoleManager.java Thu Sep 16 07:20:12 2004
@@ -21,6 +21,7 @@
import java.util.HashMap;
import java.util.Map;
+import org.apache.avalon.framework.logger.Logger;
import org.apache.lenya.ac.AccessControlException;
import org.apache.lenya.ac.Item;
import org.apache.lenya.ac.Role;
@@ -28,34 +29,33 @@
/**
* File-based role manager implementation.
- * @version $Id: FileRoleManager.java,v 1.4 2004/08/16 15:59:51 andreas Exp $
+ * @version $Id$
*/
public final class FileRoleManager extends FileItemManager implements RoleManager {
protected static final String SUFFIX = ".rml";
private static Map instances = new HashMap();
/**
- * Return the <code>RoleManager</code> for this configuration directory.
- * The <code>RoleManager</code> is a singleton.
- *
- * @param configurationDirectory the directory for which the RoleManager is requested.
- * @throws AccessControlException if the <code>RoleManager<code> could not be instantiated
- */
- protected FileRoleManager(File configurationDirectory)
- throws AccessControlException {
- super(configurationDirectory);
+ * Return the <code>RoleManager</code> for this configuration directory. The
+ * <code>RoleManager</code> is a singleton.
+ */
+ protected FileRoleManager() {
}
/**
* Returns the role manager for this configuration directory.
* @param configurationDirectory The configuration directory.
+ * @param logger The logger.
* @return A role manager.
* @throws AccessControlException when something went wrong.
*/
- public static FileRoleManager instance(File configurationDirectory)
- throws AccessControlException {
+ public static FileRoleManager instance(File configurationDirectory, Logger logger)
+ throws AccessControlException {
if (!instances.containsKey(configurationDirectory)) {
- instances.put(configurationDirectory, new FileRoleManager(configurationDirectory));
+ FileRoleManager manager = new FileRoleManager();
+ manager.enableLogging(logger);
+ manager.configure(configurationDirectory);
+ instances.put(configurationDirectory, manager);
}
return (FileRoleManager) instances.get(configurationDirectory);
@@ -63,7 +63,7 @@
/**
* Get the role for the given ID.
- *
+ *
* @param roleId The name of the role requested.
* @return a <code>Role</code> or null if no role with the given name found
*/
@@ -80,7 +80,7 @@
/**
* Get all roles
- *
+ *
* @return an array of roles.
*/
public Role[] getRoles() {
@@ -94,7 +94,7 @@
/**
* Add a role
- *
+ *
* @param role The role to add.
* @throws AccessControlException if an error occurs.
*/
@@ -104,11 +104,11 @@
/**
* Remove a role
- *
+ *
* @param role The role to remove.
* @throws AccessControlException if an error occurs.
*/
public void remove(Role role) throws AccessControlException {
super.remove(role);
}
-}
+}
\ No newline at end of file
Modified: incubator/lenya/trunk/src/java/org/apache/lenya/ac/file/FileUser.java
==============================================================================
--- incubator/lenya/trunk/src/java/org/apache/lenya/ac/file/FileUser.java (original)
+++ incubator/lenya/trunk/src/java/org/apache/lenya/ac/file/FileUser.java Thu Sep 16 07:20:12 2004
@@ -28,15 +28,12 @@
import org.apache.lenya.ac.Item;
import org.apache.lenya.ac.impl.AbstractUser;
import org.apache.lenya.ac.impl.ItemConfiguration;
-import org.apache.log4j.Category;
/**
* File-based user implementation.
* @version $Id$
*/
public class FileUser extends AbstractUser implements Item {
-
- private Category log = Category.getInstance(FileUser.class);
protected static final String ID = "identity";
protected static final String EMAIL = "email";
@@ -53,7 +50,7 @@
/**
* Create a FileUser
- *
+ *
* @param configurationDirectory where the user will be attached to
* @param id the user id
* @param fullName the full name of the user
@@ -61,14 +58,14 @@
* @param password the users password
*/
public FileUser(File configurationDirectory, String id, String fullName, String email,
- String password) {
+ String password) {
super(id, fullName, email, password);
setConfigurationDirectory(configurationDirectory);
}
/**
* Configure this FileUser.
- *
+ *
* @param config where the user details are specified
* @throws ConfigurationException if the necessary details aren't specified in the config
*/
@@ -86,11 +83,11 @@
FileGroupManager manager = null;
try {
- manager = FileGroupManager.instance(configurationDirectory);
+ manager = FileGroupManager.instance(configurationDirectory, getLogger());
} catch (AccessControlException e) {
throw new ConfigurationException(
- "Exception when trying to fetch GroupManager for directory: [" +
- configurationDirectory + "]", e);
+ "Exception when trying to fetch GroupManager for directory: ["
+ + configurationDirectory + "]", e);
}
for (int i = 0; i < groups.length; i++) {
@@ -98,9 +95,10 @@
Group group = manager.getGroup(groupId);
if (group == null) {
- throw new ConfigurationException("Couldn't find Group for group name [" + groupId + "]");
+ throw new ConfigurationException("Couldn't find Group for group name ["
+ + groupId + "]");
}
-
+
if (!group.contains(this)) {
group.add(this);
}
@@ -108,16 +106,13 @@
}
} else {
// strange, it should have groups
- log.error("User " + getId() +
- " doesn't seem to have any groups");
+ getLogger().error("User " + getId() + " doesn't seem to have any groups");
}
}
-
/**
- * Create a configuration from the current user details. Can
- * be used for saving.
- *
+ * Create a configuration from the current user details. Can be used for saving.
+ *
* @return a <code>Configuration</code>
*/
protected Configuration createConfiguration() {
@@ -173,7 +168,7 @@
super.delete();
getFile().delete();
}
-
+
/**
* Returns the configuration file.
* @return A file object.
@@ -201,5 +196,5 @@
assert (configurationDirectory != null) && configurationDirectory.isDirectory();
this.configurationDirectory = configurationDirectory;
}
-
-}
+
+}
\ No newline at end of file
Modified: incubator/lenya/trunk/src/java/org/apache/lenya/ac/file/FileUserManager.java
==============================================================================
--- incubator/lenya/trunk/src/java/org/apache/lenya/ac/file/FileUserManager.java (original)
+++ incubator/lenya/trunk/src/java/org/apache/lenya/ac/file/FileUserManager.java Thu Sep 16 07:20:12 2004
@@ -24,6 +24,7 @@
import java.util.Map;
import java.util.Set;
+import org.apache.avalon.framework.logger.Logger;
import org.apache.lenya.ac.AccessControlException;
import org.apache.lenya.ac.Item;
import org.apache.lenya.ac.User;
@@ -42,13 +43,11 @@
/**
* Create a UserManager
*
- * @param configurationDirectory for which the UserManager should be instanciated.
* @param userTypes The supported user types.
* @throws AccessControlException if the UserManager could not be instantiated.
*/
- protected FileUserManager(File configurationDirectory, UserType[] userTypes)
+ private FileUserManager(UserType[] userTypes)
throws AccessControlException {
- super(configurationDirectory);
this.userTypes = new HashSet(Arrays.asList(userTypes));
}
@@ -57,10 +56,11 @@
*
* @param configurationDirectory a directory
* @param userTypes The supported user types.
+ * @param logger The logger.
* @return an <code>UserManager</code> value
* @exception AccessControlException if an error occurs
*/
- public static FileUserManager instance(File configurationDirectory, UserType[] userTypes)
+ public static FileUserManager instance(File configurationDirectory, UserType[] userTypes, Logger logger)
throws AccessControlException {
assert configurationDirectory != null;
@@ -70,8 +70,10 @@
}
if (!instances.containsKey(configurationDirectory)) {
- instances.put(configurationDirectory, new FileUserManager(configurationDirectory,
- userTypes));
+ FileUserManager manager = new FileUserManager(userTypes);
+ manager.enableLogging(logger);
+ manager.configure(configurationDirectory);
+ instances.put(configurationDirectory, manager);
}
return (FileUserManager) instances.get(configurationDirectory);
Modified: incubator/lenya/trunk/src/java/org/apache/lenya/ac/impl/AbstractGroup.java
==============================================================================
--- incubator/lenya/trunk/src/java/org/apache/lenya/ac/impl/AbstractGroup.java (original)
+++ incubator/lenya/trunk/src/java/org/apache/lenya/ac/impl/AbstractGroup.java Thu Sep 16 07:20:12 2004
@@ -15,7 +15,7 @@
*
*/
-/* $Id: AbstractGroup.java,v 1.4 2004/08/16 16:34:06 andreas Exp $ */
+/* $Id$ */
package org.apache.lenya.ac.impl;
@@ -32,6 +32,7 @@
* A group is a set of {@link Groupable}s.
*/
public abstract class AbstractGroup extends AbstractItem implements Accreditable, Group {
+
/**
* Creates a new group.
*/
Modified: incubator/lenya/trunk/src/java/org/apache/lenya/ac/impl/AbstractGroupable.java
==============================================================================
--- incubator/lenya/trunk/src/java/org/apache/lenya/ac/impl/AbstractGroupable.java (original)
+++ incubator/lenya/trunk/src/java/org/apache/lenya/ac/impl/AbstractGroupable.java Thu Sep 16 07:20:12 2004
@@ -27,9 +27,16 @@
/**
* Abstract implementation for group members.
- * @version $Id: AbstractGroupable.java,v 1.3 2004/08/16 16:34:06 andreas Exp $
+ * @version $Id$
*/
public abstract class AbstractGroupable extends AbstractItem implements Groupable, Accreditable {
+
+ /**
+ * Ctor.
+ */
+ public AbstractGroupable() {
+ }
+
private Set groups = new HashSet();
/**
Modified: incubator/lenya/trunk/src/java/org/apache/lenya/ac/impl/AbstractIPRange.java
==============================================================================
--- incubator/lenya/trunk/src/java/org/apache/lenya/ac/impl/AbstractIPRange.java (original)
+++ incubator/lenya/trunk/src/java/org/apache/lenya/ac/impl/AbstractIPRange.java Thu Sep 16 07:20:12 2004
@@ -15,7 +15,7 @@
*
*/
-/* $Id: AbstractIPRange.java,v 1.7 2004/08/16 16:34:06 andreas Exp $ */
+/* $Id$ */
package org.apache.lenya.ac.impl;
@@ -28,7 +28,6 @@
import org.apache.lenya.ac.IPRange;
import org.apache.lenya.ac.Machine;
import org.apache.lenya.net.InetAddressUtil;
-import org.apache.log4j.Category;
/**
* <p>
@@ -62,15 +61,10 @@
* when setting these. (Once the above problems have been fixed. ;-)
* - Especially for IPv6 it would be nice to have the possibility to specify the netmask as the
* number of bits (as in "::1/128" or "127.0.0.1/24").
- * - I think, that logging should probably work the "Cocoon-Way", as explained in
- * <http://wiki.cocoondev.org/Wiki.jsp?page=JavaLogging>, rather than using
- * org.apache.log4j.Category. (But I may be wrong. ;-)
*
* FIXME II (from the previous version): why are we in the business of implementing IP ranges??
*/
- private static final Category log = Category.getInstance(AbstractIPRange.class);
-
/**
* Initializes the the IP range with the local host (127.0.0.1/24 for IPv4, ::1/128 for IPv6).
*/
@@ -104,10 +98,6 @@
* @param id The IP range ID.
*/
public AbstractIPRange(String id) {
- /*
- * FIXME? by zisch@dals.ch: Is it safe not to call the default constructor and just leave
- * the IPRange uninitialized!?
- */
setId(id);
}
@@ -246,8 +236,8 @@
*
* FIXME: This "algorithm" is rather unelegant. There should be a better way to do it! ;-)
*/
- if (log.isDebugEnabled()) {
- log.debug("CHECK_NETMASK: check " + addr2string(mask));
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("CHECK_NETMASK: check " + addr2string(mask));
}
int i = 0;
CHECK_NETMASK: while (i < mask.length) {
@@ -255,8 +245,8 @@
/* the initial byte(s) must be 255: */
if (b != 0xff) {
/* first byte != 255, test all possibilities: */
- if (log.isDebugEnabled()) {
- log.debug("CHECK_NETMASK: first byte != 255: idx: " + (i - 1)
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("CHECK_NETMASK: first byte != 255: idx: " + (i - 1)
+ ", mask[idx]: 0x" + b);
}
/* check if 0: */
@@ -264,7 +254,7 @@
break CHECK_NETMASK;
}
for (int tst = 0xfe; tst != 0; tst = (tst << 1) & 0xff) {
- log.debug("CHECK_NETMASK: tst == 0x" + Integer.toHexString(tst));
+ getLogger().debug("CHECK_NETMASK: tst == 0x" + Integer.toHexString(tst));
if (b == tst) {
break CHECK_NETMASK;
}
@@ -349,7 +339,7 @@
* the localhost (see the javdoc comment above)? (I'm not a TCP/IP-guru, so I'm not sure
* about this. ;-)
*/
- log.debug("Checking IP range: [" + getId() + "]");
+ getLogger().debug("Checking IP range: [" + getId() + "]");
return InetAddressUtil.contains(networkAddress, subnetMask, machine.getAddress());
}
Modified: incubator/lenya/trunk/src/java/org/apache/lenya/ac/impl/AbstractItem.java
==============================================================================
--- incubator/lenya/trunk/src/java/org/apache/lenya/ac/impl/AbstractItem.java (original)
+++ incubator/lenya/trunk/src/java/org/apache/lenya/ac/impl/AbstractItem.java Thu Sep 16 07:20:12 2004
@@ -17,14 +17,15 @@
package org.apache.lenya.ac.impl;
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.lenya.ac.Item;
/**
* Abstract superclass for all access control objects that can be managed by an
* {@link org.apache.lenya.ac.ItemManager}. It is only used for code reuse.
- * @version $Id: AbstractItem.java,v 1.3 2004/08/16 16:34:06 andreas Exp $
+ * @version $Id$
*/
-public abstract class AbstractItem implements Item {
+public abstract class AbstractItem extends AbstractLogEnabled implements Item {
private String id;
private String description = "";
Modified: incubator/lenya/trunk/src/java/org/apache/lenya/ac/impl/AbstractRole.java
==============================================================================
--- incubator/lenya/trunk/src/java/org/apache/lenya/ac/impl/AbstractRole.java (original)
+++ incubator/lenya/trunk/src/java/org/apache/lenya/ac/impl/AbstractRole.java Thu Sep 16 07:20:12 2004
@@ -15,10 +15,11 @@
*
*/
-/* $Id: AbstractRole.java,v 1.3 2004/03/03 12:56:33 gregor Exp $ */
+/* $Id$ */
package org.apache.lenya.ac.impl;
+import org.apache.avalon.framework.logger.Logger;
import org.apache.lenya.ac.Role;
@@ -26,6 +27,7 @@
* A Role embodies the privilege to do certain things.
*/
public abstract class AbstractRole extends AbstractItem implements Role {
+
/**
* Creates a new instance of Role.
*/
@@ -35,8 +37,9 @@
/**
* Creates a new instance of Role.
* @param name The role name.
+ * @param logger The logger.
*/
- public AbstractRole(String name) {
+ public AbstractRole(String name, Logger logger) {
assert name != null;
setName(name);
}
Modified: incubator/lenya/trunk/src/java/org/apache/lenya/ac/impl/AbstractUser.java
==============================================================================
--- incubator/lenya/trunk/src/java/org/apache/lenya/ac/impl/AbstractUser.java (original)
+++ incubator/lenya/trunk/src/java/org/apache/lenya/ac/impl/AbstractUser.java Thu Sep 16 07:20:12 2004
@@ -20,18 +20,16 @@
import org.apache.lenya.ac.AccessControlException;
import org.apache.lenya.ac.Password;
import org.apache.lenya.ac.User;
-import org.apache.log4j.Category;
/**
* Abstract user implementation.
- * @version $Id: AbstractUser.java,v 1.4 2004/08/16 16:34:06 andreas Exp $
+ * @version $Id$
*/
public abstract class AbstractUser extends AbstractGroupable implements User {
- private static Category log = Category.getInstance(AbstractUser.class);
private String email;
private String encryptedPassword;
-
+
/**
* Creates a new User.
*/
@@ -39,13 +37,13 @@
}
/**
- * Create a User instance
- *
- * @param id the user id
- * @param fullName the full name of the user
- * @param email the users email address
- * @param password the users password
- */
+ * Create a User instance
+ *
+ * @param id the user id
+ * @param fullName the full name of the user
+ * @param email the users email address
+ * @param password the users password
+ */
public AbstractUser(String id, String fullName, String email, String password) {
setId(id);
setName(fullName);
@@ -55,7 +53,7 @@
/**
* Get the email address
- *
+ *
* @return a <code>String</code>
*/
public String getEmail() {
@@ -64,7 +62,7 @@
/**
* Get the full name
- *
+ *
* @return a <code>String</code>
* @deprecated has been superceded by getName()
*/
@@ -74,7 +72,7 @@
/**
* Set the email address
- *
+ *
* @param email the new email address
*/
public void setEmail(String email) {
@@ -83,7 +81,7 @@
/**
* Set the full name
- *
+ *
* @param name the new full name
* @deprecated has been superceded by setName(String)
*/
@@ -92,7 +90,7 @@
}
/**
- * Sets the password.
+ * Sets the password.
* @param plainTextPassword The plain text passwrod.
*/
public void setPassword(String plainTextPassword) {
@@ -100,10 +98,9 @@
}
/**
- * This method can be used for subclasses to set the password without it
- * being encrypted again. Some subclass might have knowledge of the encrypted
- * password and needs to be able to set it.
- *
+ * This method can be used for subclasses to set the password without it being encrypted again.
+ * Some subclass might have knowledge of the encrypted password and needs to be able to set it.
+ *
* @param encryptedPassword the encrypted password
*/
protected void setEncryptedPassword(String encryptedPassword) {
@@ -112,7 +109,7 @@
/**
* Get the encrypted password
- *
+ *
* @return the encrypted password
*/
protected String getEncryptedPassword() {
@@ -121,14 +118,14 @@
/**
* Save the user
- *
+ *
* @throws AccessControlException if the save failed
*/
public abstract void save() throws AccessControlException;
/**
* Delete a user
- *
+ *
* @throws AccessControlException if the delete failed
*/
public void delete() throws AccessControlException {
@@ -136,19 +133,18 @@
}
/**
- * Authenticate a user. This is done by encrypting
- * the given password and comparing this to the
+ * Authenticate a user. This is done by encrypting the given password and comparing this to the
* encryptedPassword.
- *
+ *
* @param password to authenticate with
* @return true if the given password matches the password for this user
*/
public boolean authenticate(String password) {
- log.debug("Password: " + password);
- log.debug("pw encypted: " + Password.encrypt(password));
- log.debug("orig encrypted pw: " + this.encryptedPassword);
+ getLogger().debug("LDAP Password: " + password);
+ getLogger().debug("LDAP pw encypted: " + Password.encrypt(password));
+ getLogger().debug("LDAP orig encrypted pw: " + this.encryptedPassword);
return this.encryptedPassword.equals(Password.encrypt(password));
}
-
-}
+
+}
\ No newline at end of file
Modified: incubator/lenya/trunk/src/java/org/apache/lenya/ac/impl/DefaultAccessController.java
==============================================================================
--- incubator/lenya/trunk/src/java/org/apache/lenya/ac/impl/DefaultAccessController.java (original)
+++ incubator/lenya/trunk/src/java/org/apache/lenya/ac/impl/DefaultAccessController.java Thu Sep 16 07:20:12 2004
@@ -53,7 +53,7 @@
/**
* Default access controller implementation.
- * @version $Id: DefaultAccessController.java,v 1.9 2004/08/16 16:34:06 andreas Exp $
+ * @version $Id$
*/
public class DefaultAccessController extends AbstractLogEnabled implements AccessController,
Configurable, Serviceable, Disposable, ItemManagerListener {
@@ -388,6 +388,8 @@
Session session = request.getSession(true);
if (!hasValidIdentity(session)) {
Identity identity = new Identity();
+ identity.enableLogging(getLogger());
+ identity.initialize();
String remoteAddress = request.getRemoteAddr();
String clientAddress = request.getHeader("x-forwarded-for");
Modified: incubator/lenya/trunk/src/java/org/apache/lenya/ac/ldap/LDAPUser.java
==============================================================================
--- incubator/lenya/trunk/src/java/org/apache/lenya/ac/ldap/LDAPUser.java (original)
+++ incubator/lenya/trunk/src/java/org/apache/lenya/ac/ldap/LDAPUser.java Thu Sep 16 07:20:12 2004
@@ -35,7 +35,6 @@
import org.apache.avalon.framework.configuration.DefaultConfiguration;
import org.apache.lenya.ac.AccessControlException;
import org.apache.lenya.ac.file.FileUser;
-import org.apache.log4j.Category;
import com.sun.jndi.ldap.LdapCtxFactory;
@@ -45,7 +44,6 @@
*/
public class LDAPUser extends FileUser {
private static Properties defaultProperties = null;
- private static Category log = Category.getInstance(LDAPUser.class);
protected static final String LDAP_ID = "ldapid";
private static String PROVIDER_URL = "provider-url";
@@ -74,7 +72,7 @@
}
/**
- * Create an LDAPUser
+ * Create an LDAPUser.
*
* @param configurationDirectory where the user will be attached to
* @param id user id of LDAPUser
@@ -226,8 +224,8 @@
+ defaultProperties.getProperty(PARTIAL_USER_DN);
Context ctx = null;
- if (log.isDebugEnabled()) {
- log.debug("Authenticating with principal [" + principal + "]");
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Authenticating with principal [" + principal + "]");
}
boolean authenticated = false;
@@ -236,15 +234,15 @@
ctx = bind(principal, password);
authenticated = true;
close(ctx);
- if (log.isDebugEnabled()) {
- log.debug("Context closed.");
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Context closed.");
}
} catch (NamingException e) {
// log this failure
// StringWriter writer = new StringWriter();
// e.printStackTrace(new PrintWriter(writer));
- if (log.isInfoEnabled()) {
- log.info("Bind for user " + principal + " to Ldap server failed: ", e);
+ if (getLogger().isInfoEnabled()) {
+ getLogger().info("Bind for user " + principal + " to Ldap server failed: ", e);
}
}
@@ -298,7 +296,7 @@
*/
private LdapContext bind(String principal, String credentials) throws NamingException {
- log.info("Binding principal: [" + principal + "]");
+ getLogger().info("Binding principal: [" + principal + "]");
Hashtable env = new Hashtable();
@@ -316,7 +314,7 @@
LdapContext ctx = new InitialLdapContext(env, null);
- log.info("Finished binding principal.");
+ getLogger().info("Finished binding principal.");
return ctx;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: lenya-cvs-unsubscribe@cocoon.apache.org
For additional commands, e-mail: lenya-cvs-help@cocoon.apache.org