You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2006/12/09 20:28:28 UTC
svn commit: r485047 [2/2] - in
/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap:
schema/ schema/syntax/ util/
Copied: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/SyntaxChecker.java (from r482559, directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SyntaxChecker.java)
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/SyntaxChecker.java?view=diff&rev=485047&p1=directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SyntaxChecker.java&r1=482559&p2=directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/SyntaxChecker.java&r2=485047
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/SyntaxChecker.java (original)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/SyntaxChecker.java Sat Dec 9 11:28:26 2006
@@ -17,7 +17,7 @@
* under the License.
*
*/
-package org.apache.directory.shared.ldap.schema;
+package org.apache.directory.shared.ldap.schema.syntax;
import javax.naming.NamingException;
@@ -29,7 +29,6 @@
* enforce a syntax within the Eve server.
*
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- * @version $Rev$
*/
public interface SyntaxChecker
{
@@ -38,27 +37,24 @@
*
* @return the object identifier of the Syntax this SyntaxChecker validates
*/
- String getSyntaxOid();
+ abstract String getSyntaxOid();
/**
* Determines if the attribute's value conforms to the attribute syntax.
*
- * @param a_value
- * the value of some attribute with the syntax
+ * @param value the value of some attribute with the syntax
* @return true if the value is in the valid syntax, false otherwise
*/
- boolean isValidSyntax( Object a_value );
+ boolean isValidSyntax( Object value );
/**
* Asserts whether or not the attribute's value conforms to the attribute
* syntax.
*
- * @param a_value
- * the value of some attribute with the syntax
- * @throws NamingException
- * if the value does not conform to the attribute syntax.
+ * @param value the value of some attribute with the syntax
+ * @throws NamingException if the value does not conform to the attribute syntax.
*/
- void assertSyntax( Object a_value ) throws NamingException;
+ void assertSyntax( Object value ) throws NamingException;
}
Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/TelephoneNumberSyntaxChecker.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/TelephoneNumberSyntaxChecker.java?view=auto&rev=485047
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/TelephoneNumberSyntaxChecker.java (added)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/TelephoneNumberSyntaxChecker.java Sat Dec 9 11:28:26 2006
@@ -0,0 +1,160 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.directory.shared.ldap.schema.syntax;
+
+
+import javax.naming.NamingException;
+
+
+import org.apache.directory.shared.ldap.exception.LdapInvalidAttributeValueException;
+import org.apache.directory.shared.ldap.message.ResultCodeEnum;
+import org.apache.directory.shared.ldap.util.StringTools;
+
+
+/**
+ * A SyntaxChecker which verifies that a value is an Integer according to RFC 4517.
+ *
+ * From RFC 4517 :
+ *
+ * Integer = ( HYPHEN LDIGIT *DIGIT ) | number
+ *
+ * From RFC 4512 :
+ * number = DIGIT | ( LDIGIT 1*DIGIT )
+ * DIGIT = %x30 | LDIGIT ; "0"-"9"
+ * LDIGIT = %x31-39 ; "1"-"9"
+ * HYPHEN = %x2D ; hyphen ("-")
+ *
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class TelephoneNumberSyntaxChecker implements SyntaxChecker
+{
+ /** The Syntax OID, according to RFC 4517, par. 3.3.31 */
+ public static final String OID = "1.3.6.1.4.1.1466.115.121.1.27";
+
+ /**
+ *
+ * Creates a new instance of IntegerSyntaxChecker.
+ *
+ */
+ public TelephoneNumberSyntaxChecker()
+ {
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.apache.directory.shared.ldap.schema.SyntaxChecker#assertSyntax(java.lang.Object)
+ */
+ public void assertSyntax( Object value ) throws NamingException
+ {
+ if ( ! isValidSyntax( value ) )
+ {
+ throw new LdapInvalidAttributeValueException( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
+ }
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.apache.directory.shared.ldap.schema.SyntaxChecker#getSyntaxOid()
+ */
+ public String getSyntaxOid()
+ {
+ return OID;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.apache.directory.shared.ldap.schema.SyntaxChecker#isValidSyntax(java.lang.Object)
+ */
+ public boolean isValidSyntax( Object value )
+ {
+ String strValue;
+
+ if ( value == null )
+ {
+ return false;
+ }
+
+ if ( value instanceof String )
+ {
+ strValue = ( String ) value;
+ }
+ else if ( value instanceof byte[] )
+ {
+ strValue = StringTools.utf8ToString( ( byte[] ) value );
+ }
+ else
+ {
+ strValue = value.toString();
+ }
+
+ if ( strValue.length() == 0 )
+ {
+ return false;
+ }
+
+ // The first char must be either a '-' or in [0..9].
+ // If it's a '0', then there should be any other char after
+ int pos = 0;
+ char c = strValue.charAt( pos );
+
+ if ( c == '-' )
+ {
+ pos = 1;
+ }
+ else if ( !StringTools.isDigit( c ) )
+ {
+ return false;
+ }
+ else if ( c == '0' )
+ {
+ if ( strValue.length() > 1 )
+ {
+ return false;
+ }
+ else
+ {
+ return true;
+ }
+ }
+
+ // We must have at least a digit which is not '0'
+ if ( !StringTools.isDigit( strValue, pos ) )
+ {
+ return false;
+ }
+ else if ( StringTools.isCharASCII( strValue, pos, '0' ) )
+ {
+ return false;
+ }
+ else
+ {
+ pos++;
+ }
+
+ while ( StringTools.isDigit( strValue, pos) )
+ {
+ pos++;
+ }
+
+ return ( pos == strValue.length() );
+ }
+}
Added: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/UtcTimeSyntaxChecker.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/UtcTimeSyntaxChecker.java?view=auto&rev=485047
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/UtcTimeSyntaxChecker.java (added)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/schema/syntax/UtcTimeSyntaxChecker.java Sat Dec 9 11:28:26 2006
@@ -0,0 +1,151 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.directory.shared.ldap.schema.syntax;
+
+
+import java.util.regex.Pattern;
+
+import javax.naming.NamingException;
+
+
+import org.apache.directory.shared.ldap.exception.LdapInvalidAttributeValueException;
+import org.apache.directory.shared.ldap.message.ResultCodeEnum;
+import org.apache.directory.shared.ldap.util.StringTools;
+
+
+/**
+ * A SyntaxChecker which verifies that a value is a UTC time
+ * according to RFC 4517.
+ *
+ * From RFC 4517 :
+ * UTCTime = year month day hour minute [ second ] [ u-time-zone ]
+ * u-time-zone = %x5A ; "Z" | u-differential
+ * u-differential = ( MINUS | PLUS ) hour minute
+ *
+ * year = 2(%x30-39) ; "00" to "99"
+ * month = ( %x30 %x31-39 ) ; "01" (January) to "09"
+ * | ( %x31 %x30-32 ) ; "10" to "12"
+ * day = ( %x30 %x31-39 ) ; "01" to "09"
+ * | ( %x31-32 %x30-39 ) ; "10" to "29"
+ * | ( %x33 %x30-31 ) ; "30" to "31"
+ * hour = ( %x30-31 %x30-39 )
+ * | ( %x32 %x30-33 ) ; "00" to "23"
+ * minute = %x30-35 %x30-39 ; "00" to "59"
+ *
+ * second = ( %x30-35 %x30-39 ) ; "00" to "59"
+ *
+ * g-time-zone = %x5A ; "Z"
+ * | g-differential
+ * g-differential = ( MINUS / PLUS ) hour [ minute ]
+ * MINUS = %x2D ; minus sign ("-")
+ *
+ * From RFC 4512 :
+ * PLUS = %x2B ; plus sign ("+")
+ *
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class UtcTimeSyntaxChecker implements SyntaxChecker
+{
+ /** The Syntax OID, according to RFC 4517, par. 3.3.34 */
+ public static final String OID = "1.3.6.1.4.1.1466.115.121.1.53";
+
+ /** The GeneralizedDate pattern matching */
+ private static final String UTC_TIME_PATTERN =
+ "^\\d{2}" + // year : 00 to 99
+ "(0[1-9]|1[0-2])" + // month : 01 to 12
+ "(0[1-9]|[12]\\d|3[01])" + // day : 01 to 31
+ "([01]\\d|2[0-3])" + // hour: 00 to 23
+ "([0-5]\\d)" + // minute : 00 to 59
+ "(" +
+ "([0-5]\\d)?" + // optional second : 00 to 59
+ "(Z|([+-]([01]\\d|2[0-3])[0-5]\\d))?" + // optionnal time-zone
+ ")$";
+
+ // The regexp pattern matcher
+ private Pattern datePattern = Pattern.compile( UTC_TIME_PATTERN );
+
+ /**
+ *
+ * Creates a new instance of UtcTimeSyntaxChecker.
+ *
+ */
+ public UtcTimeSyntaxChecker()
+ {
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.apache.directory.shared.ldap.schema.SyntaxChecker#assertSyntax(java.lang.Object)
+ */
+ public void assertSyntax( Object value ) throws NamingException
+ {
+ if ( ! isValidSyntax( value ) )
+ {
+ throw new LdapInvalidAttributeValueException( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX );
+ }
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.apache.directory.shared.ldap.schema.SyntaxChecker#getSyntaxOid()
+ */
+ public String getSyntaxOid()
+ {
+ return OID;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.apache.directory.shared.ldap.schema.SyntaxChecker#isValidSyntax(java.lang.Object)
+ */
+ public boolean isValidSyntax( Object value )
+ {
+ String strValue;
+
+ if ( value == null )
+ {
+ return false;
+ }
+
+ if ( value instanceof String )
+ {
+ strValue = ( String ) value;
+ }
+ else if ( value instanceof byte[] )
+ {
+ strValue = StringTools.utf8ToString( ( byte[] ) value );
+ }
+ else
+ {
+ strValue = value.toString();
+ }
+
+ // A generalized time must have a minimal length of 11
+ if ( strValue.length() < 11 )
+ {
+ return false;
+ }
+
+ // Start the date parsing
+ return datePattern.matcher( strValue ).find();
+ }
+}
Modified: directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java
URL: http://svn.apache.org/viewvc/directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java?view=diff&rev=485047&r1=485046&r2=485047
==============================================================================
--- directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java (original)
+++ directory/trunks/shared/ldap/src/main/java/org/apache/directory/shared/ldap/util/StringTools.java Sat Dec 9 11:28:26 2006
@@ -102,6 +102,69 @@
true, true, true, false, false, false, false, false
};
+ /** <alpha-lower-case> ::= [0x61-0x7A] */
+ public static final boolean[] ALPHA_LOWER_CASE =
+ {
+ false, false, false, false, false, false, false, false,
+ false, false, false, false, false, false, false, false,
+ false, false, false, false, false, false, false, false,
+ false, false, false, false, false, false, false, false,
+ false, false, false, false, false, false, false, false,
+ false, false, false, false, false, false, false, false,
+ false, false, false, false, false, false, false, false,
+ false, false, false, false, false, false, false, false,
+ false, false, false, false, false, false, false, false,
+ false, false, false, false, false, false, false, false,
+ false, false, false, false, false, false, false, false,
+ false, false, false, false, false, false, false, false,
+ false, true, true, true, true, true, true, true,
+ true, true, true, true, true, true, true, true,
+ true, true, true, true, true, true, true, true,
+ true, true, true, false, false, false, false, false
+ };
+
+ /** <alpha-upper-case> ::= [0x41-0x5A] */
+ public static final boolean[] ALPHA_UPPER_CASE =
+ {
+ false, false, false, false, false, false, false, false,
+ false, false, false, false, false, false, false, false,
+ false, false, false, false, false, false, false, false,
+ false, false, false, false, false, false, false, false,
+ false, false, false, false, false, false, false, false,
+ false, false, false, false, false, false, false, false,
+ false, false, false, false, false, false, false, false,
+ false, false, false, false, false, false, false, false,
+ false, true, true, true, true, true, true, true,
+ true, true, true, true, true, true, true, true,
+ true, true, true, true, true, true, true, true,
+ true, true, true, false, false, false, false, false,
+ false, false, false, false, false, false, false, false,
+ false, false, false, false, false, false, false, false,
+ false, false, false, false, false, false, false, false,
+ false, false, false, false, false, false, false, false,
+ };
+
+ /** <alpha-digit> | <digit> */
+ public static final boolean[] ALPHA_DIGIT =
+ {
+ false, false, false, false, false, false, false, false,
+ false, false, false, false, false, false, false, false,
+ false, false, false, false, false, false, false, false,
+ false, false, false, false, false, false, false, false,
+ false, false, false, false, false, false, false, false,
+ false, false, false, false, false, false, false, false,
+ true, true, true, true, true, true, true, true,
+ true, true, false, false, false, false, false, false,
+ false, true, true, true, true, true, true, true,
+ true, true, true, true, true, true, true, true,
+ true, true, true, true, true, true, true, true,
+ true, true, true, false, false, false, false, false,
+ false, true, true, true, true, true, true, true,
+ true, true, true, true, true, true, true, true,
+ true, true, true, true, true, true, true, true,
+ true, true, true, false, false, false, false, false
+ };
+
/** <alpha> | <digit> | '-' */
public static final boolean[] CHAR =
{
@@ -205,6 +268,34 @@
0, 0, 0, 0, 0, 0, 0, 0
};
+ /** upperCase = 'A' .. 'Z', '0'..'9', '-' */
+ public static final char[] UPPER_CASE =
+ {
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, '-', 0, 0,
+ '0', '1', '2', '3', '4', '5', '6', '7',
+ '8', '9', 0, 0, 0, 0, 0, 0,
+ 0, 'A', 'B', 'C', 'D', 'E', 'F', 'G',
+ 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
+ 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
+ 'X', 'Y', 'Z', 0, 0, 0, 0, 0,
+ 0, 'A', 'B', 'C', 'D', 'E', 'F', 'G',
+ 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
+ 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
+ 'X', 'Y', 'Z', 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0
+ };
private static final int CHAR_ONE_BYTE_MASK = 0xFFFFFF80;
private static final int CHAR_TWO_BYTES_MASK = 0xFFFFF800;
@@ -462,7 +553,27 @@
for ( int i = 0; i < chars.length; i++ )
{
- chars[i] = LOWER_CASE[ chars[i]];
+ chars[i] = LOWER_CASE[ chars[i] ];
+ }
+
+ return new String( chars );
+ }
+
+ /**
+ * Rewrote the toLowercase method to improve performances.
+ * In Ldap, attributesType are supposed to use ASCII chars :
+ * 'a'-'z', 'A'-'Z', '0'-'9', '.' and '-' only.
+ *
+ * @param value The String to uppercase
+ * @return The uppercase string
+ */
+ public static final String toUpperCase( String value )
+ {
+ char[] chars = value.toCharArray();
+
+ for ( int i = 0; i < chars.length; i++ )
+ {
+ chars[i] = UPPER_CASE[ chars[i] ];
}
return new String( chars );
@@ -1482,6 +1593,31 @@
}
/**
+ * Test if the current character is a bit, ie 0 or 1.
+ *
+ * @param string
+ * The String which contains the data
+ * @param index
+ * Current position in the string
+ * @return <code>true</code> if the current character is a bit (0 or 1)
+ */
+ public static final boolean isBit( String string, int index )
+ {
+ int length = string.length();
+
+ if ( ( string == null ) || ( length == 0 ) || ( index < 0 ) || ( index >= length ) )
+ {
+ return false;
+ }
+ else
+ {
+ char c = string.charAt( index );
+ return ( ( c == '0' ) || ( c == '1' ) );
+ }
+ }
+
+
+ /**
* Get the character at a given position in a string, checking fo limits
*
* @param string
@@ -1735,6 +1871,74 @@
}
}
+ /**
+ * Test if the current character is a lowercased Alpha character : <br/>
+ * <alpha> ::= [0x61-0x7A]
+ *
+ * @param string
+ * The string which contains the data
+ * @param index
+ * Current position in the string
+ * @return <code>true</code> if the current character is a lower Alpha
+ * character
+ */
+ public static final boolean isAlphaLowercaseASCII( String string, int index )
+ {
+ int length = string.length();
+
+ if ( ( string == null ) || ( length == 0 ) || ( index < 0 ) || ( index >= length ) )
+ {
+ return false;
+ }
+ else
+ {
+ char c = string.charAt( index++ );
+
+ if ( ( c > 127 ) || ( ALPHA_LOWER_CASE[c] == false ) )
+ {
+ return false;
+ }
+ else
+ {
+ return true;
+ }
+ }
+ }
+
+ /**
+ * Test if the current character is a uppercased Alpha character : <br/>
+ * <alpha> ::= [0x61-0x7A]
+ *
+ * @param string
+ * The string which contains the data
+ * @param index
+ * Current position in the string
+ * @return <code>true</code> if the current character is a lower Alpha
+ * character
+ */
+ public static final boolean isAlphaUppercaseASCII( String string, int index )
+ {
+ int length = string.length();
+
+ if ( ( string == null ) || ( length == 0 ) || ( index < 0 ) || ( index >= length ) )
+ {
+ return false;
+ }
+ else
+ {
+ char c = string.charAt( index++ );
+
+ if ( ( c > 127 ) || ( ALPHA_UPPER_CASE[c] == false ) )
+ {
+ return false;
+ }
+ else
+ {
+ return true;
+ }
+ }
+ }
+
/**
* Test if the current character is a digit <digit> ::= '0' | '1' | '2' |
@@ -1825,6 +2029,41 @@
return ( ( ( chars[0] > 127 ) || !DIGIT[chars[0]] ) ? false : true );
}
}
+
+ /**
+ * Check if the current character is an 7 bits ASCII CHAR (between 0 and
+ * 127).
+ * <char> ::= <alpha> | <digit>
+ *
+ * @param string
+ * The string which contains the data
+ * @param index
+ * Current position in the string
+ * @return The position of the next character, if the current one is a CHAR.
+ */
+ public static final boolean isAlphaDigit( String string, int index )
+ {
+ int length = string.length();
+
+ if ( ( string == null ) || ( length == 0 ) || ( index < 0 ) || ( index >= length ) )
+ {
+ return false;
+ }
+ else
+ {
+ char c = string.charAt( index++ );
+
+ if ( ( c > 127 ) || ( ALPHA_DIGIT[c] == false ) )
+ {
+ return false;
+ }
+ else
+ {
+ return true;
+ }
+ }
+ }
+
/**