org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeTypeException Java Examples
The following examples show how to use
org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeTypeException.
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 | 6 votes |
/** * {@inheritDoc} */ public boolean compare( CompareOperationContext compareContext ) throws LdapException { if ( IS_DEBUG ) { LOG.debug( "Operation Context: {}", compareContext ); } // Check that the requested AT exists // complain if we do not recognize the attribute being compared if ( !schemaManager.getAttributeTypeRegistry().contains( compareContext.getOid() ) ) { throw new LdapInvalidAttributeTypeException( I18n.err( I18n.ERR_266, compareContext.getOid() ) ); } boolean result = next( compareContext ); return result; }
Example #2
Source File: SchemaInterceptor.java From MyVirtualDirectory with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ public boolean compare( CompareOperationContext compareContext ) throws LdapException { if ( IS_DEBUG ) { LOG.debug( "Operation Context: {}", compareContext ); } // Check that the requested AT exists // complain if we do not recognize the attribute being compared if ( !schemaManager.getAttributeTypeRegistry().contains( compareContext.getOid() ) ) { throw new LdapInvalidAttributeTypeException( I18n.err( I18n.ERR_266, compareContext.getOid() ) ); } boolean result = next( compareContext ); return result; }
Example #3
Source File: AttributeUtils.java From directory-ldap-api with Apache License 2.0 | 5 votes |
/** * Convert a BasicAttributes or a AttributesImpl to an Entry * * @param attributes the BasicAttributes or AttributesImpl instance to convert * @param dn The Dn which is needed by the Entry * @return An instance of a Entry object * * @throws LdapException If we get an invalid attribute */ public static Entry toEntry( Attributes attributes, Dn dn ) throws LdapException { if ( attributes instanceof BasicAttributes ) { try { Entry entry = new DefaultEntry( dn ); for ( NamingEnumeration<? extends javax.naming.directory.Attribute> attrs = attributes.getAll(); attrs .hasMoreElements(); ) { javax.naming.directory.Attribute attr = attrs.nextElement(); Attribute entryAttribute = toApiAttribute( attr ); if ( entryAttribute != null ) { entry.put( entryAttribute ); } } return entry; } catch ( LdapException ne ) { throw new LdapInvalidAttributeTypeException( ne.getMessage(), ne ); } } else { return null; } }
Example #4
Source File: ServerEntryUtils.java From MyVirtualDirectory with Apache License 2.0 | 5 votes |
/** * Convert a BasicAttributes or a AttributesImpl to a ServerEntry * * @param attributes the BasicAttributes or AttributesImpl instance to convert * @param registries The registries, needed ro build a ServerEntry * @param dn The Dn which is needed by the ServerEntry * @return An instance of a ServerEntry object * * @throws LdapInvalidAttributeTypeException If we get an invalid attribute */ public static Entry toServerEntry( Attributes attributes, Dn dn, SchemaManager schemaManager ) throws LdapInvalidAttributeTypeException { if ( attributes instanceof BasicAttributes ) { try { Entry entry = new DefaultEntry( schemaManager, dn ); for ( NamingEnumeration<? extends javax.naming.directory.Attribute> attrs = attributes.getAll(); attrs .hasMoreElements(); ) { javax.naming.directory.Attribute attr = attrs.nextElement(); String attributeId = attr.getID(); String id = SchemaUtils.stripOptions( attributeId ); Set<String> options = SchemaUtils.getOptions( attributeId ); // TODO : handle options. AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( id ); Attribute serverAttribute = ServerEntryUtils.toServerAttribute( attr, attributeType ); if ( serverAttribute != null ) { entry.put( serverAttribute ); } } return entry; } catch ( LdapException ne ) { throw new LdapInvalidAttributeTypeException( ne.getLocalizedMessage() ); } } else { return null; } }
Example #5
Source File: ServerEntryUtils.java From MyVirtualDirectory with Apache License 2.0 | 5 votes |
/** * Convert a BasicAttributes or a AttributesImpl to a ServerEntry * * @param attributes the BasicAttributes or AttributesImpl instance to convert * @param registries The registries, needed ro build a ServerEntry * @param dn The Dn which is needed by the ServerEntry * @return An instance of a ServerEntry object * * @throws LdapInvalidAttributeTypeException If we get an invalid attribute */ public static Entry toServerEntry( Attributes attributes, Dn dn, SchemaManager schemaManager ) throws LdapInvalidAttributeTypeException { if ( attributes instanceof BasicAttributes ) { try { Entry entry = new DefaultEntry( schemaManager, dn ); for ( NamingEnumeration<? extends javax.naming.directory.Attribute> attrs = attributes.getAll(); attrs .hasMoreElements(); ) { javax.naming.directory.Attribute attr = attrs.nextElement(); String attributeId = attr.getID(); String id = SchemaUtils.stripOptions( attributeId ); Set<String> options = SchemaUtils.getOptions( attributeId ); // TODO : handle options. AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( id ); Attribute serverAttribute = ServerEntryUtils.toServerAttribute( attr, attributeType ); if ( serverAttribute != null ) { entry.put( serverAttribute ); } } return entry; } catch ( LdapException ne ) { throw new LdapInvalidAttributeTypeException( ne.getLocalizedMessage() ); } } else { return null; } }
Example #6
Source File: NormalizationInterceptor.java From syncope with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public boolean compare( CompareOperationContext compareContext ) throws LdapException { Dn dn = compareContext.getDn(); if ( !dn.isSchemaAware() ) { compareContext.setDn( new Dn( schemaManager, dn ) ); } // Get the attributeType from the OID try { AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( compareContext.getOid() ); // Translate the value from binary to String if the AT is HR if ( attributeType.getSyntax().isHumanReadable() && ( !compareContext.getValue().isHumanReadable() ) ) { compareContext.setValue( compareContext.getValue() ); } compareContext.setAttributeType( attributeType ); } catch ( LdapException le ) { throw new LdapInvalidAttributeTypeException( I18n.err( I18n.ERR_266, compareContext.getOid() ) ); } return next( compareContext ); }
Example #7
Source File: ServerEntryUtils.java From MyVirtualDirectory with Apache License 2.0 | 4 votes |
/** * Convert a BasicAttribute or a AttributeImpl to a ServerAtribute * * @param attribute the BasicAttributes or AttributesImpl instance to convert * @param attributeType * @return An instance of a ServerEntry object * * @throws InvalidAttributeIdentifierException If we had an incorrect attribute */ public static Attribute toServerAttribute( javax.naming.directory.Attribute attribute, AttributeType attributeType ) throws LdapException { if ( attribute == null ) { return null; } try { Attribute serverAttribute = new DefaultAttribute( attributeType ); for ( NamingEnumeration<?> values = attribute.getAll(); values.hasMoreElements(); ) { Object value = values.nextElement(); int nbAdded = 0; if ( value == null ) { continue; } if ( serverAttribute.isHumanReadable() ) { if ( value instanceof String ) { nbAdded = serverAttribute.add( ( String ) value ); } else if ( value instanceof byte[] ) { nbAdded = serverAttribute.add( Strings.utf8ToString( ( byte[] ) value ) ); } else { throw new LdapInvalidAttributeTypeException(); } } else { if ( value instanceof String ) { nbAdded = serverAttribute.add( Strings.getBytesUtf8( ( String ) value ) ); } else if ( value instanceof byte[] ) { nbAdded = serverAttribute.add( ( byte[] ) value ); } else { throw new LdapInvalidAttributeTypeException(); } } if ( nbAdded == 0 ) { throw new LdapInvalidAttributeTypeException(); } } return serverAttribute; } catch ( NamingException ne ) { throw new LdapInvalidAttributeTypeException(); } }
Example #8
Source File: ServerEntryUtils.java From MyVirtualDirectory with Apache License 2.0 | 4 votes |
public static List<Modification> toServerModification( Modification[] modifications, SchemaManager schemaManager ) throws LdapException { if ( modifications != null ) { List<Modification> modificationsList = new ArrayList<Modification>(); for ( Modification modification : modifications ) { String attributeId = modification.getAttribute().getUpId(); String id = stripOptions( attributeId ); modification.getAttribute().setUpId( id ); Set<String> options = getOptions( attributeId ); // ------------------------------------------------------------------- // DIRSERVER-646 Fix: Replacing an unknown attribute with no values // (deletion) causes an error // ------------------------------------------------------------------- if ( !schemaManager.getAttributeTypeRegistry().contains( id ) && modification.getAttribute().size() == 0 && modification.getOperation() == ModificationOperation.REPLACE_ATTRIBUTE ) { // The attributeType does not exist in the schema. // It's an error String message = I18n.err( I18n.ERR_467, id ); throw new LdapInvalidAttributeTypeException( message ); } else { // TODO : handle options AttributeType attributeType = null; try { attributeType = schemaManager.lookupAttributeTypeRegistry( id ); } catch (LdapNoSuchAttributeException e) { attributeType = ApacheDSUtil.addAttributeToSchema(modification.getAttribute(), schemaManager); } modificationsList.add( toServerModification( modification, attributeType ) ); } } return modificationsList; } else { return null; } }
Example #9
Source File: ServerEntryUtils.java From MyVirtualDirectory with Apache License 2.0 | 4 votes |
/** * Convert a BasicAttribute or a AttributeImpl to a ServerAtribute * * @param attribute the BasicAttributes or AttributesImpl instance to convert * @param attributeType * @return An instance of a ServerEntry object * * @throws InvalidAttributeIdentifierException If we had an incorrect attribute */ public static Attribute toServerAttribute( javax.naming.directory.Attribute attribute, AttributeType attributeType ) throws LdapException { if ( attribute == null ) { return null; } try { Attribute serverAttribute = new DefaultAttribute( attributeType ); for ( NamingEnumeration<?> values = attribute.getAll(); values.hasMoreElements(); ) { Object value = values.nextElement(); int nbAdded = 0; if ( value == null ) { continue; } if ( serverAttribute.isHumanReadable() ) { if ( value instanceof String ) { nbAdded = serverAttribute.add( ( String ) value ); } else if ( value instanceof byte[] ) { nbAdded = serverAttribute.add( Strings.utf8ToString( ( byte[] ) value ) ); } else { throw new LdapInvalidAttributeTypeException(); } } else { if ( value instanceof String ) { nbAdded = serverAttribute.add( Strings.getBytesUtf8( ( String ) value ) ); } else if ( value instanceof byte[] ) { nbAdded = serverAttribute.add( ( byte[] ) value ); } else { throw new LdapInvalidAttributeTypeException(); } } if ( nbAdded == 0 ) { throw new LdapInvalidAttributeTypeException(); } } return serverAttribute; } catch ( NamingException ne ) { throw new LdapInvalidAttributeTypeException(); } }
Example #10
Source File: ServerEntryUtils.java From MyVirtualDirectory with Apache License 2.0 | 4 votes |
public static List<Modification> toServerModification( Modification[] modifications, SchemaManager schemaManager ) throws LdapException { if ( modifications != null ) { List<Modification> modificationsList = new ArrayList<Modification>(); for ( Modification modification : modifications ) { String attributeId = modification.getAttribute().getUpId(); String id = stripOptions( attributeId ); modification.getAttribute().setUpId( id ); Set<String> options = getOptions( attributeId ); // ------------------------------------------------------------------- // DIRSERVER-646 Fix: Replacing an unknown attribute with no values // (deletion) causes an error // ------------------------------------------------------------------- if ( !schemaManager.getAttributeTypeRegistry().contains( id ) && modification.getAttribute().size() == 0 && modification.getOperation() == ModificationOperation.REPLACE_ATTRIBUTE ) { // The attributeType does not exist in the schema. // It's an error String message = I18n.err( I18n.ERR_467, id ); throw new LdapInvalidAttributeTypeException( message ); } else { // TODO : handle options AttributeType attributeType = null; try { attributeType = schemaManager.lookupAttributeTypeRegistry( id ); } catch (LdapNoSuchAttributeException e) { attributeType = ApacheDSUtil.addAttributeToSchema(modification.getAttribute(), schemaManager); } modificationsList.add( toServerModification( modification, attributeType ) ); } } return modificationsList; } else { return null; } }