From 34496a33fbbee462f67410e2ee54a7986b3aedae Mon Sep 17 00:00:00 2001 From: Endi Sukma Dewata Date: Mon, 20 Feb 2012 11:42:23 -0600 Subject: Renamed Utils to avoid conflicts. The Utils classes in com.netscape.cms.publish.publishers and com.netscape.cms.servlet.common packages have been renamed to PublisherUtils and ServletUtils to avoid conflicts with com.netscape.cmsutil.util.Utils. Ticket #90 --- .../publish/publishers/LdapCertSubjPublisher.java | 2 +- .../publishers/LdapEncryptCertPublisher.java | 2 +- .../publish/publishers/LdapUserCertPublisher.java | 2 +- .../cms/publish/publishers/PublisherUtils.java | 136 +++++++++++++++++++++ .../com/netscape/cms/publish/publishers/Utils.java | 136 --------------------- .../com/netscape/cms/servlet/base/CMSServlet.java | 4 +- .../netscape/cms/servlet/common/ServletUtils.java | 106 ++++++++++++++++ .../src/com/netscape/cms/servlet/common/Utils.java | 106 ---------------- .../cms/servlet/profile/ProfileServlet.java | 4 +- 9 files changed, 249 insertions(+), 249 deletions(-) create mode 100644 pki/base/common/src/com/netscape/cms/publish/publishers/PublisherUtils.java delete mode 100644 pki/base/common/src/com/netscape/cms/publish/publishers/Utils.java create mode 100644 pki/base/common/src/com/netscape/cms/servlet/common/ServletUtils.java delete mode 100644 pki/base/common/src/com/netscape/cms/servlet/common/Utils.java (limited to 'pki/base/common/src/com/netscape') diff --git a/pki/base/common/src/com/netscape/cms/publish/publishers/LdapCertSubjPublisher.java b/pki/base/common/src/com/netscape/cms/publish/publishers/LdapCertSubjPublisher.java index fed865122..5975872ff 100644 --- a/pki/base/common/src/com/netscape/cms/publish/publishers/LdapCertSubjPublisher.java +++ b/pki/base/common/src/com/netscape/cms/publish/publishers/LdapCertSubjPublisher.java @@ -260,7 +260,7 @@ public class LdapCertSubjPublisher implements ILdapPublisher { while (vals.hasMoreElements()) { val = vals.nextElement(); - if (Utils.byteArraysAreEqual(certEnc, val)) { + if (PublisherUtils.byteArraysAreEqual(certEnc, val)) { hasCert = true; continue; } diff --git a/pki/base/common/src/com/netscape/cms/publish/publishers/LdapEncryptCertPublisher.java b/pki/base/common/src/com/netscape/cms/publish/publishers/LdapEncryptCertPublisher.java index d5cbfb323..d2c488620 100644 --- a/pki/base/common/src/com/netscape/cms/publish/publishers/LdapEncryptCertPublisher.java +++ b/pki/base/common/src/com/netscape/cms/publish/publishers/LdapEncryptCertPublisher.java @@ -329,7 +329,7 @@ public class LdapEncryptCertPublisher implements ILdapPublisher, IExtendedPlugin while (vals.hasMoreElements()) { val = (byte[]) vals.nextElement(); - if (Utils.byteArraysAreEqual(val, bval)) { + if (PublisherUtils.byteArraysAreEqual(val, bval)) { return true; } } diff --git a/pki/base/common/src/com/netscape/cms/publish/publishers/LdapUserCertPublisher.java b/pki/base/common/src/com/netscape/cms/publish/publishers/LdapUserCertPublisher.java index afa0601dc..0eba679ad 100644 --- a/pki/base/common/src/com/netscape/cms/publish/publishers/LdapUserCertPublisher.java +++ b/pki/base/common/src/com/netscape/cms/publish/publishers/LdapUserCertPublisher.java @@ -303,7 +303,7 @@ public class LdapUserCertPublisher implements ILdapPublisher, IExtendedPluginInf val = vals.nextElement(); if (val.length == 0) continue; - if (Utils.byteArraysAreEqual(val, bval)) { + if (PublisherUtils.byteArraysAreEqual(val, bval)) { return true; } } diff --git a/pki/base/common/src/com/netscape/cms/publish/publishers/PublisherUtils.java b/pki/base/common/src/com/netscape/cms/publish/publishers/PublisherUtils.java new file mode 100644 index 000000000..314e87e63 --- /dev/null +++ b/pki/base/common/src/com/netscape/cms/publish/publishers/PublisherUtils.java @@ -0,0 +1,136 @@ +// --- 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.cms.publish.publishers; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Vector; + +/** + * Publisher utility class. + * + * @version $Revision$, $Date$ + */ +public class PublisherUtils { + public static void checkHost(String hostname) throws UnknownHostException { + InetAddress.getByName(hostname); + } + + public static void copyStream(InputStream in, OutputStream out) throws IOException { + byte[] buf = new byte[4096]; + int len; + + while ((len = in.read(buf)) != -1) { + out.write(buf, 0, len); + } + } + + public static void copyStream(BufferedReader in, OutputStreamWriter out) throws IOException { + char[] buf = new char[4096]; + int len; + + while ((len = in.read(buf)) != -1) { + out.write(buf, 0, len); + } + } + + /// Sorts an array of Strings. + // Java currently has no general sort function. Sorting Strings is + // common enough that it's worth making a special case. + public static void sortStrings(String[] strings) { + // Just does a bubblesort. + for (int i = 0; i < strings.length - 1; ++i) { + for (int j = i + 1; j < strings.length; ++j) { + if (strings[i].compareTo(strings[j]) > 0) { + String t = strings[i]; + + strings[i] = strings[j]; + strings[j] = t; + } + } + } + } + + /// Returns a date string formatted in Unix ls style - if it's within + // six months of now, Mmm dd hh:ss, else Mmm dd yyyy. + public static String lsDateStr(Date date) { + long dateTime = date.getTime(); + + if (dateTime == -1L) + return "------------"; + long nowTime = System.currentTimeMillis(); + SimpleDateFormat formatter = new SimpleDateFormat(); + + if (Math.abs(nowTime - dateTime) < 183L * 24L * 60L * 60L * 1000L) + formatter.applyPattern("MMM dd hh:ss"); + else + formatter.applyPattern("MMM dd yyyy"); + return formatter.format(date); + } + + /** + * compares contents two byte arrays returning true if exactly same. + */ + static public boolean byteArraysAreEqual(byte[] a, byte[] b) { + if (a.length != b.length) + return false; + for (int i = 0; i < a.length; i++) { + if (a[i] != b[i]) + return false; + } + return true; + } + + /** + * strips out double quotes around String parameter + * + * @param s the string potentially bracketed with double quotes + * @return string stripped of surrounding double quotes + */ + public static String stripQuotes(String s) { + if (s == null) { + return s; + } + + if ((s.startsWith("\"")) && (s.endsWith("\""))) { + return (s.substring(1, (s.length() - 1))); + } + + return s; + } + + /** + * returns an array of strings from a vector of Strings + * there'll be trouble if the Vector contains something other + * than just Strings + */ + public static String[] getStringArrayFromVector(Vector v) { + String s[] = new String[v.size()]; + + v.copyInto(s); + return s; + } + +} diff --git a/pki/base/common/src/com/netscape/cms/publish/publishers/Utils.java b/pki/base/common/src/com/netscape/cms/publish/publishers/Utils.java deleted file mode 100644 index 03561ee78..000000000 --- a/pki/base/common/src/com/netscape/cms/publish/publishers/Utils.java +++ /dev/null @@ -1,136 +0,0 @@ -// --- 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.cms.publish.publishers; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.Vector; - -/** - * Publisher utility class. - * - * @version $Revision$, $Date$ - */ -public class Utils { - public static void checkHost(String hostname) throws UnknownHostException { - InetAddress.getByName(hostname); - } - - public static void copyStream(InputStream in, OutputStream out) throws IOException { - byte[] buf = new byte[4096]; - int len; - - while ((len = in.read(buf)) != -1) { - out.write(buf, 0, len); - } - } - - public static void copyStream(BufferedReader in, OutputStreamWriter out) throws IOException { - char[] buf = new char[4096]; - int len; - - while ((len = in.read(buf)) != -1) { - out.write(buf, 0, len); - } - } - - /// Sorts an array of Strings. - // Java currently has no general sort function. Sorting Strings is - // common enough that it's worth making a special case. - public static void sortStrings(String[] strings) { - // Just does a bubblesort. - for (int i = 0; i < strings.length - 1; ++i) { - for (int j = i + 1; j < strings.length; ++j) { - if (strings[i].compareTo(strings[j]) > 0) { - String t = strings[i]; - - strings[i] = strings[j]; - strings[j] = t; - } - } - } - } - - /// Returns a date string formatted in Unix ls style - if it's within - // six months of now, Mmm dd hh:ss, else Mmm dd yyyy. - public static String lsDateStr(Date date) { - long dateTime = date.getTime(); - - if (dateTime == -1L) - return "------------"; - long nowTime = System.currentTimeMillis(); - SimpleDateFormat formatter = new SimpleDateFormat(); - - if (Math.abs(nowTime - dateTime) < 183L * 24L * 60L * 60L * 1000L) - formatter.applyPattern("MMM dd hh:ss"); - else - formatter.applyPattern("MMM dd yyyy"); - return formatter.format(date); - } - - /** - * compares contents two byte arrays returning true if exactly same. - */ - static public boolean byteArraysAreEqual(byte[] a, byte[] b) { - if (a.length != b.length) - return false; - for (int i = 0; i < a.length; i++) { - if (a[i] != b[i]) - return false; - } - return true; - } - - /** - * strips out double quotes around String parameter - * - * @param s the string potentially bracketed with double quotes - * @return string stripped of surrounding double quotes - */ - public static String stripQuotes(String s) { - if (s == null) { - return s; - } - - if ((s.startsWith("\"")) && (s.endsWith("\""))) { - return (s.substring(1, (s.length() - 1))); - } - - return s; - } - - /** - * returns an array of strings from a vector of Strings - * there'll be trouble if the Vector contains something other - * than just Strings - */ - public static String[] getStringArrayFromVector(Vector v) { - String s[] = new String[v.size()]; - - v.copyInto(s); - return s; - } - -} diff --git a/pki/base/common/src/com/netscape/cms/servlet/base/CMSServlet.java b/pki/base/common/src/com/netscape/cms/servlet/base/CMSServlet.java index 041818d0a..a32116b43 100644 --- a/pki/base/common/src/com/netscape/cms/servlet/base/CMSServlet.java +++ b/pki/base/common/src/com/netscape/cms/servlet/base/CMSServlet.java @@ -95,7 +95,7 @@ import com.netscape.cms.servlet.common.GenSuccessTemplateFiller; import com.netscape.cms.servlet.common.GenSvcPendingTemplateFiller; import com.netscape.cms.servlet.common.GenUnexpectedErrorTemplateFiller; import com.netscape.cms.servlet.common.ICMSTemplateFiller; -import com.netscape.cms.servlet.common.Utils; +import com.netscape.cms.servlet.common.ServletUtils; import com.netscape.cmsutil.xml.XMLObject; /** @@ -274,7 +274,7 @@ public abstract class CMSServlet extends HttpServlet { mId = sc.getInitParameter(PROP_ID); try { - mAclMethod = Utils.initializeAuthz(sc, mAuthz, mId); + mAclMethod = ServletUtils.initializeAuthz(sc, mAuthz, mId); } catch (ServletException e) { log(ILogger.LL_FAILURE, e.toString()); throw e; diff --git a/pki/base/common/src/com/netscape/cms/servlet/common/ServletUtils.java b/pki/base/common/src/com/netscape/cms/servlet/common/ServletUtils.java new file mode 100644 index 000000000..5c16b8195 --- /dev/null +++ b/pki/base/common/src/com/netscape/cms/servlet/common/ServletUtils.java @@ -0,0 +1,106 @@ +// --- 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.cms.servlet.common; + +import java.util.StringTokenizer; + +import javax.servlet.ServletConfig; +import javax.servlet.ServletException; + +import com.netscape.certsrv.apps.CMS; +import com.netscape.certsrv.authorization.IAuthzSubsystem; +import com.netscape.certsrv.base.EBaseException; +import com.netscape.certsrv.base.IConfigStore; + +/** + * Utility class + * + * @version $Revision$, $Date$ + */ +public class ServletUtils { + + public final static String AUTHZ_SRC_LDAP = "ldap"; + public final static String AUTHZ_SRC_TYPE = "sourceType"; + public final static String AUTHZ_CONFIG_STORE = "authz"; + public final static String AUTHZ_SRC_XML = "web.xml"; + public final static String PROP_AUTHZ_MGR = "AuthzMgr"; + public final static String PROP_ACL = "ACLinfo"; + public final static String AUTHZ_MGR_BASIC = "BasicAclAuthz"; + public final static String AUTHZ_MGR_LDAP = "DirAclAuthz"; + + public static String initializeAuthz(ServletConfig sc, + IAuthzSubsystem authz, String id) throws ServletException { + String srcType = AUTHZ_SRC_LDAP; + + try { + IConfigStore authzConfig = + CMS.getConfigStore().getSubStore(AUTHZ_CONFIG_STORE); + + srcType = authzConfig.getString(AUTHZ_SRC_TYPE, AUTHZ_SRC_LDAP); + } catch (EBaseException e) { + CMS.debug(CMS.getLogMessage("ADMIN_SRVLT_FAIL_SRC_TYPE")); + } + + String aclMethod = null; + + if (srcType.equalsIgnoreCase(AUTHZ_SRC_XML)) { + CMS.debug(CMS.getLogMessage("ADMIN_SRVLT_AUTHZ_INITED", "")); + aclMethod = sc.getInitParameter(PROP_AUTHZ_MGR); + if (aclMethod != null && + aclMethod.equalsIgnoreCase(AUTHZ_MGR_BASIC)) { + String aclInfo = sc.getInitParameter(PROP_ACL); + + if (aclInfo != null) { + try { + addACLInfo(authz, aclMethod, aclInfo); + } catch (EBaseException ee) { + throw new ServletException( + "failed to init authz info from xml config file"); + } + + CMS.debug(CMS.getLogMessage("ADMIN_SRVLT_AUTHZ_MGR_INIT_DONE", + id)); + } else { + CMS.debug(CMS.getLogMessage( + "ADMIN_SRVLT_PROP_ACL_NOT_SPEC", PROP_ACL, id, + AUTHZ_MGR_LDAP)); + } + } else { + CMS.debug(CMS.getLogMessage("ADMIN_SRVLT_PROP_ACL_NOT_SPEC", + PROP_AUTHZ_MGR, id, AUTHZ_MGR_LDAP)); + } + } else { + aclMethod = AUTHZ_MGR_LDAP; + CMS.debug(CMS.getLogMessage("ADMIN_SRVLT_AUTH_LDAP_NOT_XML", id)); + } + + return aclMethod; + } + + public static void addACLInfo(IAuthzSubsystem authz, String aclMethod, + String aclInfo) throws EBaseException { + + StringTokenizer tokenizer = new StringTokenizer(aclInfo, "#"); + + while (tokenizer.hasMoreTokens()) { + String acl = (String) tokenizer.nextToken(); + + authz.authzMgrAccessInit(aclMethod, acl); + } + } +} diff --git a/pki/base/common/src/com/netscape/cms/servlet/common/Utils.java b/pki/base/common/src/com/netscape/cms/servlet/common/Utils.java deleted file mode 100644 index 9c728c03e..000000000 --- a/pki/base/common/src/com/netscape/cms/servlet/common/Utils.java +++ /dev/null @@ -1,106 +0,0 @@ -// --- 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.cms.servlet.common; - -import java.util.StringTokenizer; - -import javax.servlet.ServletConfig; -import javax.servlet.ServletException; - -import com.netscape.certsrv.apps.CMS; -import com.netscape.certsrv.authorization.IAuthzSubsystem; -import com.netscape.certsrv.base.EBaseException; -import com.netscape.certsrv.base.IConfigStore; - -/** - * Utility class - * - * @version $Revision$, $Date$ - */ -public class Utils { - - public final static String AUTHZ_SRC_LDAP = "ldap"; - public final static String AUTHZ_SRC_TYPE = "sourceType"; - public final static String AUTHZ_CONFIG_STORE = "authz"; - public final static String AUTHZ_SRC_XML = "web.xml"; - public final static String PROP_AUTHZ_MGR = "AuthzMgr"; - public final static String PROP_ACL = "ACLinfo"; - public final static String AUTHZ_MGR_BASIC = "BasicAclAuthz"; - public final static String AUTHZ_MGR_LDAP = "DirAclAuthz"; - - public static String initializeAuthz(ServletConfig sc, - IAuthzSubsystem authz, String id) throws ServletException { - String srcType = AUTHZ_SRC_LDAP; - - try { - IConfigStore authzConfig = - CMS.getConfigStore().getSubStore(AUTHZ_CONFIG_STORE); - - srcType = authzConfig.getString(AUTHZ_SRC_TYPE, AUTHZ_SRC_LDAP); - } catch (EBaseException e) { - CMS.debug(CMS.getLogMessage("ADMIN_SRVLT_FAIL_SRC_TYPE")); - } - - String aclMethod = null; - - if (srcType.equalsIgnoreCase(AUTHZ_SRC_XML)) { - CMS.debug(CMS.getLogMessage("ADMIN_SRVLT_AUTHZ_INITED", "")); - aclMethod = sc.getInitParameter(PROP_AUTHZ_MGR); - if (aclMethod != null && - aclMethod.equalsIgnoreCase(AUTHZ_MGR_BASIC)) { - String aclInfo = sc.getInitParameter(PROP_ACL); - - if (aclInfo != null) { - try { - addACLInfo(authz, aclMethod, aclInfo); - } catch (EBaseException ee) { - throw new ServletException( - "failed to init authz info from xml config file"); - } - - CMS.debug(CMS.getLogMessage("ADMIN_SRVLT_AUTHZ_MGR_INIT_DONE", - id)); - } else { - CMS.debug(CMS.getLogMessage( - "ADMIN_SRVLT_PROP_ACL_NOT_SPEC", PROP_ACL, id, - AUTHZ_MGR_LDAP)); - } - } else { - CMS.debug(CMS.getLogMessage("ADMIN_SRVLT_PROP_ACL_NOT_SPEC", - PROP_AUTHZ_MGR, id, AUTHZ_MGR_LDAP)); - } - } else { - aclMethod = AUTHZ_MGR_LDAP; - CMS.debug(CMS.getLogMessage("ADMIN_SRVLT_AUTH_LDAP_NOT_XML", id)); - } - - return aclMethod; - } - - public static void addACLInfo(IAuthzSubsystem authz, String aclMethod, - String aclInfo) throws EBaseException { - - StringTokenizer tokenizer = new StringTokenizer(aclInfo, "#"); - - while (tokenizer.hasMoreTokens()) { - String acl = (String) tokenizer.nextToken(); - - authz.authzMgrAccessInit(aclMethod, acl); - } - } -} diff --git a/pki/base/common/src/com/netscape/cms/servlet/profile/ProfileServlet.java b/pki/base/common/src/com/netscape/cms/servlet/profile/ProfileServlet.java index 7bc6304be..457b8422b 100644 --- a/pki/base/common/src/com/netscape/cms/servlet/profile/ProfileServlet.java +++ b/pki/base/common/src/com/netscape/cms/servlet/profile/ProfileServlet.java @@ -43,7 +43,7 @@ import com.netscape.certsrv.util.IStatsSubsystem; import com.netscape.cms.servlet.base.CMSServlet; import com.netscape.cms.servlet.base.UserInfo; import com.netscape.cms.servlet.common.CMSRequest; -import com.netscape.cms.servlet.common.Utils; +import com.netscape.cms.servlet.common.ServletUtils; /** * This servlet is the base class of all profile servlets. @@ -184,7 +184,7 @@ public class ProfileServlet extends CMSServlet { mId = sc.getInitParameter(PROP_ID); try { - mAclMethod = Utils.initializeAuthz(sc, mAuthz, mId); + mAclMethod = ServletUtils.initializeAuthz(sc, mAuthz, mId); } catch (ServletException e) { log(ILogger.LL_FAILURE, e.toString()); throw e; -- cgit