All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.unboundid.ldap.sdk.unboundidds.tools.ReportBindResultLDAPConnectionPoolHealthCheck Maven / Gradle / Ivy

Go to download

The UnboundID LDAP SDK for Java is a fast, comprehensive, and easy-to-use Java API for communicating with LDAP directory servers and performing related tasks like reading and writing LDIF, encoding and decoding data using base64 and ASN.1 BER, and performing secure communication. This package contains the Standard Edition of the LDAP SDK, which is a complete, general-purpose library for communicating with LDAPv3 directory servers.

There is a newer version: 7.0.1
Show newest version
/*
 * Copyright 2016-2018 Ping Identity Corporation
 * All Rights Reserved.
 */
/*
 * Copyright (C) 2016-2018 Ping Identity Corporation
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License (GPLv2 only)
 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see .
 */
package com.unboundid.ldap.sdk.unboundidds.tools;



import java.util.ArrayList;

import com.unboundid.ldap.sdk.BindResult;
import com.unboundid.ldap.sdk.LDAPConnection;
import com.unboundid.ldap.sdk.LDAPConnectionPoolHealthCheck;
import com.unboundid.ldap.sdk.LDAPException;
import com.unboundid.ldap.sdk.ResultCode;
import com.unboundid.util.CommandLineTool;
import com.unboundid.util.StaticUtils;
import com.unboundid.util.ThreadSafety;
import com.unboundid.util.ThreadSafetyLevel;

import static com.unboundid.ldap.sdk.unboundidds.tools.ToolMessages.*;



/**
 * This class provides an implementation of a connection pool health check that
 * can display information about the result of a bind operation.  It will always
 * report information about an unsuccessful bind.  It may optionally report
 * information about a successful bind, and optionally only if the successful
 * bind includes one or more response controls.
 * 
*
* NOTE: This class, and other classes within the * {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only * supported for use against Ping Identity, UnboundID, and * Nokia/Alcatel-Lucent 8661 server products. These classes provide support * for proprietary functionality or for external specifications that are not * considered stable or mature enough to be guaranteed to work in an * interoperable way with other types of LDAP servers. *
*
* Note that this health check is only intended to generate output when * appropriate and will never throw an exception to indicate that a connection * is unusable. If additional health checking is required, then this health * check may be combined with others via an aggregate health check in a manner * that ensures this health check will be invoked before any others that may * throw an exception. */ @ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) public final class ReportBindResultLDAPConnectionPoolHealthCheck extends LDAPConnectionPoolHealthCheck { // Indicates whether to display result details for successful binds that // include one or more response controls. private final boolean displaySuccessResultWithControls; // Indicates whether to display result details for successful binds that do // not include any response controls. private final boolean displaySuccessResultWithoutControls; // The tool whose output and error streams will be used for displaying result // details. private final CommandLineTool tool; // The column at which to wrap long lines. private final int wrapColumn; /** * Creates a new instance of this health check with the provided information. * * @param tool The tool with which this * health check is associated. * Any success messages written * will be sent to the tool's * standard output stream. Any * failure messages written will * be sent to the tool's standard * error stream. * @param displaySuccessResultWithControls Indicates whether to display * information about a bind * result with a result code of * {@code SUCCESS} that has one * or more response controls. * @param displaySuccessResultWithoutControls Indicates whether to display * information about a bind * result with a result code of * {@code SUCCESS} that has no * response controls. */ public ReportBindResultLDAPConnectionPoolHealthCheck( final CommandLineTool tool, final boolean displaySuccessResultWithControls, final boolean displaySuccessResultWithoutControls) { this.tool = tool; this.displaySuccessResultWithControls = displaySuccessResultWithControls; this.displaySuccessResultWithoutControls = displaySuccessResultWithoutControls; wrapColumn = StaticUtils.TERMINAL_WIDTH_COLUMNS - 1; } /** * {@inheritDoc} */ @Override() public void ensureConnectionValidAfterAuthentication( final LDAPConnection connection, final BindResult bindResult) throws LDAPException { if (bindResult.getResultCode() == ResultCode.SUCCESS) { final boolean displayResult; if (bindResult.hasResponseControl()) { displayResult = displaySuccessResultWithControls; } else { displayResult = displaySuccessResultWithoutControls; } if (displayResult) { final ArrayList lines = new ArrayList<>(10); lines.add("# " + INFO_REPORT_BIND_RESULT_HEADER.get()); ResultUtils.formatResult(lines, bindResult, true, false, 5, wrapColumn); for (final String line : lines) { tool.out(line); } tool.out(); } } else { final ArrayList lines = new ArrayList<>(10); lines.add("# " + INFO_REPORT_BIND_RESULT_HEADER.get()); ResultUtils.formatResult(lines, bindResult, true, false, 0, wrapColumn); for (final String line : lines) { tool.err(line); } tool.err(); } } /** * {@inheritDoc} */ @Override() public void toString(final StringBuilder buffer) { buffer.append("ReportBindResultLDAPConnectionPoolHealthCheck(" + "displaySuccessResultWithControls="); buffer.append(displaySuccessResultWithControls); buffer.append(", displaySuccessResultWithoutControls="); buffer.append(displaySuccessResultWithoutControls); buffer.append(')'); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy