Java Code Examples for org.apache.directory.api.ldap.model.entry.Attribute#getAttributeType()
The following examples show how to use
org.apache.directory.api.ldap.model.entry.Attribute#getAttributeType() .
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: SchemaInterceptor.java From MyVirtualDirectory with Apache License 2.0 | 7 votes |
/** * Checks to see if an attribute is required by as determined from an entry's * set of objectClass attribute values. * * @return true if the objectClass values require the attribute, false otherwise * @throws Exception if the attribute is not recognized */ private void assertAllAttributesAllowed( Dn dn, Entry entry, Set<String> allowed ) throws LdapException { // Never check the attributes if the extensibleObject objectClass is // declared for this entry Attribute objectClass = entry.get( OBJECT_CLASS_AT ); if ( objectClass.contains( SchemaConstants.EXTENSIBLE_OBJECT_OC ) ) { return; } for ( Attribute attribute : entry ) { String attrOid = attribute.getAttributeType().getOid(); AttributeType attributeType = attribute.getAttributeType(); if ( !attributeType.isCollective() && ( attributeType.getUsage() == UsageEnum.USER_APPLICATIONS ) && !allowed.contains( attrOid ) ) { throw new LdapSchemaViolationException( ResultCodeEnum.OBJECT_CLASS_VIOLATION, I18n.err( I18n.ERR_277, attribute.getUpId(), dn.getName() ) ); } } }
Example 2
Source File: BinaryAnonymizer.java From directory-ldap-api with Apache License 2.0 | 6 votes |
/** * Anonymize an attribute using pure random values (either chars of bytes, depending on the Attribute type) */ @Override public Attribute anonymize( Map<Value, Value> valueMap, Set<Value> valueSet, Attribute attribute ) { Attribute result = new DefaultAttribute( attribute.getAttributeType() ); for ( Value value : attribute ) { byte[] bytesValue = value.getBytes(); byte[] newValue = computeNewValue( bytesValue ); try { result.add( newValue ); Value anonValue = new Value( attribute.getAttributeType(), newValue ); valueMap.put( ( Value ) value, anonValue ); valueSet.add( anonValue ); } catch ( LdapInvalidAttributeValueException e ) { throw new RuntimeException( I18n.err( I18n.ERR_13436_ERROR_ANONYMIZING_VALUE, value ) ); } } return result; }
Example 3
Source File: SchemaInterceptor.java From MyVirtualDirectory with Apache License 2.0 | 6 votes |
/** * Checks to see if an attribute is required by as determined from an entry's * set of objectClass attribute values. * * @return true if the objectClass values require the attribute, false otherwise * @throws Exception if the attribute is not recognized */ private void assertAllAttributesAllowed( Dn dn, Entry entry, Set<String> allowed ) throws LdapException { // Never check the attributes if the extensibleObject objectClass is // declared for this entry Attribute objectClass = entry.get( OBJECT_CLASS_AT ); if ( objectClass.contains( SchemaConstants.EXTENSIBLE_OBJECT_OC ) ) { return; } for ( Attribute attribute : entry ) { String attrOid = attribute.getAttributeType().getOid(); AttributeType attributeType = attribute.getAttributeType(); if ( !attributeType.isCollective() && ( attributeType.getUsage() == UsageEnum.USER_APPLICATIONS ) && !allowed.contains( attrOid ) ) { throw new LdapSchemaViolationException( ResultCodeEnum.OBJECT_CLASS_VIOLATION, I18n.err( I18n.ERR_277, attribute.getUpId(), dn.getName() ) ); } } }
Example 4
Source File: ServerEntryUtils.java From MyVirtualDirectory with Apache License 2.0 | 5 votes |
/** * Convert a ServerAttribute into a BasicAttribute. The Dn is lost * during this conversion, as the Attributes object does not store * this element. * * @return An instance of a AttributesImpl() object */ public static javax.naming.directory.Attribute toBasicAttribute( Attribute entryAttribute ) { AttributeType attributeType = entryAttribute.getAttributeType(); javax.naming.directory.Attribute attribute = new BasicAttribute( attributeType.getName() ); for ( Value<?> value : entryAttribute ) { attribute.add( value.getValue() ); } return attribute; }
Example 5
Source File: ServerEntryUtils.java From MyVirtualDirectory with Apache License 2.0 | 5 votes |
/** * Convert a ServerEntry into a BasicAttributes. The Dn is lost * during this conversion, as the Attributes object does not store * this element. * * @return An instance of a AttributesImpl() object */ public static Attributes toBasicAttributes( Entry entry ) { if ( entry == null ) { return null; } Attributes attributes = new BasicAttributes( true ); for ( Attribute attribute : entry.getAttributes() ) { AttributeType attributeType = attribute.getAttributeType(); Attribute attr = entry.get( attributeType ); // Deal with a special case : an entry without any ObjectClass if ( attributeType.getOid().equals( SchemaConstants.OBJECT_CLASS_AT_OID ) && attr.size() == 0 ) { // We don't have any objectClass, just dismiss this element continue; } attributes.put( toBasicAttribute( attr ) ); } return attributes; }
Example 6
Source File: ServerEntryUtils.java From MyVirtualDirectory with Apache License 2.0 | 5 votes |
/** * Utility method to extract a modification item from an array of modifications. * * @param mods the array of ModificationItems to extract the Attribute from. * @param type the attributeType spec of the Attribute to extract * @return the modification item on the attributeType specified */ public static final Modification getModificationItem( List<Modification> mods, AttributeType type ) { for ( Modification modification : mods ) { Attribute attribute = modification.getAttribute(); if ( attribute.getAttributeType() == type ) { return modification; } } return null; }
Example 7
Source File: SchemaInterceptor.java From MyVirtualDirectory with Apache License 2.0 | 5 votes |
/** * Create a new attribute using the given values */ private Attribute createNewAttribute( Attribute attribute ) throws LdapException { AttributeType attributeType = attribute.getAttributeType(); // Create the new Attribute Attribute newAttribute = new DefaultAttribute( attribute.getUpId(), attributeType ); for ( Value<?> value : attribute ) { newAttribute.add( value ); } return newAttribute; }
Example 8
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 9
Source File: ServerEntryUtils.java From MyVirtualDirectory with Apache License 2.0 | 5 votes |
/** * Convert a ServerAttribute into a BasicAttribute. The Dn is lost * during this conversion, as the Attributes object does not store * this element. * * @return An instance of a AttributesImpl() object */ public static javax.naming.directory.Attribute toBasicAttribute( Attribute entryAttribute ) { AttributeType attributeType = entryAttribute.getAttributeType(); javax.naming.directory.Attribute attribute = new BasicAttribute( attributeType.getName() ); for ( Value<?> value : entryAttribute ) { attribute.add( value.getValue() ); } return attribute; }
Example 10
Source File: ServerEntryUtils.java From MyVirtualDirectory with Apache License 2.0 | 5 votes |
/** * Convert a ServerEntry into a BasicAttributes. The Dn is lost * during this conversion, as the Attributes object does not store * this element. * * @return An instance of a AttributesImpl() object */ public static Attributes toBasicAttributes( Entry entry ) { if ( entry == null ) { return null; } Attributes attributes = new BasicAttributes( true ); for ( Attribute attribute : entry.getAttributes() ) { AttributeType attributeType = attribute.getAttributeType(); Attribute attr = entry.get( attributeType ); // Deal with a special case : an entry without any ObjectClass if ( attributeType.getOid().equals( SchemaConstants.OBJECT_CLASS_AT_OID ) && attr.size() == 0 ) { // We don't have any objectClass, just dismiss this element continue; } attributes.put( toBasicAttribute( attr ) ); } return attributes; }
Example 11
Source File: ServerEntryUtils.java From MyVirtualDirectory with Apache License 2.0 | 5 votes |
/** * Utility method to extract a modification item from an array of modifications. * * @param mods the array of ModificationItems to extract the Attribute from. * @param type the attributeType spec of the Attribute to extract * @return the modification item on the attributeType specified */ public static final Modification getModificationItem( List<Modification> mods, AttributeType type ) { for ( Modification modification : mods ) { Attribute attribute = modification.getAttribute(); if ( attribute.getAttributeType() == type ) { return modification; } } return null; }
Example 12
Source File: SchemaInterceptor.java From MyVirtualDirectory with Apache License 2.0 | 5 votes |
/** * Create a new attribute using the given values */ private Attribute createNewAttribute( Attribute attribute ) throws LdapException { AttributeType attributeType = attribute.getAttributeType(); // Create the new Attribute Attribute newAttribute = new DefaultAttribute( attribute.getUpId(), attributeType ); for ( Value<?> value : attribute ) { newAttribute.add( value ); } return newAttribute; }
Example 13
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 14
Source File: LdifAnonymizer.java From directory-ldap-api with Apache License 2.0 | 4 votes |
/** * Anonymize a Add change * * @param ldifEntry The entry to anonymize * @return The anonymized entry * @throws LdapException If the anonymization failed */ private LdifEntry anonymizeChangeAdd( LdifEntry ldifEntry ) throws LdapException { Dn entryDn = ldifEntry.getDn(); LdifEntry newLdifEntry = new LdifEntry( schemaManager ); newLdifEntry.setChangeType( ChangeType.Add ); // Process the DN first Dn anonymizedDn = anonymizeDn( entryDn ); newLdifEntry.setDn( anonymizedDn ); // Now, process the entry's attributes for ( Attribute attribute : ldifEntry ) { AttributeType attributeType = attribute.getAttributeType(); Attribute anonymizedAttribute = new DefaultAttribute( attributeType ); // Deal with the special case of a DN syntax if ( attributeType.getSyntax().getSyntaxChecker() instanceof DnSyntaxChecker ) { for ( Value dnValue : attribute ) { Dn dn = new Dn( schemaManager, dnValue.getString() ); Dn newdDn = anonymizeDn( dn ); anonymizedAttribute.add( newdDn.toString() ); } newLdifEntry.addAttribute( attribute ); } else { Anonymizer anonymizer = attributeAnonymizers.get( attribute.getAttributeType().getOid() ); if ( anonymizer == null ) { newLdifEntry.addAttribute( attribute ); } else { anonymizedAttribute = anonymizer.anonymize( valueMap, valueSet, attribute ); if ( anonymizedAttribute != null ) { newLdifEntry.addAttribute( anonymizedAttribute ); } } } } return newLdifEntry; }
Example 15
Source File: SchemaInterceptor.java From MyVirtualDirectory with Apache License 2.0 | 4 votes |
/** * Check that all the attribute's values which are Human Readable can be transformed * to valid String if they are stored as byte[], and that non Human Readable attributes * stored as String can be transformed to byte[] */ private void assertHumanReadable( Entry entry ) throws LdapException { boolean isModified = false; Entry clonedEntry = null; // Loops on all attributes for ( Attribute attribute : entry ) { AttributeType attributeType = attribute.getAttributeType(); // If the attributeType is H-R, check all of its values if ( attributeType.getSyntax().isHumanReadable() ) { isModified = checkHumanReadable( attribute ); } else { isModified = checkNotHumanReadable( attribute ); } // If we have a returned attribute, then we need to store it // into a new entry if ( isModified ) { if ( clonedEntry == null ) { clonedEntry = entry.clone(); } // Switch the attributes clonedEntry.put( attribute ); isModified = false; } } if ( clonedEntry != null ) { entry = clonedEntry; } }
Example 16
Source File: SchemaInterceptor.java From MyVirtualDirectory with Apache License 2.0 | 4 votes |
/** * Check that all the attribute's values which are Human Readable can be transformed * to valid String if they are stored as byte[], and that non Human Readable attributes * stored as String can be transformed to byte[] */ private void assertHumanReadable( Entry entry ) throws LdapException { boolean isModified = false; Entry clonedEntry = null; // Loops on all attributes for ( Attribute attribute : entry ) { AttributeType attributeType = attribute.getAttributeType(); // If the attributeType is H-R, check all of its values if ( attributeType.getSyntax().isHumanReadable() ) { isModified = checkHumanReadable( attribute ); } else { isModified = checkNotHumanReadable( attribute ); } // If we have a returned attribute, then we need to store it // into a new entry if ( isModified ) { if ( clonedEntry == null ) { clonedEntry = entry.clone(); } // Switch the attributes clonedEntry.put( attribute ); isModified = false; } } if ( clonedEntry != null ) { entry = clonedEntry; } }