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-2015 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 public static final int RESOURCE_TYPE_ID_MISMATCH = 15; 063 064 public static final int UNABLE_TO_SERIALIZE_OBJECT = 200; 065 public static final int NO_SUCH_POLICY = 203; 066 public static final int UNABLE_SEARCH_PRIVILEGES = 215; 067 public static final int UNABLE_SEARCH_PRIVILEGES_MISSING_TOKEN = 216; 068 public static final int POLICY_ALREADY_EXISTS = 217; 069 public static final int RESOURCE_TYPE_ALREADY_EXISTS = 218; 070 public static final int NO_SUCH_RESOURCE_TYPE = 219; 071 public static final int RESOURCE_TYPE_IN_USE = 223; 072 public static final int RESOURCE_TYPE_RETRIEVAL_ERROR = 224; 073 public static final int APPLICATION_ALREADY_EXISTS = 228; 074 public static final int APPLICATION_NAME_MISMATCH = 229; 075 public static final int REMOVE_APPLICATION_FAIL = 230; 076 public static final int MODIFY_APPLICATION_FAIL = 231; 077 public static final int REMOVE_RESOURCE_TYPE_FAIL = 232; 078 public static final int MODIFY_RESOURCE_TYPE_FAIL = 233; 079 public static final int RESOURCE_TYPE_REFERENCED = 234; 080 public static final int POLICY_DEFINES_INVALID_RESOURCE_TYPE = 235; 081 public static final int MISSING_RESOURCE_TYPE = 236; 082 public static final int INVALID_RESOURCE_TYPE = 237; 083 public static final int NO_RESOURCE_TYPE_EXPECTED = 238; 084 public static final int APP_RETRIEVAL_ERROR = 248; 085 public static final int MISSING_RESOURCE_TYPE_NAME = 249; 086 public static final int NO_SUCH_REFERRAL_PRIVILEGE = 263; 087 088 public static final int INCONSISTENT_WILDCARDS = 300; 089 public static final int INVALID_PORT = 301; 090 public static final int MALFORMED_URL = 302; 091 public static final int INVALID_RESOURCE = 303; 092 public static final int INVALID_ENTITLEMENT_SUBJECT_CLASS = 310; 093 public static final int INVALID_CLASS = 311; 094 095 public static final int INVALID_APP_TYPE = 317; 096 public static final int INVALID_APP_REALM = 318; 097 098 public static final int NO_SUCH_APPLICATION = 321; 099 public static final int NOT_FOUND = 325; 100 101 public static final int PERMISSION_DENIED = 326; 102 103 public static final int SUBJECT_REQUIRED = 327; 104 public static final int INVALID_SEARCH_FILTER = 328; 105 public static final int UNKNOWN_POLICY_CLASS = 329; 106 public static final int UNKNOWN_RESOURCE_ATTRIBUTE_CLASS = 330; 107 public static final int POLICY_CLASS_CAST_EXCEPTION = 331; 108 public static final int POLICY_CLASS_NOT_INSTANTIABLE = 332; 109 public static final int POLICY_CLASS_NOT_ACCESSIBLE = 333; 110 public static final int INVALID_PROPERTY_VALUE = 400; 111 public static final int INVALID_VALUE = 401; 112 public static final int START_DATE_AFTER_END_DATE = 402; 113 public static final int APP_NOT_CREATED_POLICIES_EXIST = 404; 114 public static final int INVALID_PROPERTY_VALUE_UNKNOWN_VALUE = 405; 115 public static final int IP_CONDITION_CONFIGURATION_REQUIRED = 406; 116 117 public static final int MISSING_RESOURCE = 420; 118 public static final int JSON_PARSE_ERROR = 425; 119 public static final int AUTHENTICATION_ERROR = 434; 120 public static final int CLIENT_IP_EMPTY = 437; 121 public static final int RESOURCE_ENV_NOT_KNOWN = 438; 122 123 public static final int CONDITION_EVALUATION_FAILED = 510; 124 125 public static final int INVALID_OAUTH2_SCOPE = 700; 126 public static final int AUTH_LEVEL_NOT_INTEGER = 710; 127 public static final int PROPERTY_VALUE_NOT_DEFINED = 711; 128 public static final int AUTH_LEVEL_NOT_INT_OR_SET = 712; 129 public static final int AUTH_SCHEME_NOT_FOUND = 713; 130 public static final int INVALID_ADMIN = 720; 131 public static final int AM_ID_SUBJECT_MEMBERSHIP_EVALUATION_ERROR = 721; 132 public static final int UNABLE_TO_PARSE_SSOTOKEN_AUTHINSTANT = 730; 133 public static final int AT_LEAST_ONE_OF_TIME_PROPS_SHOULD_BE_DEFINED = 740; 134 public static final int PAIR_PROPERTY_NOT_DEFINED = 741; 135 public static final int END_IP_BEFORE_START_IP = 750; 136 public static final int INVALID_SCRIPT_ID = 760; 137 138 public static final int PROPERTY_IS_NOT_AN_INTEGER = 800; 139 public static final int PROPERTY_IS_NOT_A_SET = 801; 140 public static final int PROPERTY_CONTAINS_BLANK_VALUE = 802; 141 142 public static final int INTERNAL_ERROR = 900; 143 public static final int REALM_NOT_FOUND = 901; 144 145 private int errorCode; 146 private String message; 147 private Object[] params; 148 149 /** 150 * Creates an entitlement exception. 151 * 152 * @param errorCode Error code. 153 */ 154 public EntitlementException(int errorCode) { 155 this.errorCode = errorCode; 156 this.message = getLocalizedMessage(Locale.getDefault()); 157 } 158 159 /** 160 * Creates an entitlement exception. 161 * 162 * @param errorCode Error code. 163 * @param params Parameters for formatting the message string. 164 */ 165 public EntitlementException(int errorCode, Object... params) { 166 this.errorCode = errorCode; 167 this.params = params; 168 this.message = getLocalizedMessage(Locale.getDefault()); 169 } 170 171 /** 172 * Creates an entitlement exception. 173 * 174 * @param errorCode Error code. 175 * @param cause Root cause. 176 */ 177 public EntitlementException(int errorCode, Throwable cause) { 178 super(cause); 179 this.errorCode = errorCode; 180 this.message = getLocalizedMessage(Locale.getDefault()); 181 } 182 183 /** 184 * Creates an entitlement exception. 185 * 186 * @param errorCode Error code. 187 * @param params Parameters for formatting the message string. 188 * @param cause Root cause. 189 */ 190 public EntitlementException(int errorCode, Object[] params, Throwable cause) 191 { 192 super(cause); 193 this.errorCode = errorCode; 194 this.params = params; 195 this.message = getLocalizedMessage(Locale.getDefault()); 196 } 197 198 public EntitlementException(int errorCode, Throwable cause, Object...params) { 199 this(errorCode, params, cause); 200 } 201 202 /** 203 * Returns error code. 204 * 205 * @return error code. 206 */ 207 public int getErrorCode() { 208 return errorCode; 209 } 210 211 /** 212 * Returns exception message. 213 * 214 * @return exception message. 215 */ 216 @Override 217 public String getMessage() { 218 return message; 219 } 220 221 /** 222 * Returns localized exception message. 223 * 224 * @return localized exception message. 225 */ 226 @Override 227 public String getLocalizedMessage() { 228 return message; 229 } 230 231 /** 232 * Returns localized exception message using the errorCode as key. 233 * 234 * @param locale Locale of the message. 235 * @return localized exception message. 236 */ 237 public String getLocalizedMessage(Locale locale) { 238 ResourceBundle rb = ResourceBundle.getBundle(RES_BUNDLE_NAME, locale); 239 String msg = rb.getString(Integer.toString(errorCode)); 240 return (params != null) ? MessageFormat.format(msg, params) : msg; 241 } 242}