Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
Copyright 2015 Red Hat, Inc. and/or its affiliates.
This file is part of lightblue.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
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 <http://www.gnu.org/licenses/>.
*/
package com.redhat.lightblue.common.ldap;

/**
* Error codes specific to LDAP
*
* @author dcrissman
*/
public final class LdapErrorCode {

/** An unsupported feature was used. */
public static final String ERR_UNSUPPORTED_FEATURE = "ldap:UnsupportedFeature:";

/** Lightblue-Ldap does not currently support object arrays. This error indicates that such a field was used. */
public static final String ERR_UNSUPPORTED_FEATURE_OBJECT_ARRAY = ERR_UNSUPPORTED_FEATURE + "ObjectArray";

private LdapErrorCode(){}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
package com.redhat.lightblue.common.ldap;

import com.redhat.lightblue.util.Path;

/**
* Represents a class that can translate back and forth between a fieldName and an LDAP attributeName.
*
Expand All @@ -30,13 +32,13 @@ public interface LdapFieldNameTranslator {
* @param fieldName - metadata field name
* @return ldap attributeName or the fieldName back at you if no mapping is present.
*/
public String translateFieldName(String fieldName);
public String translateFieldName(Path path);

/**
* Returns the fieldName with the given attributeName.
* @param attributeName - ldap attribute name
* @return metadata fieldName or the attributeName back at you if no mapping is present.
*/
public String translateAttributeName(String attributeName);
public Path translateAttributeName(String attributeName);

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,20 @@

import com.fasterxml.jackson.databind.JsonNode;
import com.redhat.lightblue.common.ldap.LdapConstant;
import com.redhat.lightblue.common.ldap.LdapErrorCode;
import com.redhat.lightblue.common.ldap.LdapFieldNameTranslator;
import com.redhat.lightblue.common.ldap.LightblueUtil;
import com.redhat.lightblue.metadata.ArrayElement;
import com.redhat.lightblue.metadata.ArrayField;
import com.redhat.lightblue.metadata.EntityMetadata;
import com.redhat.lightblue.metadata.ObjectField;
import com.redhat.lightblue.metadata.MetadataConstants;
import com.redhat.lightblue.metadata.SimpleField;
import com.redhat.lightblue.metadata.Type;
import com.redhat.lightblue.metadata.types.BinaryType;
import com.redhat.lightblue.metadata.types.DateType;
import com.redhat.lightblue.util.Error;
import com.redhat.lightblue.util.JsonDoc;
import com.redhat.lightblue.util.JsonNodeCursor;
import com.redhat.lightblue.util.Path;
import com.unboundid.ldap.sdk.Entry;
import com.unboundid.util.StaticUtils;

Expand All @@ -55,9 +56,17 @@ public EntryBuilder(EntityMetadata md, LdapFieldNameTranslator fieldNameTranslat
}

public Entry build(String dn, JsonDoc document){
Entry entry = new Entry(dn);
translate(document, entry);
return entry;
Error.push("build entry");
Error.push(LdapConstant.ATTRIBUTE_DN + "=" + dn);
try{
Entry entry = new Entry(dn);
translate(document, entry);
return entry;
}
finally{
Error.pop();
Error.pop();
}
}

@Override
Expand All @@ -74,13 +83,12 @@ else if(type instanceof BinaryType){
}

@Override
protected void translate(SimpleField field, Path path, JsonNode node, Entry target) {
String attributeName = fieldNameTranslator.translateFieldName(field.getName());
protected void translate(SimpleField field, JsonNode node, Entry target) {
String attributeName = fieldNameTranslator.translateFieldName(field.getFullPath());

if(LdapConstant.ATTRIBUTE_DN.equalsIgnoreCase(attributeName)){
throw new IllegalArgumentException(
"'dn' should not be included as it's value will be derived from the metadata.basedn and" +
" the metadata.uniqueattr. Including the 'dn' as an insert attribute is confusing.");
//DN is derived using metadata.uniqueattr, providing it is confusing.
throw Error.get(MetadataConstants.ERR_INVALID_FIELD_REFERENCE, LdapConstant.ATTRIBUTE_DN);
}
else if(LightblueUtil.isFieldObjectType(attributeName)
|| LightblueUtil.isFieldAnArrayCount(attributeName, getEntityMetadata().getFields())){
Expand All @@ -102,15 +110,10 @@ else if(LightblueUtil.isFieldObjectType(attributeName)
}

@Override
protected void translate(ObjectField field, Path path, JsonNode node, Entry target) {
throw new UnsupportedOperationException("ObjectField type is not currently supported.");
}

@Override
protected void translateSimpleArray(ArrayField field, Path path, List<Object> items, Entry target) {
protected void translateSimpleArray(ArrayField field, List<Object> items, Entry target) {
ArrayElement arrayElement = field.getElement();
Type arrayElementType = arrayElement.getType();
String attributeName = fieldNameTranslator.translateFieldName(field.getName());
String attributeName = fieldNameTranslator.translateFieldName(field.getFullPath());

if(arrayElementType instanceof BinaryType){
List<byte[]> bytes = new ArrayList<byte[]>();
Expand All @@ -130,7 +133,7 @@ protected void translateSimpleArray(ArrayField field, Path path, List<Object> it

@Override
protected void translateObjectArray(ArrayField field, JsonNodeCursor cursor, Entry target) {
throw new UnsupportedOperationException("Object ArrayField type is not currently supported.");
throw Error.get(LdapErrorCode.ERR_UNSUPPORTED_FEATURE_OBJECT_ARRAY, field.getFullPath().toString());
}

}
Loading