/** * Returns the first name from a DN (Distinguished Name). Ex: for * <i>DN=cn=administrators,ou=groups,dc=roda,dc=org</i> returns * <i>administrators</i>. * * @param dn * the Distinguished Name. * @return a {@link String} with the first name. */ private String getFirstNameFromDN(final Dn dn) { return dn.getRdn().getValue(); }
private String getSchemaName( Dn schema ) { return schema.getRdn().getValue(); }
protected Set<String> getOids( Set<Entry> results ) { Set<String> oids = new HashSet<>( results.size() ); for ( Entry result : results ) { Dn dn = result.getDn(); oids.add( dn.getRdn().getValue() ); } return oids; }
protected String getRdnValue( String dn ) { try { return new Dn( dn ).getRdn().getNormValue(); } catch ( LdapInvalidDnException lide ) { return null; } }
private ReplicaEventLog getEventLog( OperationContext opCtx ) { Dn consumerLogDn = opCtx.getDn(); String name = ReplicaEventLog.REPLICA_EVENT_LOG_NAME_PREFIX + consumerLogDn.getRdn().getValue(); for ( ReplicaEventLog log : replicaLogMap.values() ) { if ( name.equalsIgnoreCase( log.getName() ) ) { return log; } } // end of for return null; }
/** * Method will retrieve the relative distinguished name from a distinguished name variable. * * @param dn contains ldap distinguished name. * @return rDn as string. */ protected String getRdn( String dn ) { try { return new Dn( dn ).getRdn().getName(); } catch ( LdapInvalidDnException lide ) { return null; } }
/** * rename the DnNode's Dn * * @param newRdn the new Rdn of this node * @throws LdapException If the rename failed */ public synchronized void rename( Rdn newRdn ) throws LdapException { Dn temp = nodeDn.getParent(); temp = temp.add( newRdn ); Rdn oldRdn = nodeRdn; nodeRdn = temp.getRdn(); nodeDn = temp; if ( parent != null ) { parent.children.remove( oldRdn.getNormName() ); parent.children.put( nodeRdn.getNormName(), this ); } updateAfterModDn( nodeDn ); }
/** * rename the DnNode's Dn * * @param newRdn the new Rdn of this node * @throws LdapException If the rename failed */ public synchronized void rename( Rdn newRdn ) throws LdapException { Dn temp = nodeDn.getParent(); temp = temp.add( newRdn ); Rdn oldRdn = nodeRdn; nodeRdn = temp.getRdn(); nodeDn = temp; if ( parent != null ) { parent.children.remove( oldRdn.getNormName() ); parent.children.put( nodeRdn.getNormName(), this ); } updateAfterModDn( nodeDn ); }
/** * 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 ) ) ); } }
private void addEntryIfNotExists(CoreSession session, String dnString, String... objectClasses) throws LdapException { final Dn dn = new Dn(dnString); final Rdn rdn = dn.getRdn(); final Entry entryRoda = service.newEntry(dn).add(OBJECT_CLASS, objectClasses).add(rdn.getType(), rdn.getValue()); try { session.add(entryRoda); } catch (LdapEntryAlreadyExistsException e) { LOGGER.debug("Error injecting the context entry for {}: {}", dnString, e.getMessage()); } }
/** * Creates a new instance of MoveOperationContext. * * @param session The session to use * @param oldDn the original source entry Dn to be moved and renamed * @param newSuperior the new entry superior of the target after the move */ public MoveOperationContext( CoreSession session, Dn oldDn, Dn newSuperior ) { super( session, oldDn ); this.newSuperior = newSuperior; oldSuperior = oldDn.getParent(); rdn = oldDn.getRdn().clone(); if ( session != null ) { setInterceptors( session.getDirectoryService().getInterceptors( OperationEnum.MOVE ) ); } try { newDn = newSuperior.add( rdn ); } catch ( LdapInvalidDnException lide ) { throw new IllegalArgumentException( lide.getMessage(), lide ); } }
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 ) ); } } }
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_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_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_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 ) ); } } }
private void injectRdnAttributeValues( Dn target, Entry serverEntry ) throws NamingException { // Add all the Rdn attributes and their values to this entry Rdn rdn = target.getRdn(); if ( rdn.size() == 1 ) { serverEntry.put( rdn.getType(), rdn.getValue() ); } else { for ( Ava atav : rdn ) { serverEntry.put( atav.getType(), atav.getValue() ); } } }
/** * 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() ); }
public static LdifEntry getUserAddLdif( String dnstr, byte[] password, String cn, String sn ) throws LdapException { Dn dn = new Dn( dnstr ); LdifEntry ldif = new LdifEntry(); ldif.setDn( dnstr ); ldif.setChangeType( ChangeType.Add ); Attribute attr = new DefaultAttribute( "objectClass", "top", "person", "organizationalPerson", "inetOrgPerson" ); ldif.addAttribute( attr ); attr = new DefaultAttribute( "ou", "Engineering", "People" ); ldif.addAttribute( attr ); String uid = dn.getRdn().getValue(); ldif.putAttribute( "uid", uid ); ldif.putAttribute( "l", "Bogusville" ); ldif.putAttribute( "cn", cn ); ldif.putAttribute( "sn", sn ); ldif.putAttribute( "mail", uid + "@apache.org" ); ldif.putAttribute( "telephoneNumber", "+1 408 555 4798" ); ldif.putAttribute( "facsimileTelephoneNumber", "+1 408 555 9751" ); ldif.putAttribute( "roomnumber", "4612" ); ldif.putAttribute( "userPassword", password ); String givenName = cn.split( " " )[0]; ldif.putAttribute( "givenName", givenName ); return ldif; }