From 2e3b338baa2520be49c8623b1fec45d4ae1f1277 Mon Sep 17 00:00:00 2001 From: Endi Sukma Dewata Date: Fri, 11 Jan 2013 10:30:29 -0500 Subject: WIP --- .../netscape/certsrv/ldap/LDAPExceptionUtil.java | 38 ++++++++++++++++++++++ .../netscape/cms/servlet/admin/UserService.java | 5 +-- .../cms/servlet/admin/UsrGrpAdminServlet.java | 3 +- .../com/netscape/cmscore/usrgrp/UGSubsystem.java | 4 --- 4 files changed, 42 insertions(+), 8 deletions(-) create mode 100644 base/common/src/com/netscape/certsrv/ldap/LDAPExceptionUtil.java (limited to 'base/common/src/com/netscape') diff --git a/base/common/src/com/netscape/certsrv/ldap/LDAPExceptionUtil.java b/base/common/src/com/netscape/certsrv/ldap/LDAPExceptionUtil.java new file mode 100644 index 000000000..cbf9f36ef --- /dev/null +++ b/base/common/src/com/netscape/certsrv/ldap/LDAPExceptionUtil.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.ldap; + +import netscape.ldap.LDAPException; + +import com.netscape.certsrv.base.ConflictingOperationException; +import com.netscape.certsrv.base.PKIException; + +/** + * @author Endi S. Dewata + */ +public class LDAPExceptionUtil { + + public static PKIException createPKIException(LDAPException le) { + switch (le.getLDAPResultCode()) { + case LDAPException.ENTRY_ALREADY_EXISTS: + return new ConflictingOperationException("Entry already exists", le); + default: + return new PKIException("LDAP error ("+le.getLDAPResultCode()+"): "+le.getMessage()); + } + } +} diff --git a/base/common/src/com/netscape/cms/servlet/admin/UserService.java b/base/common/src/com/netscape/cms/servlet/admin/UserService.java index 9a54802ef..e0c7ca9f9 100644 --- a/base/common/src/com/netscape/cms/servlet/admin/UserService.java +++ b/base/common/src/com/netscape/cms/servlet/admin/UserService.java @@ -40,6 +40,7 @@ import com.netscape.certsrv.base.PKIException; import com.netscape.certsrv.base.UserNotFoundException; import com.netscape.certsrv.common.OpDef; import com.netscape.certsrv.common.ScopeDef; +import com.netscape.certsrv.ldap.LDAPExceptionUtil; import com.netscape.certsrv.logging.IAuditor; import com.netscape.certsrv.logging.ILogger; import com.netscape.certsrv.password.IPasswordCheck; @@ -303,11 +304,11 @@ public class UserService extends PKIService implements UserResource { } catch (LDAPException e) { log(ILogger.LL_FAILURE, CMS.getLogMessage("ADMIN_SRVLT_ADD_USER_FAIL", e.toString())); - throw new PKIException(getUserMessage("CMS_USRGRP_USER_ADD_FAILED")); + throw LDAPExceptionUtil.createPKIException(e); } catch (Exception e) { log(ILogger.LL_FAILURE, e.toString()); - throw new PKIException(getUserMessage("CMS_USRGRP_USER_ADD_FAILED")); + throw new PKIException(e.getMessage(), e); } } catch (PKIException e) { diff --git a/base/common/src/com/netscape/cms/servlet/admin/UsrGrpAdminServlet.java b/base/common/src/com/netscape/cms/servlet/admin/UsrGrpAdminServlet.java index 506d608cd..2cd337123 100644 --- a/base/common/src/com/netscape/cms/servlet/admin/UsrGrpAdminServlet.java +++ b/base/common/src/com/netscape/cms/servlet/admin/UsrGrpAdminServlet.java @@ -897,8 +897,7 @@ public class UsrGrpAdminServlet extends AdminServlet { CMS.getUserMessage(getLocale(req), "CMS_USRGRP_USER_ADD_FAILED_1", "uid"), null, resp); } else { sendResponse(ERROR, - CMS.getUserMessage(getLocale(req), "CMS_USRGRP_USER_ADD_FAILED_2", user.getUserID()), null, - resp); + CMS.getUserMessage(getLocale(req), "CMS_USRGRP_USER_ADD_FAILED"), null, resp); } return; } catch (LDAPException e) { diff --git a/base/common/src/com/netscape/cmscore/usrgrp/UGSubsystem.java b/base/common/src/com/netscape/cmscore/usrgrp/UGSubsystem.java index 6314c226f..034357b6e 100644 --- a/base/common/src/com/netscape/cmscore/usrgrp/UGSubsystem.java +++ b/base/common/src/com/netscape/cmscore/usrgrp/UGSubsystem.java @@ -646,10 +646,6 @@ public final class UGSubsystem implements IUGSubsystem { throw new EUsrGrpException(CMS.getUserMessage("CMS_USRGRP_ADD_USER_FAIL_NO_UID")); } - if (getUser(id.getUserID()) != null) { - throw new EUsrGrpException(CMS.getUserMessage("CMS_USRGRP_USER_ADD_FAILED_2", id.getUserID())); - } - LDAPAttributeSet attrs = new LDAPAttributeSet(); String oc[] = { "top", "person", "organizationalPerson", "inetOrgPerson", "cmsuser" }; -- cgit