From 595b0d2a712585e169ccde6476818e72c2c75630 Mon Sep 17 00:00:00 2001
From: Jean-Noël Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Fri, 01 Apr 2016 10:15:43 +0000
Subject: [PATCH] Removed all uses of AttributeType.getNormalizedNameOrOID()
---
opendj-server-legacy/src/main/java/org/opends/server/types/Entry.java | 25 ++++-
opendj-server-legacy/src/main/java/org/opends/server/tools/tasks/TaskEntry.java | 92 ++++++----------------
opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/HistoricalTest.java | 2
opendj-server-legacy/src/main/java/org/opends/server/extensions/SubjectAttributeToUserAttributeCertificateMapper.java | 66 +++------------
4 files changed, 60 insertions(+), 125 deletions(-)
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/extensions/SubjectAttributeToUserAttributeCertificateMapper.java b/opendj-server-legacy/src/main/java/org/opends/server/extensions/SubjectAttributeToUserAttributeCertificateMapper.java
index 33949c2..dc17701 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/extensions/SubjectAttributeToUserAttributeCertificateMapper.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/extensions/SubjectAttributeToUserAttributeCertificateMapper.java
@@ -77,8 +77,6 @@
{
private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
- /** The DN of the configuration entry for this certificate mapper. */
- private DN configEntryDN;
/** The mappings between certificate attribute names and user attribute types. */
private LinkedHashMap<String,AttributeType> attributeMap;
/** The current configuration for this certificate mapper. */
@@ -86,7 +84,6 @@
/** The set of attributes to return in search result entries. */
private LinkedHashSet<String> requestedAttributes;
-
/**
* Creates a new instance of this certificate mapper. Note that all actual
* initialization should be done in the
@@ -97,9 +94,6 @@
super();
}
-
-
- /** {@inheritDoc} */
@Override
public void initializeCertificateMapper(
SubjectAttributeToUserAttributeCertificateMapperCfg configuration)
@@ -108,11 +102,10 @@
configuration.addSubjectAttributeToUserAttributeChangeListener(this);
currentConfig = configuration;
- configEntryDN = configuration.dn();
// Get and validate the subject attribute to user attribute mappings.
ConfigChangeResult ccr = new ConfigChangeResult();
- attributeMap = buildAttributeMap(configuration, configEntryDN, ccr);
+ attributeMap = buildAttributeMap(configuration, ccr);
List<LocalizableMessage> messages = ccr.getMessages();
if (!messages.isEmpty())
{
@@ -140,16 +133,12 @@
requestedAttributes = newLinkedHashSet("*", "+");
}
- /** {@inheritDoc} */
@Override
public void finalizeCertificateMapper()
{
currentConfig.removeSubjectAttributeToUserAttributeChangeListener(this);
}
-
-
- /** {@inheritDoc} */
@Override
public Entry mapCertificateToUser(Certificate[] certificateChain)
throws DirectoryException
@@ -157,7 +146,6 @@
SubjectAttributeToUserAttributeCertificateMapperCfg config = currentConfig;
LinkedHashMap<String,AttributeType> theAttributeMap = this.attributeMap;
-
// Make sure that a peer certificate was provided.
if (certificateChain == null || certificateChain.length == 0)
{
@@ -165,14 +153,13 @@
throw new DirectoryException(ResultCode.INVALID_CREDENTIALS, message);
}
-
// Get the first certificate in the chain. It must be an X.509 certificate.
X509Certificate peerCertificate;
try
{
peerCertificate = (X509Certificate) certificateChain[0];
}
- catch (Exception e)
+ catch (ClassCastException e)
{
logger.traceException(e);
@@ -180,9 +167,7 @@
throw new DirectoryException(ResultCode.INVALID_CREDENTIALS, message);
}
-
- // Get the subject from the peer certificate and use it to create a search
- // filter.
+ // Get the subject from the peer certificate and use it to create a search filter
DN peerDN;
X500Principal peerPrincipal = peerCertificate.getSubjectX500Principal();
String peerName = peerPrincipal.getName(X500Principal.RFC2253);
@@ -202,11 +187,7 @@
{
for (AVA ava : rdn)
{
- String lowerName = toLowerCase(ava.getAttributeName());
-
- // Try to normalize lowerName
- lowerName = normalizeAttributeName(lowerName);
-
+ String lowerName = normalizeAttributeName(ava.getAttributeName());
AttributeType attrType = theAttributeMap.get(lowerName);
if (attrType != null)
{
@@ -278,13 +259,10 @@
}
}
-
- // If we've gotten here, then we either found exactly one user entry or we
- // didn't find any. Either way, return the entry or null to the caller.
+ // We either found exactly one user entry or we did not find any.
return userEntry;
}
- /** {@inheritDoc} */
@Override
public boolean isConfigurationAcceptable(CertificateMapperCfg configuration,
List<LocalizableMessage> unacceptableReasons)
@@ -294,26 +272,22 @@
return isConfigurationChangeAcceptable(config, unacceptableReasons);
}
-
-
- /** {@inheritDoc} */
@Override
public boolean isConfigurationChangeAcceptable(
SubjectAttributeToUserAttributeCertificateMapperCfg configuration,
List<LocalizableMessage> unacceptableReasons)
{
ConfigChangeResult ccr = new ConfigChangeResult();
- buildAttributeMap(configuration, configuration.dn(), ccr);
+ buildAttributeMap(configuration, ccr);
unacceptableReasons.addAll(ccr.getMessages());
return ResultCode.SUCCESS.equals(ccr.getResultCode());
}
- /** {@inheritDoc} */
@Override
public ConfigChangeResult applyConfigurationChange(SubjectAttributeToUserAttributeCertificateMapperCfg configuration)
{
final ConfigChangeResult ccr = new ConfigChangeResult();
- LinkedHashMap<String, AttributeType> newAttributeMap = buildAttributeMap(configuration, configEntryDN, ccr);
+ LinkedHashMap<String, AttributeType> newAttributeMap = buildAttributeMap(configuration, ccr);
// Make sure that all the user attributes are configured with equality
// indexes in all appropriate backends.
@@ -358,17 +332,17 @@
/** Get and validate the subject attribute to user attribute mappings. */
private LinkedHashMap<String, AttributeType> buildAttributeMap(
- SubjectAttributeToUserAttributeCertificateMapperCfg configuration, DN cfgEntryDN, ConfigChangeResult ccr)
+ SubjectAttributeToUserAttributeCertificateMapperCfg cfg, ConfigChangeResult ccr)
{
LinkedHashMap<String, AttributeType> results = new LinkedHashMap<>();
- for (String mapStr : configuration.getSubjectAttributeMapping())
+ for (String mapStr : cfg.getSubjectAttributeMapping())
{
String lowerMap = toLowerCase(mapStr);
int colonPos = lowerMap.indexOf(':');
if (colonPos <= 0)
{
ccr.setResultCodeIfSuccess(ResultCode.CONSTRAINT_VIOLATION);
- ccr.addMessage(ERR_SATUACM_INVALID_MAP_FORMAT.get(cfgEntryDN, mapStr));
+ ccr.addMessage(ERR_SATUACM_INVALID_MAP_FORMAT.get(cfg.dn(), mapStr));
return null;
}
@@ -377,7 +351,7 @@
if (certAttrName.length() == 0 || userAttrName.length() == 0)
{
ccr.setResultCodeIfSuccess(ResultCode.CONSTRAINT_VIOLATION);
- ccr.addMessage(ERR_SATUACM_INVALID_MAP_FORMAT.get(cfgEntryDN, mapStr));
+ ccr.addMessage(ERR_SATUACM_INVALID_MAP_FORMAT.get(cfg.dn(), mapStr));
return null;
}
@@ -386,7 +360,7 @@
if (results.containsKey(certAttrName))
{
ccr.setResultCodeIfSuccess(ResultCode.CONSTRAINT_VIOLATION);
- ccr.addMessage(ERR_SATUACM_DUPLICATE_CERT_ATTR.get(cfgEntryDN, certAttrName));
+ ccr.addMessage(ERR_SATUACM_DUPLICATE_CERT_ATTR.get(cfg.dn(), certAttrName));
return null;
}
@@ -394,13 +368,13 @@
if (userAttrType.isPlaceHolder())
{
ccr.setResultCodeIfSuccess(ResultCode.CONSTRAINT_VIOLATION);
- ccr.addMessage(ERR_SATUACM_NO_SUCH_ATTR.get(mapStr, cfgEntryDN, userAttrName));
+ ccr.addMessage(ERR_SATUACM_NO_SUCH_ATTR.get(mapStr, cfg.dn(), userAttrName));
return null;
}
if (results.values().contains(userAttrType))
{
ccr.setResultCodeIfSuccess(ResultCode.CONSTRAINT_VIOLATION);
- ccr.addMessage(ERR_SATUACM_DUPLICATE_USER_ATTR.get(cfgEntryDN, userAttrType.getNameOrOID()));
+ ccr.addMessage(ERR_SATUACM_DUPLICATE_USER_ATTR.get(cfg.dn(), userAttrType.getNameOrOID()));
return null;
}
@@ -409,18 +383,8 @@
return results;
}
-
-
- /**
- * Normalizes the given attribute name; if normalization is not
- * possible the original String value is returned.
- *
- * @param attrName The attribute name which should be normalized.
- * @return The normalized attribute name.
- */
private static String normalizeAttributeName(String attrName)
{
- AttributeType attrType = DirectoryServer.getAttributeType(attrName);
- return attrType.isPlaceHolder() ? attrName : attrType.getNormalizedNameOrOID();
+ return toLowerCase(DirectoryServer.getAttributeType(attrName).getNameOrOID());
}
}
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/tools/tasks/TaskEntry.java b/opendj-server-legacy/src/main/java/org/opends/server/tools/tasks/TaskEntry.java
index 5f04b8d..a45495d 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/tools/tasks/TaskEntry.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/tools/tasks/TaskEntry.java
@@ -16,31 +16,31 @@
*/
package org.opends.server.tools.tasks;
-import org.forgerock.i18n.LocalizableMessage;
-import org.forgerock.opendj.ldap.ByteString;
-import org.forgerock.opendj.ldap.schema.AttributeType;
-import org.opends.server.backends.task.FailedDependencyAction;
-import org.opends.server.backends.task.Task;
-import org.opends.server.backends.task.TaskState;
-import org.opends.server.types.Attribute;
-import org.forgerock.opendj.ldap.DN;
-import org.opends.server.types.Entry;
+import static org.opends.server.util.ServerConstants.*;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.List;
import java.util.Map;
-import java.util.Set;
import java.util.TimeZone;
-import java.lang.reflect.Method;
-import java.text.DateFormat;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import static org.opends.server.util.ServerConstants.*;
+import org.forgerock.i18n.LocalizableMessage;
+import org.forgerock.opendj.ldap.ByteString;
+import org.forgerock.opendj.ldap.DN;
+import org.forgerock.opendj.ldap.schema.AttributeType;
+import org.opends.server.backends.task.FailedDependencyAction;
+import org.opends.server.backends.task.Task;
+import org.opends.server.backends.task.TaskState;
+import org.opends.server.core.DirectoryServer;
+import org.opends.server.types.Attribute;
+import org.opends.server.types.Entry;
+import org.opends.server.types.ObjectClass;
+import org.opends.server.util.StaticUtils;
/**
* Processes information from a task entry from the directory and
@@ -54,27 +54,6 @@
private int hashCode;
- /**
- * These attributes associated with the ds-task object
- * class are all handled explicitly below in the constructor.
- */
- private static Set<String> supAttrNames = new HashSet<>();
- static {
- supAttrNames.add("ds-task-id");
- supAttrNames.add("ds-task-class-name");
- supAttrNames.add("ds-task-state");
- supAttrNames.add("ds-task-scheduled-start-time");
- supAttrNames.add("ds-task-actual-start-time");
- supAttrNames.add("ds-task-completion-time");
- supAttrNames.add("ds-task-dependency-id");
- supAttrNames.add("ds-task-failed-dependency-action");
- supAttrNames.add("ds-task-log-message");
- supAttrNames.add("ds-task-notify-on-completion");
- supAttrNames.add("ds-task-notify-on-error");
- supAttrNames.add("ds-recurring-task-id");
- supAttrNames.add("ds-recurring-task-schedule");
- }
-
private String id;
private String className;
private String state;
@@ -119,17 +98,12 @@
notifyComp = getMultiStringValue(entry, p + "notify-on-completion");
schedTab = getSingleStringValue(entry, "ds-recurring-task-schedule");
-
- // Build a map of non-superior attribute value pairs for display
- Map<AttributeType, List<Attribute>> attrMap = entry.getUserAttributes();
- for (AttributeType type : attrMap.keySet()) {
- String typeName = type.getNormalizedNameOrOID();
-
- // See if we've handled it already above
- if (!supAttrNames.contains(typeName)) {
- LocalizableMessage attrTypeName = getAttributeDisplayName(typeName);
- List<Attribute> attrList = entry.getUserAttribute(type);
- for (Attribute attr : attrList) {
+ final ObjectClass dsTask = DirectoryServer.getObjectClass("ds-task");
+ final ObjectClass dsRecurringTask = DirectoryServer.getObjectClass("ds-recurring-task");
+ for (AttributeType attrType : entry.getUserAttributes().keySet()) {
+ if (!dsTask.isRequiredOrOptional(attrType) && !dsRecurringTask.isRequiredOrOptional(attrType)) {
+ LocalizableMessage attrTypeName = getAttributeDisplayName(attrType);
+ for (Attribute attr : entry.getUserAttribute(attrType)) {
for (ByteString av : attr) {
List<String> valueList = taskSpecificAttrValues.get(attrTypeName);
if (valueList == null) {
@@ -156,18 +130,12 @@
hashCode += taskSpecificAttrValues.hashCode();
}
- /**
- * Retrieves a hash code for this task entry.
- *
- * @return The hash code for this task entry.
- */
@Override
public int hashCode()
{
return hashCode;
}
- /** {@inheritDoc} */
@Override
public boolean equals(Object o)
{
@@ -175,12 +143,6 @@
{
return true;
}
-
- if (o == null)
- {
- return false;
- }
-
if (! (o instanceof TaskEntry))
{
return false;
@@ -440,16 +402,15 @@
return valuesList;
}
- private LocalizableMessage getAttributeDisplayName(String attrName) {
+ private LocalizableMessage getAttributeDisplayName(AttributeType attrType) {
+ final String attrName = StaticUtils.toLowerCase(attrType.getNameOrOID());
LocalizableMessage name = mapAttrToDisplayName.get(attrName);
if (name == null) {
Task task = getTask();
if (task != null) {
try {
- Method m = Task.class.getMethod(
- "getAttributeDisplayName", String.class);
- Object o = m.invoke(task, attrName);
- if (o != null && LocalizableMessage.class.isAssignableFrom(o.getClass())) {
+ Object o = task.getAttributeDisplayName(attrName);
+ if (o instanceof LocalizableMessage) {
name= (LocalizableMessage)o;
mapAttrToDisplayName.put(attrName, name);
}
@@ -507,5 +468,4 @@
}
return task;
}
-
}
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/types/Entry.java b/opendj-server-legacy/src/main/java/org/opends/server/types/Entry.java
index 55cc922..b039fe8 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/types/Entry.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/types/Entry.java
@@ -22,7 +22,6 @@
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
@@ -2818,20 +2817,20 @@
// Get collective attribute exclusions.
AttributeType exclusionsType = DirectoryServer.getAttributeType(ATTR_COLLECTIVE_EXCLUSIONS_LC);
List<Attribute> exclusionsAttrList = operationalAttributes.get(exclusionsType);
- Set<String> exclusionsNameSet = new HashSet<>();
+ List<String> excludedAttrNames = new ArrayList<>();
if (exclusionsAttrList != null && !exclusionsAttrList.isEmpty())
{
for (Attribute attr : exclusionsAttrList)
{
for (ByteString attrValue : attr)
{
- String exclusionsName = attrValue.toString().toLowerCase();
- if (VALUE_COLLECTIVE_EXCLUSIONS_EXCLUDE_ALL_LC.equals(exclusionsName)
- || OID_COLLECTIVE_EXCLUSIONS_EXCLUDE_ALL.equals(exclusionsName))
+ String excludedAttrName = attrValue.toString().toLowerCase();
+ if (VALUE_COLLECTIVE_EXCLUSIONS_EXCLUDE_ALL_LC.equals(excludedAttrName)
+ || OID_COLLECTIVE_EXCLUSIONS_EXCLUDE_ALL.equals(excludedAttrName))
{
return;
}
- exclusionsNameSet.add(exclusionsName);
+ excludedAttrNames.add(excludedAttrName);
}
}
}
@@ -2914,7 +2913,7 @@
for (Attribute collectiveAttr : collectiveAttrList)
{
AttributeType attributeType = collectiveAttr.getAttributeDescription().getAttributeType();
- if (exclusionsNameSet.contains(attributeType.getNormalizedNameOrOID()))
+ if (hasAnyNameOrOID(attributeType, excludedAttrNames))
{
continue;
}
@@ -2961,6 +2960,18 @@
}
}
+ private boolean hasAnyNameOrOID(AttributeType attributeType, Collection<String> attrNames)
+ {
+ for (String attrName : attrNames)
+ {
+ if (attributeType.hasNameOrOID(attrName))
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
private ByteString normalize(MatchingRule matchingRule, ByteString value)
throws DirectoryException
{
diff --git a/opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/HistoricalTest.java b/opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/HistoricalTest.java
index 298ec4b..5e6b083 100644
--- a/opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/HistoricalTest.java
+++ b/opendj-server-legacy/src/test/java/org/opends/server/replication/plugin/HistoricalTest.java
@@ -340,7 +340,7 @@
private static void publishModify(ReplicationBroker broker, CSN changeNum,
DN dn, String entryuuid, AttributeType attrType, String newValue)
{
- Attribute attr = Attributes.create(attrType.getNormalizedNameOrOID(), newValue);
+ Attribute attr = Attributes.create(attrType, newValue);
List<Modification> mods = newArrayList(new Modification(ModificationType.ADD, attr));
broker.publish(new ModifyMsg(changeNum, dn, mods, entryuuid));
}
--
Gitblit v1.10.0