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 response 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 JSONIntermediateClientResponseControl 071 implements Serializable 072{ 073 /** 074 * The serial version UID for this serializable class. 075 */ 076 private static final long serialVersionUID = -3708412493324053872L; 077 078 079 080 // Indicates whether communication with an upstream server is secure. 081 @Nullable private final Boolean upstreamServerSecure; 082 083 // An upstream response embedded in the control. 084 @Nullable private final JSONIntermediateClientResponseControl 085 upstreamResponse; 086 087 // The JSON object with an encoded representation of this control. 088 @NotNull private final JSONObject controlObject; 089 090 // The name of the server application. 091 @Nullable private final String serverName; 092 093 // The upstream server address. 094 @Nullable private final String upstreamServerAddress; 095 096 // The response ID assigned by the upstream server. 097 @Nullable private final String responseID; 098 099 // The session ID assigned by the upstream server. 100 @Nullable private final String sessionID; 101 102 103 104 /** 105 * Creates a new JSON intermediate client response control that is decoded 106 * from the provided JSON object. 107 * 108 * @param controlObject The JSON object containing an encoded representation 109 * of this intermediate client response control. 110 */ 111 public JSONIntermediateClientResponseControl( 112 @NotNull final JSONObject controlObject) 113 { 114 this.controlObject = controlObject; 115 116 upstreamServerAddress = controlObject.getFieldAsString( 117 INTERMEDIATE_CLIENT_RESPONSE_CONTROL_UPSTREAM_SERVER_ADDRESS. 118 getFieldName()); 119 upstreamServerSecure = controlObject.getFieldAsBoolean( 120 INTERMEDIATE_CLIENT_RESPONSE_CONTROL_UPSTREAM_SERVER_SECURE. 121 getFieldName()); 122 serverName = controlObject.getFieldAsString( 123 INTERMEDIATE_CLIENT_RESPONSE_CONTROL_SERVER_NAME.getFieldName()); 124 sessionID = controlObject.getFieldAsString( 125 INTERMEDIATE_CLIENT_RESPONSE_CONTROL_SESSION_ID.getFieldName()); 126 responseID = controlObject.getFieldAsString( 127 INTERMEDIATE_CLIENT_RESPONSE_CONTROL_RESPONSE_ID.getFieldName()); 128 129 final JSONObject upstreamObject = controlObject.getFieldAsObject( 130 INTERMEDIATE_CLIENT_RESPONSE_CONTROL_UPSTREAM_RESPONSE.getFieldName()); 131 if (upstreamObject == null) 132 { 133 upstreamResponse = null; 134 } 135 else 136 { 137 upstreamResponse = 138 new JSONIntermediateClientResponseControl(upstreamObject); 139 } 140 } 141 142 143 144 /** 145 * Retrieves a JSON object containing an encoded representation of this 146 * intermediate client response control. 147 * 148 * @return A JSON object containing an encoded representation of this 149 * intermediate client response control. 150 */ 151 @NotNull() 152 public JSONObject getControlObject() 153 { 154 return controlObject; 155 } 156 157 158 159 /** 160 * Retrieves the address of an upstream server. 161 * 162 * @return The address of an upstream server, or {@code null} if no upstream 163 * server address is available. 164 */ 165 @Nullable() 166 public String getUpstreamServerAddress() 167 { 168 return upstreamServerAddress; 169 } 170 171 172 173 /** 174 * Indicates whether communication with the upstream server is secure. 175 * 176 * @return {@code Boolean.TRUE} if communication with the upstream server is 177 * secure, {@code Boolean.FALSE} if communication with the upstream 178 * server is not secure, or {@code null} if this information is not 179 * available. 180 */ 181 @Nullable() 182 public Boolean getUpstreamServerSecure() 183 { 184 return upstreamServerSecure; 185 } 186 187 188 189 /** 190 * Retrieves the name of the upstream server application. 191 * 192 * @return The name of the upstream server application, or {@code null} if 193 * this information is not available. 194 */ 195 @Nullable() 196 public String getServerName() 197 { 198 return serverName; 199 } 200 201 202 203 /** 204 * Retrieves the session ID assigned by the upstream server. 205 * 206 * @return The session ID assigned by the upstream server, or {@code null} 207 * if no session ID is available. 208 */ 209 @Nullable() 210 public String getSessionID() 211 { 212 return sessionID; 213 } 214 215 216 217 /** 218 * Retrieves the response ID assigned by the upstream server. 219 * 220 * @return The response ID assigned by the upstream server, or {@code null} 221 * if no response ID is available. 222 */ 223 @Nullable() 224 public String getResponseID() 225 { 226 return responseID; 227 } 228 229 230 231 /** 232 * Retrieves an upstream response embedded in the control. 233 * 234 * @return An upstream response embedded in the control, or {@code null} if 235 * no upstream response is available. 236 */ 237 @Nullable() 238 public JSONIntermediateClientResponseControl getUpstreamResponse() 239 { 240 return upstreamResponse; 241 } 242 243 244 245 /** 246 * Retrieves a string representation of this intermediate client request 247 * control. 248 * 249 * @return A string representation of this intermediate client request 250 * control. 251 */ 252 @NotNull() 253 public String toString() 254 { 255 return controlObject.toSingleLineString(); 256 } 257}