From 621d9e5c413e561293d7484b93882d985b3fe15f Mon Sep 17 00:00:00 2001 From: Endi Sukma Dewata Date: Sat, 24 Mar 2012 02:27:47 -0500 Subject: Removed unnecessary pki folder. Previously the source code was located inside a pki folder. This folder was created during svn migration and is no longer needed. This folder has now been removed and the contents have been moved up one level. Ticket #131 --- .../src/com/netscape/certsrv/base/ASubsystem.java | 70 +++++ .../netscape/certsrv/base/AttributeNameHelper.java | 68 +++++ .../com/netscape/certsrv/base/BaseResources.java | 45 ++++ .../com/netscape/certsrv/base/EBaseException.java | 159 +++++++++++ .../netscape/certsrv/base/EPropertyNotDefined.java | 46 ++++ .../netscape/certsrv/base/EPropertyNotFound.java | 46 ++++ .../netscape/certsrv/base/ExtendedPluginInfo.java | 88 ++++++ .../src/com/netscape/certsrv/base/IArgBlock.java | 283 ++++++++++++++++++++ .../src/com/netscape/certsrv/base/IAttrSet.java | 70 +++++ .../src/com/netscape/certsrv/base/IAuthInfo.java | 31 +++ .../com/netscape/certsrv/base/ICRLPrettyPrint.java | 48 ++++ .../netscape/certsrv/base/ICertPrettyPrint.java | 38 +++ .../com/netscape/certsrv/base/IConfigStore.java | 297 +++++++++++++++++++++ .../certsrv/base/IConfigStoreEventListener.java | 48 ++++ .../com/netscape/certsrv/base/IExtPrettyPrint.java | 34 +++ .../netscape/certsrv/base/IExtendedPluginInfo.java | 79 ++++++ .../src/com/netscape/certsrv/base/IPluginImpl.java | 104 ++++++++ .../netscape/certsrv/base/IPrettyPrintFormat.java | 66 +++++ .../certsrv/base/ISecurityDomainSessionTable.java | 48 ++++ .../netscape/certsrv/base/ISourceConfigStore.java | 81 ++++++ .../src/com/netscape/certsrv/base/ISubsystem.java | 78 ++++++ .../netscape/certsrv/base/ISubsystemSource.java | 36 +++ .../src/com/netscape/certsrv/base/ITimeSource.java | 41 +++ .../src/com/netscape/certsrv/base/KeyGenInfo.java | 229 ++++++++++++++++ .../netscape/certsrv/base/MessageFormatter.java | 155 +++++++++++ .../netscape/certsrv/base/MetaAttributeDef.java | 198 ++++++++++++++ .../src/com/netscape/certsrv/base/MetaInfo.java | 115 ++++++++ .../src/com/netscape/certsrv/base/Nonces.java | 123 +++++++++ .../netscape/certsrv/base/PasswordResources.java | 42 +++ .../src/com/netscape/certsrv/base/Plugin.java | 59 ++++ .../com/netscape/certsrv/base/SessionContext.java | 166 ++++++++++++ 31 files changed, 2991 insertions(+) create mode 100644 base/common/src/com/netscape/certsrv/base/ASubsystem.java create mode 100644 base/common/src/com/netscape/certsrv/base/AttributeNameHelper.java create mode 100644 base/common/src/com/netscape/certsrv/base/BaseResources.java create mode 100644 base/common/src/com/netscape/certsrv/base/EBaseException.java create mode 100644 base/common/src/com/netscape/certsrv/base/EPropertyNotDefined.java create mode 100644 base/common/src/com/netscape/certsrv/base/EPropertyNotFound.java create mode 100644 base/common/src/com/netscape/certsrv/base/ExtendedPluginInfo.java create mode 100644 base/common/src/com/netscape/certsrv/base/IArgBlock.java create mode 100644 base/common/src/com/netscape/certsrv/base/IAttrSet.java create mode 100644 base/common/src/com/netscape/certsrv/base/IAuthInfo.java create mode 100644 base/common/src/com/netscape/certsrv/base/ICRLPrettyPrint.java create mode 100644 base/common/src/com/netscape/certsrv/base/ICertPrettyPrint.java create mode 100644 base/common/src/com/netscape/certsrv/base/IConfigStore.java create mode 100644 base/common/src/com/netscape/certsrv/base/IConfigStoreEventListener.java create mode 100644 base/common/src/com/netscape/certsrv/base/IExtPrettyPrint.java create mode 100644 base/common/src/com/netscape/certsrv/base/IExtendedPluginInfo.java create mode 100644 base/common/src/com/netscape/certsrv/base/IPluginImpl.java create mode 100644 base/common/src/com/netscape/certsrv/base/IPrettyPrintFormat.java create mode 100644 base/common/src/com/netscape/certsrv/base/ISecurityDomainSessionTable.java create mode 100644 base/common/src/com/netscape/certsrv/base/ISourceConfigStore.java create mode 100644 base/common/src/com/netscape/certsrv/base/ISubsystem.java create mode 100644 base/common/src/com/netscape/certsrv/base/ISubsystemSource.java create mode 100644 base/common/src/com/netscape/certsrv/base/ITimeSource.java create mode 100644 base/common/src/com/netscape/certsrv/base/KeyGenInfo.java create mode 100644 base/common/src/com/netscape/certsrv/base/MessageFormatter.java create mode 100644 base/common/src/com/netscape/certsrv/base/MetaAttributeDef.java create mode 100644 base/common/src/com/netscape/certsrv/base/MetaInfo.java create mode 100644 base/common/src/com/netscape/certsrv/base/Nonces.java create mode 100644 base/common/src/com/netscape/certsrv/base/PasswordResources.java create mode 100644 base/common/src/com/netscape/certsrv/base/Plugin.java create mode 100644 base/common/src/com/netscape/certsrv/base/SessionContext.java (limited to 'base/common/src/com/netscape/certsrv/base') diff --git a/base/common/src/com/netscape/certsrv/base/ASubsystem.java b/base/common/src/com/netscape/certsrv/base/ASubsystem.java new file mode 100644 index 000000000..2b4c6d15a --- /dev/null +++ b/base/common/src/com/netscape/certsrv/base/ASubsystem.java @@ -0,0 +1,70 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.certsrv.base; + +/** + * This class represents a basic subsystem. Each basic + * subsystem is named with an identifier and has a + * configuration store. + * + * @version $Revision$, $Date$ + */ +public abstract class ASubsystem implements ISubsystem { + + private ISubsystem mParent; + private IConfigStore mCfg; + private String mId; + + /** + * Initializes this subsystem. + * + * @param parent parent subsystem + * @param cfg configuration store + */ + public void init(ISubsystem parent, IConfigStore cfg) { + mParent = parent; + mCfg = cfg; + } + + /** + * Retrieves the configuration store. + * + * @return configuration store + */ + public IConfigStore getConfigStore() { + return mCfg; + } + + /** + * Sets the identifier of this subsystem. + * + * @param id subsystem identifier + */ + public void setId(String id) { + mId = id; + } + + /** + * Retrieves the subsystem identifier. + * + * @return subsystem identifier + */ + public String getId() { + return mId; + } +} diff --git a/base/common/src/com/netscape/certsrv/base/AttributeNameHelper.java b/base/common/src/com/netscape/certsrv/base/AttributeNameHelper.java new file mode 100644 index 000000000..5b6db131e --- /dev/null +++ b/base/common/src/com/netscape/certsrv/base/AttributeNameHelper.java @@ -0,0 +1,68 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.certsrv.base; + +/** + * AttributeNameHelper. This Helper class used to decompose + * dot-separated attribute name into prefix and suffix. + * + * @version $Revision$, $Date$ + */ +public class AttributeNameHelper { + // Public members + private static final char SEPARATOR = '.'; + + // Private data members + private String prefix = null; + private String suffix = null; + + /** + * Default constructor for the class. Name is of the form + * "proofOfPosession.type". + * + * @param name the attribute name. + */ + public AttributeNameHelper(String name) { + int i = name.indexOf(SEPARATOR); + + if (i == (-1)) { + prefix = name; + } else { + prefix = name.substring(0, i); + suffix = name.substring(i + 1); + } + } + + /** + * Return the prefix of the name. + * + * @return attribute prefix + */ + public String getPrefix() { + return (prefix); + } + + /** + * Return the suffix of the name. + * + * @return attribute suffix + */ + public String getSuffix() { + return (suffix); + } +} diff --git a/base/common/src/com/netscape/certsrv/base/BaseResources.java b/base/common/src/com/netscape/certsrv/base/BaseResources.java new file mode 100644 index 000000000..41159481f --- /dev/null +++ b/base/common/src/com/netscape/certsrv/base/BaseResources.java @@ -0,0 +1,45 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.certsrv.base; + +import java.util.ListResourceBundle; + +/** + * A class represents a resource bundle for the entire + * system. + *

+ * + * @version $Revision$, $Date$ + * @see java.util.ListResourceBundle + */ +public class BaseResources extends ListResourceBundle { + + /** + * Returns the content of this resource. + */ + public Object[][] getContents() { + return contents; + } + + /* + * Constants. The suffix represents the number of + * possible parameters. + */ + + static final Object[][] contents = {}; +} diff --git a/base/common/src/com/netscape/certsrv/base/EBaseException.java b/base/common/src/com/netscape/certsrv/base/EBaseException.java new file mode 100644 index 000000000..26def60f5 --- /dev/null +++ b/base/common/src/com/netscape/certsrv/base/EBaseException.java @@ -0,0 +1,159 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.certsrv.base; + +import java.util.Locale; + +/** + * An exception with localizable error messages. It is the + * base class for all exceptions in certificate server. + *

+ * + * @version $Revision$, $Date$ + * @see java.text.MessageFormat + * @see com.netscape.certsrv.base.BaseResources + */ +public class EBaseException extends Exception { + + /** + * + */ + private static final long serialVersionUID = 8213021692117483973L; + + /** + * The resource bundle to use for error messages. + * Subclasses can override to use its own resource bundle. + */ + private static final String BASE_RESOURCES = BaseResources.class.getName(); + + /** + * Parameters to the exception error message. + */ + public Object mParams[] = null; + + /** + * Constructs an instance of this exception with the given resource key. + * If resource key is not found in the resource bundle, the resource key + * specified is used as the error message. + * + *

+     * new EBaseException(BaseResources.PERMISSION_DENIED);
+     * new EBaseException("An plain error message");
+     * 

+ * @param msgFormat The error message resource key. + */ + public EBaseException(String msgFormat) { + super(msgFormat); + mParams = null; + } + + /** + * Constructs an instance of this exception with the given resource key + * and a parameter as a string. + * + *

+     * new EBaseException(BaseResource.NO_CONFIG_FILE, fileName);
+     * 
+ *

+ * + * @param msgFormat exception details in message string format + * @param param message string parameter + */ + public EBaseException(String msgFormat, String param) { + super(msgFormat); + mParams = new String[1]; + mParams[0] = param; + } + + /** + * Constructs an instance of the exception given the resource key and + * a exception parameter. + * + *

+     * 		try {
+     *  		...
+     * 		} catch (IOExeption e) {
+     * 		 	throw new EBaseException(BaseResources.INTERNAL_ERROR_1, e);
+     *      }
+     * 
+ *

+ * + * @param msgFormat The resource key + * @param param The parameter as an exception + */ + public EBaseException(String msgFormat, Exception param) { + super(msgFormat); + mParams = new Exception[1]; + mParams[0] = param; + } + + /** + * Constructs an instance of this exception given the resource key and + * an array of parameters. + *

+ * + * @param msgFormat The resource key + * @param params Array of params + */ + public EBaseException(String msgFormat, Object params[]) { + super(msgFormat); + mParams = params; + } + + /** + * Returns the list of parameters. + *

+ * + * @return List of parameters. + */ + public Object[] getParameters() { + return mParams; + } + + /** + * Returns the exception string in the default locale. + *

+ * + * @return The exception string in the default locale. + */ + public String toString() { + return toString(Locale.getDefault()); + } + + /** + * Returns the exception string in the given locale. + *

+ * + * @param locale The locale + * @return The exception string in the given locale. + */ + public String toString(Locale locale) { + return MessageFormatter.getLocalizedString(locale, getBundleName(), + super.getMessage(), mParams); + } + + /** + * Returns the given resource bundle name. + * + * @return the name of the resource bundle for this class. + */ + protected String getBundleName() { + return BASE_RESOURCES; + } + +} diff --git a/base/common/src/com/netscape/certsrv/base/EPropertyNotDefined.java b/base/common/src/com/netscape/certsrv/base/EPropertyNotDefined.java new file mode 100644 index 000000000..466306582 --- /dev/null +++ b/base/common/src/com/netscape/certsrv/base/EPropertyNotDefined.java @@ -0,0 +1,46 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.certsrv.base; + +/** + * This class represents an exception thrown when a + * property is not defined (empty string) the configuration store. + * It extends EBaseException and uses the same resource bundle. + *

+ * + * @version $Revision$, $Date$ + * @see com.netscape.certsrv.base.EBaseException + */ +public class EPropertyNotDefined extends EBaseException { + + /** + * + */ + private static final long serialVersionUID = -7986464387187170352L; + + /** + * Constructs an instance of this exception given the name of the + * property that's not found. + *

+ * + * @param errorString Detailed error message. + */ + public EPropertyNotDefined(String errorString) { + super(errorString); + } +} diff --git a/base/common/src/com/netscape/certsrv/base/EPropertyNotFound.java b/base/common/src/com/netscape/certsrv/base/EPropertyNotFound.java new file mode 100644 index 000000000..5a8a9550f --- /dev/null +++ b/base/common/src/com/netscape/certsrv/base/EPropertyNotFound.java @@ -0,0 +1,46 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.certsrv.base; + +/** + * This class represents an exception thrown when a + * property is not found in the configuration store. + * It extends EBaseException and uses the same resource bundle. + *

+ * + * @version $Revision$, $Date$ + * @see com.netscape.certsrv.base.EBaseException + */ +public class EPropertyNotFound extends EBaseException { + + /** + * + */ + private static final long serialVersionUID = 2701966082697733003L; + + /** + * Constructs an instance of this exception given the name of the + * property that's not found. + *

+ * + * @param errorString Detailed error message. + */ + public EPropertyNotFound(String errorString) { + super(errorString); + } +} diff --git a/base/common/src/com/netscape/certsrv/base/ExtendedPluginInfo.java b/base/common/src/com/netscape/certsrv/base/ExtendedPluginInfo.java new file mode 100644 index 000000000..86f5999d9 --- /dev/null +++ b/base/common/src/com/netscape/certsrv/base/ExtendedPluginInfo.java @@ -0,0 +1,88 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.certsrv.base; + +import java.util.Locale; + +/** + * Plugin which can return extended information to console + *

+ * + * @version $Revision$, $Date$ + */ +public class ExtendedPluginInfo implements IExtendedPluginInfo { + + private String _epi[] = null; + + /** + * Constructs an extended plugin info object. + * + * @param epi plugin info list + */ + public ExtendedPluginInfo(String epi[]) { + _epi = epi; + } + + /** + * This method returns an array of strings. Each element of the + * array represents a configurable parameter, or some other + * meta-info (such as help-token) + * + * there is an entry indexed on that parameter name + * ;[,required];;... + * + * Where: + * + * type_info is either 'string', 'number', 'boolean', 'password' or + * 'choice(ch1,ch2,ch3,...)' + * + * If the marker 'required' is included after the type_info, + * the parameter will has some visually distinctive marking in + * the UI. + * + * 'description' is a short sentence describing the parameter + * 'choice' is rendered as a drop-down list. The first parameter in the + * list will be activated by default + * 'boolean' is rendered as a checkbox. The resulting parameter will be + * either 'true' or 'false' + * 'string' allows any characters + * 'number' allows only numbers + * 'password' is rendered as a password field (the characters are replaced + * with *'s when being types. This parameter is not passed through to + * the plugin. It is instead inserted directly into the password cache + * keyed on the instance name. The value of the parameter + * 'bindPWPrompt' (see example below) is set to the key. + * + * In addition to the configurable parameters, the following magic parameters + * may be defined: + * + * HELP_TOKEN;helptoken - a pointer to the online manual section for this plugin + * HELP_TEXT;helptext - a general help string describing the plugin + * + * For example: + * "username;string;The username you wish to login as" + * "bindPWPrompt;password;Enter password to bind as above user with" + * "algorithm;choice(RSA,DSA);Which algorithm do you want to use" + * "enable;boolean;Do you want to run this plugin" + * "port;number;Which port number do you want to use" + * + */ + public String[] getExtendedPluginInfo(Locale locale) { + return _epi; + } +} diff --git a/base/common/src/com/netscape/certsrv/base/IArgBlock.java b/base/common/src/com/netscape/certsrv/base/IArgBlock.java new file mode 100644 index 000000000..adddccba6 --- /dev/null +++ b/base/common/src/com/netscape/certsrv/base/IArgBlock.java @@ -0,0 +1,283 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.certsrv.base; + +import java.io.Serializable; +import java.math.BigInteger; +import java.util.Enumeration; + +import netscape.security.pkcs.PKCS10; + +/** + * This interface defines the abstraction for the generic collection + * of attributes indexed by string names. + * Set of cooperating implementations of this interface may exploit + * dot-separated attribute names to provide seamless access to the + * attributes of attribute value which also implements AttrSet + * interface as if it was direct attribute of the container + * E.g., ((AttrSet)container.get("x")).get("y") is equivalent to + * container.get("x.y"); + *

+ * + * @version $Revision$, $Date$ + **/ +public interface IArgBlock extends Serializable { + + /** + * Checks if this argument block contains the given key. + * + * @param n key + * @return true if key is present + */ + public boolean isValuePresent(String n); + + /** + * Adds string-based value into this argument block. + * + * @param n key + * @param v value + * @return value + */ + public Object addStringValue(String n, String v); + + /** + * Retrieves argument value as string. + * + * @param n key + * @return argument value as string + * @exception EBaseException failed to retrieve value + */ + public String getValueAsString(String n) throws EBaseException; + + /** + * Retrieves argument value as string. + * + * @param n key + * @param def default value to be returned if key is not present + * @return argument value as string + */ + public String getValueAsString(String n, String def); + + /** + * Retrieves argument value as integer. + * + * @param n key + * @return argument value as int + * @exception EBaseException failed to retrieve value + */ + public int getValueAsInt(String n) throws EBaseException; + + /** + * Retrieves argument value as integer. + * + * @param n key + * @param def default value to be returned if key is not present + * @return argument value as int + */ + public int getValueAsInt(String n, int def); + + /** + * Retrieves argument value as big integer. + * + * @param n key + * @return argument value as big integer + * @exception EBaseException failed to retrieve value + */ + public BigInteger getValueAsBigInteger(String n) throws EBaseException; + + /** + * Retrieves argument value as big integer. + * + * @param n key + * @param def default value to be returned if key is not present + * @return argument value as big integer + */ + public BigInteger getValueAsBigInteger(String n, BigInteger def); + + /** + * Retrieves argument value as object + * + * @param n key + * @return argument value as object + * @exception EBaseException failed to retrieve value + */ + public Object getValue(Object n) throws EBaseException; + + /** + * Retrieves argument value as object + * + * @param n key + * @param def default value to be returned if key is not present + * @return argument value as object + */ + public Object getValue(Object n, Object def); + + /** + * Gets boolean value. They should be "true" or "false". + * + * @param name name of the input type + * @return boolean type: true or false + * @exception EBaseException failed to retrieve value + */ + public boolean getValueAsBoolean(String name) throws EBaseException; + + /** + * Gets boolean value. They should be "true" or "false". + * + * @param name name of the input type + * @param def Default value to return. + * @return boolean type: true or false + */ + public boolean getValueAsBoolean(String name, boolean def); + + /** + * Gets KeyGenInfo + * + * @param name name of the input type + * @param def default value to return + * @exception EBaseException On error. + * @return KeyGenInfo object + */ + public KeyGenInfo getValueAsKeyGenInfo(String name, KeyGenInfo def) throws EBaseException; + + /** + * Gets PKCS10 request. This pkcs10 attribute does not + * contain header information. + * + * @param name name of the input type + * @return pkcs10 request + * @exception EBaseException failed to retrieve value + */ + public PKCS10 getValueAsRawPKCS10(String name) throws EBaseException; + + /** + * Gets PKCS10 request. This pkcs10 attribute does not + * contain header information. + * + * @param name name of the input type + * @param def default PKCS10 + * @return pkcs10 request + * @exception EBaseException failed to retrieve value + */ + public PKCS10 getValueAsRawPKCS10(String name, PKCS10 def) throws EBaseException; + + /** + * Retrieves PKCS10 + * + * @param name name of the input type + * @param checkheader true if header must be present + * @return PKCS10 object + * @exception EBaseException failed to retrieve value + */ + public PKCS10 getValueAsPKCS10(String name, boolean checkheader) throws EBaseException; + + /** + * Retrieves PKCS10 + * + * @param name name of the input type + * @param checkheader true if header must be present + * @param def default PKCS10 + * @return PKCS10 object + * @exception EBaseException on error + */ + public PKCS10 getValueAsPKCS10(String name, boolean checkheader, PKCS10 def) throws EBaseException; + + /** + * Retrieves PKCS10 + * + * @param name name of the input type + * @param def default PKCS10 + * @return PKCS10 object + * @exception EBaseException on error + */ + public PKCS10 getValuePKCS10(String name, PKCS10 def) throws EBaseException; + + /** + * Retrieves a list of argument keys. + * + * @return a list of string-based keys + */ + public Enumeration elements(); + + /** + * Adds long-type arguments to this block. + * + * @param n key + * @param v value + * @return value + */ + public Object addLongValue(String n, long v); + + /** + * Adds integer-type arguments to this block. + * + * @param n key + * @param v value + * @return value + */ + public Object addIntegerValue(String n, int v); + + /** + * Adds boolean-type arguments to this block. + * + * @param n key + * @param v value + * @return value + */ + public Object addBooleanValue(String n, boolean v); + + /** + * Adds integer-type arguments to this block. + * + * @param n key + * @param v value + * @param radix radix + * @return value + */ + public Object addBigIntegerValue(String n, BigInteger v, int radix); + + /** + * Sets argument into this block. + * + * @param name key + * @param obj value + */ + public void set(String name, Object obj); + + /** + * Retrieves argument. + * + * @param name key + * @return object value + */ + public Object get(String name); + + /** + * Deletes argument by the given key. + * + * @param name key + */ + public void delete(String name); + + /** + * Retrieves a list of argument keys. + * + * @return a list of string-based keys + */ + public Enumeration getElements(); +} diff --git a/base/common/src/com/netscape/certsrv/base/IAttrSet.java b/base/common/src/com/netscape/certsrv/base/IAttrSet.java new file mode 100644 index 000000000..e396b072a --- /dev/null +++ b/base/common/src/com/netscape/certsrv/base/IAttrSet.java @@ -0,0 +1,70 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.certsrv.base; + +import java.io.Serializable; +import java.util.Enumeration; + +/** + * This interface defines the abstraction for the generic collection + * of attributes indexed by string names. + * Set of cooperating implementations of this interface may exploit + * dot-separated attribute names to provide seamless access to the + * attributes of attribute value which also implements AttrSet + * interface as if it was direct attribute of the container + * E.g., ((AttrSet)container.get("x")).get("y") is equivalent to + * container.get("x.y"); + *

+ * + * @version $Revision$, $Date$ + **/ +public interface IAttrSet extends Serializable { + + /** + * Sets an attribute value within this AttrSet. + * + * @param name the name of the attribute + * @param obj the attribute object. + * @exception EBaseException on attribute handling errors. + */ + public void set(String name, Object obj) throws EBaseException; + + /** + * Gets an attribute value. + * + * @param name the name of the attribute to return. + * @exception EBaseException on attribute handling errors. + */ + public Object get(String name) throws EBaseException; + + /** + * Deletes an attribute value from this AttrSet. + * + * @param name the name of the attribute to delete. + * @exception EBaseException on attribute handling errors. + */ + public void delete(String name) throws EBaseException; + + /** + * Returns an enumeration of the names of the attributes existing within + * this AttrSet. + * + * @return an enumeration of the attribute names. + */ + public Enumeration getElements(); +} diff --git a/base/common/src/com/netscape/certsrv/base/IAuthInfo.java b/base/common/src/com/netscape/certsrv/base/IAuthInfo.java new file mode 100644 index 000000000..4806a94c0 --- /dev/null +++ b/base/common/src/com/netscape/certsrv/base/IAuthInfo.java @@ -0,0 +1,31 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.certsrv.base; + +/** + * An interface represents an authentication context. This + * is an entity that encapsulates the authentication + * information of a service requestor. For example, CMS + * user needs to authenticate to CMS using SSL. The + * client certificate is expressed in authenticated context. + *

+ * + * @version $Revision$, $Date$ + */ +public interface IAuthInfo { +} diff --git a/base/common/src/com/netscape/certsrv/base/ICRLPrettyPrint.java b/base/common/src/com/netscape/certsrv/base/ICRLPrettyPrint.java new file mode 100644 index 000000000..d111063a7 --- /dev/null +++ b/base/common/src/com/netscape/certsrv/base/ICRLPrettyPrint.java @@ -0,0 +1,48 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.certsrv.base; + +import java.util.Locale; + +/** + * This interface represents a CRL pretty print handler. + * It converts a CRL object into a printable CRL string. + * + * @version $Revision$, $Date$ + */ +public interface ICRLPrettyPrint { + + /** + * Retrieves the printable CRL string. + * + * @param clientLocale end user clocale + * @param crlSize CRL size + * @param pageStart starting page number + * @param pageSize page size in rows + * @return printable CRL string + */ + public String toString(Locale clientLocale, long crlSize, long pageStart, long pageSize); + + /** + * Retrieves the printable CRL string. + * + * @param clientLocale end user clocale + * @return printable CRL string + */ + public String toString(Locale clientLocale); +} diff --git a/base/common/src/com/netscape/certsrv/base/ICertPrettyPrint.java b/base/common/src/com/netscape/certsrv/base/ICertPrettyPrint.java new file mode 100644 index 000000000..e991d5a11 --- /dev/null +++ b/base/common/src/com/netscape/certsrv/base/ICertPrettyPrint.java @@ -0,0 +1,38 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.certsrv.base; + +import java.util.Locale; + +/** + * This interface represents a certificate pretty print + * handler. This handler converts certificate object into + * a printable certificate string. + * + * @version $Revision$, $Date$ + */ +public interface ICertPrettyPrint { + + /** + * Returns printable certificate string. + * + * @param clientLocale end user locale + * @return printable certificate string + */ + public String toString(Locale clientLocale); +} diff --git a/base/common/src/com/netscape/certsrv/base/IConfigStore.java b/base/common/src/com/netscape/certsrv/base/IConfigStore.java new file mode 100644 index 000000000..d12265e83 --- /dev/null +++ b/base/common/src/com/netscape/certsrv/base/IConfigStore.java @@ -0,0 +1,297 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.certsrv.base; + +import java.math.BigInteger; +import java.util.Enumeration; + +/** + * An interface represents a configuration store. + * A configuration store is an abstraction of a hierarchical store + * to keep arbitrary data indexed by string names. + *

+ * In the following example: + * + *

+ *      param1=value1
+ *      configStore1.param11=value11
+ *      configStore1.param12=value12
+ *      configStore1.subStore1.param111=value111
+ *      configStore1.subStore1.param112=value112
+ *      configStore2.param21=value21
+ * 
+ * + * The top config store has parameters param1 and sub-stores configStore1 and configStore2.
+ * The following illustrates how a config store is used. + * + *
+ * // the top config store is passed to the following method. 
+ * public void init(IConfigStore config) throws EBaseException {
+ *     IConfigStore store = config;
+ *     String valx = config.getString("param1");
+ *     // valx is "value1" <p>
+ * 
+ *     IConfigStore substore1 = config.getSubstore("configStore1");
+ *     String valy = substore1.getString("param11");
+ *     // valy is "value11" <p>
+ * 
+ *     IConfigStore substore2 = config.getSubstore("configStore2");
+ *     String valz = substore2.getString("param21");
+ *     // valz is "value21" <p>
+ * }
+ * 
+ * + * @version $Revision$, $Date$ + */ +public interface IConfigStore extends ISourceConfigStore { + + /** + * Gets the name of this Configuration Store. + *

+ * + * @return The name of this Configuration store + */ + public String getName(); + + /** + * Retrieves the value of the given property as a string. + *

+ * + * @param name The name of the property to get + * @return The value of the property as a String + * @exception EPropertyNotFound If the property is not present + * @exception EBaseException If an internal error occurred + */ + public String getString(String name) + throws EPropertyNotFound, EBaseException; + + /** + * Retrieves the value of a given property as a string or the + * given default value if the property is not present. + *

+ * + * @param name The property to retrive + * @param defval The default value to return if the property is not present + * @return The roperty value as a string + * @exception EBaseException If an internal error occurred + */ + public String getString(String name, String defval) + throws EBaseException; + + /** + * Stores a property and its value as a string. + *

+ * + * @param name The name of the property + * @param value The value as a string + */ + public void putString(String name, String value); + + /** + * Retrieves the value of a property as a byte array. + *

+ * + * @param name The property name + * @return The property value as a byte array + * @exception EPropertyNotFound If the property is not present + * @exception EBaseException If an internal error occurred + */ + public byte[] getByteArray(String name) + throws EPropertyNotFound, EBaseException; + + /** + * Retrieves the value of a property as a byte array, using the + * given default value if property is not present. + *

+ * + * @param name The name of the property + * @param defval The default value if the property is not present. + * @return The property value as a byte array. + * @exception EBaseException If an internal error occurred + */ + public byte[] getByteArray(String name, byte defval[]) + throws EBaseException; + + /** + * Stores the given property and value as a byte array. + *

+ * + * @param name The property name + * @param value The value as a byte array to store + */ + public void putByteArray(String name, byte value[]); + + /** + * Retrieves the given property as a boolean. + *

+ * + * @param name The name of the property as a string. + * @return The value of the property as a boolean. + * @exception EPropertyNotFound If the property is not present + * @exception EBaseException If an internal error occurred + */ + public boolean getBoolean(String name) + throws EPropertyNotFound, EBaseException; + + /** + * Retrieves the given property as a boolean. + *

+ * + * @param name The name of the property + * @param defval The default value to turn as a boolean if + * property is not present + * @return The value of the property as a boolean. + * @exception EBaseException If an internal error occurred + */ + public boolean getBoolean(String name, boolean defval) + throws EBaseException; + + /** + * Stores the given property and its value as a boolean. + *

+ * + * @param name The property name + * @param value The value as a boolean + */ + public void putBoolean(String name, boolean value); + + /** + * Retrieves the given property as an integer. + *

+ * + * @param name The property name + * @return The property value as an integer + * @exception EPropertyNotFound If property is not found + * @exception EBaseException If an internal error occurred + */ + public int getInteger(String name) + throws EPropertyNotFound, EBaseException; + + /** + * Retrieves the given property as an integer. + *

+ * + * @param name The property name + * @return int The default value to return as an integer + * @exception EBaseException If the value cannot be converted to a + * integer + */ + public int getInteger(String name, int defval) + throws EBaseException; + + /** + * Sets a property and its value as an integer. + *

+ * + * @param name parameter name + * @param value integer value + */ + public void putInteger(String name, int value); + + /** + * Retrieves the given property as a big integer. + *

+ * + * @param name The property name + * @return The property value as a big integer + * @exception EPropertyNotFound If property is not found + * @exception EBaseException If an internal error occurred + */ + public BigInteger getBigInteger(String name) + throws EPropertyNotFound, EBaseException; + + /** + * Retrieves the given property as a big integer. + *

+ * + * @param name The property name + * @return int The default value to return as a big integer + * @exception EBaseException If the value cannot be converted to a + * integer + */ + public BigInteger getBigInteger(String name, BigInteger defval) + throws EBaseException; + + /** + * Sets a property and its value as an integer. + *

+ * + * @param name parameter name + * @param value big integer value + */ + public void putBigInteger(String name, BigInteger value); + + /** + * Creates a nested sub-store with the specified name. + *

+ * + * @param name The name of the sub-store + * @return The sub-store created + */ + public IConfigStore makeSubStore(String name); + + /** + * Retrieves the given sub-store. + *

+ * + * @param name The name of the sub-store + * @return The sub-store + */ + public IConfigStore getSubStore(String name); + + /** + * Removes sub-store with the given name. + * (Removes all properties and sub-stores under this sub-store.) + *

+ * + * @param name The name of the sub-store to remove + */ + public void removeSubStore(String name); + + public void remove(String name); + + /** + * Retrives and enumeration of all properties in this config-store. + * + * @return An enumeration of all properties in this config-store + */ + public Enumeration getPropertyNames(); + + /** + * Returns an enumeration of the names of the substores of + * this config-store. + *

+ * + * @return An enumeration of the names of the sub-stores of this + * config-store + */ + public Enumeration getSubStoreNames(); + + /** + * Commits all the data into file immediately. + * + * @param createBackup true if a backup file should be created + * @exception EBaseException failed to commit + */ + public void commit(boolean createBackup) throws EBaseException; + + /** + * Return the number of items in this substore + */ + public int size(); +} diff --git a/base/common/src/com/netscape/certsrv/base/IConfigStoreEventListener.java b/base/common/src/com/netscape/certsrv/base/IConfigStoreEventListener.java new file mode 100644 index 000000000..06e7d522a --- /dev/null +++ b/base/common/src/com/netscape/certsrv/base/IConfigStoreEventListener.java @@ -0,0 +1,48 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.certsrv.base; + +import java.util.Hashtable; + +/** + * ConfigStore Parameters Event Notification. + * + * @version $Revision$, $Date$ + */ +public interface IConfigStoreEventListener { + + /** + * Called to validate the config store parameters that changed + * + * @param action action + * @param params configuration parameters changed + * @exception EBaseException failed to validate + */ + public void validateConfigParams(String action, + Hashtable params) throws EBaseException; + + /** + * Validates the config store parameters that changed + * + * @param action action + * @param params configuration parameters changed + * @exception EBaseException failed to validate + */ + public void doConfigParams(String action, + Hashtable params) throws EBaseException; +} diff --git a/base/common/src/com/netscape/certsrv/base/IExtPrettyPrint.java b/base/common/src/com/netscape/certsrv/base/IExtPrettyPrint.java new file mode 100644 index 000000000..8d95a40ca --- /dev/null +++ b/base/common/src/com/netscape/certsrv/base/IExtPrettyPrint.java @@ -0,0 +1,34 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.certsrv.base; + +/** + * This class will display the certificate content in predefined + * format. + * + * @version $Revision$, $Date$ + */ +public interface IExtPrettyPrint { + + /** + * Retrieves the printable extension string. + * + * @return printable extension string + */ + public String toString(); +} diff --git a/base/common/src/com/netscape/certsrv/base/IExtendedPluginInfo.java b/base/common/src/com/netscape/certsrv/base/IExtendedPluginInfo.java new file mode 100644 index 000000000..aff3daf4d --- /dev/null +++ b/base/common/src/com/netscape/certsrv/base/IExtendedPluginInfo.java @@ -0,0 +1,79 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.certsrv.base; + +import java.util.Locale; + +/** + * Plugin which can return extended information to console + *

+ * + * @version $Revision$, $Date$ + */ +public interface IExtendedPluginInfo { + + public static final String HELP_TOKEN = "HELP_TOKEN"; + public static final String HELP_TEXT = "HELP_TEXT"; + + /** + * This method returns an array of strings. Each element of the + * array represents a configurable parameter, or some other + * meta-info (such as help-token) + * + * there is an entry indexed on that parameter name + * ;[,required];;... + * + * Where: + * + * type_info is either 'string', 'number', 'boolean', 'password' or + * 'choice(ch1,ch2,ch3,...)' + * + * If the marker 'required' is included after the type_info, + * the parameter will has some visually distinctive marking in + * the UI. + * + * 'description' is a short sentence describing the parameter + * 'choice' is rendered as a drop-down list. The first parameter in the + * list will be activated by default + * 'boolean' is rendered as a checkbox. The resulting parameter will be + * either 'true' or 'false' + * 'string' allows any characters + * 'number' allows only numbers + * 'password' is rendered as a password field (the characters are replaced + * with *'s when being types. This parameter is not passed through to + * the plugin. It is instead inserted directly into the password cache + * keyed on the instance name. The value of the parameter + * 'bindPWPrompt' (see example below) is set to the key. + * + * In addition to the configurable parameters, the following magic parameters + * may be defined: + * + * HELP_TOKEN;helptoken - a pointer to the online manual section for this plugin + * HELP_TEXT;helptext - a general help string describing the plugin + * + * For example: + * "username;string;The username you wish to login as" + * "bindPWPrompt;password;Enter password to bind as above user with" + * "algorithm;choice(RSA,DSA);Which algorithm do you want to use" + * "enable;boolean;Do you want to run this plugin" + * "port;number;Which port number do you want to use" + * + */ + public String[] getExtendedPluginInfo(Locale locale); + +} diff --git a/base/common/src/com/netscape/certsrv/base/IPluginImpl.java b/base/common/src/com/netscape/certsrv/base/IPluginImpl.java new file mode 100644 index 000000000..a7a0560b5 --- /dev/null +++ b/base/common/src/com/netscape/certsrv/base/IPluginImpl.java @@ -0,0 +1,104 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.certsrv.base; + +import java.util.Vector; + +/** + * This interface represents a plugin instance. + * + * @version $Revision$, $Date$ + */ +public interface IPluginImpl { + + public static final String PROP_IMPLNAME = "implName"; + + /** + * Gets the description for this plugin instance. + *

+ * + * @return The Description for this plugin instance. + */ + public String getDescription(); + + /** + * Returns the name of the plugin class. + *

+ * + * @return The name of the plugin class. + */ + public String getImplName(); + + /** + * Returns the name of the plugin instance. + *

+ * + * @return The name of the plugin instance. If none is set + * the name of the implementation will be returned.xxxx + */ + public String getInstanceName(); + + /** + * Initializes this plugin instance. + * + * @param sys parent subsystem + * @param instanceName instance name of this plugin + * @param className class name of this plugin + * @param config configuration store + * @exception EBaseException failed to initialize + */ + public void init(ISubsystem sys, String instanceName, String className, + IConfigStore config) + throws EBaseException; + + /** + * Shutdowns this plugin. + */ + public void shutdown(); + + /** + * Retrieves the configuration store. + * + * @return configuration store + */ + public IConfigStore getConfigStore(); + + /** + * Return configured parameters for a plugin instance. + * + * @return nvPairs A Vector of name/value pairs. Each name/value + * pair is constructed as a String in name=value format. + */ + public Vector getInstanceParams(); + + /** + * Retrieves a list of configuration parameter names. + * + * @return a list of parameter names + */ + public String[] getConfigParams(); + + /** + * Return default parameters for a plugin implementation. + * + * @return nvPairs A Vector of name/value pairs. Each name/value + * pair is constructed as a String in name=value. + */ + public Vector getDefaultParams(); + +} diff --git a/base/common/src/com/netscape/certsrv/base/IPrettyPrintFormat.java b/base/common/src/com/netscape/certsrv/base/IPrettyPrintFormat.java new file mode 100644 index 000000000..67c1b01d1 --- /dev/null +++ b/base/common/src/com/netscape/certsrv/base/IPrettyPrintFormat.java @@ -0,0 +1,66 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.certsrv.base; + +/** + * This class will display the certificate content in predefined + * format. + * + * @version $Revision$, $Date$ + */ +public interface IPrettyPrintFormat { + + /** + * Retrieves a pretty print string of the given byte array. + * + * @param in byte array + * @param indentSize indentation size + * @param lineLen length of line + * @param separator separator string + * @return pretty print string + */ + public String toHexString(byte[] in, int indentSize, + int lineLen, String separator); + + /** + * Retrieves a pretty print string of the given byte array. + * + * @param in byte array + * @param indentSize indentation size + * @param lineLen length of line + * @return pretty print string + */ + public String toHexString(byte[] in, int indentSize, int lineLen); + + /** + * Retrieves a pretty print string of the given byte array. + * + * @param in byte array + * @param indentSize indentation size + * @return pretty print string + */ + public String toHexString(byte[] in, int indentSize); + + /** + * Retrieves a pretty print string of the given byte array. + * + * @param in byte array + * @return pretty print string + */ + public String toHexString(byte[] in); +} diff --git a/base/common/src/com/netscape/certsrv/base/ISecurityDomainSessionTable.java b/base/common/src/com/netscape/certsrv/base/ISecurityDomainSessionTable.java new file mode 100644 index 000000000..24c55d086 --- /dev/null +++ b/base/common/src/com/netscape/certsrv/base/ISecurityDomainSessionTable.java @@ -0,0 +1,48 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.certsrv.base; + +import java.util.Enumeration; + +/** + * This interface defines the abstraction for the cookie table. + **/ +public interface ISecurityDomainSessionTable { + public static final int SUCCESS = 0; + public static final int FAILURE = 1; + + public int addEntry(String cookieId, String ip, String uid, String group); + + public int removeEntry(String sessionId); + + public boolean isSessionIdExist(String sessionId); + + public String getIP(String sessionId); + + public String getUID(String sessionId); + + public String getGroup(String sessionId); + + public long getBeginTime(String sessionId); + + public int getSize(); + + public long getTimeToLive(); + + public Enumeration getSessionIds(); +} diff --git a/base/common/src/com/netscape/certsrv/base/ISourceConfigStore.java b/base/common/src/com/netscape/certsrv/base/ISourceConfigStore.java new file mode 100644 index 000000000..eb848c54e --- /dev/null +++ b/base/common/src/com/netscape/certsrv/base/ISourceConfigStore.java @@ -0,0 +1,81 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.certsrv.base; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.Serializable; +import java.util.Enumeration; + +/** + * An interface that represents the source that creates the configuration + * store tree. Note that the tree can be built based on the information + * from a text file or ldap entries. + * + * @see com.netscape.certsrv.base.IConfigStore + * + * @version $Revision$, $Date$ + */ +public interface ISourceConfigStore extends Serializable { + + /** + * Gets a property. + *

+ * + * @param name The property name + * @return property value + */ + public String get(String name); + + /** + * Retrieves a property. + *

+ * + * @param name The property name + * @param value The property value + */ + public String put(String name, String value); + + /** + * Returns an enumeration of the config store's keys. + *

+ * + * @return a list of keys + * @see java.util.Hashtable#elements + * @see java.util.Enumeration + */ + public Enumeration keys(); + + /** + * Reads a config store from an input stream. + * + * @param in input stream where the properties are located + * @exception IOException If an IO error occurs while loading from input. + */ + public void load(InputStream in) throws IOException; + + /** + * Stores this config store to the specified output stream. + * + * @param out output stream where the properties should be serialized + * @param header optional header to be serialized + */ + public void save(OutputStream out, String header); + +} diff --git a/base/common/src/com/netscape/certsrv/base/ISubsystem.java b/base/common/src/com/netscape/certsrv/base/ISubsystem.java new file mode 100644 index 000000000..7b2a37d7d --- /dev/null +++ b/base/common/src/com/netscape/certsrv/base/ISubsystem.java @@ -0,0 +1,78 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.certsrv.base; + +/** + * An interface represents a CMS subsystem. CMS is made up of a list + * subsystems. Each subsystem is responsible for a set of + * speciailized functions. + *

+ * + * @version $Revision$, $Date$ + */ +public interface ISubsystem { + + /** + * Retrieves the name of this subsystem. + * + * @return subsystem identifier + */ + public String getId(); + + /** + * Sets specific to this subsystem. + * + * @param id subsystem identifier + * @exception EBaseException failed to set id + */ + public void setId(String id) throws EBaseException; + + /** + * Initializes this subsystem with the given configuration + * store. + *

+ * + * @param owner owner of this subsystem + * @param config configuration store + * @exception EBaseException failed to initialize + */ + public void init(ISubsystem owner, IConfigStore config) + throws EBaseException; + + /** + * Notifies this subsystem if owner is in running mode. + * + * @exception EBaseException failed to start up + */ + public void startup() throws EBaseException; + + /** + * Stops this system. The owner may call shutdown + * anytime after initialization. + *

+ */ + public void shutdown(); + + /** + * Returns the root configuration storage of this system. + *

+ * + * @return configuration store of this subsystem + */ + public IConfigStore getConfigStore(); +} diff --git a/base/common/src/com/netscape/certsrv/base/ISubsystemSource.java b/base/common/src/com/netscape/certsrv/base/ISubsystemSource.java new file mode 100644 index 000000000..f6bb6378b --- /dev/null +++ b/base/common/src/com/netscape/certsrv/base/ISubsystemSource.java @@ -0,0 +1,36 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.certsrv.base; + +/** + * An interface represents a subsystem source. A subsystem + * source is a container that manages multiple subsystems. + *

+ * + * @version $Revision$, $Date$ + */ +public interface ISubsystemSource { + + /** + * Retrieves subsystem from the source. + * + * @param sid subsystem identifier + * @return subsystem + */ + public ISubsystem getSubsystem(String sid); +} diff --git a/base/common/src/com/netscape/certsrv/base/ITimeSource.java b/base/common/src/com/netscape/certsrv/base/ITimeSource.java new file mode 100644 index 000000000..1e7dd0fb0 --- /dev/null +++ b/base/common/src/com/netscape/certsrv/base/ITimeSource.java @@ -0,0 +1,41 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.certsrv.base; + +import java.util.Date; + +/** + * This interface represents a time source where + * current time can be retrieved. CMS is installed + * with a default time source that returns + * current time based on the system time. It is + * possible to register a time source that returns + * the current time from a NTP server. + * + * @version $Revision$, $Date$ + */ +public interface ITimeSource { + + /** + * Retrieves current time and date. + * + * @return current time and date + */ + public Date getCurrentDate(); + +} diff --git a/base/common/src/com/netscape/certsrv/base/KeyGenInfo.java b/base/common/src/com/netscape/certsrv/base/KeyGenInfo.java new file mode 100644 index 000000000..8c13fca56 --- /dev/null +++ b/base/common/src/com/netscape/certsrv/base/KeyGenInfo.java @@ -0,0 +1,229 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.certsrv.base; + +import java.io.IOException; + +import com.netscape.cmsutil.util.Utils; + +import netscape.security.util.DerInputStream; +import netscape.security.util.DerValue; +import netscape.security.x509.AlgorithmId; +import netscape.security.x509.X509Key; + +/** + * + * The KeyGenInfo represents the information generated by + * the KeyGen tag of the HTML forms. It provides the parsing and accessing + * mechanisms. + *

+ * + *

+ * SignedPublicKeyAndChallenge ::= SEQUENCE {
+ *      publicKeyAndChallenge PublicKeyAndChallenge,
+ *      signatureAlgorithm AlgorithmIdentifier,
+ *      signature BIT STRING
+ * }
+ * 
+ * PublicKeyAndChallenge ::= SEQUENCE {
+ *      spki SubjectPublicKeyInfo,
+ *      challenge IA5STRING
+ * }
+ * 
+ * + * + * @version $Revision$, $Date$ + */ + +public class KeyGenInfo { + + /*========================================================== + * variables + *==========================================================*/ + private String mSPKACString; + private byte mPKAC[]; + private byte mSPKAC[]; + private X509Key mSPKI; + private DerValue mDerSPKI; + private String mChallenge; + private DerValue mDerChallenge; + private byte mSignature[]; + private AlgorithmId mAlgId; + + /*========================================================== + * constructors + *==========================================================*/ + + /** + * Construct empty KeyGenInfo. Need to call decode function + * later to initialize. + */ + public KeyGenInfo() { + + } + + /** + * Construct KeyGenInfo using the SignedPublicKeyAndChallenge + * string representation. + * + * @param spkac SignedPublicKeyAndChallenge string representation + */ + public KeyGenInfo(String spkac) + throws IOException { + decode(spkac); + } + + /*========================================================== + * public methods + *==========================================================*/ + + /** + * Initialize using the SPKAC string + * + * @param spkac SPKAC string from the end user + */ + public void decode(String spkac) throws IOException { + mSPKACString = spkac; + mSPKAC = base64Decode(spkac); + derDecode(mSPKAC); + } + + /** + * Der encoded into buffer + * + * @return Der encoded buffer + */ + public byte[] encode() { + return mSPKAC; + } + + /** + * Get SPKI in DerValue form + * + * @return SPKI in DerValue form + */ + public DerValue getDerSPKI() { + return mDerSPKI; + } + + /** + * Get SPKI as X509Key + * + * @return SPKI in X509Key form + */ + public X509Key getSPKI() { + return mSPKI; + } + + /** + * Get Challenge phrase in DerValue form + * + * @return Challenge in DerValue form. null if none. + */ + public DerValue getDerChallenge() { + return mDerChallenge; + } + + /** + * Get Challenge phrase in string format + * + * @return challenge phrase. null if none. + */ + public String getChallenge() { + return mChallenge; + } + + /** + * Get Signature + * + * @return signature + */ + public byte[] getSignature() { + return mSignature; + } + + /** + * Get Algorithm ID + * + * @return the algorithm id + */ + public AlgorithmId getAlgorithmId() { + return mAlgId; + } + + /** + * Validate Signature and Challenge Phrase + * + * @param challenge phrase; null if none + * @return true if validated; otherwise, false + */ + public boolean validateChallenge(String challenge) { + if (challenge != null) { + if (!challenge.equals(mChallenge)) { + return false; + } + } + return true; + } + + /** + * String representation of KenGenInfo + * + * @return string representation of KeGenInfo + */ + public String toString() { + if (mSPKACString != null) + return mSPKACString; + return ""; + } + + /*========================================================== + * private methods + *==========================================================*/ + + private byte[] base64Decode(String spkac) + throws IOException { + + return Utils.base64decode(spkac); + } + + private void derDecode(byte spkac[]) + throws IOException { + DerInputStream derIn = new DerInputStream(spkac); + + /* get SPKAC Algorithm & Signature */ + DerValue derSPKACContent[] = derIn.getSequence(3); + + mAlgId = AlgorithmId.parse(derSPKACContent[1]); + mSignature = derSPKACContent[2].getBitString(); + + /* get PKAC SPKI & Challenge */ + mPKAC = derSPKACContent[0].toByteArray(); + derIn = new DerInputStream(mPKAC); + DerValue derPKACContent[] = derIn.getSequence(2); + + mDerSPKI = derPKACContent[0]; + mSPKI = X509Key.parse(derPKACContent[0]); + + mDerChallenge = derPKACContent[1]; + if (mDerChallenge.length() != 0) + mChallenge = derPKACContent[1].getIA5String(); + + } + +} diff --git a/base/common/src/com/netscape/certsrv/base/MessageFormatter.java b/base/common/src/com/netscape/certsrv/base/MessageFormatter.java new file mode 100644 index 000000000..903b534e0 --- /dev/null +++ b/base/common/src/com/netscape/certsrv/base/MessageFormatter.java @@ -0,0 +1,155 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.certsrv.base; + +import java.lang.reflect.Method; +import java.text.MessageFormat; +import java.util.Date; +import java.util.Locale; +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +/** + * Factors out common function of formatting internatinalized + * messages taking arguments and using java.util.ResourceBundle + * and java.text.MessageFormat mechanism. + *

+ * + * @version $Revision$, $Date$ + * @see java.text.MessageFormat + * @see java.util.ResourceBundle + */ +public class MessageFormatter { + + private static final Class[] toStringSignature = { Locale.class }; + + /** + * Retrieves the localized string. + * + * @param locale end user locale + * @param resourceBundleBaseName resource bundle class name + * @param formatString format string + * @return localized string + */ + public static String getLocalizedString( + Locale locale, String resourceBundleBaseName, + String formatString) { + return getLocalizedString(locale, resourceBundleBaseName, + formatString, null); + } + + /** + * Retrieves the localized string. + * + * @param locale end user locale + * @param resourceBundleBaseName resource bundle class name + * @param formatString format string + * @param params parameters to be substituted + * @return localized string + */ + public static String getLocalizedString( + Locale locale, String resourceBundleBaseName, + String formatString, Object params) { + Object o[] = new Object[1]; + + o[0] = params; + return getLocalizedString(locale, resourceBundleBaseName, + formatString, o); + } + + /** + * Retrieves the localized string. + * + * @param locale end user locale + * @param resourceBundleBaseName resource bundle class name + * @param formatString format string + * @param params parameters to be substituted + * @return localized string + */ + public static String getLocalizedString( + Locale locale, String resourceBundleBaseName, + String formatString, Object[] params) { + + String localizedFormat = null; + + try { + try { + // if you are worried about the efficiency of the + // following line, dont worry. ResourceBundle has + // an internal cache. So resource bundle wont be + // instantiated everytime you call toString(). + + localizedFormat = ResourceBundle.getBundle( + resourceBundleBaseName, locale).getString(formatString); + } catch (MissingResourceException e) { + return formatString; + + } + Object[] localizedParams = params; + Object[] localeArg = null; + + if (params != null) { + for (int i = 0; i < params.length; ++i) { + if (!(params[i] instanceof String) || + !(params[i] instanceof Date) || + !(params[i] instanceof Number)) { + if (localizedParams == params) { + + // only done once + // NB if the following variant of cloning code is used + // localizedParams = (Object [])mParams.clone(); + // it causes ArrayStoreException in + // localizedParams[i] = params[i].toString(); + // below + + localizedParams = new Object[params.length]; + System.arraycopy(params, 0, localizedParams, 0, + params.length); + } + try { + Method toStringMethod = params[i].getClass().getMethod( + "toString", toStringSignature); + + if (localeArg == null) { + // only done once + localeArg = new Object[] { locale }; + } + localizedParams[i] = toStringMethod.invoke( + params[i], localeArg); + } catch (Exception e) { + // no method for localization, fall back + localizedParams[i] = params[i].toString(); + } + } + } + } + try { + // XXX - runtime exception may be raised by the following function + MessageFormat format = new MessageFormat(localizedFormat); + + return format.format(localizedParams); + } catch (IllegalArgumentException e) { + // XXX - for now, we just print the unformatted message + // if the exception is raised + return localizedFormat; + } + } catch (Exception e) { + return localizedFormat; + } + } +} diff --git a/base/common/src/com/netscape/certsrv/base/MetaAttributeDef.java b/base/common/src/com/netscape/certsrv/base/MetaAttributeDef.java new file mode 100644 index 000000000..3a7bac977 --- /dev/null +++ b/base/common/src/com/netscape/certsrv/base/MetaAttributeDef.java @@ -0,0 +1,198 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.certsrv.base; + +import java.util.Enumeration; +import java.util.Hashtable; + +import netscape.security.util.ObjectIdentifier; + +/** + * A class representing a meta attribute defintion. + *

+ * + * @version $Revision$, $Date$ + */ +public class MetaAttributeDef { + + private String mName; + private ObjectIdentifier mOid; + private Class mValueClass; + private static Hashtable mNameToAttrDef = new Hashtable(); + private static Hashtable mOidToAttrDef = + new Hashtable(); + + private MetaAttributeDef() { + } + + /** + * Constructs a MetaAttribute defintion + *

+ * + * @param name attribute name + * @param valueClass attribute value class + * @param oid attribute object identifier + */ + private MetaAttributeDef(String name, Class valueClass, + ObjectIdentifier oid) { + mName = name; + mValueClass = valueClass; + mOid = oid; + } + + /** + * Gets an attribute OID. + *

+ * + * @return returns attribute OID or null if not defined. + */ + public ObjectIdentifier getOID() { + return mOid; + } + + /** + * Gets an Java class for the attribute values + *

+ * + * @return returns Java class for the attribute values + */ + public Class getValueClass() { + return mValueClass; + } + + /** + * Gets attribute name + *

+ * + * @return returns attribute name + */ + public String getName() { + return mName; + } + + /** + * Registers new MetaAttribute defintion + * Attribute is defined by name, Java class for attribute values and + * optional object identifier + *

+ * + * @param name attribute name + * @param valueClass attribute value class + * @param oid attribute object identifier + * @exception IllegalArgumentException if name or valueClass are null, or + * conflicting attribute definition already exists + */ + public static MetaAttributeDef register(String name, Class valueClass, + ObjectIdentifier oid) { + if (name == null) { + throw new IllegalArgumentException( + "Attribute name must not be null"); + } + if (valueClass == null) { + throw new IllegalArgumentException( + "Attribute value class must not be null"); + } + + MetaAttributeDef newDef = new MetaAttributeDef(name, valueClass, oid); + MetaAttributeDef oldDef; + + if ((oldDef = (MetaAttributeDef) mNameToAttrDef.get(name)) != null && + !oldDef.equals(newDef)) { + throw new IllegalArgumentException( + "Attribute \'" + name + "\' is already defined"); + } + if (oid != null && + (oldDef = (MetaAttributeDef) mOidToAttrDef.get(oid)) != null && + !oldDef.equals(newDef)) { + throw new IllegalArgumentException( + "OID \'" + oid + "\' is already in use"); + } + mNameToAttrDef.put(name, newDef); + if (oid != null) { + mOidToAttrDef.put(oid, newDef); + } + return newDef; + } + + /** + * Compares this attribute definition with another, for equality. + *

+ * + * @return true iff names, valueClasses and object identifiers + * are identical. + */ + public boolean equals(Object other) { + if (other == this) + return true; + + if (other instanceof MetaAttributeDef) { + MetaAttributeDef otherDef = (MetaAttributeDef) other; + + if ((mOid != null && otherDef.mOid != null && + !mOid.equals(otherDef.mOid)) || + (mOid == null && otherDef.mOid != null) || + !mName.equals(otherDef.mName) || + !mValueClass.equals(otherDef.mValueClass)) { + return false; + } + } + return false; + } + + /** + * Retrieves attribute definition by name + *

+ * + * @param name attribute name + * @return attribute definition or null if not found + */ + public static MetaAttributeDef forName(String name) { + return (MetaAttributeDef) mNameToAttrDef.get(name); + } + + /** + * Retrieves attribute definition by object identifier + *

+ * + * @param oid attribute object identifier + * @return attribute definition or null if not found + */ + public static MetaAttributeDef forOID(ObjectIdentifier oid) { + return (MetaAttributeDef) mOidToAttrDef.get(oid); + } + + /** + * Returns enumeration of the registered attribute names + *

+ * + * @return returns enumeration of the registered attribute names + */ + public static Enumeration getAttributeNames() { + return mNameToAttrDef.keys(); + } + + /** + * Returns enumeration of the registered attribute object identifiers + *

+ * + * @return returns enumeration of the attribute object identifiers + */ + public static Enumeration getAttributeNameOids() { + return mOidToAttrDef.keys(); + } +} diff --git a/base/common/src/com/netscape/certsrv/base/MetaInfo.java b/base/common/src/com/netscape/certsrv/base/MetaInfo.java new file mode 100644 index 000000000..8aed6b840 --- /dev/null +++ b/base/common/src/com/netscape/certsrv/base/MetaInfo.java @@ -0,0 +1,115 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.certsrv.base; + +import java.util.Enumeration; +import java.util.Hashtable; + +/** + * A class represents meta information. A meta information + * object is just a generic hashtable that is embedded into + * a request object. + *

+ * + * @version $Revision$, $Date$ + */ +public class MetaInfo implements IAttrSet { + + /** + * + */ + private static final long serialVersionUID = 7722068404789828101L; + public static final String REQUEST_ID = "requestId"; + public static final String IN_LDAP_PUBLISH_DIR = "inLdapPublishDir"; + + private Hashtable content = new Hashtable(); + + /** + * Constructs a meta information. + *

+ */ + public MetaInfo() { + } + + /** + * Returns a short string describing this certificate attribute. + *

+ * + * @return information about this certificate attribute. + */ + public String toString() { + StringBuffer sb = new StringBuffer(); + + sb.append("[\n"); + sb.append(" Meta information:\n"); + Enumeration enum1 = content.keys(); + + while (enum1.hasMoreElements()) { + String key = (String) enum1.nextElement(); + + sb.append(" " + key + " : " + content.get(key) + "\n"); + } + sb.append("]\n"); + return sb.toString(); + } + + /** + * Gets an attribute value. + *

+ * + * @param name the name of the attribute to return. + * @exception EBaseException on attribute handling errors. + */ + public Object get(String name) throws EBaseException { + return content.get(name); + } + + /** + * Sets an attribute value. + * + * @param name the name of the attribute + * @param obj the attribute object. + * + * @exception EBaseException on attribute handling errors. + */ + public void set(String name, Object obj) throws EBaseException { + content.put(name, obj); + } + + /** + * Deletes an attribute value from this CertAttrSet. + *

+ * + * @param name the name of the attribute to delete. + * @exception EBaseException on attribute handling errors. + */ + public void delete(String name) throws EBaseException { + content.remove(name); + } + + /** + * Returns an enumeration of the names of the attributes existing within + * this attribute. + *

+ * + * @return an enumeration of the attribute names. + */ + public Enumeration getElements() { + return content.keys(); + } +} diff --git a/base/common/src/com/netscape/certsrv/base/Nonces.java b/base/common/src/com/netscape/certsrv/base/Nonces.java new file mode 100644 index 000000000..cc0231ac3 --- /dev/null +++ b/base/common/src/com/netscape/certsrv/base/Nonces.java @@ -0,0 +1,123 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.certsrv.base; + +import java.security.cert.X509Certificate; +import java.util.Hashtable; +import java.util.Vector; + +/** + * This class manages nonces sometimes used to control request state flow. + *

+ * + * @version $Revision$, $Date$ + */ +public class Nonces { + + private Hashtable mNonces = new Hashtable(); + private Vector mNonceList = new Vector(); + private int mNonceLimit; + + /** + * Constructs nonces. + */ + public Nonces() { + this(100); + } + + public Nonces(int limit) { + mNonceLimit = limit; + } + + public long addNonce(long nonce, X509Certificate cert) { + long i; + long k = 0; + long n = nonce; + long m = (long) ((mNonceLimit / 2) + 1); + + for (i = 0; i < m; i++) { + k = n + i; + // avoid collisions + if (!mNonceList.contains((Object) k)) { + break; + } + k = n - i; + // avoid collisions + if (!mNonceList.contains((Object) k)) { + break; + } + } + if (i < m) { + mNonceList.add(k); + mNonces.put(k, cert); + if (mNonceList.size() > mNonceLimit) { + n = ((Long) (mNonceList.firstElement())).longValue(); + mNonceList.remove(0); + mNonces.remove((Object) n); + } + } else { + // failed to resolved collision + k = -nonce; + } + return k; + } + + public X509Certificate getCertificate(long nonce) { + X509Certificate cert = (X509Certificate) mNonces.get(nonce); + return cert; + } + + public X509Certificate getCertificate(int index) { + X509Certificate cert = null; + if (index >= 0 && index < mNonceList.size()) { + long nonce = ((Long) (mNonceList.elementAt(index))).longValue(); + cert = (X509Certificate) mNonces.get(nonce); + } + return cert; + } + + public long getNonce(int index) { + long nonce = 0; + if (index >= 0 && index < mNonceList.size()) { + nonce = ((Long) (mNonceList.elementAt(index))).longValue(); + } + return nonce; + } + + public void removeNonce(long nonce) { + mNonceList.remove((Object) nonce); + mNonces.remove((Object) nonce); + } + + public int size() { + return mNonceList.size(); + } + + public int maxSize() { + return mNonceLimit; + } + + public void clear() { + mNonceList.clear(); + mNonces.clear(); + } + + public boolean isInSync() { + return (mNonceList.size() == mNonces.size()); + } +} diff --git a/base/common/src/com/netscape/certsrv/base/PasswordResources.java b/base/common/src/com/netscape/certsrv/base/PasswordResources.java new file mode 100644 index 000000000..c3309c5fa --- /dev/null +++ b/base/common/src/com/netscape/certsrv/base/PasswordResources.java @@ -0,0 +1,42 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.certsrv.base; + +import java.util.ListResourceBundle; + +/** + * A class represents a resource bundle for the password checker. + *

+ * + * @version $Revision$, $Date$ + * @see java.util.ListResourceBundle + */ +public class PasswordResources extends ListResourceBundle { + + /** + * Returns the content of this resource. + */ + public Object[][] getContents() { + return contents; + } + + /* + * Constants. The suffix represents the number of possible parameters. + */ + static final Object[][] contents = {}; +} diff --git a/base/common/src/com/netscape/certsrv/base/Plugin.java b/base/common/src/com/netscape/certsrv/base/Plugin.java new file mode 100644 index 000000000..79fae88ac --- /dev/null +++ b/base/common/src/com/netscape/certsrv/base/Plugin.java @@ -0,0 +1,59 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.certsrv.base; + +/** + * This represents a generici CMS plugin. + *

+ * + * @version $Revision$, $Date$ + */ +public class Plugin { + + private String mId = null; + private String mClassPath = null; + + /** + * Constructs a plugin. + * + * @param id plugin implementation name + * @param classPath class path + */ + public Plugin(String id, String classPath) { + mId = id; + mClassPath = classPath; + } + + /** + * Returns the plugin identifier. + * + * @return plugin id + */ + public String getId() { + return mId; + } + + /** + * Returns the plugin classpath. + * + * @return plugin classpath + */ + public String getClassPath() { + return mClassPath; + } +} diff --git a/base/common/src/com/netscape/certsrv/base/SessionContext.java b/base/common/src/com/netscape/certsrv/base/SessionContext.java new file mode 100644 index 000000000..b4ecd1241 --- /dev/null +++ b/base/common/src/com/netscape/certsrv/base/SessionContext.java @@ -0,0 +1,166 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2007 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- +package com.netscape.certsrv.base; + +import java.util.Hashtable; + +/** + * This class specifies the context object that includes + * authentication environment and connection information. + * This object is later used in access control evaluation. + * This is a global object that can be accessible + * throughout the server. It is useful for passing + * global and per-thread infomration in methods. + *

+ * + * @version $Revision$, $Date$ + */ +public class SessionContext extends Hashtable { + + /** + * + */ + private static final long serialVersionUID = -3376355842991589505L; + + /** + * End user locale of the current processing request in the current thread. + */ + public static final String LOCALE = "locale"; // Locale + + /** + * Authentication token in the current thread. + */ + public static final String AUTH_TOKEN = "AuthToken"; // IAuthToken + + /** + * ID of the authentication manager in the current thread. + */ + public static final String AUTH_MANAGER_ID = "authManagerId"; // String + + /** + * User object of the authenticated user in the current thread. + */ + public static final String USER = "user"; // IUser + + /** + * User ID of the authenticated user in the current thread. + */ + public static final String USER_ID = "userid"; // String + + /** + * Group ID of the authenticated user in the current thread. + */ + public static final String GROUP_ID = "groupid"; //String + + /** + * ID of the processing request in the current thread. + */ + public static final String REQUESTER_ID = "requesterID"; // String + + /** + * Recovery ID of a recovery operation in KRA in the current thread. + */ + public static final String RECOVERY_ID = "recoveryID"; // String + + /** + * IP Address of the requestor of the request in the current thread. + */ + public static final String IPADDRESS = "ipAddress"; + + private static Hashtable mContexts = new Hashtable(); + + /** + * Constructs a session context. + */ + public SessionContext() { + super(); + } + + /** + * Creates a new context and associates it with + * the current thread. If the current thread is + * also associated with a old context, the old + * context will be replaced. + */ + private static SessionContext createContext() { + SessionContext sc = new SessionContext(); + + setContext(sc); + return sc; + } + + /** + * Sets the current context. This allows the + * caller to associate a specific session context + * with the current thread. + * This methods makes custom session context + * possible. + * + * @param sc session context + */ + public static void setContext(SessionContext sc) { + mContexts.put(Thread.currentThread(), sc); + } + + /** + * Retrieves the session context associated with + * the current thread. If no context is associated, + * a context is created. + * + * @return sesssion context + */ + public static SessionContext getContext() { + SessionContext sc = (SessionContext) mContexts.get( + Thread.currentThread()); + + if (sc == null) { + sc = createContext(); + } + return sc; + } + + /** + * Retrieves the session context associated with + * the current thread. If no context is associated, + * null is returned. + * + * @return sesssion context + */ + public static SessionContext getExistingContext() { + SessionContext sc = (SessionContext) + mContexts.get(Thread.currentThread()); + + if (sc == null) { + return null; + } + + return sc; + } + + /** + * Releases the current session context. + */ + public static void releaseContext() { + SessionContext sc = (SessionContext) mContexts.get( + Thread.currentThread()); + + if (sc != null) { + mContexts.remove(Thread.currentThread()); + } + } +} -- cgit