Java Code Examples for org.apache.directory.api.ldap.model.message.ResultCodeEnum#INVALID_ATTRIBUTE_SYNTAX
The following examples show how to use
org.apache.directory.api.ldap.model.message.ResultCodeEnum#INVALID_ATTRIBUTE_SYNTAX .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Value.java From directory-ldap-api with Apache License 2.0 | 6 votes |
/** * Uses the syntaxChecker associated with the attributeType to check if the * value is valid. * * @param syntaxChecker the SyntaxChecker to use to validate the value * @return <code>true</code> if the value is valid * @exception LdapInvalidAttributeValueException if the value cannot be validated */ public final boolean isValid( SyntaxChecker syntaxChecker ) throws LdapInvalidAttributeValueException { if ( syntaxChecker == null ) { String message = I18n.err( I18n.ERR_13219_NULL_SYNTAX_CHECKER, toString() ); LOG.error( message ); throw new LdapInvalidAttributeValueException( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, message ); } // No attributeType, or it's in relaxed mode if ( isHR ) { // We need to prepare the String in this case return syntaxChecker.isValidSyntax( getString() ); } else { return syntaxChecker.isValidSyntax( bytes ); } }
Example 2
Source File: DefaultAttribute.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public byte[] getBytes() throws LdapInvalidAttributeValueException { Value value = get(); if ( !isHumanReadable() && ( value != null ) ) { return value.getBytes(); } String message = I18n.err( I18n.ERR_13214_VALUE_EXPECT_BYTES ); LOG.error( message ); throw new LdapInvalidAttributeValueException( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, message ); }
Example 3
Source File: SchemaInterceptor.java From MyVirtualDirectory with Apache License 2.0 | 5 votes |
/** * Check the entry attributes syntax, using the syntaxCheckers */ private void assertSyntaxes( Entry entry ) throws LdapException { // First, loop on all attributes for ( Attribute attribute : entry ) { AttributeType attributeType = attribute.getAttributeType(); SyntaxChecker syntaxChecker = attributeType.getSyntax().getSyntaxChecker(); if ( syntaxChecker instanceof OctetStringSyntaxChecker ) { // This is a speedup : no need to check the syntax of any value // if all the syntaxes are accepted... continue; } // Then loop on all values for ( Value<?> value : attribute ) { if ( value.isSchemaAware() ) { // No need to validate something which is already ok continue; } try { syntaxChecker.assertSyntax( value.getValue() ); } catch ( Exception ne ) { String message = I18n.err( I18n.ERR_280, value.getString(), attribute.getUpId() ); LOG.info( message ); throw new LdapInvalidAttributeValueException( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, message ); } } } }
Example 4
Source File: SchemaInterceptor.java From MyVirtualDirectory with Apache License 2.0 | 5 votes |
/** * Check the entry attributes syntax, using the syntaxCheckers */ private void assertSyntaxes( Entry entry ) throws LdapException { // First, loop on all attributes for ( Attribute attribute : entry ) { AttributeType attributeType = attribute.getAttributeType(); SyntaxChecker syntaxChecker = attributeType.getSyntax().getSyntaxChecker(); if ( syntaxChecker instanceof OctetStringSyntaxChecker ) { // This is a speedup : no need to check the syntax of any value // if all the syntaxes are accepted... continue; } // Then loop on all values for ( Value<?> value : attribute ) { if ( value.isSchemaAware() ) { // No need to validate something which is already ok continue; } try { syntaxChecker.assertSyntax( value.getValue() ); } catch ( Exception ne ) { String message = I18n.err( I18n.ERR_280, value.getString(), attribute.getUpId() ); LOG.info( message ); throw new LdapInvalidAttributeValueException( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, message ); } } } }
Example 5
Source File: StoreCompareRequestAttributeDesc.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public void action( LdapMessageContainer<CompareRequest> container ) throws DecoderException { // Get the CompareRequest Object CompareRequest compareRequest = container.getMessage(); // Get the Value and store it in the CompareRequest TLV tlv = container.getCurrentTLV(); // We have to handle the special case of a 0 length matched // Dn if ( tlv.getLength() == 0 ) { String msg = I18n.err( I18n.ERR_05118_NULL_ATTRIBUTE_DESC ); LOG.error( msg ); CompareResponseImpl response = new CompareResponseImpl( compareRequest.getMessageId() ); throw new ResponseCarryingException( msg, response, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, compareRequest.getName(), null ); } String type = Strings.utf8ToString( tlv.getValue().getData() ); compareRequest.setAttributeId( type ); if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_05122_COMPARING_ATTRIBUTE_DESCRIPTION, compareRequest.getAttributeId() ) ); } }
Example 6
Source File: AddModifyRequestAttribute.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public void action( LdapMessageContainer<ModifyRequest> container ) throws DecoderException { ModifyRequest modifyRequest = container.getMessage(); TLV tlv = container.getCurrentTLV(); // Store the value. It can't be null String type; if ( tlv.getLength() == 0 ) { String msg = I18n.err( I18n.ERR_05123_TYPE_CANT_BE_NULL ); LOG.error( msg ); ModifyResponseImpl response = new ModifyResponseImpl( modifyRequest.getMessageId() ); throw new ResponseCarryingException( msg, response, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, modifyRequest.getName(), null ); } else { type = Strings.utf8ToString( tlv.getValue().getData() ); Attribute currentAttribute = new DefaultAttribute( type ); container.setCurrentAttribute( currentAttribute ); container.getCurrentModification().setAttribute( currentAttribute ); } // We can have an END transition if the operation was INCREMENT if ( container.getCurrentModification().getOperation() == ModificationOperation.INCREMENT_ATTRIBUTE ) { container.setGrammarEndAllowed( true ); } if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_05128_MODIFYING_TYPE, type ) ); } }
Example 7
Source File: GeneralizedTimeNormalizer.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public String normalize( String value, PrepareString.AssertionType assertionType ) throws LdapException { if ( value == null ) { throw new LdapInvalidAttributeValueException( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, I18n.err( I18n.ERR_13724_INVALID_VALUE, value ) ); } // Special case : the PPolicy "0000010000Z", for permanently locked accounts if ( "000001010000Z".equals( value ) ) { return value; } try { GeneralizedTime time = new GeneralizedTime( value ); return time.toGeneralizedTime( Format.YEAR_MONTH_DAY_HOUR_MIN_SEC_FRACTION, FractionDelimiter.DOT, 3, TimeZoneFormat.Z ); } catch ( ParseException pe ) { throw new LdapInvalidAttributeValueException( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, I18n.err( I18n.ERR_13724_INVALID_VALUE, value ), pe ); } }
Example 8
Source File: Value.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Creates a schema aware StringValue with an initial user provided String value and * its normalized Value * * @param attributeType the schema type associated with this StringValue * @param upValue the value to wrap * @param normValue the normalized value to wrap * @throws LdapInvalidAttributeValueException If the added value is invalid accordingly * to the schema */ public Value( AttributeType attributeType, String upValue, String normValue ) throws LdapInvalidAttributeValueException { init( attributeType ); this.upValue = upValue; if ( upValue != null ) { bytes = Strings.getBytesUtf8( upValue ); } else { bytes = null; } this.normValue = normValue; if ( !attributeType.isRelaxed() ) { // Check the value if ( attributeType.getSyntax().getSyntaxChecker() != null ) { if ( !attributeType.getSyntax().getSyntaxChecker().isValidSyntax( upValue ) ) { throw new LdapInvalidAttributeValueException( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, I18n.err( I18n.ERR_13246_INVALID_VALUE_PER_SYNTAX ) ); } } else { // We should always have a SyntaxChecker throw new IllegalArgumentException( I18n.err( I18n.ERR_13219_NULL_SYNTAX_CHECKER, normValue ) ); } } hashCode(); }
Example 9
Source File: DefaultAttribute.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public String getString() throws LdapInvalidAttributeValueException { Value value = get(); if ( isHumanReadable() ) { if ( value != null ) { return value.getString(); } else { return ""; } } if ( attributeType == null ) { // Special case : the Attribute is not schema aware. // The value is binary, we will try to convert it to a String return Strings.utf8ToString( value.getBytes() ); } String message = I18n.err( I18n.ERR_13215_VALUE_EXPECT_STRING ); LOG.error( message ); throw new LdapInvalidAttributeValueException( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, message ); }
Example 10
Source File: Value.java From directory-ldap-api with Apache License 2.0 | 4 votes |
/** * Deserialize a StringValue from a byte[], starting at a given position * * @param buffer The buffer containing the StringValue * @param pos The position in the buffer * @return The new position * @throws IOException If the serialized value is not a StringValue * @throws LdapInvalidAttributeValueException If the value is invalid */ public int deserialize( byte[] buffer, int pos ) throws IOException, LdapInvalidAttributeValueException { if ( ( pos < 0 ) || ( pos >= buffer.length ) ) { throw new ArrayIndexOutOfBoundsException(); } // Read the isHR flag isHR = Serialize.deserializeBoolean( buffer, pos ); pos++; if ( isHR ) { // Read the user provided value, if it's not null boolean hasValue = Serialize.deserializeBoolean( buffer, pos ); pos++; if ( hasValue ) { bytes = Serialize.deserializeBytes( buffer, pos ); pos += 4 + bytes.length; upValue = Strings.utf8ToString( bytes ); } // Read the prepared value, if not null boolean hasPreparedValue = Serialize.deserializeBoolean( buffer, pos ); pos++; if ( hasPreparedValue ) { byte[] preparedBytes = Serialize.deserializeBytes( buffer, pos ); pos += 4 + preparedBytes.length; normValue = Strings.utf8ToString( preparedBytes ); } } else { // Read the user provided value, if it's not null boolean hasBytes = Serialize.deserializeBoolean( buffer, pos ); pos++; if ( hasBytes ) { bytes = Serialize.deserializeBytes( buffer, pos ); pos += 4 + bytes.length; } } if ( attributeType != null ) { try { computeNormValue(); } catch ( LdapException le ) { throw new LdapInvalidAttributeValueException( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, le.getMessage() ); } } hashCode(); return pos; }
Example 11
Source File: LdifUtils.java From directory-ldap-api with Apache License 2.0 | 4 votes |
/** * Build a new Attributes instance from a LDIF list of lines. The values can be * either a complete Ava, or a couple of AttributeType ID and a value (a String or * a byte[]). The following sample shows the three cases : * * <pre> * Attribute attr = AttributeUtils.createAttributes( * "objectclass: top", * "cn", "My name", * "jpegPhoto", new byte[]{0x01, 0x02} ); * </pre> * * @param avas The AttributeType and Values, using a ldif format, or a couple of * Attribute ID/Value * @return An Attributes instance * @throws LdapException If the data are invalid */ public static Attributes createJndiAttributes( Object... avas ) throws LdapException { StringBuilder sb = new StringBuilder(); int pos = 0; boolean valueExpected = false; for ( Object ava : avas ) { if ( !valueExpected ) { if ( !( ava instanceof String ) ) { throw new LdapInvalidAttributeValueException( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, I18n.err( I18n.ERR_13233_ATTRIBUTE_ID_MUST_BE_A_STRING, pos + 1 ) ); } String attribute = ( String ) ava; sb.append( attribute ); if ( attribute.indexOf( ':' ) != -1 ) { sb.append( '\n' ); } else { valueExpected = true; } } else { if ( ava instanceof String ) { sb.append( ": " ).append( ( String ) ava ).append( '\n' ); } else if ( ava instanceof byte[] ) { sb.append( ":: " ); sb.append( new String( Base64.encode( ( byte[] ) ava ) ) ); sb.append( '\n' ); } else { throw new LdapInvalidAttributeValueException( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, I18n.err( I18n.ERR_13234_ATTRIBUTE_VAL_STRING_OR_BYTE, pos + 1 ) ); } valueExpected = false; } } if ( valueExpected ) { throw new LdapInvalidAttributeValueException( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, I18n .err( I18n.ERR_13234_ATTRIBUTE_VAL_STRING_OR_BYTE ) ); } try ( LdifAttributesReader reader = new LdifAttributesReader() ) { return AttributeUtils.toAttributes( reader.parseEntry( sb.toString() ) ); } catch ( IOException ioe ) { throw new LdapLdifException( ioe.getMessage(), ioe ); } }
Example 12
Source File: Registries.java From directory-ldap-api with Apache License 2.0 | 4 votes |
/** * Unlink the SchemaObject references * * @param schemaObject The SchemaObject to remove */ public void removeReference( SchemaObject schemaObject ) { try { switch ( schemaObject.getObjectType() ) { case ATTRIBUTE_TYPE: AttributeTypeHelper.removeFromRegistries( ( AttributeType ) schemaObject, errorHandler, this ); break; case LDAP_SYNTAX: LdapSyntaxHelper.removeFromRegistries( ( LdapSyntax ) schemaObject, errorHandler, this ); break; case MATCHING_RULE: MatchingRuleHelper.removeFromRegistries( ( MatchingRule ) schemaObject, errorHandler, this ); break; case OBJECT_CLASS: ObjectClassHelper.removeFromRegistries( ( ObjectClass ) schemaObject, errorHandler, this ); break; case DIT_CONTENT_RULE : // TODO break; case DIT_STRUCTURE_RULE : // TODO break; case NAME_FORM : // TODO break; case MATCHING_RULE_USE : // TODO break; case SYNTAX_CHECKER: case NORMALIZER: case COMPARATOR: // Those were not registered break; default: throw new IllegalArgumentException( I18n.err( I18n.ERR_13718_UNEXPECTED_SCHEMA_OBJECT_TYPE, schemaObject.getObjectType() ) ); } } catch ( LdapException ne ) { // Not allowed. String msg = I18n.err( I18n.ERR_13747_CANNOT_REMOVE_REFERENCES, schemaObject.getName(), ne.getLocalizedMessage() ); LdapSchemaViolationException error = new LdapSchemaViolationException( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, msg, ne ); errorHandler.handle( LOG, msg, error ); } }
Example 13
Source File: DeepTrimToLowerNormalizer.java From directory-ldap-api with Apache License 2.0 | 4 votes |
/** * {@inheritDoc} */ @Override public String normalize( String value, PrepareString.AssertionType assertionType ) throws LdapException { if ( value == null ) { return null; } String normValue = null; try { // Transcoding is useless // Map String mapped = PrepareString.mapIgnoreCase( value ); // Normalize String normalized = PrepareString.normalize( mapped ); char[] chars = normalized.toCharArray(); // Prohibit PrepareString.checkProhibited( chars ); // Bidi is ignored // Insignificant Characters Handling switch ( assertionType ) { case ATTRIBUTE_VALUE : normValue = PrepareString.insignificantSpacesStringValue( chars ); break; case SUBSTRING_INITIAL : normValue = PrepareString.insignificantSpacesStringInitial( chars ); break; case SUBSTRING_ANY : normValue = PrepareString.insignificantSpacesStringAny( chars ); break; case SUBSTRING_FINAL : normValue = PrepareString.insignificantSpacesStringFinal( chars ); break; default : // Do nothing break; } return normValue; } catch ( IOException ioe ) { throw new LdapInvalidAttributeValueException( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, I18n.err( I18n.ERR_13724_INVALID_VALUE, value ), ioe ); } }
Example 14
Source File: ObjectIdentifierNormalizer.java From directory-ldap-api with Apache License 2.0 | 4 votes |
/** * {@inheritDoc} */ @Override public String normalize( String value ) throws LdapException { if ( Strings.isEmpty( value ) ) { return ""; } String trimmedValue = value.trim(); if ( Strings.isEmpty( trimmedValue ) ) { return ""; } String oid = schemaManager.getRegistries().getOid( trimmedValue ); if ( oid == null ) { // Not found in the schemaManager : keep it as is if ( Oid.isOid( trimmedValue ) ) { // It's an numericOid oid = trimmedValue; } else { // It's a descr : ALPHA ( ALPHA | DIGIT | '-' )* for ( int i = 0; i < trimmedValue.length(); i++ ) { char c = trimmedValue.charAt( i ); if ( i == 0 ) { if ( !Character.isLetter( c ) ) { throw new LdapInvalidAttributeValueException( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, I18n.err( I18n.ERR_13724_INVALID_VALUE, value ) ); } } else { if ( !( Character.isDigit( c ) || Character.isLetter( c ) || ( c == '-' ) || ( c == '_' ) ) ) { throw new LdapInvalidAttributeValueException( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, I18n.err( I18n.ERR_13724_INVALID_VALUE, value ) ); } } } oid = trimmedValue; } } return oid; }
Example 15
Source File: DeepTrimNormalizer.java From directory-ldap-api with Apache License 2.0 | 4 votes |
/** * {@inheritDoc} */ @Override public String normalize( String value, PrepareString.AssertionType assertionType ) throws LdapException { if ( value == null ) { return null; } String normValue = null; try { // Transcoding is useless // Map String mapped = PrepareString.mapCaseSensitive( value ); // Normalize String normalized = PrepareString.normalize( mapped ); char[] chars = normalized.toCharArray(); // Prohibit PrepareString.checkProhibited( chars ); // Bidi is ignored // Insignificant Characters Handling switch ( assertionType ) { case ATTRIBUTE_VALUE : normValue = PrepareString.insignificantSpacesStringValue( chars ); break; case SUBSTRING_INITIAL : normValue = PrepareString.insignificantSpacesStringInitial( chars ); break; case SUBSTRING_ANY : normValue = PrepareString.insignificantSpacesStringAny( chars ); break; case SUBSTRING_FINAL : normValue = PrepareString.insignificantSpacesStringFinal( chars ); break; default : // Do nothing break; } return normValue; } catch ( IOException ioe ) { throw new LdapInvalidAttributeValueException( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, I18n.err( I18n.ERR_13724_INVALID_VALUE, value ), ioe ); } }
Example 16
Source File: Value.java From directory-ldap-api with Apache License 2.0 | 4 votes |
/** * Creates a schema aware StringValue with an initial user provided String value. * * @param attributeType the schema type associated with this StringValue * @param upValue the value to wrap * @throws LdapInvalidAttributeValueException If the added value is invalid accordingly * to the schema */ public Value( AttributeType attributeType, String upValue ) throws LdapInvalidAttributeValueException { init( attributeType ); this.upValue = upValue; if ( upValue != null ) { bytes = Strings.getBytesUtf8( upValue ); } else { bytes = null; } try { computeNormValue(); } catch ( LdapException le ) { LOG.error( le.getMessage() ); throw new IllegalArgumentException( I18n.err( I18n.ERR_13247_INVALID_VALUE_CANT_NORMALIZE, upValue ) ); } if ( !attributeType.isRelaxed() ) { // Check the value LdapSyntax syntax = attributeType.getSyntax(); if ( ( syntax != null ) && ( syntax.getSyntaxChecker() != null ) ) { if ( !attributeType.getSyntax().getSyntaxChecker().isValidSyntax( upValue ) ) { throw new LdapInvalidAttributeValueException( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, I18n.err( I18n.ERR_13246_INVALID_VALUE_PER_SYNTAX ) ); } } else { // We should always have a SyntaxChecker throw new IllegalArgumentException( I18n.err( I18n.ERR_13219_NULL_SYNTAX_CHECKER, normValue ) ); } } hashCode(); }
Example 17
Source File: Value.java From directory-ldap-api with Apache License 2.0 | 4 votes |
/** * Creates a schema aware binary Value with an initial value. * * @param attributeType the schema type associated with this Value * @param upValue the value to wrap * @throws LdapInvalidAttributeValueException If the added value is invalid accordingly * to the schema */ public Value( AttributeType attributeType, byte[] upValue ) throws LdapInvalidAttributeValueException { init( attributeType ); if ( upValue != null ) { bytes = new byte[upValue.length]; System.arraycopy( upValue, 0, bytes, 0, upValue.length ); if ( isHR ) { this.upValue = Strings.utf8ToString( upValue ); } } else { bytes = null; } if ( ( attributeType != null ) && !attributeType.isRelaxed() ) { // Check the value SyntaxChecker syntaxChecker = attributeType.getSyntax().getSyntaxChecker(); if ( syntaxChecker != null ) { if ( !syntaxChecker.isValidSyntax( bytes ) ) { throw new LdapInvalidAttributeValueException( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, I18n.err( I18n.ERR_13246_INVALID_VALUE_PER_SYNTAX ) ); } } else { // We should always have a SyntaxChecker throw new IllegalArgumentException( I18n.err( I18n.ERR_13219_NULL_SYNTAX_CHECKER, normValue ) ); } } hashCode(); }
Example 18
Source File: DefaultEntry.java From MyVirtualDirectory with Apache License 2.0 | 4 votes |
private Entry createEntry( SchemaManager schemaManager, Object... elements ) throws LdapInvalidAttributeValueException, LdapLdifException { StringBuilder sb = new StringBuilder(); int pos = 0; boolean valueExpected = false; for ( Object element : elements ) { if ( !valueExpected ) { if ( !( element instanceof String ) ) { throw new LdapInvalidAttributeValueException( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, I18n.err( I18n.ERR_12085, ( pos + 1 ) ) ); } String attribute = ( String ) element; sb.append( attribute ); if ( attribute.indexOf( ':' ) != -1 ) { sb.append( '\n' ); } else { valueExpected = true; } } else { if ( element instanceof String ) { sb.append( ": " ).append( ( String ) element ).append( '\n' ); } else if ( element instanceof byte[] ) { sb.append( ":: " ); sb.append( new String( Base64.encode( ( byte[] ) element ) ) ); sb.append( '\n' ); } else { throw new LdapInvalidAttributeValueException( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, I18n.err( I18n.ERR_12086, ( pos + 1 ) ) ); } valueExpected = false; } } if ( valueExpected ) { throw new LdapInvalidAttributeValueException( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, I18n .err( I18n.ERR_12087 ) ); } LdifAttributesReader reader = new LdifAttributesReader(); Entry entry = reader.parseEntry( schemaManager, sb.toString() ); return entry; }
Example 19
Source File: DefaultEntry.java From directory-ldap-api with Apache License 2.0 | 4 votes |
private Entry createEntry( SchemaManager schemaManager, Object... elements ) throws LdapInvalidAttributeValueException, LdapLdifException { StringBuilder sb = new StringBuilder(); int pos = 0; boolean valueExpected = false; for ( Object element : elements ) { if ( !valueExpected ) { if ( !( element instanceof String ) ) { throw new LdapInvalidAttributeValueException( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, I18n.err( I18n.ERR_13233_ATTRIBUTE_ID_MUST_BE_A_STRING, pos + 1 ) ); } String attribute = ( String ) element; sb.append( attribute ); if ( attribute.indexOf( ':' ) != -1 ) { sb.append( '\n' ); } else { valueExpected = true; } } else { if ( element instanceof String ) { sb.append( ": " ).append( ( String ) element ).append( '\n' ); } else if ( element instanceof byte[] ) { sb.append( ":: " ); sb.append( new String( Base64.encode( ( byte[] ) element ) ) ); sb.append( '\n' ); } else { throw new LdapInvalidAttributeValueException( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, I18n.err( I18n.ERR_13234_ATTRIBUTE_VAL_STRING_OR_BYTE, pos + 1 ) ); } valueExpected = false; } } if ( valueExpected ) { throw new LdapInvalidAttributeValueException( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, I18n .err( I18n.ERR_13250_VALUE_MISSING_AT_THE_END ) ); } try ( LdifAttributesReader reader = new LdifAttributesReader() ) { return reader.parseEntry( schemaManager, sb.toString() ); } catch ( IOException e ) { throw new LdapLdifException( I18n.err( I18n.ERR_13248_CANNOT_READ_ENTRY ), e ); } }
Example 20
Source File: DefaultEntry.java From MyVirtualDirectory with Apache License 2.0 | 4 votes |
private Entry createEntry( SchemaManager schemaManager, Object... elements ) throws LdapInvalidAttributeValueException, LdapLdifException { StringBuilder sb = new StringBuilder(); int pos = 0; boolean valueExpected = false; for ( Object element : elements ) { if ( !valueExpected ) { if ( !( element instanceof String ) ) { throw new LdapInvalidAttributeValueException( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, I18n.err( I18n.ERR_12085, ( pos + 1 ) ) ); } String attribute = ( String ) element; sb.append( attribute ); if ( attribute.indexOf( ':' ) != -1 ) { sb.append( '\n' ); } else { valueExpected = true; } } else { if ( element instanceof String ) { sb.append( ": " ).append( ( String ) element ).append( '\n' ); } else if ( element instanceof byte[] ) { sb.append( ":: " ); sb.append( new String( Base64.encode( ( byte[] ) element ) ) ); sb.append( '\n' ); } else { throw new LdapInvalidAttributeValueException( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, I18n.err( I18n.ERR_12086, ( pos + 1 ) ) ); } valueExpected = false; } } if ( valueExpected ) { throw new LdapInvalidAttributeValueException( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, I18n .err( I18n.ERR_12087 ) ); } LdifAttributesReader reader = null; try { reader = new LdifAttributesReader(); Entry entry = reader.parseEntry( schemaManager, sb.toString() ); return entry; } finally { try { reader.close(); } catch ( IOException e ) { e.printStackTrace(); } } }