8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Copyright (c) 2005 Sun Microsystems Inc. All Rights Reserved
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The contents of this file are subject to the terms
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * of the Common Development and Distribution License
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * (the License). You may not use this file except in
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * compliance with the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * You can obtain a copy of the License at
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * https://opensso.dev.java.net/public/CDDLv1.0.html or
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * See the License for the specific language governing
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * permission and limitations under the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * When distributing Covered Code, include this CDDL
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Header Notice in each file and include the License file
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * If applicable, add the following below the CDDL Header,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * with the fields enclosed by brackets [] replaced by
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * your own identifying information:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * "Portions Copyrighted [year] [name of copyright owner]"
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * $Id: IdRepoException.java,v 1.8 2009/11/19 18:18:47 bhavnab Exp $
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington * Portions Copyrighted 2011-2015 ForgeRock AS.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.shared.locale.AMResourceBundleCache;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.shared.locale.L10NMessage;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The exception class whose instance is thrown if there is any error during the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * operation of objects of the <code>com.sun.identity.sms</code> package. This
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * class maps the exception that occurred at a lower level to a high level
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * error. Using the exception status code <code>getExceptionCode()</code> the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * errors are categorized as a <code>ABORT</code>, <code>RETRY</code>,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * <code>CONFIG_PROBLEM</code> or <code>LDAP_OP_FAILED</code> (typically a
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @supported.all.api
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpublic class IdRepoException extends Exception implements L10NMessage {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Static variable
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private transient AMResourceBundleCache amCache = AMResourceBundleCache
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private transient Debug debug = AMIdentityRepository.debug;
ee24f4fbfc8ea42cfe595af5cc4e0dae17434a16David Luna private final static Pattern PATTERN = Pattern.compile("(.*)(?=: (.*?)uid=)|(.*)(?=(.*?)uid=)|(.*)");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Instance variables
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param msg
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The message provided by the object which is throwing the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public IdRepoException(String msg, String errorCode) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * This constructor is used to pass the localized error message At this
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * level, the locale of the caller is not known and it is not possible to
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * throw localized error message at this level. Instead this constructor
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * provides Resource Bundle name ,error code and LDAP error code ( in case
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * of LDAP related exception for correctly locating the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * error message. The default <code>getMessage()</code> will always return
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * English messages only. This is in consistent with current JRE.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param rbName
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Resource bundle Name to be used for getting localized error
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param errorCode
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Key to resource bundle. You can use <code>ResourceBundle rb =
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * ResourceBunde.getBundle(rbName,locale);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * String localizedStr = rb.getString(errorCode)</code>.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param ldapErrCode
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * ldap error code
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param args
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * arguments to message. If it is not present pass the as null.
ce4d3fddc8fe2eddd68a20af9570b3cc63ece5abNeil Madden * @deprecated
ce4d3fddc8fe2eddd68a20af9570b3cc63ece5abNeil Madden * Passing in an ldapErrorCode as a String is not recommended, use the
ce4d3fddc8fe2eddd68a20af9570b3cc63ece5abNeil Madden * OO ctor instead.
ce4d3fddc8fe2eddd68a20af9570b3cc63ece5abNeil Madden public IdRepoException(String rbName, String errorCode, String ldapErrCode, Object[] args)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster this.message = getL10NMessage(java.util.Locale.ENGLISH);
ce4d3fddc8fe2eddd68a20af9570b3cc63ece5abNeil Madden * This constructor is used to pass the localized error message At this
ce4d3fddc8fe2eddd68a20af9570b3cc63ece5abNeil Madden * level, the locale of the caller is not known and it is not possible to
ce4d3fddc8fe2eddd68a20af9570b3cc63ece5abNeil Madden * throw localized error message at this level. Instead this constructor
ce4d3fddc8fe2eddd68a20af9570b3cc63ece5abNeil Madden * provides Resource Bundle name ,error code and LDAP Result Code ( in case
ce4d3fddc8fe2eddd68a20af9570b3cc63ece5abNeil Madden * of LDAP related exception for correctly locating the
ce4d3fddc8fe2eddd68a20af9570b3cc63ece5abNeil Madden * error message. The default <code>getMessage()</code> will always return
ce4d3fddc8fe2eddd68a20af9570b3cc63ece5abNeil Madden * English messages only. This is in consistent with current JRE.
ce4d3fddc8fe2eddd68a20af9570b3cc63ece5abNeil Madden * @param rbName
ce4d3fddc8fe2eddd68a20af9570b3cc63ece5abNeil Madden * Resource bundle Name to be used for getting localized error
ce4d3fddc8fe2eddd68a20af9570b3cc63ece5abNeil Madden * @param errorCode
ce4d3fddc8fe2eddd68a20af9570b3cc63ece5abNeil Madden * Key to resource bundle. You can use <code>ResourceBundle rb =
ce4d3fddc8fe2eddd68a20af9570b3cc63ece5abNeil Madden * ResourceBunde.getBundle(rbName,locale);
ce4d3fddc8fe2eddd68a20af9570b3cc63ece5abNeil Madden * String localizedStr = rb.getString(errorCode)</code>.
ce4d3fddc8fe2eddd68a20af9570b3cc63ece5abNeil Madden * @param ldapResultCode
ce4d3fddc8fe2eddd68a20af9570b3cc63ece5abNeil Madden * ldap result code
ce4d3fddc8fe2eddd68a20af9570b3cc63ece5abNeil Madden * @param args
ce4d3fddc8fe2eddd68a20af9570b3cc63ece5abNeil Madden * arguments to message. If it is not present pass the as null.
ce4d3fddc8fe2eddd68a20af9570b3cc63ece5abNeil Madden public IdRepoException(String rbName, String errorCode, ResultCode ldapResultCode, Object[] args) {
ce4d3fddc8fe2eddd68a20af9570b3cc63ece5abNeil Madden this.ldapErrCode = String.valueOf(ldapResultCode.intValue());
ce4d3fddc8fe2eddd68a20af9570b3cc63ece5abNeil Madden this.message = getL10NMessage(java.util.Locale.ENGLISH);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * This constructor is used to pass the localized error message At this
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * level, the locale of the caller is not known and it is not possible to
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * throw localized error message at this level. Instead this constructor
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * provides Resource Bundle name and error code for correctly locating the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * error message. The default <code>getMessage()</code> will always return
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * English messages only. This is in consistent with current JRE.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param rbName
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Resource bundle Name to be used for getting localized error
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param errorCode
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Key to resource bundle. You can use <code>ResourceBundle rb =
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * ResourceBunde.getBundle(rbName,locale);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * String localizedStr = rb.getString(errorCode)</code>.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param args
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * arguments to message. If it is not present pass the as null.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public IdRepoException(String rbName, String errorCode, Object[] args) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster this.message = getL10NMessage(java.util.Locale.ENGLISH);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns a localized error message
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param locale
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Uses the locale object to create the appropriate localized
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * error message
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return localized error message.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @see #IdRepoException(String, String, Object[])
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public String getL10NMessage(java.util.Locale locale) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ResourceBundle bundle = amCache.getResBundle(bundleName, locale);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String mid = Locale.getString(bundle, errorCode, debug);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns <code>ResourceBundle</code> Name associated with this error
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return <code>ResourceBundle</code> name associated with this error
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @see #IdRepoException(String, String, Object[])
ce4d3fddc8fe2eddd68a20af9570b3cc63ece5abNeil Madden * Returns an int representation of <code>ldapErrCode</code>.
ce4d3fddc8fe2eddd68a20af9570b3cc63ece5abNeil Madden * This is to be used with ResultCode.valueOf() which will return a valid
ce4d3fddc8fe2eddd68a20af9570b3cc63ece5abNeil Madden * ResultCode object regardless of the return of this method.
ce4d3fddc8fe2eddd68a20af9570b3cc63ece5abNeil Madden * A null or invalid <code>ldapErrorCode</code> will return <code>-1</code>.
ce4d3fddc8fe2eddd68a20af9570b3cc63ece5abNeil Madden * @return an int representation of this exception's LDAP error code.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns error code associated with this error message.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return Error code associated with this error message.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @see #IdRepoException(String, String, Object[])
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns the LDAP error code associated with this error message.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return Error code associated with this error message and null if
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * not caused by <code>LDAPException</code>.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @see #IdRepoException(String, String, Object[])
60e9e896a1a7a9e62db162e1e9fb6b3c2df50c33Quentin CASTEL * @deprecated
60e9e896a1a7a9e62db162e1e9fb6b3c2df50c33Quentin CASTEL * Use #getLdapErrorIntCode() instead. The ldap error code is always an int
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Replace the LDAP error code associated with this error message.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @see #IdRepoException(String, String, Object[])
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public void setLDAPErrorCode(String errorCode) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns arguments for formatting this error message.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return arguments for formatting this error message. You need to use
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * <code>MessageFormat</code> class to format the message It can
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @see #IdRepoException(String, String, Object[])
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns the error message of this exception.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return String representing the error message
ee24f4fbfc8ea42cfe595af5cc4e0dae17434a16David Luna * If this error is an instance of a LDAP Constraint Violated Error (LDAP code 313)
ee24f4fbfc8ea42cfe595af5cc4e0dae17434a16David Luna * attempts to return useful information about the error that occured without
ee24f4fbfc8ea42cfe595af5cc4e0dae17434a16David Luna * leaking additional information about the system to the calling user.
ee24f4fbfc8ea42cfe595af5cc4e0dae17434a16David Luna * If this error is not an instance of LDAP Constraint Violated Error, the message
ee24f4fbfc8ea42cfe595af5cc4e0dae17434a16David Luna * of the error is returned.
ee24f4fbfc8ea42cfe595af5cc4e0dae17434a16David Luna * @return a user-facing representation of this exception.
60e9e896a1a7a9e62db162e1e9fb6b3c2df50c33Quentin CASTEL if (!IdRepoErrorCode.LDAP_EXCEPTION.equals(getErrorCode()) || args == null || args.length < 3) {
ee24f4fbfc8ea42cfe595af5cc4e0dae17434a16David Luna return "Cannot update attributes due to server's attribute constraints being violated.";