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) 2008-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.controls; 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.controls.ControlMessages.*; 048 049 050 051/** 052 * This class provides an implementation of the authorization identity bind 053 * request control as described in 054 * <A HREF="http://www.ietf.org/rfc/rfc3829.txt">RFC 3829</A>. It may be 055 * included in a bind request to request that the server include the 056 * authorization identity associated with the client connection in the bind 057 * response message, in the form of an 058 * {@link AuthorizationIdentityResponseControl}. 059 * <BR><BR> 060 * The authorization identity request control is similar to the "Who Am I?" 061 * extended request as implemented in the 062 * {@link com.unboundid.ldap.sdk.extensions.WhoAmIExtendedRequest} class. The 063 * primary difference between them is that the "Who Am I?" extended request can 064 * be used at any time but requires a separate operation, while the 065 * authorization identity request control can be included only with a bind 066 * request but does not require a separate operation. 067 * <BR><BR> 068 * <H2>Example</H2> 069 * The following example demonstrates the use of the authorization identity 070 * request and response controls. It authenticates to the directory server and 071 * attempts to retrieve the authorization identity from the response: 072 * <PRE> 073 * String authzID = null; 074 * BindRequest bindRequest = 075 * new SimpleBindRequest("uid=test.user,ou=People,dc=example,dc=com", 076 * "password", new AuthorizationIdentityRequestControl()); 077 * 078 * BindResult bindResult = connection.bind(bindRequest); 079 * AuthorizationIdentityResponseControl authzIdentityResponse = 080 * AuthorizationIdentityResponseControl.get(bindResult); 081 * if (authzIdentityResponse != null) 082 * { 083 * authzID = authzIdentityResponse.getAuthorizationID(); 084 * } 085 * </PRE> 086 */ 087@NotMutable() 088@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 089public final class AuthorizationIdentityRequestControl 090 extends Control 091{ 092 /** 093 * The OID (2.16.840.1.113730.3.4.16) for the authorization identity request 094 * control. 095 */ 096 public static final String AUTHORIZATION_IDENTITY_REQUEST_OID = 097 "2.16.840.1.113730.3.4.16"; 098 099 100 101 /** 102 * The serial version UID for this serializable class. 103 */ 104 private static final long serialVersionUID = -4059607155175828138L; 105 106 107 108 /** 109 * Creates a new authorization identity request control. The control will not 110 * be marked critical. 111 */ 112 public AuthorizationIdentityRequestControl() 113 { 114 super(AUTHORIZATION_IDENTITY_REQUEST_OID, false, null); 115 } 116 117 118 119 /** 120 * Creates a new authorization identity request control. 121 * 122 * @param isCritical Indicates whether the control should be marked 123 * critical. 124 */ 125 public AuthorizationIdentityRequestControl(final boolean isCritical) 126 { 127 super(AUTHORIZATION_IDENTITY_REQUEST_OID, isCritical, null); 128 } 129 130 131 132 /** 133 * Creates a new authorization identity request control which is decoded from 134 * the provided generic control. 135 * 136 * @param control The generic control to be decoded as an authorization 137 * identity request control. 138 * 139 * @throws LDAPException If the provided control cannot be decoded as an 140 * authorization identity request control. 141 */ 142 public AuthorizationIdentityRequestControl(final Control control) 143 throws LDAPException 144 { 145 super(control); 146 147 if (control.hasValue()) 148 { 149 throw new LDAPException(ResultCode.DECODING_ERROR, 150 ERR_AUTHZID_REQUEST_HAS_VALUE.get()); 151 } 152 } 153 154 155 156 /** 157 * {@inheritDoc} 158 */ 159 @Override() 160 public String getControlName() 161 { 162 return INFO_CONTROL_NAME_AUTHZID_REQUEST.get(); 163 } 164 165 166 167 /** 168 * {@inheritDoc} 169 */ 170 @Override() 171 public void toString(final StringBuilder buffer) 172 { 173 buffer.append("AuthorizationIdentityRequestControl(isCritical="); 174 buffer.append(isCritical()); 175 buffer.append(')'); 176 } 177}