/** * Returns the attributeType from an Attribute ID. * * @param upId The ID we are looking for * @return The found attributeType * @throws LdapException If the lookup failed */ protected AttributeType getAttributeType( String upId ) throws LdapException { if ( Strings.isEmpty( Strings.trim( upId ) ) ) { String message = I18n.err( I18n.ERR_13204_NULL_ATTRIBUTE_ID ); LOG.error( message ); throw new IllegalArgumentException( message ); } return schemaManager.lookupAttributeTypeRegistry( upId ); }
private void injectNames( List<String> names, Entry entry, SchemaManager schemaManager ) throws LdapException { if ( ( names == null ) || names.isEmpty() ) { return; } Attribute attr; if ( schemaManager != null ) { attr = new DefaultAttribute( schemaManager.getAttributeType( MetaSchemaConstants.M_NAME_AT ) ); } else { attr = new DefaultAttribute( MetaSchemaConstants.M_NAME_AT ); } for ( String name : names ) { attr.add( name ); } entry.put( attr ); }
/** * Generate the comparators attribute from the registry */ private static Attribute generateComparators( SchemaManager schemaManager ) throws LdapException { Attribute attr = new DefaultAttribute( schemaManager.lookupAttributeTypeRegistry( SchemaConstants.COMPARATORS_AT ) ); for ( LdapComparator<?> comparator : schemaManager.getComparatorRegistry() ) { attr.add( SchemaUtils.render( comparator ) ); } return attr; }
/** * Enabling a schema consist on switching all of its schema element to enable. * We have to do it on a temporary registries. */ private boolean enableSchema( String schemaName ) throws LdapException { Schema schema = schemaManager.getLoadedSchema( schemaName ); if ( schema == null ) { // We have to load the schema before enabling it. schemaManager.loadDisabled( schemaName ); } return schemaManager.enable( schemaName ); }
private static Attribute generateSyntaxes( SchemaManager schemaManager ) throws LdapException { Attribute attr = new DefaultAttribute( schemaManager.getAttributeType( SchemaConstants.LDAP_SYNTAXES_AT ) ); for ( LdapSyntax syntax : schemaManager.getLdapSyntaxRegistry() ) { attr.add( SchemaObjectRenderer.SUBSCHEMA_SUBENTRY_RENDERER.render( syntax ) ); } return attr; }
private static Attribute generateObjectClasses( SchemaManager schemaManager ) throws LdapException { Attribute attr = new DefaultAttribute( schemaManager.getAttributeType( SchemaConstants.OBJECT_CLASSES_AT ) ); for ( ObjectClass objectClass : schemaManager.getObjectClassRegistry() ) { attr.add( SchemaObjectRenderer.SUBSCHEMA_SUBENTRY_RENDERER.render( objectClass ) ); } return attr; }
public void add( Entry entry ) throws LdapException Dn dn = entry.getDn(); Dn parentDn = dn.getParent(); LdapComparator<?> comparator = factory.getLdapComparator( schemaManager, entry, schemaManager.getRegistries(), schemaName ); Schema schema = schemaManager.getLoadedSchema( schemaName ); if ( schemaManager.add( comparator ) ) LOG.debug( "Added {} into the enabled schema {}", dn.getName(), schemaName ); String msg = I18n.err( I18n.ERR_350, entry.getDn().getName(), Strings.listToString( schemaManager.getErrors() ) ); LOG.info( msg ); throw new LdapUnwillingToPerformException( ResultCodeEnum.UNWILLING_TO_PERFORM, msg );
public Entry add( String upId, Value... values ) throws LdapException if ( Strings.isEmpty( upId ) ) String message = I18n.err( I18n.ERR_13204_NULL_ATTRIBUTE_ID ); LOG.error( message ); throw new IllegalArgumentException( message ); add( upId, schemaManager.lookupAttributeTypeRegistry( upId ), values ); attribute.add( values ); attribute.setUpId( upId );
/** * {@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 ); } }
public void delete( Entry entry, boolean cascade ) throws LdapException Dn dn = entry.getDn(); Dn parentDn = dn.getParent(); String schemaName = getSchemaName( entry.getDn() ); Schema schema = schemaManager.getLoadedSchema( schemaName ); dn.getName(), schemaName ); if ( schemaManager.delete( objectClass ) ) String msg = I18n.err( I18n.ERR_374, entry.getDn().getName(), Strings.listToString( schemaManager.getErrors() ) ); LOG.info( msg ); throw new LdapUnwillingToPerformException( ResultCodeEnum.UNWILLING_TO_PERFORM, msg );
/** * Creates a new instance of DefaultModification. * * @param schemaManager The schema manager * @param modification The modification */ public DefaultModification( SchemaManager schemaManager, Modification modification ) { operation = modification.getOperation(); Attribute modAttribute = modification.getAttribute(); try { AttributeType at = modAttribute.getAttributeType(); if ( at == null ) { at = schemaManager.lookupAttributeTypeRegistry( modAttribute.getId() ); } attribute = new DefaultAttribute( at, modAttribute ); } catch ( LdapException ne ) { // The attributeType is incorrect. Log, but do nothing otherwise. LOG.error( I18n.err( I18n.ERR_13230_INCORRECT_ATTRIBUTE, modAttribute.getId() ) ); } }
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 ) ); } } }
/** * {@inheritDoc} */ @Override public boolean contains( String upId, byte[]... values ) { if ( Strings.isEmpty( upId ) ) { return false; } String id = getId( upId ); if ( schemaManager != null ) { try { return contains( schemaManager.lookupAttributeTypeRegistry( id ), values ); } catch ( LdapException le ) { return false; } } Attribute attribute = attributes.get( id ); if ( attribute == null ) { return false; } return attribute.contains( values ); }
/** * Creates and initializes a new instance of Schema synchronizer * * @param schemaManager The server schemaManager * @throws Exception If something went wrong */ public SchemaSynchronizer( SchemaManager schemaManager ) throws Exception { this.schemaManager = schemaManager; disabledAT = schemaManager.lookupAttributeTypeRegistry( MetaSchemaConstants.M_DISABLED_AT ); factory = new SchemaEntityFactory(); cnAT = schemaManager.lookupAttributeTypeRegistry( SchemaConstants.CN_AT ); dependenciesAT = schemaManager.lookupAttributeTypeRegistry( MetaSchemaConstants.M_DEPENDENCIES_AT ); ouSchemaDn = new Dn( schemaManager, SchemaConstants.OU_SCHEMA ); }
/** * {@inheritDoc} */ @Override public void registerSupportedSaslMechanisms( Set<String> supportedSaslMechanisms ) throws LdapException { Attribute supportedSaslMechanismsAt; supportedSaslMechanismsAt = new DefaultAttribute( schemaManager.lookupAttributeTypeRegistry( SchemaConstants.SUPPORTED_SASL_MECHANISMS_AT ) ); for ( String saslMechanism : supportedSaslMechanisms ) { supportedSaslMechanismsAt.add( saslMechanism ); } rootDse.add( supportedSaslMechanismsAt ); }
/** * {@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 ); } }
public SchemaPartition( SchemaManager schemaManager ) { try { schemaDN = new Dn( schemaManager, SchemaConstants.OU_SCHEMA ); } catch ( LdapInvalidDnException lide ) { // Nothing to do : this is a valid DN anyways } id = SCHEMA_ID; suffixDn = schemaDN; this.schemaManager = schemaManager; objectClassAT = schemaManager.getAttributeType( SchemaConstants.OBJECT_CLASS_AT_OID ); }
tmp.loadAllEnabled(); if ( !tmp.getErrors().isEmpty() && loader.isStrict() ) String msg = I18n.err( I18n.ERR_04115_ERROR_LOADING_SCHEMA ); LOG.error( I18n.err( I18n.ERR_05114_ERROR_MESSAGE, msg, Strings.listToString( tmp.getErrors() ) ) ); LOG.error( I18n.err( I18n.ERR_04116_FAIL_LOAD_SCHEMA ), e ); throw new LdapException( e );
private static void enabledPosixSchema( DirectoryService service ) throws LdapException { service.getSchemaManager().getLoadedSchema( "nis" ).enable(); service.getAdminSession().modify( new Dn( "cn=nis,ou=schema" ), new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, "m-disabled", "FALSE" ) ); }
schemaManager.loadAllEnabled(); ComparatorRegistry comparatorRegistry = schemaManager.getComparatorRegistry(); directoryService.setSchemaPartition( schemaPartition ); List<Throwable> errors = schemaManager.getErrors();