001/* 002 * CDDL HEADER START 003 * 004 * The contents of this file are subject to the terms of the 005 * Common Development and Distribution License, Version 1.0 only 006 * (the "License"). You may not use this file except in compliance 007 * with the License. 008 * 009 * You can obtain a copy of the license at 010 * docs/licenses/cddl.txt 011 * or http://www.opensource.org/licenses/cddl1.php. 012 * See the License for the specific language governing permissions 013 * and limitations under the License. 014 * 015 * When distributing Covered Code, include this CDDL HEADER in each 016 * file and include the License file at 017 * docs/licenses/cddl.txt. If applicable, 018 * add the following below this CDDL HEADER, with the fields enclosed 019 * by brackets "[]" replaced with your own identifying information: 020 * Portions Copyright [yyyy] [name of copyright owner] 021 * 022 * CDDL HEADER END 023 * 024 * 025 * Copyright 2021 Ping Identity Corporation 026 */ 027package com.unboundid.directory.sdk.scim2.types; 028 029import com.fasterxml.jackson.databind.JsonNode; 030import com.fasterxml.jackson.databind.node.TextNode; 031import com.unboundid.asn1.ASN1OctetString; 032import com.unboundid.ldap.sdk.Attribute; 033import com.unboundid.scim2.common.exceptions.ScimException; 034import com.unboundid.util.ThreadSafety; 035import com.unboundid.util.ThreadSafetyLevel; 036 037/** 038 * This interface provides a set of utility methods that SCIM 2-based 039 * extensions can use to convert between JSON attribute values and LDAP 040 * attribute values. 041 */ 042@ThreadSafety(level=ThreadSafetyLevel.INTERFACE_THREADSAFE) 043public interface SCIMLDAPAttributeMapper 044{ 045 /** 046 * Converts an LDAP attribute to a JSON node. If the LDAP attribute is 047 * multivalued, then an array node will be returned. 048 * 049 * @param ldapAttribute An LDAP attribute object. 050 * 051 * @return The equivalent value as a Jackson JsonNode. 052 * @throws ScimException If the attribute cannot be converted. 053 */ 054 JsonNode toJsonNode(final Attribute ldapAttribute) 055 throws ScimException; 056 057 /** 058 * Converts an LDAP attribute to a JSON text node. If the LDAP attribute is 059 * multivalued, then the first value will be returned as a text node. 060 * 061 * @param ldapAttribute An LDAP attribute object. 062 * 063 * @return The equivalent value as a Jackson TextNode. 064 * @throws ScimException If the attribute cannot be converted. 065 */ 066 TextNode toTextNode(final Attribute ldapAttribute) 067 throws ScimException; 068 069 /** 070 * Converts the given JSON node to an LDAP attribute. 071 * 072 * @param jsonNode A SCIM attribute as a Jackson JsonNode. 073 * @param scimAttributeName The SCIM attribute name. 074 * @param ldapAttributeName The LDAP attribute name. 075 * 076 * @return The equivalent LDAP attribute. 077 * @throws ScimException If the attribute cannot be converted. 078 */ 079 Attribute toLdapAttribute(final JsonNode jsonNode, 080 final String scimAttributeName, 081 final String ldapAttributeName) 082 throws ScimException; 083 084 /** 085 * Converts the value of the given JSON node to a raw 086 * {@link ASN1OctetString} value for use in constructing an LDAP 087 * {@link Attribute} object. If the SCIM attribute is multivalued, then the 088 * first value will be returned. 089 * 090 * @param jsonNode A SCIM attribute as a Jackson JsonNode. 091 * @param ldapAttributeName The LDAP attribute name. 092 * @return The equivalent LDAP value. 093 * @throws ScimException If the attribute cannot be converted. 094 */ 095 ASN1OctetString toLdapValue(final JsonNode jsonNode, 096 final String ldapAttributeName) 097 throws ScimException; 098 099 /** 100 * Converts the value of the given JSON node to an array of raw 101 * {@link ASN1OctetString} values for use in constructing an LDAP 102 * {@link Attribute} object. 103 * 104 * @param jsonNode A SCIM attribute as a Jackson JsonNode. 105 * @param ldapAttributeName The LDAP attribute name. 106 * @return The equivalent LDAP value. 107 * @throws ScimException If the attribute cannot be converted. 108 */ 109 ASN1OctetString[] toLdapValues(final JsonNode jsonNode, 110 final String ldapAttributeName) 111 throws ScimException; 112}