001/* 002 * Copyright 2008-2014 UnboundID Corp. 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright (C) 2008-2014 UnboundID Corp. 007 * 008 * This program is free software; you can redistribute it and/or modify 009 * it under the terms of the GNU General Public License (GPLv2 only) 010 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only) 011 * as published by the Free Software Foundation. 012 * 013 * This program is distributed in the hope that it will be useful, 014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 016 * GNU General Public License for more details. 017 * 018 * You should have received a copy of the GNU General Public License 019 * along with this program; if not, see <http://www.gnu.org/licenses>. 020 */ 021package com.unboundid.ldap.matchingrules; 022 023 024 025import com.unboundid.asn1.ASN1OctetString; 026import com.unboundid.ldap.sdk.DN; 027import com.unboundid.ldap.sdk.LDAPException; 028import com.unboundid.ldap.sdk.ResultCode; 029import com.unboundid.util.ThreadSafety; 030import com.unboundid.util.ThreadSafetyLevel; 031 032import static com.unboundid.ldap.matchingrules.MatchingRuleMessages.*; 033import static com.unboundid.util.Debug.*; 034import static com.unboundid.util.StaticUtils.*; 035 036 037 038/** 039 * This class provides an implementation of a matching rule that performs 040 * equality comparisons against values that should be distinguished names. 041 * Substring and ordering matching are not supported. 042 */ 043@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 044public final class DistinguishedNameMatchingRule 045 extends MatchingRule 046{ 047 /** 048 * The singleton instance that will be returned from the {@code getInstance} 049 * method. 050 */ 051 private static final DistinguishedNameMatchingRule INSTANCE = 052 new DistinguishedNameMatchingRule(); 053 054 055 056 /** 057 * The name for the distinguishedNameMatch equality matching rule. 058 */ 059 public static final String EQUALITY_RULE_NAME = "distinguishedNameMatch"; 060 061 062 063 /** 064 * The name for the distinguishedNameMatch equality matching rule, formatted 065 * in all lowercase characters. 066 */ 067 static final String LOWER_EQUALITY_RULE_NAME = 068 toLowerCase(EQUALITY_RULE_NAME); 069 070 071 072 /** 073 * The OID for the distinguishedNameMatch equality matching rule. 074 */ 075 public static final String EQUALITY_RULE_OID = "2.5.13.1"; 076 077 078 079 /** 080 * The serial version UID for this serializable class. 081 */ 082 private static final long serialVersionUID = -2617356571703597868L; 083 084 085 086 /** 087 * Creates a new instance of this distinguished name matching rule. 088 */ 089 public DistinguishedNameMatchingRule() 090 { 091 // No implementation is required. 092 } 093 094 095 096 /** 097 * Retrieves a singleton instance of this matching rule. 098 * 099 * @return A singleton instance of this matching rule. 100 */ 101 public static DistinguishedNameMatchingRule getInstance() 102 { 103 return INSTANCE; 104 } 105 106 107 108 /** 109 * {@inheritDoc} 110 */ 111 @Override() 112 public String getEqualityMatchingRuleName() 113 { 114 return EQUALITY_RULE_NAME; 115 } 116 117 118 119 /** 120 * {@inheritDoc} 121 */ 122 @Override() 123 public String getEqualityMatchingRuleOID() 124 { 125 return EQUALITY_RULE_OID; 126 } 127 128 129 130 /** 131 * {@inheritDoc} 132 */ 133 @Override() 134 public String getOrderingMatchingRuleName() 135 { 136 return null; 137 } 138 139 140 141 /** 142 * {@inheritDoc} 143 */ 144 @Override() 145 public String getOrderingMatchingRuleOID() 146 { 147 return null; 148 } 149 150 151 152 /** 153 * {@inheritDoc} 154 */ 155 @Override() 156 public String getSubstringMatchingRuleName() 157 { 158 return null; 159 } 160 161 162 163 /** 164 * {@inheritDoc} 165 */ 166 @Override() 167 public String getSubstringMatchingRuleOID() 168 { 169 return null; 170 } 171 172 173 174 /** 175 * {@inheritDoc} 176 */ 177 @Override() 178 public boolean valuesMatch(final ASN1OctetString value1, 179 final ASN1OctetString value2) 180 throws LDAPException 181 { 182 final DN dn1; 183 try 184 { 185 dn1 = new DN(value1.stringValue()); 186 } 187 catch (LDAPException le) 188 { 189 debugException(le); 190 throw new LDAPException(ResultCode.INVALID_ATTRIBUTE_SYNTAX, 191 le.getMessage(), le); 192 } 193 194 final DN dn2; 195 try 196 { 197 dn2 = new DN(value2.stringValue()); 198 } 199 catch (LDAPException le) 200 { 201 debugException(le); 202 throw new LDAPException(ResultCode.INVALID_ATTRIBUTE_SYNTAX, 203 le.getMessage(), le); 204 } 205 206 return dn1.equals(dn2); 207 } 208 209 210 211 /** 212 * {@inheritDoc} 213 */ 214 @Override() 215 public boolean matchesSubstring(final ASN1OctetString value, 216 final ASN1OctetString subInitial, 217 final ASN1OctetString[] subAny, 218 final ASN1OctetString subFinal) 219 throws LDAPException 220 { 221 throw new LDAPException(ResultCode.INAPPROPRIATE_MATCHING, 222 ERR_DN_SUBSTRING_MATCHING_NOT_SUPPORTED.get()); 223 } 224 225 226 227 /** 228 * {@inheritDoc} 229 */ 230 @Override() 231 public int compareValues(final ASN1OctetString value1, 232 final ASN1OctetString value2) 233 throws LDAPException 234 { 235 throw new LDAPException(ResultCode.INAPPROPRIATE_MATCHING, 236 ERR_DN_ORDERING_MATCHING_NOT_SUPPORTED.get()); 237 } 238 239 240 241 /** 242 * {@inheritDoc} 243 */ 244 @Override() 245 public ASN1OctetString normalize(final ASN1OctetString value) 246 throws LDAPException 247 { 248 try 249 { 250 final DN dn = new DN(value.stringValue()); 251 return new ASN1OctetString(dn.toNormalizedString()); 252 } 253 catch (LDAPException le) 254 { 255 debugException(le); 256 throw new LDAPException(ResultCode.INVALID_ATTRIBUTE_SYNTAX, 257 le.getMessage(), le); 258 } 259 } 260 261 262 263 /** 264 * {@inheritDoc} 265 */ 266 @Override() 267 public ASN1OctetString normalizeSubstring(final ASN1OctetString value, 268 final byte substringType) 269 throws LDAPException 270 { 271 throw new LDAPException(ResultCode.INAPPROPRIATE_MATCHING, 272 ERR_DN_SUBSTRING_MATCHING_NOT_SUPPORTED.get()); 273 } 274}