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