Search in sources :

Example 26 with PersistenceEntryManager

use of org.gluu.persist.PersistenceEntryManager in project oxTrust by GluuFederation.

the class CacheRefreshTimer method loadSourceServerEntriesWithoutLimits.

private List<GluuSimplePerson> loadSourceServerEntriesWithoutLimits(CacheRefreshConfiguration cacheRefreshConfiguration, LdapServerConnection[] sourceServerConnections) throws SearchException {
    Filter customFilter = cacheRefreshService.createFilter(cacheRefreshConfiguration.getCustomLdapFilter());
    String[] keyAttributes = getCompoundKeyAttributes(cacheRefreshConfiguration);
    String[] keyAttributesWithoutValues = getCompoundKeyAttributesWithoutValues(cacheRefreshConfiguration);
    String[] keyObjectClasses = getCompoundKeyObjectClasses(cacheRefreshConfiguration);
    String[] sourceAttributes = getSourceAttributes(cacheRefreshConfiguration);
    String[] returnAttributes = ArrayHelper.arrayMerge(keyAttributesWithoutValues, sourceAttributes);
    Set<String> addedDns = new HashSet<String>();
    List<GluuSimplePerson> sourcePersons = new ArrayList<GluuSimplePerson>();
    for (LdapServerConnection sourceServerConnection : sourceServerConnections) {
        String sourceServerName = sourceServerConnection.getSourceServerName();
        PersistenceEntryManager sourcePersistenceEntryManager = sourceServerConnection.getPersistenceEntryManager();
        String[] baseDns = sourceServerConnection.getBaseDns();
        Filter filter = cacheRefreshService.createFilter(keyAttributes, keyObjectClasses, "", customFilter);
        if (log.isTraceEnabled()) {
            log.trace("Using next filter to load entris from source server: {}", filter);
        }
        for (String baseDn : baseDns) {
            List<GluuSimplePerson> currentSourcePersons = sourcePersistenceEntryManager.findEntries(baseDn, GluuSimplePerson.class, filter, SearchScope.SUB, returnAttributes, null, 0, 0, cacheRefreshConfiguration.getLdapSearchSizeLimit());
            // Add to result and ignore root entry if needed
            for (GluuSimplePerson currentSourcePerson : currentSourcePersons) {
                currentSourcePerson.setSourceServerName(sourceServerName);
                // if (!StringHelper.equalsIgnoreCase(baseDn,
                // currentSourcePerson.getDn())) {
                String currentSourcePersonDn = currentSourcePerson.getDn().toLowerCase();
                if (!addedDns.contains(currentSourcePersonDn)) {
                    sourcePersons.add(currentSourcePerson);
                    addedDns.add(currentSourcePersonDn);
                }
            // }
            }
        }
    }
    return sourcePersons;
}
Also used : GluuSimplePerson(org.gluu.oxtrust.ldap.cache.model.GluuSimplePerson) PersistenceEntryManager(org.gluu.persist.PersistenceEntryManager) Filter(org.gluu.search.filter.Filter) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 27 with PersistenceEntryManager

use of org.gluu.persist.PersistenceEntryManager in project oxTrust by GluuFederation.

the class AppInitializer method applicationInitialized.

/**
 * Initialize components and schedule DS connection time checker
 */
public void applicationInitialized(@Observes @Initialized(ApplicationScoped.class) Object init) {
    log.debug("Initializing application services");
    showBuildInfo();
    configurationFactory.create();
    PersistenceEntryManager localLdapEntryManager = persistenceEntryManagerInstance.get();
    initializeLdifArchiver(localLdapEntryManager);
    // Initialize template engine
    templateService.initTemplateEngine();
    // Initialize python interpreter
    pythonService.initPythonInterpreter(configurationFactory.getBaseConfiguration().getString("pythonModulesDir", null));
    // Initialize Shibboleth
    shibbolethInitializer.createShibbolethConfiguration();
    // Initialize script manager
    List<CustomScriptType> supportedCustomScriptTypes = Arrays.asList(CustomScriptType.CACHE_REFRESH, CustomScriptType.UPDATE_USER, CustomScriptType.USER_REGISTRATION, CustomScriptType.ID_GENERATOR, CustomScriptType.PERSISTENCE_EXTENSION);
    // Start timer
    initSchedulerService();
    // Schedule timer tasks
    metricService.initTimer();
    configurationFactory.initTimer();
    loggerService.initTimer();
    ldapStatusTimer.initTimer();
    metadataValidationTimer.initTimer();
    entityIDMonitoringService.initTimer();
    cacheRefreshTimer.initTimer();
    customScriptManager.initTimer(supportedCustomScriptTypes);
    cleanerTimer.initTimer();
    statusCheckerDaily.initTimer();
    statusCheckerTimer.initTimer();
    logFileSizeChecker.initTimer();
    updateChecker.initTimer();
    transcodingRulesUpdater.initTimer();
    // Notify other components/plugins about finish application initialization
    eventApplicationInitialized.select(ApplicationInitialized.Literal.APPLICATION).fire(new ApplicationInitializedEvent());
}
Also used : PersistenceEntryManager(org.gluu.persist.PersistenceEntryManager) ApplicationInitializedEvent(org.gluu.service.cdi.event.ApplicationInitializedEvent) CustomScriptType(org.gluu.model.custom.script.CustomScriptType)

Example 28 with PersistenceEntryManager

use of org.gluu.persist.PersistenceEntryManager in project oxCore by GluuFederation.

the class SchemaService method addObjectClass.

/**
 * Add new object class with specified attributes
 *
 * @param objectClass
 *            Object class name
 * @param attributeTypes
 *            Attribute types
 */
public void addObjectClass(String objectClass, String attributeTypes, String schemaAddObjectClassWithoutAttributeTypesDefinition, String schemaAddObjectClassWithAttributeTypesDefinition) {
    SchemaEntry schemaEntry = new SchemaEntry();
    schemaEntry.setDn(getDnForSchema());
    String objectClassDefinition;
    if (StringHelper.isEmpty(attributeTypes)) {
        objectClassDefinition = String.format(schemaAddObjectClassWithoutAttributeTypesDefinition, objectClass, objectClass);
    } else {
        objectClassDefinition = String.format(schemaAddObjectClassWithAttributeTypesDefinition, objectClass, objectClass, attributeTypes);
    }
    schemaEntry.addObjectClass(objectClassDefinition);
    log.debug("Adding new objectClass: {}", schemaEntry);
    PersistenceEntryManager ldapPersistenceEntryManager = getPersistenceEntryManager();
    ldapPersistenceEntryManager.merge(schemaEntry);
}
Also used : PersistenceEntryManager(org.gluu.persist.PersistenceEntryManager) SchemaEntry(org.gluu.model.SchemaEntry)

Example 29 with PersistenceEntryManager

use of org.gluu.persist.PersistenceEntryManager in project oxCore by GluuFederation.

the class SchemaService method addAttributeTypeToObjectClass.

/**
 * Add attribute type to object class
 *
 * @param objectClass
 *            Object class name
 * @param attributeType
 *            Attribute type name
 * @throws Exception
 */
public void addAttributeTypeToObjectClass(String objectClass, String attributeType) throws Exception {
    SchemaEntry schema = getSchema();
    String objectClassDefinition = getObjectClassDefinition(schema, objectClass);
    if (objectClassDefinition == null) {
        throw new InvalidSchemaUpdateException(String.format("Can't add attributeType %s to objectClass %s because objectClass doesn't exist", attributeType, objectClass));
    }
    String newObjectClassDefinition = null;
    String attributeTypesStartPattern = "MAY ( ";
    int index = objectClassDefinition.indexOf(attributeTypesStartPattern);
    if (index != -1) {
        int index2 = objectClassDefinition.indexOf(")", index);
        newObjectClassDefinition = objectClassDefinition.substring(0, index2) + "$ " + attributeType + " " + objectClassDefinition.substring(index2);
    } else {
        attributeTypesStartPattern = "MUST objectClass ";
        index = objectClassDefinition.indexOf(attributeTypesStartPattern);
        if (index != -1) {
            int index2 = index + attributeTypesStartPattern.length();
            newObjectClassDefinition = objectClassDefinition.substring(0, index2) + "MAY ( " + attributeType + " ) " + objectClassDefinition.substring(index2);
        }
    }
    log.debug("Current object class definition:" + objectClassDefinition);
    log.debug("New object class definition:" + newObjectClassDefinition);
    if (newObjectClassDefinition == null) {
        throw new InvalidSchemaUpdateException(String.format("Invalid objectClass definition format"));
    }
    // Remove OC definition
    removeObjectClassWithDefinition(objectClassDefinition);
    // Add updated OC definition
    SchemaEntry newSchemaEntry = new SchemaEntry();
    newSchemaEntry.setDn(getDnForSchema());
    newSchemaEntry.addObjectClass(newObjectClassDefinition);
    log.debug("Adding attributeType to objectClass: {}", newSchemaEntry);
    PersistenceEntryManager ldapPersistenceEntryManager = getPersistenceEntryManager();
    ldapPersistenceEntryManager.merge(newSchemaEntry);
}
Also used : PersistenceEntryManager(org.gluu.persist.PersistenceEntryManager) SchemaEntry(org.gluu.model.SchemaEntry) InvalidSchemaUpdateException(org.gluu.util.exception.InvalidSchemaUpdateException)

Example 30 with PersistenceEntryManager

use of org.gluu.persist.PersistenceEntryManager in project oxCore by GluuFederation.

the class ExternalPersistenceExtensionService method reloadExternal.

@Override
protected void reloadExternal() {
    for (Iterator<PersistenceEntryManager> it = persistenceEntryManagerInstance.iterator(); it.hasNext(); ) {
        PersistenceEntryManager persistenceEntryManager = it.next();
        executePersistenceExtensionAfterCreate(null, persistenceEntryManager);
    }
    for (Iterator<List<PersistenceEntryManager>> it = persistenceEntryManagerListInstance.iterator(); it.hasNext(); ) {
        List<PersistenceEntryManager> persistenceEntryManagerList = it.next();
        for (PersistenceEntryManager persistenceEntryManager : persistenceEntryManagerList) {
            executePersistenceExtensionAfterCreate(null, persistenceEntryManager);
        }
    }
}
Also used : PersistenceEntryManager(org.gluu.persist.PersistenceEntryManager) List(java.util.List)

Aggregations

PersistenceEntryManager (org.gluu.persist.PersistenceEntryManager)38 Properties (java.util.Properties)8 SchemaEntry (org.gluu.model.SchemaEntry)7 ArrayList (java.util.ArrayList)6 ApplicationScoped (javax.enterprise.context.ApplicationScoped)5 Produces (javax.enterprise.inject.Produces)5 Named (javax.inject.Named)5 GluuSimplePerson (org.gluu.oxtrust.ldap.cache.model.GluuSimplePerson)5 BasePersistenceException (org.gluu.persist.exception.BasePersistenceException)5 PersistenceEntryManagerFactory (org.gluu.persist.PersistenceEntryManagerFactory)4 Filter (org.gluu.search.filter.Filter)4 GluuLdapConfiguration (org.gluu.model.ldap.GluuLdapConfiguration)3 GluuInumMap (org.gluu.oxtrust.ldap.cache.model.GluuInumMap)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 LinkedHashSet (java.util.LinkedHashSet)2 List (java.util.List)2 CustomScriptType (org.gluu.model.custom.script.CustomScriptType)2 CacheCompoundKey (org.gluu.oxtrust.ldap.cache.model.CacheCompoundKey)2 ApplicationInitializedEvent (org.gluu.service.cdi.event.ApplicationInitializedEvent)2