/** * Gets the prefix, cuts the suffix from the given Dn. * * @param dn the Dn * @param suffix the suffix * * @return the prefix */ public static Dn getPrefixName( Dn dn, Dn suffix ) { if ( suffix.size() < 1 ) { return null; } else { try { Dn prefix = dn.getDescendantOf( suffix ); return prefix; } catch ( LdapInvalidDnException lide ) { return null; } } }
/** * {@inheritDoc} */ @Override public void writeExternal( ObjectOutput out ) throws IOException { if ( upName == null ) { String message = I18n.err( I18n.ERR_13624_CANNOT_SERIALIZE_NULL_DN ); LOG.error( message ); throw new IOException( message ); } // Write the UPName out.writeUTF( upName ); // Write the RDNs. // First the number of RDNs out.writeInt( size() ); // Loop on the RDNs for ( Rdn rdn : rdns ) { rdn.writeExternal( out ); } out.flush(); }
/** * {@inheritDoc} */ @Override public void writeExternal( ObjectOutput out ) throws IOException { if ( upName == null ) { String message = I18n.err( I18n.ERR_13624_CANNOT_SERIALIZE_NULL_DN ); LOG.error( message ); throw new IOException( message ); } // Write the UPName out.writeUTF( upName ); // Write the RDNs. // First the number of RDNs out.writeInt( size() ); // Loop on the RDNs for ( Rdn rdn : rdns ) { rdn.writeExternal( out ); } out.flush(); }
/** * {@inheritDoc} */ @Override public void writeExternal( ObjectOutput out ) throws IOException { if ( upName == null ) { String message = I18n.err( I18n.ERR_13624_CANNOT_SERIALIZE_NULL_DN ); LOG.error( message ); throw new IOException( message ); } // Write the UPName out.writeUTF( upName ); // Write the RDNs. // First the number of RDNs out.writeInt( size() ); // Loop on the RDNs for ( Rdn rdn : rdns ) { rdn.writeExternal( out ); } out.flush(); }
/** * @return True if one of the node below the current node has one element, * False otherwise * @param dn The Dn we want to get the element for */ public synchronized List<N> getDescendantElements( Dn dn ) { List<N> descendants = new ArrayList<>(); DnNode<N> node = getNode( dn ); if ( node == null ) { return descendants; } // We must be at the right place in the tree if ( node.getDn().size() != dn.size() ) { return descendants; } if ( node.hasChildren() ) { for ( DnNode<N> child : node.getChildren().values() ) { getDescendantElements( child, descendants ); } } return descendants; }
/** * @return True if one of the node below the current node has one element, * False otherwise * @param dn The Dn we want to get the element for */ public synchronized List<N> getDescendantElements( Dn dn ) { List<N> descendants = new ArrayList<>(); DnNode<N> node = getNode( dn ); if ( node == null ) { return descendants; } // We must be at the right place in the tree if ( node.getDn().size() != dn.size() ) { return descendants; } if ( node.hasChildren() ) { for ( DnNode<N> child : node.getChildren().values() ) { getDescendantElements( child, descendants ); } } return descendants; }
/** * @return True if one of the node below the current node has one element, * False otherwise * @param dn The Dn we want to get the element for */ public synchronized boolean hasDescendantElement( Dn dn ) { DnNode<N> node = getNode( dn ); if ( node == null ) { return false; } // We must be at the right place in the tree if ( node.getDn().size() != dn.size() ) { return false; } if ( node.hasChildren() ) { for ( DnNode<N> child : node.getChildren().values() ) { if ( hasDescendantElement( child ) ) { return true; } } } return false; }
/** * Checks that the parent Dn is a valid Dn * * @param newParent The parent DN to check * @param schemaManager The SchemaManager instance * @param objectType The ObjectType to check * @throws LdapException If the deletion failed */ protected void checkParent( Dn newParent, SchemaManager schemaManager, String objectType ) throws LdapException { if ( newParent.size() != 3 ) { throw new LdapInvalidDnException( ResultCodeEnum.NAMING_VIOLATION, I18n.err( I18n.ERR_337 ) ); } Rdn rdn = newParent.getRdn(); if ( !schemaManager.getAttributeTypeRegistry().getOidByName( rdn.getNormType() ) .equals( SchemaConstants.OU_AT_OID ) ) { throw new LdapInvalidDnException( ResultCodeEnum.NAMING_VIOLATION, I18n.err( I18n.ERR_338, objectType ) ); } if ( !rdn.getValue().equalsIgnoreCase( OBJECT_TYPE_TO_PATH.get( objectType ) ) ) { throw new LdapInvalidDnException( ResultCodeEnum.NAMING_VIOLATION, I18n.err( I18n.ERR_339, objectType, OBJECT_TYPE_TO_PATH.get( objectType ) ) ); } }
if ( ( dn.size() != parentNode.depth ) || parentNode.hasChildren() )
/** * {@inheritDoc} */ public boolean evaluate( ExprNode node, Dn dn, Entry record ) throws LdapException { ScopeNode snode = ( ScopeNode ) node; switch ( snode.getScope() ) { case OBJECT: return dn.equals( snode.getBaseDn() ); case ONELEVEL: if ( dn.isDescendantOf( snode.getBaseDn() ) ) { return ( snode.getBaseDn().size() + 1 ) == dn.size(); } case SUBTREE: return dn.isDescendantOf( snode.getBaseDn() ); default: throw new LdapInvalidSearchFilterException( I18n.err( I18n.ERR_247 ) ); } } }
private void checkNewParent( Dn newParent ) throws LdapException { if ( newParent.size() != 3 ) { throw new LdapInvalidDnException( ResultCodeEnum.NAMING_VIOLATION, I18n.err( I18n.ERR_370 ) ); } Rdn rdn = newParent.getRdn(); if ( !schemaManager.getAttributeTypeRegistry().getOidByName( rdn.getNormType() ).equals( SchemaConstants.OU_AT_OID ) ) { throw new LdapInvalidDnException( ResultCodeEnum.NAMING_VIOLATION, I18n.err( I18n.ERR_371 ) ); } if ( !rdn.getValue().equalsIgnoreCase( SchemaConstants.NORMALIZERS_AT ) ) { throw new LdapInvalidDnException( ResultCodeEnum.NAMING_VIOLATION, I18n.err( I18n.ERR_372 ) ); } } }
private void checkNewParent( Dn newParent ) throws LdapException { if ( newParent.size() != 3 ) { throw new LdapInvalidDnException( ResultCodeEnum.NAMING_VIOLATION, "The parent dn of a objectClass should be at most 3 name components in length." ); } Rdn rdn = newParent.getRdn(); if ( !schemaManager.getAttributeTypeRegistry().getOidByName( rdn.getNormType() ).equals( SchemaConstants.OU_AT_OID ) ) { throw new LdapInvalidDnException( ResultCodeEnum.NAMING_VIOLATION, I18n.err( I18n.ERR_376 ) ); } if ( !rdn.getValue().equalsIgnoreCase( SchemaConstants.OBJECT_CLASSES_AT ) ) { throw new LdapInvalidDnException( ResultCodeEnum.NAMING_VIOLATION, I18n.err( I18n.ERR_377 ) ); } } }
private void checkNewParent( Dn newParent ) throws LdapException { if ( newParent.size() != 3 ) { throw new LdapInvalidDnException( ResultCodeEnum.NAMING_VIOLATION, I18n.err( I18n.ERR_402 ) ); } Rdn rdn = newParent.getRdn(); if ( !schemaManager.getAttributeTypeRegistry().getOidByName( rdn.getNormType() ).equals( SchemaConstants.OU_AT_OID ) ) { throw new LdapInvalidDnException( ResultCodeEnum.NAMING_VIOLATION, I18n.err( I18n.ERR_403 ) ); } if ( !rdn.getValue().equalsIgnoreCase( SchemaConstants.SYNTAXES ) ) { throw new LdapInvalidDnException( ResultCodeEnum.NAMING_VIOLATION, I18n.err( I18n.ERR_363 ) ); } } }
/** * @see javax.naming.Context#destroySubcontext(javax.naming.Name) */ public void destroySubcontext( Name name ) throws NamingException { Dn target = buildTarget( JndiUtils.fromName( name ) ); if ( target.size() == 0 ) { throw new NoPermissionException( I18n.err( I18n.ERR_492 ) ); } try { doDeleteOperation( target ); } catch ( Exception e ) { JndiUtils.wrap( e ); } }
private void checkNewParent( Dn newParent ) throws LdapException { if ( newParent.size() != 3 ) { throw new LdapInvalidDnException( ResultCodeEnum.NAMING_VIOLATION, I18n.err( I18n.ERR_361 ) ); } Rdn rdn = newParent.getRdn(); if ( !schemaManager.getAttributeTypeRegistry().getOidByName( rdn.getNormType() ).equals( SchemaConstants.OU_AT_OID ) ) { throw new LdapInvalidDnException( ResultCodeEnum.NAMING_VIOLATION, I18n.err( I18n.ERR_362 ) ); } if ( !rdn.getValue().equalsIgnoreCase( SchemaConstants.MATCHING_RULES_AT ) ) { throw new LdapInvalidDnException( ResultCodeEnum.NAMING_VIOLATION, I18n.err( I18n.ERR_363 ) ); } } }
private void checkNewParent( Dn newParent ) throws LdapException { if ( newParent.size() != 3 ) { throw new LdapInvalidDnException( ResultCodeEnum.NAMING_VIOLATION, I18n.err( I18n.ERR_357 ) ); } Rdn rdn = newParent.getRdn(); if ( !schemaManager.getAttributeTypeRegistry().getOidByName( rdn.getNormType() ).equals( SchemaConstants.OU_AT_OID ) ) { throw new LdapInvalidDnException( ResultCodeEnum.NAMING_VIOLATION, I18n.err( I18n.ERR_358 ) ); } if ( !rdn.getValue().equalsIgnoreCase( SchemaConstants.COMPARATORS_AT ) ) { throw new LdapInvalidDnException( ResultCodeEnum.NAMING_VIOLATION, I18n.err( I18n.ERR_359 ) ); } } }
private void checkNewParent( Dn newParent ) throws LdapException { if ( newParent.size() != 3 ) { throw new LdapInvalidDnException( ResultCodeEnum.NAMING_VIOLATION, I18n.err( I18n.ERR_396 ) ); } Rdn rdn = newParent.getRdn(); if ( !schemaManager.getAttributeTypeRegistry().getOidByName( rdn.getNormType() ).equals( SchemaConstants.OU_AT_OID ) ) { throw new LdapInvalidDnException( ResultCodeEnum.NAMING_VIOLATION, I18n.err( I18n.ERR_397 ) ); } if ( !rdn.getValue().equalsIgnoreCase( SchemaConstants.SYNTAX_CHECKERS_AT ) ) { throw new LdapInvalidDnException( ResultCodeEnum.NAMING_VIOLATION, I18n.err( I18n.ERR_372 ) ); } } }
/** * {@inheritDoc} */ @Override public EntryFilteringCursor search( SearchOperationContext searchContext ) throws LdapException { Dn baseDn = searchContext.getDn(); // TODO since we're handling the *, and + in the EntryFilteringCursor // we may not need this code: we need see if this is actually the // case and remove this code. if ( baseDn.size() == 0 ) { return searchFromRoot( searchContext ); } // Not sure we need this code... if ( !baseDn.isSchemaAware() ) { baseDn = new Dn( schemaManager, baseDn ); } // Normal case : do a search on the specific partition Partition backend = searchContext.getPartition(); return backend.search( searchContext ); }
/** * Exctract the schema name from the Dn. It is supposed to be the * second Rdn in the dn : * <pre> * ou=schema, cn=MySchema, ... * </pre> * Here, the schemaName is MySchema * * @param dn The Dn we want to get the schema name from * @return The schema name * @throws LdapException If we got an error */ protected String getSchemaName( Dn dn ) throws LdapException { int size = dn.size(); if ( size < 2 ) { throw new LdapInvalidDnException( I18n.err( I18n.ERR_276 ) ); } Rdn rdn = dn.getRdn( size - 2 ); return Strings.trim( rdn.getAva().getValue().getNormalized() ); }