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.util.Collections;
041import java.util.LinkedHashMap;
042import java.util.List;
043import java.util.Map;
044
045import com.unboundid.ldap.sdk.unboundidds.logs.AccessLogMessageType;
046import com.unboundid.ldap.sdk.unboundidds.logs.LogException;
047import com.unboundid.ldap.sdk.unboundidds.logs.v2.
048            SecurityNegotiationAccessLogMessage;
049import com.unboundid.util.NotMutable;
050import com.unboundid.util.NotNull;
051import com.unboundid.util.Nullable;
052import com.unboundid.util.ThreadSafety;
053import com.unboundid.util.ThreadSafetyLevel;
054import com.unboundid.util.json.JSONObject;
055import com.unboundid.util.json.JSONValue;
056
057
058
059/**
060 * This class provides a data structure that holds information about a
061 * JSON-formatted security negotiation access log message.
062 * <BR>
063 * <BLOCKQUOTE>
064 *   <B>NOTE:</B>  This class, and other classes within the
065 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
066 *   supported for use against Ping Identity, UnboundID, and
067 *   Nokia/Alcatel-Lucent 8661 server products.  These classes provide support
068 *   for proprietary functionality or for external specifications that are not
069 *   considered stable or mature enough to be guaranteed to work in an
070 *   interoperable way with other types of LDAP servers.
071 * </BLOCKQUOTE>
072 */
073@NotMutable()
074@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
075public final class JSONSecurityNegotiationAccessLogMessage
076       extends JSONAccessLogMessage
077       implements SecurityNegotiationAccessLogMessage
078{
079  /**
080   * The serial version UID for this serializable class.
081   */
082  private static final long serialVersionUID = 1857193839548987368L;
083
084
085
086  // The set of security negotiation properties for this log message.
087  @NotNull private final Map<String,String> negotiationProperties;
088
089  // The cipher for this log message.
090  @Nullable private final String cipher;
091
092  // The protocol for this log message.
093  @Nullable private final String protocol;
094
095
096
097  /**
098   * Creates a new JSON security negotiation access log message from the
099   * provided JSON object.
100   *
101   * @param  jsonObject  The JSON object that contains an encoded representation
102   *                     of this log message.  It must not be {@code null}.
103   *
104   * @throws  LogException  If the provided JSON object cannot be parsed as a
105   *                        valid log message.
106   */
107  public JSONSecurityNegotiationAccessLogMessage(
108              @NotNull final JSONObject jsonObject)
109         throws LogException
110  {
111    super(jsonObject);
112
113    protocol = getString(JSONFormattedAccessLogFields.PROTOCOL);
114    cipher = getString(JSONFormattedAccessLogFields.CIPHER);
115
116    final Map<String,String> propertyMap = new LinkedHashMap<>();
117    final List<JSONValue> propertiesObjects = jsonObject.getFieldAsArray(
118         JSONFormattedAccessLogFields.SECURITY_NEGOTIATION_PROPERTIES.
119              getFieldName());
120    if (propertiesObjects != null)
121    {
122      for (final JSONValue v : propertiesObjects)
123      {
124        if (v instanceof JSONObject)
125        {
126          final JSONObject propertyObject = (JSONObject) v;
127          final String propertyName =
128               propertyObject.getFieldAsString(
129                    JSONFormattedAccessLogFields.
130                         SECURITY_NEGOTIATION_PROPERTIES_NAME.getFieldName());
131          final String propertyValue =
132               propertyObject.getFieldAsString(
133                    JSONFormattedAccessLogFields.
134                         SECURITY_NEGOTIATION_PROPERTIES_VALUE.getFieldName());
135          if ((propertyName != null) && (propertyValue != null))
136          {
137            propertyMap.put(propertyName, propertyValue);
138          }
139        }
140      }
141    }
142
143    negotiationProperties = Collections.unmodifiableMap(propertyMap);
144  }
145
146
147
148  /**
149   * {@inheritDoc}
150   */
151  @Override()
152  @NotNull()
153  public AccessLogMessageType getMessageType()
154  {
155    return AccessLogMessageType.SECURITY_NEGOTIATION;
156  }
157
158
159
160  /**
161   * {@inheritDoc}
162   */
163  @Override()
164  @Nullable()
165  public String getProtocol()
166  {
167    return protocol;
168  }
169
170
171
172  /**
173   * {@inheritDoc}
174   */
175  @Override()
176  @Nullable()
177  public String getCipher()
178  {
179    return cipher;
180  }
181
182
183
184  /**
185   * Retrieves a map with any additional properties that may be associated with
186   * the security negotiation.
187   *
188   * @return  A map with any additional properties that may be associated with
189   *          the security negotiation, or an empty map if no negotiation
190   *          properties are available.
191   */
192  @NotNull()
193  public Map<String,String> getNegotiationProperties()
194  {
195    return negotiationProperties;
196  }
197}