001/* 002 * Copyright 2022-2024 Ping Identity Corporation 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright 2022-2024 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) 2022-2024 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.logs.v2.json; 037 038 039 040import java.io.Serializable; 041 042import com.unboundid.util.NotMutable; 043import com.unboundid.util.NotNull; 044import com.unboundid.util.Nullable; 045import com.unboundid.util.ThreadSafety; 046import com.unboundid.util.ThreadSafetyLevel; 047import com.unboundid.util.json.JSONObject; 048 049import static com.unboundid.ldap.sdk.unboundidds.logs.v2.json. 050 JSONFormattedAccessLogFields.*; 051 052 053 054/** 055 * This class provides a data structure that contains information about an 056 * JSON-formatted intermediate client request control. 057 * <BR> 058 * <BLOCKQUOTE> 059 * <B>NOTE:</B> This class, and other classes within the 060 * {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only 061 * supported for use against Ping Identity, UnboundID, and 062 * Nokia/Alcatel-Lucent 8661 server products. These classes provide support 063 * for proprietary functionality or for external specifications that are not 064 * considered stable or mature enough to be guaranteed to work in an 065 * interoperable way with other types of LDAP servers. 066 * </BLOCKQUOTE> 067 */ 068@NotMutable() 069@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 070public final class JSONIntermediateClientRequestControl 071 implements Serializable 072{ 073 /** 074 * The serial version UID for this serializable class. 075 */ 076 private static final long serialVersionUID = -575977471763904665L; 077 078 079 080 // Indicates whether communication with the downstream client is secure. 081 @Nullable private final Boolean downstreamClientSecure; 082 083 // A downstream request embedded in the control. 084 @Nullable private final JSONIntermediateClientRequestControl 085 downstreamRequest; 086 087 // The JSON object with an encoded representation of this control. 088 @NotNull private final JSONObject controlObject; 089 090 // The requested client authorization identity. 091 @Nullable private final String clientIdentity; 092 093 // The name of the client application. 094 @Nullable private final String clientName; 095 096 // The downstream client address. 097 @Nullable private final String downstreamClientAddress; 098 099 // The request ID assigned by the downstream client. 100 @Nullable private final String requestID; 101 102 // The session ID assigned by the downstream client. 103 @Nullable private final String sessionID; 104 105 106 107 /** 108 * Creates a new JSON intermediate client request control that is decoded from 109 * the provided JSON object. 110 * 111 * @param controlObject The JSON object containing an encoded representation 112 * of this intermediate client request control. 113 */ 114 public JSONIntermediateClientRequestControl( 115 @NotNull final JSONObject controlObject) 116 { 117 this.controlObject = controlObject; 118 119 downstreamClientAddress = controlObject.getFieldAsString( 120 INTERMEDIATE_CLIENT_REQUEST_CONTROL_DOWNSTREAM_CLIENT_ADDRESS. 121 getFieldName()); 122 downstreamClientSecure = controlObject.getFieldAsBoolean( 123 INTERMEDIATE_CLIENT_REQUEST_CONTROL_DOWNSTREAM_CLIENT_SECURE. 124 getFieldName()); 125 clientIdentity = controlObject.getFieldAsString( 126 INTERMEDIATE_CLIENT_REQUEST_CONTROL_CLIENT_IDENTITY.getFieldName()); 127 clientName = controlObject.getFieldAsString( 128 INTERMEDIATE_CLIENT_REQUEST_CONTROL_CLIENT_NAME.getFieldName()); 129 sessionID = controlObject.getFieldAsString( 130 INTERMEDIATE_CLIENT_REQUEST_CONTROL_SESSION_ID.getFieldName()); 131 requestID = controlObject.getFieldAsString( 132 INTERMEDIATE_CLIENT_REQUEST_CONTROL_REQUEST_ID.getFieldName()); 133 134 final JSONObject downstreamObject = controlObject.getFieldAsObject( 135 INTERMEDIATE_CLIENT_REQUEST_CONTROL_DOWNSTREAM_REQUEST.getFieldName()); 136 if (downstreamObject == null) 137 { 138 downstreamRequest = null; 139 } 140 else 141 { 142 downstreamRequest = 143 new JSONIntermediateClientRequestControl(downstreamObject); 144 } 145 } 146 147 148 149 /** 150 * Retrieves a JSON object containing an encoded representation of this 151 * intermediate client request control. 152 * 153 * @return A JSON object containing an encoded representation of this 154 * intermediate client request control. 155 */ 156 @NotNull() 157 public JSONObject getControlObject() 158 { 159 return controlObject; 160 } 161 162 163 164 /** 165 * Retrieves the address of a downstream client. 166 * 167 * @return The address of a downstream client, or {@code null} if no 168 * downstream client address is available. 169 */ 170 @Nullable() 171 public String getDownstreamClientAddress() 172 { 173 return downstreamClientAddress; 174 } 175 176 177 178 /** 179 * Indicates whether communication with the downstream client is secure. 180 * 181 * @return {@code Boolean.TRUE} if communication with the downstream client 182 * is secure, {@code Boolean.FALSE} if communication with the 183 * downstream client is not secure, or {@code null} if this 184 * information is not available. 185 */ 186 @Nullable() 187 public Boolean getDownstreamClientSecure() 188 { 189 return downstreamClientSecure; 190 } 191 192 193 194 /** 195 * Retrieves the requested client authorization identity. 196 * 197 * @return The requested client authorization identity, or {@code null} if 198 * no client identity is available. 199 */ 200 @Nullable() 201 public String getClientIdentity() 202 { 203 return clientIdentity; 204 } 205 206 207 208 /** 209 * Retrieves the name of the client application. 210 * 211 * @return The name of the client application, or {@code null} if no client 212 * name is available. 213 */ 214 @Nullable() 215 public String getClientName() 216 { 217 return clientName; 218 } 219 220 221 222 /** 223 * Retrieves the session ID assigned by the downstream client. 224 * 225 * @return The session ID assigned by the downstream client, or {@code null} 226 * if no session ID is available. 227 */ 228 @Nullable() 229 public String getSessionID() 230 { 231 return sessionID; 232 } 233 234 235 236 /** 237 * Retrieves the request ID assigned by the downstream client. 238 * 239 * @return The request ID assigned by the downstream client, or {@code null} 240 * if no request ID is available. 241 */ 242 @Nullable() 243 public String getRequestID() 244 { 245 return requestID; 246 } 247 248 249 250 /** 251 * Retrieves a downstream request embedded in the control. 252 * 253 * @return A downstream request embedded in the control, or {@code null} if 254 * no downstream request is available. 255 */ 256 @Nullable() 257 public JSONIntermediateClientRequestControl getDownstreamRequest() 258 { 259 return downstreamRequest; 260 } 261 262 263 264 /** 265 * Retrieves a string representation of this intermediate client request 266 * control. 267 * 268 * @return A string representation of this intermediate client request 269 * control. 270 */ 271 @NotNull() 272 public String toString() 273 { 274 return controlObject.toSingleLineString(); 275 } 276}