From 1d336277358c93894a01cc7c586a258c1b98cf17 Mon Sep 17 00:00:00 2001
From: Matthew Swift <matthew.swift@forgerock.com>
Date: Mon, 12 Sep 2011 13:39:42 +0000
Subject: [PATCH] Issue OPENDJ-262: Implement pass through authentication (PTA)

---
 opends/src/server/org/opends/server/extensions/LDAPPassThroughAuthenticationPolicyFactory.java |   47 ++++++++++++++++++++++++++++++++---------------
 1 files changed, 32 insertions(+), 15 deletions(-)

diff --git a/opends/src/server/org/opends/server/extensions/LDAPPassThroughAuthenticationPolicyFactory.java b/opends/src/server/org/opends/server/extensions/LDAPPassThroughAuthenticationPolicyFactory.java
index c212f79..d02d685 100644
--- a/opends/src/server/org/opends/server/extensions/LDAPPassThroughAuthenticationPolicyFactory.java
+++ b/opends/src/server/org/opends/server/extensions/LDAPPassThroughAuthenticationPolicyFactory.java
@@ -36,10 +36,7 @@
 import java.io.Closeable;
 import java.io.IOException;
 import java.net.*;
-import java.util.LinkedHashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Set;
+import java.util.*;
 import java.util.concurrent.ConcurrentLinkedQueue;
 import java.util.concurrent.Semaphore;
 import java.util.concurrent.atomic.AtomicInteger;
@@ -65,7 +62,6 @@
 import org.opends.server.tools.LDAPReader;
 import org.opends.server.tools.LDAPWriter;
 import org.opends.server.types.*;
-import org.opends.server.util.StaticUtils;
 
 
 
@@ -1382,11 +1378,10 @@
                * references a non-user entry.
                */
               throw new DirectoryException(ResultCode.INVALID_CREDENTIALS,
-                  ERR_LDAP_PTA_MAPPING_ATTRIBUTE_NOT_FOUND.get(
-                      String.valueOf(userEntry.getDN()),
-                      String.valueOf(configuration.dn()),
-                      StaticUtils.collectionToString(
-                          configuration.getMappedAttribute(), ", ")));
+                  ERR_LDAP_PTA_MAPPING_ATTRIBUTE_NOT_FOUND.get(String
+                      .valueOf(userEntry.getDN()), String.valueOf(configuration
+                      .dn()), mappedAttributesAsString(configuration
+                      .getMappedAttribute())));
             }
 
             break;
@@ -1422,11 +1417,10 @@
                * references a non-user entry.
                */
               throw new DirectoryException(ResultCode.INVALID_CREDENTIALS,
-                  ERR_LDAP_PTA_MAPPING_ATTRIBUTE_NOT_FOUND.get(
-                      String.valueOf(userEntry.getDN()),
-                      String.valueOf(configuration.dn()),
-                      StaticUtils.collectionToString(
-                          configuration.getMappedAttribute(), ", ")));
+                  ERR_LDAP_PTA_MAPPING_ATTRIBUTE_NOT_FOUND.get(String
+                      .valueOf(userEntry.getDN()), String.valueOf(configuration
+                      .dn()), mappedAttributesAsString(configuration
+                      .getMappedAttribute())));
             }
 
             final SearchFilter filter;
@@ -1906,4 +1900,27 @@
     return true;
   }
 
+
+
+  private static String mappedAttributesAsString(
+      Collection<AttributeType> attributes)
+  {
+    switch (attributes.size())
+    {
+    case 0:
+      return "";
+    case 1:
+      return attributes.iterator().next().getNameOrOID();
+    default:
+      StringBuilder builder = new StringBuilder();
+      Iterator<AttributeType> i = attributes.iterator();
+      builder.append(i.next().getNameOrOID());
+      while (i.hasNext())
+      {
+        builder.append(", ");
+        builder.append(i.next().getNameOrOID());
+      }
+      return builder.toString();
+    }
+  }
 }

--
Gitblit v1.10.0