001/* 002 * CDDL HEADER START 003 * 004 * The contents of this file are subject to the terms of the 005 * Common Development and Distribution License, Version 1.0 only 006 * (the "License"). You may not use this file except in compliance 007 * with the License. 008 * 009 * You can obtain a copy of the license at 010 * docs/licenses/cddl.txt 011 * or http://www.opensource.org/licenses/cddl1.php. 012 * See the License for the specific language governing permissions 013 * and limitations under the License. 014 * 015 * When distributing Covered Code, include this CDDL HEADER in each 016 * file and include the License file at 017 * docs/licenses/cddl.txt. If applicable, 018 * add the following below this CDDL HEADER, with the fields enclosed 019 * by brackets "[]" replaced with your own identifying information: 020 * Portions Copyright [yyyy] [name of copyright owner] 021 * 022 * CDDL HEADER END 023 * 024 * 025 * Copyright 2021 Ping Identity Corporation 026 */ 027package com.unboundid.directory.sdk.ds.types; 028 029 030import com.unboundid.util.NotNull; 031import com.unboundid.util.Nullable; 032import com.unboundid.util.StaticUtils; 033import com.unboundid.util.ThreadSafety; 034import com.unboundid.util.ThreadSafetyLevel; 035 036 037/** 038 * This class defines the set of result codes for use in 039 * {@link PassThroughAuthenticationResult} objects. 040 */ 041@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 042public enum PassThroughAuthenticationResultCode 043{ 044 /** 045 * Indicates that pass-through authentication attempt succeeded. 046 */ 047 SUCCESS("success"), 048 049 050 051 /** 052 * Indicates that the pass-through authentication attempt failed because the 053 * pass-through authentication handler could not identify exactly one account 054 * in the external service that corresponds to the account in the local 055 * server. 056 */ 057 NO_SUCH_USER("no-such-user"), 058 059 060 061 /** 062 * Indicates that the pass-through authentication attempt failed because the 063 * client provided the wrong password for the target user. 064 */ 065 WRONG_PASSWORD("wrong-password"), 066 067 068 069 /** 070 * Indicates that the pass-through authentication attempt failed because the 071 * password for the mapped account must be changed before the account can be 072 * used. 073 */ 074 MUST_CHANGE_PASSWORD("must-change-password"), 075 076 077 078 /** 079 * Indicates that the pass-through authentication attempt filed because the 080 * mapped account in the external authentication service is not in a usable 081 * state (e.g., the password is expired, the account is locked, etc.). 082 */ 083 ACCOUNT_NOT_USABLE("account-not-usable"), 084 085 086 087 /** 088 * Indicates that the pass-through authentication attempt failed, but the 089 * server did not provide enough information to identify a specific reason 090 * (e.g., whether the user doesn't exist, the wrong password was provided, the 091 * account is in an unusable state, etc.). 092 */ 093 NON_SPECIFIC_AUTHENTICATION_FAILURE("non-specific-authentication-failure"), 094 095 096 097 /** 098 * Indicates that the pass-through authentication attempt failed because the 099 * external service reported an error result. 100 */ 101 EXTERNAL_SERVICE_ERROR("external-service-error"), 102 103 104 105 /** 106 * Indicates that the pass-through authentication attempt failed because the 107 * external service is unavailable. 108 */ 109 EXTERNAL_SERVICE_UNAVAILABLE("external-service-unavailable"), 110 111 112 113 /** 114 * Indicates that the pass-through authentication attempt failed because the 115 * external service did not return a response within an expected timeout 116 * period. 117 */ 118 TIMEOUT("timeout"), 119 120 121 122 /** 123 * Indicates that the pass-through authentication attempt failed for a reason 124 * that is not suited to any other defined result code. 125 */ 126 OTHER_FAILURE("other-failure"); 127 128 129 130 // The human-readable name for this result code. 131 private final String name; 132 133 134 135 /** 136 * Creates a new {@code PassThroughAuthenticationResultCode} with the 137 * specified name. 138 * 139 * @param name The human-readable name for this result code. It must not be 140 * {@code null}. 141 */ 142 PassThroughAuthenticationResultCode(@NotNull final String name) 143 { 144 this.name = name; 145 } 146 147 148 149 /** 150 * Retrieves the human-readable name for this result code. 151 * 152 * @return The human-readable name for this result code. 153 */ 154 @NotNull() 155 public String getName() 156 { 157 return name; 158 } 159 160 161 162 /** 163 * Retrieves the {@code PassThroughAuthenticationResultCode} value that 164 * corresponds to the provided name. 165 * 166 * @param name The name for which to retrieve the corresponding result code. 167 * It must not be {@code null}. 168 * 169 * @return The requested result code value, or {@code null} if there is no 170 * result code with the provided name. 171 */ 172 @Nullable() 173 public static PassThroughAuthenticationResultCode forName( 174 @NotNull final String name) 175 { 176 final String lowerName = StaticUtils.toLowerCase(name).replace('_', '-'); 177 switch (lowerName) 178 { 179 case "success": 180 return SUCCESS; 181 case "no-such-user": 182 return NO_SUCH_USER; 183 case "wrong-password": 184 return WRONG_PASSWORD; 185 case "must-change-password": 186 return MUST_CHANGE_PASSWORD; 187 case "account-not-usable": 188 return ACCOUNT_NOT_USABLE; 189 case "non-specific-authentication-failure": 190 return NON_SPECIFIC_AUTHENTICATION_FAILURE; 191 case "external-service-error": 192 return EXTERNAL_SERVICE_ERROR; 193 case "external-service-unavailable": 194 return EXTERNAL_SERVICE_UNAVAILABLE; 195 case "timeout": 196 return TIMEOUT; 197 case "other-failure": 198 return OTHER_FAILURE; 199 default: 200 return null; 201 } 202 } 203 204 205 206 /** 207 * Retrieves the human-readable name for this {@code IndexType}. 208 * 209 * @return The human-readable name for this {@code IndexType}. 210 */ 211 @Override 212 @NotNull() 213 public String toString() 214 { 215 return name; 216 } 217}