001/* 002 * Copyright 2008-2018 Ping Identity Corporation 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright (C) 2008-2018 Ping Identity Corporation 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.LDAPException; 027import com.unboundid.util.Extensible; 028import com.unboundid.util.ThreadSafety; 029import com.unboundid.util.ThreadSafetyLevel; 030 031import static com.unboundid.util.Debug.*; 032 033 034 035/** 036 * This class provides a common matching rule framework that may be extended by 037 * matching rule implementations in which equality, ordering, and substring 038 * matching can all be made based on byte-for-byte comparisons of the normalized 039 * value, and any value is acceptable. 040 */ 041@Extensible() 042@ThreadSafety(level=ThreadSafetyLevel.INTERFACE_THREADSAFE) 043public abstract class AcceptAllSimpleMatchingRule 044 extends SimpleMatchingRule 045{ 046 /** 047 * The serial version UID for this serializable class. 048 */ 049 private static final long serialVersionUID = -7450007924568660003L; 050 051 052 053 /** 054 * {@inheritDoc} 055 */ 056 @Override() 057 public boolean valuesMatch(final ASN1OctetString value1, 058 final ASN1OctetString value2) 059 { 060 return normalize(value1).equalsIgnoreType(normalize(value2)); 061 } 062 063 064 065 /** 066 * {@inheritDoc} 067 */ 068 @Override() 069 public boolean matchesAnyValue(final ASN1OctetString assertionValue, 070 final ASN1OctetString[] attributeValues) 071 { 072 if ((assertionValue == null) || (attributeValues == null) || 073 (attributeValues.length == 0)) 074 { 075 return false; 076 } 077 078 final ASN1OctetString normalizedAssertionValue = normalize(assertionValue); 079 080 for (final ASN1OctetString attributeValue : attributeValues) 081 { 082 if (normalizedAssertionValue.equalsIgnoreType(normalize(attributeValue))) 083 { 084 return true; 085 } 086 } 087 088 return false; 089 } 090 091 092 093 /** 094 * {@inheritDoc} 095 */ 096 @Override() 097 public boolean matchesSubstring(final ASN1OctetString value, 098 final ASN1OctetString subInitial, 099 final ASN1OctetString[] subAny, 100 final ASN1OctetString subFinal) 101 { 102 try 103 { 104 return super.matchesSubstring(value, subInitial, subAny, subFinal); 105 } 106 catch (final LDAPException le) 107 { 108 debugException(le); 109 110 // This should never happen, as the only reason the superclass version of 111 // this method will throw an exception is if an exception is thrown by 112 // normalize or normalizeSubstring. 113 return false; 114 } 115 } 116 117 118 119 /** 120 * {@inheritDoc} 121 */ 122 @Override() 123 public int compareValues(final ASN1OctetString value1, 124 final ASN1OctetString value2) 125 { 126 try 127 { 128 return super.compareValues(value1, value2); 129 } 130 catch (final LDAPException le) 131 { 132 debugException(le); 133 134 // This should never happen, as the only reason the superclass version of 135 // this method will throw an exception is if an exception is thrown by 136 // normalize or normalizeSubstring. 137 return 0; 138 } 139 } 140 141 142 143 /** 144 * {@inheritDoc} This variant of the {@code normalize} method is not allowed 145 * to throw exceptions. 146 */ 147 @Override() 148 public abstract ASN1OctetString normalize(ASN1OctetString value); 149 150 151 152 /** 153 * {@inheritDoc} This variant of the {@code normalizeSubstring} method is not 154 * allowed to throw exceptions. 155 */ 156 @Override() 157 public abstract ASN1OctetString normalizeSubstring(ASN1OctetString value, 158 byte substringType); 159}