001/* 002 * Copyright 2020 Ping Identity Corporation 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright 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) 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; 037 038 039 040import java.io.Serializable; 041 042import com.unboundid.util.Mutable; 043import com.unboundid.util.NotNull; 044import com.unboundid.util.Nullable; 045import com.unboundid.util.ThreadSafety; 046import com.unboundid.util.ThreadSafetyLevel; 047import com.unboundid.util.Validator; 048 049 050 051/** 052 * This class provides a data structure that may be used to hold a number of 053 * properties used during processing for a OAUTHBEARER SASL bind operation. 054 * 055 * @see OAUTHBEARERBindRequest 056 */ 057@Mutable() 058@ThreadSafety(level=ThreadSafetyLevel.NOT_THREADSAFE) 059public final class OAUTHBEARERBindRequestProperties 060 implements Serializable 061{ 062 /** 063 * The serial version UID for this serializable class. 064 */ 065 private static final long serialVersionUID = -7664683436256231975L; 066 067 068 069 // The port of the server to which the request will be sent. 070 @Nullable private Integer serverPort; 071 072 // The access token to include in the bind request. 073 @NotNull private String accessToken; 074 075 // The authorization identity to include in the GS2 header for the bind 076 // request. 077 @Nullable private String authorizationID; 078 079 // The method to use for HTTP-based requests. 080 @Nullable private String requestMethod; 081 082 // The path to use for HTTP-based requests. 083 @Nullable private String requestPath; 084 085 // The post data for HTTP-based requests. 086 @Nullable private String requestPostData; 087 088 // The query string for HTTP-based requests. 089 @Nullable private String requestQueryString; 090 091 // The address of the server to which the request will be sent. 092 @Nullable private String serverAddress; 093 094 095 096 /** 097 * Creates a new set of OAUTHBEARER bind request properties with the provided 098 * access token. 099 * 100 * @param accessToken The access token to include in the bind request. It 101 * must not be {@code null} or empty. 102 */ 103 public OAUTHBEARERBindRequestProperties(@NotNull final String accessToken) 104 { 105 Validator.ensureNotNullOrEmpty(accessToken, 106 "OAUTHBEARERBindRequestProperties.accessToken must not be null or " + 107 "empty."); 108 109 this.accessToken = accessToken; 110 111 authorizationID = null; 112 serverAddress = null; 113 serverPort = null; 114 requestMethod = null; 115 requestPath = null; 116 requestPostData = null; 117 requestQueryString = null; 118 } 119 120 121 122 /** 123 * Creates a new set of OAUTHBEARER bind request properties that is a copy of 124 * the provided set of properties. 125 * 126 * @param properties The set of properties to duplicate. It must not be 127 * {@code null}. 128 */ 129 public OAUTHBEARERBindRequestProperties( 130 @NotNull final OAUTHBEARERBindRequestProperties properties) 131 { 132 Validator.ensureNotNullWithMessage(properties, 133 "OAUTHBEARERBindRequestProperties.properties must not be null."); 134 135 accessToken = properties.accessToken; 136 authorizationID = properties.authorizationID; 137 serverAddress = properties.serverAddress; 138 serverPort = properties.serverPort; 139 requestMethod = properties.requestMethod; 140 requestPath = properties.requestPath; 141 requestPostData = properties.requestPostData; 142 requestQueryString = properties.requestQueryString; 143 } 144 145 146 147 /** 148 * Creates a new set of OAUTHBEARER bind request properties that is a copy of 149 * the properties used for the provided bind request. 150 * 151 * @param bindRequest The OAUTHBEARER bind request to use to create this set 152 * of properties. It must not be {@code null}. 153 */ 154 public OAUTHBEARERBindRequestProperties( 155 @NotNull final OAUTHBEARERBindRequest bindRequest) 156 { 157 Validator.ensureNotNullWithMessage(bindRequest, 158 "OAUTHBEARERBindRequestProperties.bindRequest must not be null."); 159 160 accessToken = bindRequest.getAccessToken(); 161 authorizationID = bindRequest.getAuthorizationID(); 162 serverAddress = bindRequest.getServerAddress(); 163 serverPort = bindRequest.getServerPort(); 164 requestMethod = bindRequest.getRequestMethod(); 165 requestPath = bindRequest.getRequestPath(); 166 requestPostData = bindRequest.getRequestPostData(); 167 requestQueryString = bindRequest.getRequestQueryString(); 168 } 169 170 171 172 /** 173 * Retrieves the access token to include in the bind request. 174 * 175 * @return The access token to include in the bind request. 176 */ 177 @NotNull() 178 public String getAccessToken() 179 { 180 return accessToken; 181 } 182 183 184 185 /** 186 * Specifies the access token to include in the bind request. 187 * 188 * @param accessToken The access token to include in the bind request. It 189 * must not be {@code null} or empty. 190 */ 191 public void setAccessToken(@NotNull final String accessToken) 192 { 193 Validator.ensureNotNullOrEmpty(accessToken, 194 "OAUTHBEARERBindRequestProperties.accessToken must not be null or " + 195 "empty."); 196 197 this.accessToken = accessToken; 198 } 199 200 201 202 /** 203 * Retrieves the authorization ID to include in the GS2 header for the bind 204 * request, if any. 205 * 206 * @return The authorization ID to include in the GS2 header for the bind 207 * request, or {@code null} if no authorization ID should be 208 * included. 209 */ 210 @Nullable() 211 public String getAuthorizationID() 212 { 213 return authorizationID; 214 } 215 216 217 218 /** 219 * Specifies the authorization ID to include in the GS2 header for the bind 220 * request, if any. 221 * 222 * @param authorizationID The authorization ID to include in the bind 223 * request. It may be {@code null} if no 224 * authorization ID should be provided. 225 */ 226 public void setAuthorizationID(@Nullable final String authorizationID) 227 { 228 this.authorizationID = authorizationID; 229 } 230 231 232 233 /** 234 * Retrieves the server address to include in the bind request, if any. 235 * 236 * @return The server address to include in the bind request, or {@code null} 237 * if it should be omitted. 238 */ 239 @Nullable() 240 public String getServerAddress() 241 { 242 return serverAddress; 243 } 244 245 246 247 /** 248 * Specifies the server address to include in the bind request, if any. 249 * 250 * @param serverAddress The server address to include in the bind request. 251 * It may be {@code null} if the server address should 252 * be omitted. 253 */ 254 public void setServerAddress(@Nullable final String serverAddress) 255 { 256 this.serverAddress = serverAddress; 257 } 258 259 260 261 /** 262 * Retrieves the server port to include in the bind request, if any. 263 * 264 * @return The server port to include in the bind request, or {@code null} 265 * if it should be omitted. 266 */ 267 @Nullable() 268 public Integer getServerPort() 269 { 270 return serverPort; 271 } 272 273 274 275 /** 276 * Specifies the server port to include in the bind request, if any. 277 * 278 * @param serverPort The server port to include in the bind request. It 279 * may be {@code null} if the server port should be 280 * omitted. If it is non-{@code null}, then the value 281 * must be between 1 and 65535, inclusive. 282 */ 283 public void setServerPort(@Nullable final Integer serverPort) 284 { 285 if (serverPort != null) 286 { 287 Validator.ensureTrue(((serverPort >= 1) && (serverPort <= 65535)), 288 "If provided, OAUTHBEARERBindRequestProperties.serverPort must be " + 289 "between 1 and 65535, inclusive."); 290 } 291 292 this.serverPort = serverPort; 293 } 294 295 296 297 /** 298 * Retrieves the method to use for HTTP-based requests, if any. 299 * 300 * @return The method to use for HTTP-based requests, or {@code null} if it 301 * should be omitted from the bind request. 302 */ 303 @Nullable() 304 public String getRequestMethod() 305 { 306 return requestMethod; 307 } 308 309 310 311 /** 312 * Specifies the method to use for HTTP-based requests, if it should be 313 * included in the bind request. 314 * 315 * @param requestMethod The method to use for HTTP-based requests. It may 316 * be {@code null} if the request method should be 317 * omitted. 318 */ 319 public void setRequestMethod(@Nullable final String requestMethod) 320 { 321 this.requestMethod = requestMethod; 322 } 323 324 325 326 /** 327 * Retrieves the path to use for HTTP-based requests, if any. 328 * 329 * @return The path to use for HTTP-based requests, or {@code null} if it 330 * should be omitted from the bind request. 331 */ 332 @Nullable() 333 public String getRequestPath() 334 { 335 return requestPath; 336 } 337 338 339 340 /** 341 * Specifies the path to use for HTTP-based requests, if it should be included 342 * in the bind request. 343 * 344 * @param requestPath The path to use for HTTP-based requests. It may be 345 * {@code null} if the request path should be omitted. 346 */ 347 public void setRequestPath(@Nullable final String requestPath) 348 { 349 this.requestPath = requestPath; 350 } 351 352 353 354 /** 355 * Retrieves the data to submit when posting an HTTP-based request, if any. 356 * 357 * @return The post data for HTTP-based requests, or {@code null} if it 358 * should be omitted from the bind request. 359 */ 360 @Nullable() 361 public String getRequestPostData() 362 { 363 return requestPostData; 364 } 365 366 367 368 /** 369 * Specifies the data to submit when posting an HTTP-based request, if it 370 * should be included in the bind request. 371 * 372 * @param requestPostData The post data for HTTP-based requests. It may be 373 * {@code null} if the post data should be omitted. 374 */ 375 public void setRequestPostData(@Nullable final String requestPostData) 376 { 377 this.requestPostData = requestPostData; 378 } 379 380 381 382 /** 383 * Retrieves the query string to use for HTTP-based requests, if any. 384 * 385 * @return The query string to use for HTTP-based requests, or {@code null} 386 * if it should be omitted from the bind request. 387 */ 388 @Nullable() 389 public String getRequestQueryString() 390 { 391 return requestQueryString; 392 } 393 394 395 396 /** 397 * Specifies the query string to use for HTTP-based requests, if it should be 398 * included in the bind request. 399 * 400 * @param requestQueryString The query string to use for HTTP-based 401 * requests. It may be {@code null} if it should 402 * be omitted from the bind request. 403 */ 404 public void setRequestQueryString(@Nullable final String requestQueryString) 405 { 406 this.requestQueryString = requestQueryString; 407 } 408 409 410 411 /** 412 * Retrieves a string representation of the OAUTHBEARER bind request 413 * properties. 414 * 415 * @return A string representation of the OAUTHBEARER bind request 416 * properties. 417 */ 418 @Override() 419 @NotNull() 420 public String toString() 421 { 422 final StringBuilder buffer = new StringBuilder(); 423 toString(buffer); 424 return buffer.toString(); 425 } 426 427 428 429 /** 430 * Appends a string representation of the OAUTHBEARER bind request properties 431 * to the provided buffer. 432 * 433 * @param buffer The buffer to which the information should be appended. It 434 * must not be {@code null}. 435 */ 436 public void toString(@NotNull final StringBuilder buffer) 437 { 438 buffer.append("OAUTHBEARERBindRequestProperties(accessToken='{redacted}'"); 439 440 if (authorizationID != null) 441 { 442 buffer.append(", authorizationID='"); 443 buffer.append(authorizationID); 444 buffer.append('\''); 445 } 446 447 if (serverAddress != null) 448 { 449 buffer.append(", serverAddress='"); 450 buffer.append(serverAddress); 451 buffer.append('\''); 452 } 453 454 if (serverPort != null) 455 { 456 buffer.append(", serverPort="); 457 buffer.append(serverPort); 458 } 459 460 if (requestMethod != null) 461 { 462 buffer.append(", requestMethod='"); 463 buffer.append(requestMethod); 464 buffer.append('\''); 465 } 466 467 if (requestPath != null) 468 { 469 buffer.append(", requestPath='"); 470 buffer.append(requestPath); 471 buffer.append('\''); 472 } 473 474 if (requestPostData != null) 475 { 476 buffer.append(", requestPostData='{redacted}'"); 477 } 478 479 if (requestQueryString != null) 480 { 481 buffer.append(", requestQueryString='"); 482 buffer.append(requestQueryString); 483 buffer.append('\''); 484 } 485 486 buffer.append(')'); 487 } 488}