001/* 002 * Copyright 2008-2020 Ping Identity Corporation 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright 2008-2020 Ping Identity Corporation 007 * 008 * Licensed under the Apache License, Version 2.0 (the "License"); 009 * you may not use this file except in compliance with the License. 010 * You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, software 015 * distributed under the License is distributed on an "AS IS" BASIS, 016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 017 * See the License for the specific language governing permissions and 018 * limitations under the License. 019 */ 020/* 021 * Copyright (C) 2008-2020 Ping Identity Corporation 022 * 023 * This program is free software; you can redistribute it and/or modify 024 * it under the terms of the GNU General Public License (GPLv2 only) 025 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only) 026 * as published by the Free Software Foundation. 027 * 028 * This program is distributed in the hope that it will be useful, 029 * but WITHOUT ANY WARRANTY; without even the implied warranty of 030 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 031 * GNU General Public License for more details. 032 * 033 * You should have received a copy of the GNU General Public License 034 * along with this program; if not, see <http://www.gnu.org/licenses>. 035 */ 036package com.unboundid.ldap.matchingrules; 037 038 039 040import com.unboundid.asn1.ASN1OctetString; 041import com.unboundid.ldap.sdk.LDAPException; 042import com.unboundid.util.Debug; 043import com.unboundid.util.Extensible; 044import com.unboundid.util.ThreadSafety; 045import com.unboundid.util.ThreadSafetyLevel; 046 047 048 049/** 050 * This class provides a common matching rule framework that may be extended by 051 * matching rule implementations in which equality, ordering, and substring 052 * matching can all be made based on byte-for-byte comparisons of the normalized 053 * value, and any value is acceptable. 054 */ 055@Extensible() 056@ThreadSafety(level=ThreadSafetyLevel.INTERFACE_THREADSAFE) 057public abstract class AcceptAllSimpleMatchingRule 058 extends SimpleMatchingRule 059{ 060 /** 061 * The serial version UID for this serializable class. 062 */ 063 private static final long serialVersionUID = -7450007924568660003L; 064 065 066 067 /** 068 * {@inheritDoc} 069 */ 070 @Override() 071 public boolean valuesMatch(final ASN1OctetString value1, 072 final ASN1OctetString value2) 073 { 074 return normalize(value1).equalsIgnoreType(normalize(value2)); 075 } 076 077 078 079 /** 080 * {@inheritDoc} 081 */ 082 @Override() 083 public boolean matchesAnyValue(final ASN1OctetString assertionValue, 084 final ASN1OctetString[] attributeValues) 085 { 086 if ((assertionValue == null) || (attributeValues == null) || 087 (attributeValues.length == 0)) 088 { 089 return false; 090 } 091 092 final ASN1OctetString normalizedAssertionValue = normalize(assertionValue); 093 094 for (final ASN1OctetString attributeValue : attributeValues) 095 { 096 if (normalizedAssertionValue.equalsIgnoreType(normalize(attributeValue))) 097 { 098 return true; 099 } 100 } 101 102 return false; 103 } 104 105 106 107 /** 108 * {@inheritDoc} 109 */ 110 @Override() 111 public boolean matchesSubstring(final ASN1OctetString value, 112 final ASN1OctetString subInitial, 113 final ASN1OctetString[] subAny, 114 final ASN1OctetString subFinal) 115 { 116 try 117 { 118 return super.matchesSubstring(value, subInitial, subAny, subFinal); 119 } 120 catch (final LDAPException le) 121 { 122 Debug.debugException(le); 123 124 // This should never happen, as the only reason the superclass version of 125 // this method will throw an exception is if an exception is thrown by 126 // normalize or normalizeSubstring. 127 return false; 128 } 129 } 130 131 132 133 /** 134 * {@inheritDoc} 135 */ 136 @Override() 137 public int compareValues(final ASN1OctetString value1, 138 final ASN1OctetString value2) 139 { 140 try 141 { 142 return super.compareValues(value1, value2); 143 } 144 catch (final LDAPException le) 145 { 146 Debug.debugException(le); 147 148 // This should never happen, as the only reason the superclass version of 149 // this method will throw an exception is if an exception is thrown by 150 // normalize or normalizeSubstring. 151 return 0; 152 } 153 } 154 155 156 157 /** 158 * {@inheritDoc} This variant of the {@code normalize} method is not allowed 159 * to throw exceptions. 160 */ 161 @Override() 162 public abstract ASN1OctetString normalize(ASN1OctetString value); 163 164 165 166 /** 167 * {@inheritDoc} This variant of the {@code normalizeSubstring} method is not 168 * allowed to throw exceptions. 169 */ 170 @Override() 171 public abstract ASN1OctetString normalizeSubstring(ASN1OctetString value, 172 byte substringType); 173}