/** * 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; }
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; }
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()); } }
/** * 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 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() ); } } }
oldRdn.getValue() ) ) )
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; }
/** * {@inheritDoc} */ @Override public void rename( Entry entry, Rdn newRdn, boolean cascade ) throws LdapException { String schemaName = getSchemaName( entry.getDn() ); MatchingRule oldMr = factory.getMatchingRule( schemaManager, entry, schemaManager.getRegistries(), schemaName ); Entry targetEntry = entry.clone(); String newOid = newRdn.getValue(); checkOidIsUnique( newOid ); targetEntry.put( MetaSchemaConstants.M_OID_AT, newOid ); MatchingRule mr = factory.getMatchingRule( schemaManager, targetEntry, schemaManager.getRegistries(), schemaName ); if ( isSchemaEnabled( schemaName ) ) { schemaManager.unregisterMatchingRule( oldMr.getOid() ); schemaManager.add( mr ); } else { unregisterOids( oldMr ); registerOids( mr ); } }
/** * {@inheritDoc} */ @Override public void moveAndRename( Dn oriChildName, Dn newParentName, Rdn newRdn, boolean deleteOldRn, Entry entry, boolean cascade ) throws LdapException { checkNewParent( newParentName ); String oldOid = getOid( entry ); String oldSchemaName = getSchemaName( oriChildName ); String newSchemaName = getSchemaName( newParentName ); if ( schemaManager.getMatchingRuleRegistry().contains( oldOid ) ) { throw new LdapUnwillingToPerformException( ResultCodeEnum.UNWILLING_TO_PERFORM, I18n.err( I18n.ERR_367, oldOid ) ); } String oid = newRdn.getValue(); checkOidIsUniqueForNormalizer( oid ); Normalizer normalizer = factory.getNormalizer( schemaManager, entry, schemaManager.getRegistries(), newSchemaName ); if ( isSchemaEnabled( oldSchemaName ) ) { schemaManager.unregisterNormalizer( oldOid ); } if ( isSchemaEnabled( newSchemaName ) ) { schemaManager.add( normalizer ); } }
/** * {@inheritDoc} */ @Override public void rename( Entry entry, Rdn newRdn, boolean cascade ) throws LdapException { String oldOid = getOid( entry ); String schemaName = getSchemaName( entry.getDn() ); if ( schemaManager.getLdapSyntaxRegistry().contains( oldOid ) ) { throw new LdapUnwillingToPerformException( ResultCodeEnum.UNWILLING_TO_PERFORM, I18n.err( I18n.ERR_389, oldOid ) ); } Entry targetEntry = entry.clone(); String newOid = newRdn.getValue(); if ( schemaManager.getSyntaxCheckerRegistry().contains( newOid ) ) { throw new LdapSchemaViolationException( ResultCodeEnum.OTHER, I18n.err( I18n.ERR_390, newOid ) ); } targetEntry.put( MetaSchemaConstants.M_OID_AT, newOid ); if ( isSchemaEnabled( schemaName ) ) { SyntaxChecker syntaxChecker = factory.getSyntaxChecker( schemaManager, targetEntry, schemaManager .getRegistries(), schemaName ); schemaManager.unregisterSyntaxChecker( oldOid ); schemaManager.add( syntaxChecker ); } }
/** * {@inheritDoc} */ @Override public void rename( Entry entry, Rdn newRdn, boolean cascade ) throws LdapException { String oldOid = getOid( entry ); String schemaName = getSchemaName( entry.getDn() ); if ( schemaManager.getMatchingRuleRegistry().contains( oldOid ) ) { throw new LdapUnwillingToPerformException( ResultCodeEnum.UNWILLING_TO_PERFORM, I18n.err( I18n.ERR_367, oldOid ) ); } String newOid = newRdn.getValue(); checkOidIsUniqueForNormalizer( newOid ); if ( isSchemaEnabled( schemaName ) ) { // Inject the new OID Entry targetEntry = entry.clone(); targetEntry.put( MetaSchemaConstants.M_OID_AT, newOid ); // Inject the new Dn Dn newDn = targetEntry.getDn().getParent(); newDn = newDn.add( newRdn ); targetEntry.setDn( newDn ); Normalizer normalizer = factory.getNormalizer( schemaManager, targetEntry, schemaManager.getRegistries(), schemaName ); schemaManager.unregisterNormalizer( oldOid ); schemaManager.add( normalizer ); } }