[java-identity-provider COMMIT] in /trunk/idp-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/reso...
noreply at shibboleth.net
noreply at shibboleth.net
Mon Oct 20 00:54:06 EDT 2014
Author: scantor
Date: Mon Oct 20 00:54:06 2014
New Revision: 6746
URL: http://svn.shibboleth.net/view/java-identity-provider?rev=6746&view=rev
Log:
IDP-494 - extend LDAP result mapper to handle aliasing, also handle multiple results properly
Modified:
trunk/idp-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/resolver/dc/ldap/impl/StringAttributeValueMappingStrategy.java
trunk/idp-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/resolver/dc/rdbms/impl/StringResultMappingStrategy.java
Modified: trunk/idp-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/resolver/dc/ldap/impl/StringAttributeValueMappingStrategy.java
URL: http://svn.shibboleth.net/view/java-identity-provider/trunk/idp-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/resolver/dc/ldap/impl/StringAttributeValueMappingStrategy.java?rev=6746&r1=6745&r2=6746&view=diff
==============================================================================
--- trunk/idp-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/resolver/dc/ldap/impl/StringAttributeValueMappingStrategy.java (original)
+++ trunk/idp-attribute-resolver-impl/src/main/java/net/shibboleth/idp/attribute/resolver/dc/ldap/impl/StringAttributeValueMappingStrategy.java Mon Oct 20 00:54:06 2014
@@ -17,7 +17,6 @@
package net.shibboleth.idp.attribute.resolver.dc.ldap.impl;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -25,8 +24,10 @@
import javax.annotation.Nullable;
import net.shibboleth.idp.attribute.IdPAttribute;
+import net.shibboleth.idp.attribute.IdPAttributeValue;
import net.shibboleth.idp.attribute.StringAttributeValue;
import net.shibboleth.idp.attribute.resolver.ResolutionException;
+import net.shibboleth.idp.attribute.resolver.dc.AbstractMappingStrategy;
import net.shibboleth.utilities.java.support.logic.Constraint;
import org.ldaptive.LdapAttribute;
@@ -36,37 +37,56 @@
import org.slf4j.LoggerFactory;
import com.google.common.collect.Lists;
-
-//TODO(lajoie): do we want something that can map data types too like the RDBMS equivalent?
-//TODO(lajoie): want some settings to control what happens if there is more than one LdapEntry
+import com.google.common.collect.Maps;
/**
* A simple {@link SearchResultMappingStrategy} that iterates over all result entries and includes all attribute values
* as strings.
*/
-public class StringAttributeValueMappingStrategy implements SearchResultMappingStrategy {
+public class StringAttributeValueMappingStrategy extends AbstractMappingStrategy<SearchResult>
+ implements SearchResultMappingStrategy {
/** Class logger. */
- private final Logger log = LoggerFactory.getLogger(StringAttributeValueMappingStrategy.class);
+ @Nonnull private final Logger log = LoggerFactory.getLogger(StringAttributeValueMappingStrategy.class);
/** {@inheritDoc} */
- @Override @Nullable public Map<String, IdPAttribute> map(@Nonnull final SearchResult results)
+ @Override @Nullable public Map<String,IdPAttribute> map(@Nonnull final SearchResult results)
throws ResolutionException {
Constraint.isNotNull(results, "Results can not be null");
- final Map<String, IdPAttribute> attributes = new HashMap<String, IdPAttribute>();
- for (LdapEntry entry : results.getEntries()) {
- for (LdapAttribute attr : entry.getAttributes()) {
- final IdPAttribute attribute = new IdPAttribute(attr.getName());
- final List<StringAttributeValue> hs = Lists.newArrayListWithExpectedSize(attr.getStringValues().size());
+ final Map<String,IdPAttribute> attributes = Maps.newHashMapWithExpectedSize(results.size());
+
+ final Map<String,String> aliases = getResultRenamingMap();
- for (String value : attr.getStringValues()) {
- hs.add(new StringAttributeValue(value));
+ for (final LdapEntry entry : results.getEntries()) {
+ for (final LdapAttribute attr : entry.getAttributes()) {
+
+ final String originalId = attr.getName();
+ final String effectiveId = aliases.containsKey(originalId) ? aliases.get(originalId) : originalId;
+ if (log.isDebugEnabled()) {
+ if (!effectiveId.equals(originalId)) {
+ log.debug("Remapping attribute {} to {}", originalId, effectiveId);
+ }
}
- attribute.setValues(hs);
- attributes.put(attribute.getId(), attribute);
+
+ IdPAttribute attribute = attributes.get(effectiveId);
+ if (attribute == null) {
+ attribute = new IdPAttribute(effectiveId);
+ attributes.put(effectiveId, attribute);
+ }
+
+ final List<IdPAttributeValue<?>> values = Lists.newArrayListWithExpectedSize(
+ attr.getStringValues().size() + attribute.getValues().size());
+
[... 28 lines stripped ...]
More information about the commits
mailing list