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