001/* 002 * Copyright 2007-2020 Ping Identity Corporation 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright 2007-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) 2007-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.experimental; 037 038 039 040import com.unboundid.ldap.sdk.Control; 041import com.unboundid.ldap.sdk.LDAPException; 042import com.unboundid.ldap.sdk.ResultCode; 043import com.unboundid.util.NotMutable; 044import com.unboundid.util.ThreadSafety; 045import com.unboundid.util.ThreadSafetyLevel; 046 047import static com.unboundid.ldap.sdk.experimental.ExperimentalMessages.*; 048 049 050 051/** 052 * This class provides an implementation of the password policy request control 053 * as described in draft-behera-ldap-password-policy-10. It may be used to 054 * request information related to a user's password policy. In the Ping 055 * Identity, UnboundID, and Nokia/Alcatel-Lucent 8661 Directory Server, this 056 * control may be included with add, bind, compare, modify, and password modify 057 * requests. 058 * <BR><BR> 059 * The corresponding {@link DraftBeheraLDAPPasswordPolicy10ResponseControl} may 060 * include at most one warning from the set of 061 * {@link DraftBeheraLDAPPasswordPolicy10WarningType} values and at most one 062 * error from the set of {@link DraftBeheraLDAPPasswordPolicy10ErrorType} 063 * values. See the documentation for those classes for more information on the 064 * information that may be included. 065 * <BR><BR> 066 * <H2>Example</H2> 067 * The following example demonstrates the use of the password policy request 068 * control in conjunction with a bind operation: 069 * <PRE> 070 * SimpleBindRequest bindRequest = new SimpleBindRequest( 071 * "uid=john.doe,ou=People,dc=example,dc=com", "password", 072 * new DraftBeheraLDAPPasswordPolicy10RequestControl()); 073 * 074 * BindResult bindResult; 075 * try 076 * { 077 * bindResult = connection.bind(bindRequest); 078 * } 079 * catch (LDAPException le) 080 * { 081 * // The bind failed. There may be a password policy response control to 082 * // help tell us why. 083 * bindResult = new BindResult(le.toLDAPResult()); 084 * } 085 * 086 * DraftBeheraLDAPPasswordPolicy10ResponseControl pwpResponse = 087 * DraftBeheraLDAPPasswordPolicy10ResponseControl.get(bindResult); 088 * if (pwpResponse != null) 089 * { 090 * DraftBeheraLDAPPasswordPolicy10ErrorType errorType = 091 * pwpResponse.getErrorType(); 092 * if (errorType != null) 093 * { 094 * // There was a password policy error. 095 * } 096 * 097 * DraftBeheraLDAPPasswordPolicy10WarningType warningType = 098 * pwpResponse.getWarningType(); 099 * if (warningType != null) 100 * { 101 * // There was a password policy warning. 102 * int value = pwpResponse.getWarningValue(); 103 * switch (warningType) 104 * { 105 * case TIME_BEFORE_EXPIRATION: 106 * // The warning value is the number of seconds until expiration. 107 * break; 108 * case GRACE_LOGINS_REMAINING: 109 * // The warning value is the number of grace logins remaining. 110 * } 111 * } 112 * } 113 * </PRE> 114 */ 115@NotMutable() 116@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 117public final class DraftBeheraLDAPPasswordPolicy10RequestControl 118 extends Control 119{ 120 /** 121 * The OID (1.3.6.1.4.1.42.2.27.8.5.1) for the password policy request 122 * control. 123 */ 124 public static final String PASSWORD_POLICY_REQUEST_OID = 125 "1.3.6.1.4.1.42.2.27.8.5.1"; 126 127 128 129 /** 130 * The serial version UID for this serializable class. 131 */ 132 private static final long serialVersionUID = 6495056761590890150L; 133 134 135 136 /** 137 * Creates a new password policy request control. The control will not be 138 * marked critical. 139 */ 140 public DraftBeheraLDAPPasswordPolicy10RequestControl() 141 { 142 super(PASSWORD_POLICY_REQUEST_OID, false, null); 143 } 144 145 146 147 /** 148 * Creates a new password policy request control. 149 * 150 * @param isCritical Indicates whether the control should be marked 151 * critical. 152 */ 153 public DraftBeheraLDAPPasswordPolicy10RequestControl(final boolean isCritical) 154 { 155 super(PASSWORD_POLICY_REQUEST_OID, isCritical, null); 156 } 157 158 159 160 /** 161 * Creates a new password policy request control which is decoded from the 162 * provided generic control. 163 * 164 * @param control The generic control to be decoded as a password policy 165 * request control. 166 * 167 * @throws LDAPException If the provided control cannot be decoded as a 168 * password policy request control. 169 */ 170 public DraftBeheraLDAPPasswordPolicy10RequestControl(final Control control) 171 throws LDAPException 172 { 173 super(control); 174 175 if (control.hasValue()) 176 { 177 throw new LDAPException(ResultCode.DECODING_ERROR, 178 ERR_PWP_REQUEST_HAS_VALUE.get()); 179 } 180 } 181 182 183 184 /** 185 * {@inheritDoc} 186 */ 187 @Override() 188 public String getControlName() 189 { 190 return INFO_CONTROL_NAME_PW_POLICY_REQUEST.get(); 191 } 192 193 194 195 /** 196 * {@inheritDoc} 197 */ 198 @Override() 199 public void toString(final StringBuilder buffer) 200 { 201 buffer.append("PasswordPolicyRequestControl(isCritical="); 202 buffer.append(isCritical()); 203 buffer.append(')'); 204 } 205}