001/* 002 * Copyright 2007-2017 UnboundID Corp. 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright (C) 2007-2017 UnboundID Corp. 007 * 008 * This program is free software; you can redistribute it and/or modify 009 * it under the terms of the GNU General Public License (GPLv2 only) 010 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only) 011 * as published by the Free Software Foundation. 012 * 013 * This program is distributed in the hope that it will be useful, 014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 016 * GNU General Public License for more details. 017 * 018 * You should have received a copy of the GNU General Public License 019 * along with this program; if not, see <http://www.gnu.org/licenses>. 020 */ 021package com.unboundid.ldap.sdk.experimental; 022 023 024 025import com.unboundid.ldap.sdk.Control; 026import com.unboundid.ldap.sdk.LDAPException; 027import com.unboundid.ldap.sdk.ResultCode; 028import com.unboundid.util.NotMutable; 029import com.unboundid.util.ThreadSafety; 030import com.unboundid.util.ThreadSafetyLevel; 031 032import static com.unboundid.ldap.sdk.experimental.ExperimentalMessages.*; 033 034 035 036/** 037 * This class provides an implementation of the password policy request control 038 * as described in draft-behera-ldap-password-policy-10. It may be used to 039 * request information related to a user's password policy. In the Ping 040 * Identity, UnboundID, and Alcatel-Lucent 8661 Directory Server, this control 041 * may be included with add, bind, compare, modify, and password modify 042 * requests. 043 * <BR><BR> 044 * The corresponding {@link DraftBeheraLDAPPasswordPolicy10ResponseControl} may 045 * include at most one warning from the set of 046 * {@link DraftBeheraLDAPPasswordPolicy10WarningType} values and at most one 047 * error from the set of {@link DraftBeheraLDAPPasswordPolicy10ErrorType} 048 * values. See the documentation for those classes for more information on the 049 * information that may be included. 050 * <BR><BR> 051 * <H2>Example</H2> 052 * The following example demonstrates the use of the password policy request 053 * control in conjunction with a bind operation: 054 * <PRE> 055 * SimpleBindRequest bindRequest = new SimpleBindRequest( 056 * "uid=john.doe,ou=People,dc=example,dc=com", "password", 057 * new DraftBeheraLDAPPasswordPolicy10RequestControl()); 058 * 059 * BindResult bindResult; 060 * try 061 * { 062 * bindResult = connection.bind(bindRequest); 063 * } 064 * catch (LDAPException le) 065 * { 066 * // The bind failed. There may be a password policy response control to 067 * // help tell us why. 068 * bindResult = new BindResult(le.toLDAPResult()); 069 * } 070 * 071 * DraftBeheraLDAPPasswordPolicy10ResponseControl pwpResponse = 072 * DraftBeheraLDAPPasswordPolicy10ResponseControl.get(bindResult); 073 * if (pwpResponse != null) 074 * { 075 * DraftBeheraLDAPPasswordPolicy10ErrorType errorType = 076 * pwpResponse.getErrorType(); 077 * if (errorType != null) 078 * { 079 * // There was a password policy error. 080 * } 081 * 082 * DraftBeheraLDAPPasswordPolicy10WarningType warningType = 083 * pwpResponse.getWarningType(); 084 * if (warningType != null) 085 * { 086 * // There was a password policy warning. 087 * int value = pwpResponse.getWarningValue(); 088 * switch (warningType) 089 * { 090 * case TIME_BEFORE_EXPIRATION: 091 * // The warning value is the number of seconds until expiration. 092 * break; 093 * case GRACE_LOGINS_REMAINING: 094 * // The warning value is the number of grace logins remaining. 095 * } 096 * } 097 * } 098 * </PRE> 099 */ 100@NotMutable() 101@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 102public final class DraftBeheraLDAPPasswordPolicy10RequestControl 103 extends Control 104{ 105 /** 106 * The OID (1.3.6.1.4.1.42.2.27.8.5.1) for the password policy request 107 * control. 108 */ 109 public static final String PASSWORD_POLICY_REQUEST_OID = 110 "1.3.6.1.4.1.42.2.27.8.5.1"; 111 112 113 114 /** 115 * The serial version UID for this serializable class. 116 */ 117 private static final long serialVersionUID = 6495056761590890150L; 118 119 120 121 /** 122 * Creates a new password policy request control. The control will not be 123 * marked critical. 124 */ 125 public DraftBeheraLDAPPasswordPolicy10RequestControl() 126 { 127 super(PASSWORD_POLICY_REQUEST_OID, false, null); 128 } 129 130 131 132 /** 133 * Creates a new password policy request control. 134 * 135 * @param isCritical Indicates whether the control should be marked 136 * critical. 137 */ 138 public DraftBeheraLDAPPasswordPolicy10RequestControl(final boolean isCritical) 139 { 140 super(PASSWORD_POLICY_REQUEST_OID, isCritical, null); 141 } 142 143 144 145 /** 146 * Creates a new password policy request control which is decoded from the 147 * provided generic control. 148 * 149 * @param control The generic control to be decoded as a password policy 150 * request control. 151 * 152 * @throws LDAPException If the provided control cannot be decoded as a 153 * password policy request control. 154 */ 155 public DraftBeheraLDAPPasswordPolicy10RequestControl(final Control control) 156 throws LDAPException 157 { 158 super(control); 159 160 if (control.hasValue()) 161 { 162 throw new LDAPException(ResultCode.DECODING_ERROR, 163 ERR_PWP_REQUEST_HAS_VALUE.get()); 164 } 165 } 166 167 168 169 /** 170 * {@inheritDoc} 171 */ 172 @Override() 173 public String getControlName() 174 { 175 return INFO_CONTROL_NAME_PW_POLICY_REQUEST.get(); 176 } 177 178 179 180 /** 181 * {@inheritDoc} 182 */ 183 @Override() 184 public void toString(final StringBuilder buffer) 185 { 186 buffer.append("PasswordPolicyRequestControl(isCritical="); 187 buffer.append(isCritical()); 188 buffer.append(')'); 189 } 190}