001/**
002 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003 *
004 * Copyright (c) 2008 Sun Microsystems Inc. All Rights Reserved
005 *
006 * The contents of this file are subject to the terms
007 * of the Common Development and Distribution License
008 * (the License). You may not use this file except in
009 * compliance with the License.
010 *
011 * You can obtain a copy of the License at
012 * https://opensso.dev.java.net/public/CDDLv1.0.html or
013 * opensso/legal/CDDLv1.0.txt
014 * See the License for the specific language governing
015 * permission and limitations under the License.
016 *
017 * When distributing Covered Code, include this CDDL
018 * Header Notice in each file and include the License file
019 * at opensso/legal/CDDLv1.0.txt.
020 * If applicable, add the following below the CDDL Header,
021 * with the fields enclosed by brackets [] replaced by
022 * your own identifying information:
023 * "Portions Copyrighted [year] [name of copyright owner]"
024 *
025 * $Id: EntitlementException.java,v 1.2 2009/09/03 17:06:23 veiming Exp $
026 *
027 * Portions copyright 2010-2014 ForgeRock AS.
028 */
029
030package com.sun.identity.entitlement;
031
032import java.text.MessageFormat;
033import java.util.Locale;
034import java.util.ResourceBundle;
035
036/**
037 * Entitlement related exception.
038 *
039 * @supported.all.api
040 */
041public class EntitlementException extends Exception {
042    public static final String RES_BUNDLE_NAME = "EntitlementException";
043
044    /*
045     * Selected error code constants. See EntitlementException.properties for full list.
046     */
047
048    public static final int UNABLE_TO_CREATE_POLICY = 1;
049    public static final int INVALID_PRIVILEGE_CLASS = 2;
050    public static final int EMPTY_PRIVILEGE_NAME = 3;
051    public static final int NULL_ENTITLEMENT = 4;
052    public static final int UNSUPPORTED_OPERATION = 5;
053    public static final int INVALID_APPLICATION_CLASS = 6;
054    public static final int INVALID_XML = 7;
055    public static final int INVALID_WSDL_LOCATION = 8;
056    public static final int MISSING_PRIVILEGE_JSON = 9;
057    public static final int SESSION_HAS_EXPIRED = 10;
058    public static final int INVALID_JSON = 11;
059    public static final int MISSING_PRIVILEGE_NAME = 12;
060    public static final int POLICY_NAME_MISMATCH = 13;
061    public static final int RESOURCE_LIST_EMPTY = 14;
062
063    public static final int UNABLE_TO_SERIALIZE_OBJECT = 200;
064    public static final int NO_SUCH_POLICY = 203;
065    public static final int POLICY_ALREADY_EXISTS = 217;
066    public static final int APPLICATION_ALREADY_EXISTS = 228;
067    public static final int APPLICATION_NAME_MISMATCH = 229;
068    public static final int APP_RETRIEVAL_ERROR = 248;
069    public static final int NO_SUCH_REFERRAL_PRIVILEGE = 263;
070
071    public static final int INCONSISTENT_WILDCARDS = 300;
072    public static final int INVALID_PORT = 301;
073    public static final int MALFORMED_URL = 302;
074    public static final int INVALID_RESOURCE = 303;
075    public static final int INVALID_ENTITLEMENT_SUBJECT_CLASS = 310;
076    public static final int INVALID_CLASS = 311;
077
078    public static final int INVALID_APP_TYPE = 317;
079    public static final int INVALID_APP_REALM = 318;
080
081    public static final int NO_SUCH_APPLICATION = 321;
082    public static final int NOT_FOUND = 325;
083
084    public static final int PERMISSION_DENIED = 326;
085
086    public static final int SUBJECT_REQUIRED = 327;
087    public static final int INVALID_SEARCH_FILTER = 328;
088    public static final int UNKNOWN_POLICY_CLASS = 329;
089    public static final int UNKNOWN_RESOURCE_ATTRIBUTE_CLASS = 330;
090    public static final int POLICY_CLASS_CAST_EXCEPTION = 331;
091    public static final int POLICY_CLASS_NOT_INSTANTIABLE = 332;
092    public static final int POLICY_CLASS_NOT_ACCESSIBLE = 333;
093    public static final int INVALID_PROPERTY_VALUE = 400;
094    public static final int INVALID_VALUE = 401;
095    public static final int START_DATE_AFTER_END_DATE = 402;
096    public static final int APP_NOT_CREATED_POLICIES_EXIST = 404;
097    public static final int INVALID_PROPERTY_VALUE_UNKNOWN_VALUE = 405;
098    public static final int IP_CONDITION_CONFIGURATION_REQUIRED = 406;
099
100    public static final int MISSING_RESOURCE = 420;
101    public static final int JSON_PARSE_ERROR = 425;
102    public static final int AUTHENTICATION_ERROR = 434;
103    public static final int CLIENT_IP_EMPTY = 437;
104    public static final int RESOURCE_ENV_NOT_KNOWN = 438;
105
106    public static final int CONDITION_EVALUTATION_FAILED = 510;
107
108    public static final int INVALID_OAUTH2_SCOPE = 700;
109    public static final int AUTH_LEVEL_NOT_INTEGER = 710;
110    public static final int PROPERTY_VALUE_NOT_DEFINED = 711;
111    public static final int AUTH_LEVEL_NOT_INT_OR_SET = 712;
112    public static final int AUTH_SCHEME_NOT_FOUND = 713;
113    public static final int INVALID_ADMIN = 720;
114    public static final int AM_ID_SUBJECT_MEMBERSHIP_EVALUATION_ERROR = 721;
115    public static final int UNABLE_TO_PARSE_SSOTOKEN_AUTHINSTANT = 730;
116    public static final int AT_LEAST_ONE_OF_TIME_PROPS_SHOULD_BE_DEFINED = 740;
117    public static final int PAIR_PROPERTY_NOT_DEFINED = 741;
118    public static final int END_IP_BEFORE_START_IP = 750;
119
120    public static final int PROPERTY_IS_NOT_AN_INTEGER = 800;
121    public static final int PROPERTY_IS_NOT_A_SET = 801;
122    public static final int PROPERTY_CONTAINS_BLANK_VALUE = 802;
123
124    public static final int INTERNAL_ERROR = 900;
125    public static final int REALM_NOT_FOUND = 901;
126
127    private int errorCode;
128    private String message;
129    private Object[] params;
130
131    /**
132     * Creates an entitlement exception.
133     *
134     * @param errorCode Error code.
135     */
136    public EntitlementException(int errorCode) {
137        this.errorCode = errorCode;
138        this.message = getLocalizedMessage(Locale.getDefault());
139    }
140
141    /**
142     * Creates an entitlement exception.
143     * 
144     * @param errorCode Error code.
145     * @param params Parameters for formatting the message string.
146     */
147    public EntitlementException(int errorCode, Object... params) {
148        this.errorCode = errorCode;
149        this.params = params;
150        this.message = getLocalizedMessage(Locale.getDefault());
151    }
152
153    /**
154     * Creates an entitlement exception.
155     *
156     * @param errorCode Error code.
157     * @param cause Root cause.
158     */
159    public EntitlementException(int errorCode, Throwable cause) {
160        super(cause);
161        this.errorCode = errorCode;
162        this.message = getLocalizedMessage(Locale.getDefault());
163    }
164
165    /**
166     * Creates an entitlement exception.
167     *
168     * @param errorCode Error code.
169     * @param params Parameters for formatting the message string.
170     * @param cause Root cause.
171     */
172    public EntitlementException(int errorCode, Object[] params, Throwable cause)
173    {
174        super(cause);
175        this.errorCode = errorCode;
176        this.params = params;
177        this.message = getLocalizedMessage(Locale.getDefault());
178    }
179
180    public EntitlementException(int errorCode, Throwable cause, Object...params) {
181        this(errorCode, params, cause);
182    }
183
184    /**
185     * Returns error code.
186     * 
187     * @return error code.
188     */
189    public int getErrorCode() {
190        return errorCode;
191    }
192
193    /**
194     * Returns exception message.
195     *
196     * @return exception message.
197     */
198    @Override
199    public String getMessage() {
200        return message;
201    }
202
203    /**
204     * Returns localized exception message.
205     *
206     * @return localized exception message.
207     */
208    @Override
209    public String getLocalizedMessage() {
210        return message;
211    }
212
213    /**
214     * Returns localized exception message using the errorCode as key.
215     *
216     * @param locale Locale of the message.
217     * @return localized exception message.
218     */
219    public String getLocalizedMessage(Locale locale) {
220        ResourceBundle rb = ResourceBundle.getBundle(RES_BUNDLE_NAME, locale);
221        String msg = rb.getString(Integer.toString(errorCode));
222        return (params != null) ? MessageFormat.format(msg, params) : msg;
223    }
224}




























































Copyright © 2010-2017, ForgeRock All Rights Reserved.