001/* 002 * Copyright 2015-2020 Ping Identity Corporation 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright 2015-2020 Ping Identity Corporation 007 * 008 * Licensed under the Apache License, Version 2.0 (the "License"); 009 * you may not use this file except in compliance with the License. 010 * You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, software 015 * distributed under the License is distributed on an "AS IS" BASIS, 016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 017 * See the License for the specific language governing permissions and 018 * limitations under the License. 019 */ 020/* 021 * Copyright (C) 2015-2020 Ping Identity Corporation 022 * 023 * This program is free software; you can redistribute it and/or modify 024 * it under the terms of the GNU General Public License (GPLv2 only) 025 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only) 026 * as published by the Free Software Foundation. 027 * 028 * This program is distributed in the hope that it will be useful, 029 * but WITHOUT ANY WARRANTY; without even the implied warranty of 030 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 031 * GNU General Public License for more details. 032 * 033 * You should have received a copy of the GNU General Public License 034 * along with this program; if not, see <http://www.gnu.org/licenses>. 035 */ 036package com.unboundid.ldap.sdk.unboundidds.extensions; 037 038 039 040import java.io.Serializable; 041import java.util.StringTokenizer; 042 043import com.unboundid.ldap.sdk.LDAPException; 044import com.unboundid.ldap.sdk.ResultCode; 045import com.unboundid.util.Debug; 046import com.unboundid.util.NotMutable; 047import com.unboundid.util.StaticUtils; 048import com.unboundid.util.ThreadSafety; 049import com.unboundid.util.ThreadSafetyLevel; 050import com.unboundid.util.Validator; 051 052import static com.unboundid.ldap.sdk.unboundidds.extensions.ExtOpMessages.*; 053 054 055 056/** 057 * This class defines a data structure that will provide information about 058 * notices pertaining to a user's password policy state (items that might be 059 * of interest, but do not necessarily represent a current or imminent problem 060 * with the account). It includes a number of predefined notice types, but also 061 * allows for the possibility of additional notice types that have not been 062 * defined. 063 * <BR> 064 * <BLOCKQUOTE> 065 * <B>NOTE:</B> This class, and other classes within the 066 * {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only 067 * supported for use against Ping Identity, UnboundID, and 068 * Nokia/Alcatel-Lucent 8661 server products. These classes provide support 069 * for proprietary functionality or for external specifications that are not 070 * considered stable or mature enough to be guaranteed to work in an 071 * interoperable way with other types of LDAP servers. 072 * </BLOCKQUOTE> 073 */ 074@NotMutable() 075@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 076public final class PasswordPolicyStateAccountUsabilityNotice 077 implements Serializable 078{ 079 /** 080 * The numeric value for the notice type that indicates the user has a valid 081 * outstanding retired password. 082 */ 083 public static final int NOTICE_TYPE_OUTSTANDING_RETIRED_PASSWORD = 1; 084 085 086 087 /** 088 * The name for the notice type that indicates the user user has a valid 089 * outstanding retired password. 090 */ 091 public static final String NOTICE_NAME_OUTSTANDING_RETIRED_PASSWORD = 092 "outstanding-retired-password"; 093 094 095 096 /** 097 * The numeric value for the notice type that indicates the user has a valid 098 * outstanding one-time password. 099 */ 100 public static final int NOTICE_TYPE_OUTSTANDING_ONE_TIME_PASSWORD = 2; 101 102 103 104 /** 105 * The name for the notice type that indicates the user has a valid 106 * outstanding one-time password. 107 */ 108 public static final String NOTICE_NAME_OUTSTANDING_ONE_TIME_PASSWORD = 109 "outstanding-one-time-password"; 110 111 112 113 /** 114 * The numeric value for the notice type that indicates the user has a valid 115 * outstanding password reset token. 116 */ 117 public static final int NOTICE_TYPE_OUTSTANDING_PASSWORD_RESET_TOKEN = 3; 118 119 120 121 /** 122 * The name for the notice type that indicates the user has a valid 123 * outstanding password reset token that will expire in the near future. 124 */ 125 public static final String NOTICE_NAME_OUTSTANDING_PASSWORD_RESET_TOKEN = 126 "outstanding-password-reset-token"; 127 128 129 130 /** 131 * The numeric value for the notice type that indicates the user is not 132 * currently allowed to change his/her password because they are within the 133 * minimum password age. 134 */ 135 public static final int NOTICE_TYPE_IN_MINIMUM_PASSWORD_AGE = 4; 136 137 138 139 /** 140 * The name for the notice type that indicates the user is not currently 141 * allowed to change his/her password because they are within the minimum 142 * password age. 143 */ 144 public static final String NOTICE_NAME_IN_MINIMUM_PASSWORD_AGE = 145 "in-minimum-password-age"; 146 147 148 149 /** 150 * The numeric value for the notice type that indicates that the user does not 151 * have a static password. 152 */ 153 public static final int NOTICE_TYPE_NO_STATIC_PASSWORD = 5; 154 155 156 157 /** 158 * The name for the notice type that indicates that the user does not have a 159 * static password. 160 */ 161 public static final String NOTICE_NAME_NO_STATIC_PASSWORD = 162 "no-static-password"; 163 164 165 166 /** 167 * The serial version UID for this serializable class. 168 */ 169 private static final long serialVersionUID = 6147730018701385799L; 170 171 172 173 // The integer value for this account usability notice. 174 private final int intValue; 175 176 // A human-readable message that provides specific details about this account 177 // usability notice. 178 private final String message; 179 180 // The name for this account usability notice. 181 private final String name; 182 183 // The encoded string representation for this account usability notice. 184 private final String stringRepresentation; 185 186 187 188 /** 189 * Creates a new account usability notice with the provided information. 190 * 191 * @param intValue The integer value for this account usability notice. 192 * @param name The name for this account usability notice. It must not 193 * be {@code null}. 194 * @param message A human-readable message that provides specific details 195 * about this account usability notice. It may be 196 * {@code null} if no message is available. 197 */ 198 public PasswordPolicyStateAccountUsabilityNotice(final int intValue, 199 final String name, 200 final String message) 201 { 202 Validator.ensureNotNull(name); 203 204 this.intValue = intValue; 205 this.name = name; 206 this.message = message; 207 208 final StringBuilder buffer = new StringBuilder(); 209 buffer.append("code="); 210 buffer.append(intValue); 211 buffer.append("\tname="); 212 buffer.append(name); 213 214 if (message != null) 215 { 216 buffer.append("\tmessage="); 217 buffer.append(message); 218 } 219 220 stringRepresentation = buffer.toString(); 221 } 222 223 224 225 /** 226 * Creates a new account usability notice that is decoded from the provided 227 * string representation. 228 * 229 * @param stringRepresentation The string representation of the account 230 * usability notice to decode. It must not be 231 * {@code null}. 232 * 233 * @throws LDAPException If the provided string cannot be decoded as a valid 234 * account usability notice. 235 */ 236 public PasswordPolicyStateAccountUsabilityNotice( 237 final String stringRepresentation) 238 throws LDAPException 239 { 240 this.stringRepresentation = stringRepresentation; 241 242 try 243 { 244 Integer i = null; 245 String n = null; 246 String m = null; 247 248 final StringTokenizer tokenizer = 249 new StringTokenizer(stringRepresentation, "\t"); 250 while (tokenizer.hasMoreTokens()) 251 { 252 final String token = tokenizer.nextToken(); 253 final int equalPos = token.indexOf('='); 254 final String fieldName = token.substring(0, equalPos); 255 final String fieldValue = token.substring(equalPos+1); 256 if (fieldName.equals("code")) 257 { 258 i = Integer.valueOf(fieldValue); 259 } 260 else if (fieldName.equals("name")) 261 { 262 n = fieldValue; 263 } 264 else if (fieldName.equals("message")) 265 { 266 m = fieldValue; 267 } 268 } 269 270 if (i == null) 271 { 272 throw new LDAPException(ResultCode.DECODING_ERROR, 273 ERR_PWP_STATE_ACCOUNT_USABILITY_NOTICE_CANNOT_DECODE.get( 274 stringRepresentation, 275 ERR_PWP_STATE_ACCOUNT_USABILITY_NOTICE_NO_CODE.get())); 276 } 277 278 if (n == null) 279 { 280 throw new LDAPException(ResultCode.DECODING_ERROR, 281 ERR_PWP_STATE_ACCOUNT_USABILITY_NOTICE_CANNOT_DECODE.get( 282 stringRepresentation, 283 ERR_PWP_STATE_ACCOUNT_USABILITY_NOTICE_NO_NAME.get())); 284 } 285 286 intValue = i; 287 name = n; 288 message = m; 289 } 290 catch (final LDAPException le) 291 { 292 Debug.debugException(le); 293 294 throw le; 295 } 296 catch (final Exception e) 297 { 298 Debug.debugException(e); 299 300 throw new LDAPException(ResultCode.DECODING_ERROR, 301 ERR_PWP_STATE_ACCOUNT_USABILITY_NOTICE_CANNOT_DECODE.get( 302 stringRepresentation, StaticUtils.getExceptionMessage(e)), 303 e); 304 } 305 } 306 307 308 309 /** 310 * Retrieves the integer value for this account usability notice. 311 * 312 * @return The integer value for this account usability notice. 313 */ 314 public int getIntValue() 315 { 316 return intValue; 317 } 318 319 320 321 /** 322 * Retrieves the name for this account usability notice. 323 * 324 * @return The name for this account usability notice. 325 */ 326 public String getName() 327 { 328 return name; 329 } 330 331 332 333 /** 334 * Retrieves a human-readable message that provides specific details about 335 * this account usability notice. 336 * 337 * @return A human-readable message that provides specific details about this 338 * account usability notice, or {@code null} if no message is 339 * available. 340 */ 341 public String getMessage() 342 { 343 return message; 344 } 345 346 347 348 /** 349 * Retrieves a string representation of this account usability notice. 350 * 351 * @return A string representation of this account usability notice. 352 */ 353 @Override() 354 public String toString() 355 { 356 return stringRepresentation; 357 } 358}