Refine search
/** * loads the default schema that is bundled in the shared-ldap-schema.jar * * @throws LdapException in case of problems while loading the schema */ public void loadSchema() throws LdapException { try { JarLdifSchemaLoader jarSchemaLoader = new JarLdifSchemaLoader(); schemaManager = new DefaultSchemaManager( jarSchemaLoader ); schemaManager.loadAllEnabled(); if( ! schemaManager.getErrors().isEmpty() ) { String msg = "there are errors while loading the schema"; LOG.error( msg + " {}", schemaManager.getErrors() ); throw new LdapException( msg ); } } catch( LdapException le ) { throw le; } catch( Exception e ) { LOG.error( "failed to load the schema", e ); throw new LdapException( e ); } }
private void setupUserIndices() throws Exception { if ( userIndices != null && userIndices.size() > 0 ) { Map<String, AvlIndex<? extends Object, E>> tmp = new HashMap<String, AvlIndex<? extends Object, E>>(); for ( AvlIndex<? extends Object, E> index : userIndices.values() ) { String oid = schemaManager.getAttributeTypeRegistry().getOidByName( index.getAttributeId() ); AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( oid ); // Check that the attributeType has an EQUALITY matchingRule MatchingRule mr = attributeType.getEquality(); if ( mr != null ) { index.initialize( schemaManager.lookupAttributeTypeRegistry( oid ) ); tmp.put( oid, index ); } else { LOG.error( I18n.err( I18n.ERR_4, attributeType.getName() ) ); } } userIndices = tmp; } else { userIndices = new HashMap<String, AvlIndex<? extends Object, E>>(); } }
/** * {@inheritDoc} */ public String normalize( String value ) throws LdapException { DN dn = null; dn = new DN( value ); dn.normalize( schemaManager.getNormalizerMapping() ); return dn.getNormName(); }
/** * {@inheritDoc} * TODO why this and initRegistries on Store interface ??? */ public void init( SchemaManager schemaManager ) throws Exception { this.schemaManager = schemaManager; OBJECT_CLASS_AT = schemaManager.lookupAttributeTypeRegistry( SchemaConstants.OBJECT_CLASS_AT ); ALIASED_OBJECT_NAME_AT = schemaManager.lookupAttributeTypeRegistry( SchemaConstants.ALIASED_OBJECT_NAME_AT ); // Create the master table (the table containing all the entries) master = new AvlMasterTable<ServerEntry>( name, new LongComparator(), null, false ); suffixDn.normalize( schemaManager.getNormalizerMapping() ); // ------------------------------------------------------------------- // Initializes the user and system indices // ------------------------------------------------------------------- setupSystemIndices(); setupUserIndices(); // We are done ! initialized = true; }
/** * initialize the schema manager and add the schema partition to diectory service * * @throws Exception if the schema LDIF files are not found on the classpath */ private void initSchemaPartition() throws Exception { SchemaPartition schemaPartition = service.getSchemaService().getSchemaPartition(); // Init the LdifPartition LdifPartition ldifPartition = new LdifPartition(); String workingDirectory = service.getWorkingDirectory().getPath(); ldifPartition.setWorkingDirectory(workingDirectory + "/schema"); // Extract the schema on disk (a brand new one) and load the registries File schemaRepository = new File(workingDirectory, "schema"); SchemaLdifExtractor extractor = new DefaultSchemaLdifExtractor(new File(workingDirectory)); extractor.extractOrCopy(true); schemaPartition.setWrappedPartition(ldifPartition); SchemaLoader loader = new LdifSchemaLoader(schemaRepository); SchemaManager schemaManager = new DefaultSchemaManager(loader); service.setSchemaManager(schemaManager); // We have to load the schema now, otherwise we won't be able // to initialize the Partitions, as we won't be able to parse // and normalize their suffix DN schemaManager.loadAllEnabled(); schemaPartition.setSchemaManager(schemaManager); List<Throwable> errors = schemaManager.getErrors(); if (errors.size() != 0) { throw new Exception("Schema load failed : " + errors); } }
normalizedAliasTargetDn = new DN( aliasTarget ); normalizedAliasTargetDn.normalize( schemaManager.getNormalizerMapping() ); if ( aliasDn.isChildOf( normalizedAliasTargetDn ) ) if ( aliasDn.equals( normalizedAliasTargetDn ) ) throw new Exception( I18n.err( I18n.ERR_223 ) ); throw new Exception( I18n.err( I18n.ERR_224, aliasTarget, aliasDn ) ); throw new Exception( I18n.err( I18n.ERR_225, suffixDn.getName() ) );
ServerEntry targetEntry = ( ServerEntry ) entry.clone(); ModificationOperation modOp = mod.getOperation(); String id = mod.getAttribute().getId(); AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( id ); targetEntry.put( mod.getAttribute() ); break; EntryAttribute toBeRemoved = mod.getAttribute(); if ( toBeRemoved.size() == 0 ) targetEntry.removeAttributes( id ); existing.remove( value ); throw new IllegalStateException( I18n.err( I18n.ERR_464, modOp ) );
throw new Exception( I18n.err( I18n.ERR_215 ) ); String modsOid = schemaManager.getAttributeTypeRegistry().getOidByName( mods.getId() ); AttributeType type = schemaManager.lookupAttributeTypeRegistry( modsOid ); entry.add( type, value ); addAliasIndices( id, new DN( ndnStr ), mods.getString() );
throw new Exception( I18n.err( I18n.ERR_215 ) ); String modsOid = schemaManager.getAttributeTypeRegistry().getOidByName( mods.getId() ); if ( mods.size() > 0 ) entry.put( mods ); entry.remove( mods ); if ( modsOid.equals( aliasAttributeOid ) && mods.size() > 0 ) addAliasIndices( id, new DN( ndnStr ), mods.getString() );
throw new Exception( I18n.err( I18n.ERR_215 ) ); String modsOid = schemaManager.getAttributeTypeRegistry().getOidByName( mods.getId() ); AttributeType attrType = schemaManager.lookupAttributeTypeRegistry( modsOid ); if ( mods.size() == 0 ) entry.removeAttributes( attrType ); EntryAttribute entryAttr = entry.get( attrType ); entryAttr.remove( ( String ) value.get() ); if ( entryAttr.size() == 0 ) entry.removeAttributes( entryAttr.getId() );
String attributeId = modification.getAttribute().getId(); String id = stripOptions( attributeId ); modification.getAttribute().setId( id ); Set<String> options = getOptions( attributeId ); if ( ! schemaManager.getAttributeTypeRegistry().contains( id ) && modification.getAttribute().size() == 0 && modification.getOperation() == ModificationOperation.REPLACE_ATTRIBUTE ) String message = I18n.err( I18n.ERR_467, id ); throw new LdapInvalidAttributeTypeException( message ); AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( id ); modificationsList.add( toServerModification( modification, attributeType ) );
if ( !updn.isNormalized() ) updn.normalize( schemaManager.getNormalizerMapping() ); ndnIdx.add( updn.getNormName(), id ); String rdn = oldUpdn.get( oldUpdn.size() - 1 ); DN rdnDN = new DN( rdn ); rdnDN.normalize( schemaManager.getNormalizerMapping() ); childUpdn.add( rdnDN.getRdn() ); entry.setDn( childUpdn ); master.put( childId, entry );
/** * {@inheritDoc} */ public Index<? extends Object, E, Long> getUserIndex( String id ) throws IndexNotFoundException { try { id = schemaManager.getAttributeTypeRegistry().getOidByName( id ); } catch ( LdapException e ) { LOG.error( I18n.err( I18n.ERR_1, id ), e.getLocalizedMessage() ); throw new IndexNotFoundException( I18n.err( I18n.ERR_1, id ), id, e ); } if ( userIndices.containsKey( id ) ) { return userIndices.get( id ); } throw new IndexNotFoundException( I18n.err( I18n.ERR_3, id, name ) ); }
public void rename( DN dn, RDN newRdn, boolean deleteOldRdn ) throws Exception Long id = getEntryId( dn.getNormName() ); ServerEntry entry = lookup( id ); DN updn = entry.getDn(); AttributeType newRdnAttrType = schemaManager.lookupAttributeTypeRegistry( newNormType ); entry.add( newRdnAttrType, newAtav.getUpValue() ); RDN oldRdn = updn.getRdn(); for ( AVA oldAtav : oldRdn ) AttributeType oldRdnAttrType = schemaManager.lookupAttributeTypeRegistry( oldNormType ); entry.remove( oldRdnAttrType, oldNormValue ); DN newUpdn = ( DN ) updn.clone(); // copy da old updn newUpdn.remove( newUpdn.size() - 1 ); // remove old upRdn newUpdn.add( newRdn.getName() ); // add da new upRdn newUpdn.normalize( schemaManager.getNormalizerMapping() );
DN crowdDN = new DN(m_Suffix); crowdDN.normalize( m_SchemaManager.getRegistries().getAttributeTypeRegistry() .getNormalizerMapping() ); RDN rdn = crowdDN.getRdn(); crowdDN ); dcEntry.put(SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, SchemaConstants.DOMAIN_OC); dcEntry.put(SchemaConstants.DC_AT, rdn.getUpValue().toString()); dcEntry.put("description", "Crowd Domain"); m_CrowdEntry = dcEntry;
AttributeType attributeType = directoryService.getSchemaManager().lookupAttributeTypeRegistry( oid ); throw new LdapException( I18n.err( I18n.ERR_309, oid ) ); throw new LdapException( I18n.err( I18n.ERR_309, oid ) );
return true; } else { int dnSize = dn.size(); m_EntryCache.put(dn.getName(), m_CrowdEntry); return true; } else { m_EntryCache.put(dn.getName(), m_CrowdGroupsEntry); return true; } else if (isCrowdUsers(dn)) { DN prefix = dn.getPrefix(2); try { prefix.normalize(m_SchemaManager.getNormalizerMapping()); } catch (Exception ex) { log.error("hasEntry()", ex); } else { log.debug("Prefix is neither users nor groups"); log.debug("Crowd Users = " + m_CrowdUsersEntry.getDn()); log.debug("Crowd Groups = " + m_CrowdGroupsEntry.getDn().toString()); return false;
dn = (DN)entry.getDn().clone(); if ( !dn.isNormalized( ) ) dn.normalize( schemaManager.getNormalizerMapping() ); AttributeType attributeType = attribute.getAttributeType(); attributeType = schemaManager.lookupAttributeTypeRegistry( attribute.getId() ); LOG.warn( "The attribute '" + attribute.getId() + "' cannot be stored" );
public DN getDn( Object obj ) throws LdapInvalidDnException { DN dn = null; if ( obj instanceof DN ) { dn = (DN)obj; dn = ( dn.isNormalized() ? dn : DN.normalize( dn, schemaManager.getNormalizerMapping() ) ); } else if ( obj instanceof String ) { dn = new DN( ( String ) obj ); dn.normalize( schemaManager.getNormalizerMapping() ); } else { throw new IllegalStateException( I18n.err( I18n.ERR_04218, (obj == null ? null : obj.getClass() ) ) ); } return dn; }
private final void injectNames( List<String> names, ServerEntry entry, SchemaManager schemaManager ) throws LdapException { if ( ( names == null ) || ( names.size() == 0 ) ) { return; } EntryAttribute attr = new DefaultServerAttribute( schemaManager.lookupAttributeTypeRegistry( MetaSchemaConstants.M_NAME_AT ) ); for ( String name:names ) { attr.add( name ); } entry.put( attr ); }