001/* 002 * Copyright 2016-2024 Ping Identity Corporation 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright 2016-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) 2016-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.experimental; 037 038 039 040import com.unboundid.ldap.sdk.Entry; 041import com.unboundid.ldap.sdk.LDAPException; 042import com.unboundid.ldap.sdk.OperationType; 043import com.unboundid.ldap.sdk.ResultCode; 044import com.unboundid.util.Debug; 045import com.unboundid.util.NotMutable; 046import com.unboundid.util.NotNull; 047import com.unboundid.util.Nullable; 048import com.unboundid.util.StaticUtils; 049import com.unboundid.util.ThreadSafety; 050import com.unboundid.util.ThreadSafetyLevel; 051 052import static com.unboundid.ldap.sdk.experimental.ExperimentalMessages.*; 053 054 055 056/** 057 * This class represents an entry that holds information about a bind operation 058 * processed by an LDAP server, as per the specification described in 059 * draft-chu-ldap-logschema-00. 060 */ 061@NotMutable() 062@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 063public final class DraftChuLDAPLogSchema00BindEntry 064 extends DraftChuLDAPLogSchema00Entry 065{ 066 /** 067 * The name of the attribute used to hold the bind request method. 068 */ 069 @NotNull public static final String ATTR_BIND_METHOD = "reqMethod"; 070 071 072 073 /** 074 * The name of the attribute used to hold the LDAP protocol version specified 075 * in the bind request. 076 */ 077 @NotNull public static final String ATTR_PROTOCOL_VERSION = "reqVersion"; 078 079 080 081 /** 082 * The serial version UID for this serializable class. 083 */ 084 private static final long serialVersionUID = 864660009992589945L; 085 086 087 088 // The LDAP protocol version from the bind request. 089 private final int protocolVersion; 090 091 // The base name of the bind request method. 092 @NotNull private final String bindMethod; 093 094 // The name of the SASL mechanism, if available. 095 @Nullable private final String saslMechanism; 096 097 098 099 /** 100 * Creates a new instance of this bind access log entry from the provided 101 * entry. 102 * 103 * @param entry The entry used to create this bind access log entry. 104 * 105 * @throws LDAPException If the provided entry cannot be decoded as a valid 106 * bind access log entry as per the specification 107 * contained in draft-chu-ldap-logschema-00. 108 */ 109 public DraftChuLDAPLogSchema00BindEntry(@NotNull final Entry entry) 110 throws LDAPException 111 { 112 super(entry, OperationType.BIND); 113 114 115 // Get the protocol version. 116 final String versionString = entry.getAttributeValue(ATTR_PROTOCOL_VERSION); 117 if (versionString == null) 118 { 119 throw new LDAPException(ResultCode.DECODING_ERROR, 120 ERR_LOGSCHEMA_DECODE_MISSING_REQUIRED_ATTR.get(entry.getDN(), 121 ATTR_PROTOCOL_VERSION)); 122 } 123 else 124 { 125 try 126 { 127 protocolVersion = Integer.parseInt(versionString); 128 } 129 catch (final Exception e) 130 { 131 Debug.debugException(e); 132 throw new LDAPException(ResultCode.DECODING_ERROR, 133 ERR_LOGSCHEMA_DECODE_BIND_VERSION_ERROR.get(entry.getDN(), 134 ATTR_PROTOCOL_VERSION, versionString), 135 e); 136 } 137 } 138 139 140 // Get the bind method. If it starts with "SASL/", then separate out the 141 // SASL mechanism name. 142 final String rawMethod = entry.getAttributeValue(ATTR_BIND_METHOD); 143 if (rawMethod == null) 144 { 145 throw new LDAPException(ResultCode.DECODING_ERROR, 146 ERR_LOGSCHEMA_DECODE_MISSING_REQUIRED_ATTR.get(entry.getDN(), 147 ATTR_BIND_METHOD)); 148 } 149 150 final String lowerMethod = StaticUtils.toLowerCase(rawMethod); 151 if (lowerMethod.equals("simple")) 152 { 153 bindMethod = "SIMPLE"; 154 saslMechanism = null; 155 } 156 else if (lowerMethod.startsWith("sasl/")) 157 { 158 bindMethod = "SASL"; 159 saslMechanism = rawMethod.substring(5); 160 } 161 else 162 { 163 bindMethod = rawMethod; 164 saslMechanism = null; 165 } 166 } 167 168 169 170 /** 171 * Retrieves the LDAP protocol version for the bind request described by this 172 * bind access log entry. 173 * 174 * @return The LDAP protocol version for the bind request described by this 175 * bind access log entry. 176 */ 177 public int getProtocolVersion() 178 { 179 return protocolVersion; 180 } 181 182 183 184 /** 185 * Retrieves the name of the bind method for the bind request described by 186 * this bind access log entry. It is expected to be one of "SIMPLE" or 187 * "SASL". 188 * 189 * @return The name of the bind method for the bind request described by this 190 * bind access log entry. 191 */ 192 @NotNull() 193 public String getBindMethod() 194 { 195 return bindMethod; 196 } 197 198 199 200 /** 201 * Retrieves the name of the SASL mechanism name for the bind request 202 * described by this bind access log entry, if appropriate. 203 * 204 * @return The name of the SASL mechanism for the bind request described by 205 * this bind access log entry, or {@code null} if the bind method is 206 * not "SASL". 207 */ 208 @Nullable() 209 public String getSASLMechanism() 210 { 211 return saslMechanism; 212 } 213}