| | |
| | | * Header, with the fields enclosed by brackets [] replaced by your own identifying |
| | | * information: "Portions Copyright [year] [name of copyright owner]". |
| | | * |
| | | * Copyright 2012 ForgeRock AS. |
| | | * Copyright 2012-2013 ForgeRock AS. |
| | | */ |
| | | package org.forgerock.opendj.rest2ldap; |
| | | |
| | |
| | | import org.forgerock.json.fluent.JsonValue; |
| | | import org.forgerock.json.resource.ResourceException; |
| | | import org.forgerock.json.resource.ResultHandler; |
| | | import org.forgerock.json.resource.ServerContext; |
| | | import org.forgerock.opendj.ldap.Attribute; |
| | | import org.forgerock.opendj.ldap.Entry; |
| | | import org.forgerock.opendj.ldap.Filter; |
| | | |
| | | /** |
| | | * An attribute mapper which maps a single JSON attribute to the result of |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public void getLDAPAttributes(final JsonPointer jsonAttribute, final Set<String> ldapAttributes) { |
| | | if (attributeMatchesPointer(jsonAttribute)) { |
| | | public void getLDAPAttributes(final Context c, final JsonPointer jsonAttribute, |
| | | final Set<String> ldapAttributes) { |
| | | if (jsonAttribute.isEmpty() || matches(jsonAttribute)) { |
| | | final JsonPointer relativePointer = jsonAttribute.relativePointer(); |
| | | mapper.getLDAPAttributes(relativePointer, ldapAttributes); |
| | | mapper.getLDAPAttributes(c, relativePointer, ldapAttributes); |
| | | } |
| | | } |
| | | |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public void toJSON(final ServerContext c, final Entry e, |
| | | public void getLDAPFilter(final Context c, final FilterType type, |
| | | final JsonPointer jsonAttribute, final String operator, final Object valueAssertion, |
| | | final ResultHandler<Filter> h) { |
| | | if (matches(jsonAttribute)) { |
| | | final JsonPointer relativePointer = jsonAttribute.relativePointer(); |
| | | mapper.getLDAPFilter(c, type, relativePointer, operator, valueAssertion, h); |
| | | } else { |
| | | // This attribute mapper cannot handle the provided filter component. |
| | | h.handleResult(null); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public void toJSON(final Context c, final Entry e, |
| | | final ResultHandler<Map<String, Object>> h) { |
| | | final ResultHandler<Map<String, Object>> wrapper = new ResultHandler<Map<String, Object>>() { |
| | | final ResultHandler<Map<String, Object>> wrapper = |
| | | new ResultHandler<Map<String, Object>>() { |
| | | |
| | | @Override |
| | | public void handleError(final ResourceException e) { |
| | | h.handleError(e); |
| | | } |
| | | @Override |
| | | public void handleError(final ResourceException e) { |
| | | h.handleError(e); |
| | | } |
| | | |
| | | @Override |
| | | public void handleResult(final Map<String, Object> result) { |
| | | final Map<String, Object> complexResult = Collections.singletonMap( |
| | | jsonAttributeName, (Object) result); |
| | | h.handleResult(complexResult); |
| | | } |
| | | }; |
| | | @Override |
| | | public void handleResult(final Map<String, Object> result) { |
| | | final Map<String, Object> complexResult = |
| | | Collections.singletonMap(jsonAttributeName, (Object) result); |
| | | h.handleResult(complexResult); |
| | | } |
| | | }; |
| | | mapper.toJSON(c, e, wrapper); |
| | | } |
| | | |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public void toLDAP(final ServerContext c, final JsonValue v, |
| | | public void toLDAP(final Context c, final JsonValue v, |
| | | final ResultHandler<List<Attribute>> h) { |
| | | // TODO Auto-generated method stub |
| | | |
| | | } |
| | | |
| | | private boolean attributeMatchesPointer(final JsonPointer resourceAttribute) { |
| | | return resourceAttribute.isEmpty() |
| | | || toLowerCase(resourceAttribute.get(0)).equals(normalizedJsonAttributeName); |
| | | private boolean matches(final JsonPointer jsonAttribute) { |
| | | return !jsonAttribute.isEmpty() |
| | | && toLowerCase(jsonAttribute.get(0)).equals(normalizedJsonAttributeName); |
| | | } |
| | | |
| | | } |