Search in sources :

Example 6 with CustomScriptType

use of org.gluu.model.custom.script.CustomScriptType in project oxTrust by GluuFederation.

the class ManageOtherCustomScriptAction method modify.

public String modify() {
    if (this.initialized) {
        return OxTrustConstants.RESULT_SUCCESS;
    }
    CustomScriptType[] allowedCustomScriptTypes = getScriptType();
    this.customScriptsByTypes = new HashMap<CustomScriptType, List<CustomScript>>();
    for (CustomScriptType customScriptType : allowedCustomScriptTypes) {
        this.customScriptsByTypes.put(customScriptType, new ArrayList<CustomScript>());
    }
    try {
        List<CustomScript> customScripts = customScriptService.findCustomScripts(Arrays.asList(allowedCustomScriptTypes));
        for (CustomScript customScript : customScripts) {
            CustomScriptType customScriptType = customScript.getScriptType();
            List<CustomScript> customScriptsByType = this.customScriptsByTypes.get(customScriptType);
            CustomScript typedCustomScript = customScript;
            if (CustomScriptType.PERSON_AUTHENTICATION == customScriptType) {
                typedCustomScript = new AuthenticationCustomScript(customScript);
            }
            if (typedCustomScript.getConfigurationProperties() == null) {
                typedCustomScript.setConfigurationProperties(new ArrayList<SimpleExtendedCustomProperty>());
            }
            if (typedCustomScript.getModuleProperties() == null) {
                typedCustomScript.setModuleProperties(new ArrayList<SimpleCustomProperty>());
            }
            customScriptsByType.add(typedCustomScript);
        }
    } catch (Exception ex) {
        log.error("Failed to load custom scripts ", ex);
        facesMessages.add(FacesMessage.SEVERITY_ERROR, "Failed to load custom scripts");
        conversationService.endConversation();
        return OxTrustConstants.RESULT_FAILURE;
    }
    this.initialized = true;
    return OxTrustConstants.RESULT_SUCCESS;
}
Also used : CustomScript(org.gluu.model.custom.script.model.CustomScript) AuthenticationCustomScript(org.gluu.model.custom.script.model.auth.AuthenticationCustomScript) AuthenticationCustomScript(org.gluu.model.custom.script.model.auth.AuthenticationCustomScript) SimpleExtendedCustomProperty(org.gluu.model.SimpleExtendedCustomProperty) CustomScriptType(org.gluu.model.custom.script.CustomScriptType) ArrayList(java.util.ArrayList) List(java.util.List) SimpleCustomProperty(org.gluu.model.SimpleCustomProperty)

Example 7 with CustomScriptType

use of org.gluu.model.custom.script.CustomScriptType 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 8 with CustomScriptType

use of org.gluu.model.custom.script.CustomScriptType in project oxTrust by GluuFederation.

the class ManageOtherCustomScriptAction method save.

public String save() {
    try {
        List<CustomScript> oldCustomScripts = customScriptService.findCustomScripts(Arrays.asList(getScriptType()), "dn", "inum");
        List<String> updatedInums = new ArrayList<String>();
        for (Entry<CustomScriptType, List<CustomScript>> customScriptsByType : this.customScriptsByTypes.entrySet()) {
            List<CustomScript> customScripts = customScriptsByType.getValue();
            for (CustomScript customScript : customScripts) {
                String configId = customScript.getName();
                if (StringHelper.equalsIgnoreCase(configId, OxConstants.SCRIPT_TYPE_INTERNAL_RESERVED_NAME)) {
                    facesMessages.add(FacesMessage.SEVERITY_ERROR, "'%s' is reserved script name", configId);
                    return OxTrustConstants.RESULT_FAILURE;
                }
                boolean nameValidation = NAME_PATTERN.matcher(customScript.getName()).matches();
                if (!nameValidation) {
                    facesMessages.add(FacesMessage.SEVERITY_ERROR, "'%s' is invalid script name. Only alphabetic, numeric and underscore characters are allowed in Script Name", configId);
                    return OxTrustConstants.RESULT_FAILURE;
                }
                customScript.setRevision(customScript.getRevision() + 1);
                boolean update = true;
                String dn = customScript.getDn();
                String customScriptId = customScript.getInum();
                if (StringHelper.isEmpty(dn)) {
                    customScriptId = INumGenerator.generate(2);
                    dn = customScriptService.buildDn(customScriptId);
                    customScript.setDn(dn);
                    customScript.setInum(customScriptId);
                    update = false;
                }
                customScript.setDn(dn);
                customScript.setInum(customScriptId);
                if (ScriptLocationType.LDAP == customScript.getLocationType()) {
                    customScript.removeModuleProperty(CustomScript.LOCATION_PATH_MODEL_PROPERTY);
                }
                if ((customScript.getConfigurationProperties() != null) && (customScript.getConfigurationProperties().size() == 0)) {
                    customScript.setConfigurationProperties(null);
                }
                if ((customScript.getConfigurationProperties() != null) && (customScript.getModuleProperties().size() == 0)) {
                    customScript.setModuleProperties(null);
                }
                updatedInums.add(customScriptId);
                if (update) {
                    customScriptService.update(customScript);
                } else {
                    customScriptService.add(customScript);
                }
            }
        }
        // Remove removed scripts
        for (CustomScript oldCustomScript : oldCustomScripts) {
            if (!updatedInums.contains(oldCustomScript.getInum())) {
                customScriptService.remove(oldCustomScript);
            }
        }
    } catch (Exception ex) {
        log.error("Failed to update custom scripts", ex);
        facesMessages.add(FacesMessage.SEVERITY_ERROR, "Failed to update custom script configuration");
        return OxTrustConstants.RESULT_FAILURE;
    }
    facesMessages.add(FacesMessage.SEVERITY_INFO, "Custom script configuration updated successfully");
    return OxTrustConstants.RESULT_SUCCESS;
}
Also used : CustomScript(org.gluu.model.custom.script.model.CustomScript) AuthenticationCustomScript(org.gluu.model.custom.script.model.auth.AuthenticationCustomScript) CustomScriptType(org.gluu.model.custom.script.CustomScriptType) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 9 with CustomScriptType

use of org.gluu.model.custom.script.CustomScriptType in project oxTrust by GluuFederation.

the class GluuRadiusConfigWebResource method isValidAcrValue.

private final boolean isValidAcrValue(String acrValue) {
    List<CustomScriptType> script_types = new ArrayList<CustomScriptType>();
    script_types.add(CustomScriptType.RESOURCE_OWNER_PASSWORD_CREDENTIALS);
    List<CustomScript> allowed_scripts = customScriptService.findCustomScripts(script_types);
    for (CustomScript custom_script : allowed_scripts) {
        if (!custom_script.isEnabled())
            continue;
        if (StringUtils.equals(custom_script.getName(), acrValue))
            return true;
    }
    return false;
}
Also used : CustomScript(org.gluu.model.custom.script.model.CustomScript) CustomScriptType(org.gluu.model.custom.script.CustomScriptType) ArrayList(java.util.ArrayList)

Example 10 with CustomScriptType

use of org.gluu.model.custom.script.CustomScriptType in project oxTrust by GluuFederation.

the class ManageCustomScriptAction method save.

public String save() {
    try {
        List<CustomScript> oldCustomScripts = customScriptService.findCustomScripts(Arrays.asList(getScriptType()), "dn", "inum");
        List<String> updatedInums = new ArrayList<String>();
        for (Entry<CustomScriptType, List<CustomScript>> customScriptsByType : this.customScriptsByTypes.entrySet()) {
            List<CustomScript> customScripts = customScriptsByType.getValue();
            for (CustomScript customScript : customScripts) {
                String configId = customScript.getName();
                if (StringHelper.equalsIgnoreCase(configId, OxConstants.SCRIPT_TYPE_INTERNAL_RESERVED_NAME)) {
                    facesMessages.add(FacesMessage.SEVERITY_ERROR, "'%s' is reserved script name", configId);
                    return OxTrustConstants.RESULT_FAILURE;
                }
                boolean nameValidation = NAME_PATTERN.matcher(customScript.getName()).matches();
                if (!nameValidation) {
                    facesMessages.add(FacesMessage.SEVERITY_ERROR, "'%s' is invalid script name. Only alphabetic, numeric and underscore characters are allowed in Script Name", configId);
                    return OxTrustConstants.RESULT_FAILURE;
                }
                customScript.setRevision(customScript.getRevision() + 1);
                boolean update = true;
                String dn = customScript.getDn();
                String customScriptId = customScript.getInum();
                if (StringHelper.isEmpty(dn)) {
                    customScriptId = INumGenerator.generate(2);
                    dn = customScriptService.buildDn(customScriptId);
                    customScript.setDn(dn);
                    customScript.setInum(customScriptId);
                    update = false;
                }
                customScript.setDn(dn);
                customScript.setInum(customScriptId);
                if (ScriptLocationType.LDAP == customScript.getLocationType()) {
                    customScript.removeModuleProperty(CustomScript.LOCATION_PATH_MODEL_PROPERTY);
                }
                if ((customScript.getConfigurationProperties() != null) && (customScript.getConfigurationProperties().size() == 0)) {
                    customScript.setConfigurationProperties(null);
                }
                if ((customScript.getConfigurationProperties() != null) && (customScript.getModuleProperties().size() == 0)) {
                    customScript.setModuleProperties(null);
                }
                if (ScriptLocationType.FILE == customScript.getLocationType()) {
                    customScript.setScript(null);
                }
                updatedInums.add(customScriptId);
                if (update) {
                    customScriptService.update(customScript);
                } else {
                    customScriptService.add(customScript);
                }
            }
        }
        // Remove removed scripts
        for (CustomScript oldCustomScript : oldCustomScripts) {
            if (!updatedInums.contains(oldCustomScript.getInum())) {
                customScriptService.remove(oldCustomScript);
            }
        }
    } catch (Exception ex) {
        log.error("Failed to update custom scripts", ex);
        facesMessages.add(FacesMessage.SEVERITY_ERROR, "Failed to update custom script configuration");
        return OxTrustConstants.RESULT_FAILURE;
    }
    facesMessages.add(FacesMessage.SEVERITY_INFO, "Custom script configuration updated successfully");
    return OxTrustConstants.RESULT_SUCCESS;
}
Also used : CustomScript(org.gluu.model.custom.script.model.CustomScript) AuthenticationCustomScript(org.gluu.model.custom.script.model.auth.AuthenticationCustomScript) CustomScriptType(org.gluu.model.custom.script.CustomScriptType) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

CustomScriptType (org.gluu.model.custom.script.CustomScriptType)12 ArrayList (java.util.ArrayList)9 CustomScript (org.gluu.model.custom.script.model.CustomScript)8 List (java.util.List)5 AuthenticationCustomScript (org.gluu.model.custom.script.model.auth.AuthenticationCustomScript)5 SimpleCustomProperty (org.gluu.model.SimpleCustomProperty)2 SimpleExtendedCustomProperty (org.gluu.model.SimpleExtendedCustomProperty)2 CustomScriptConfiguration (org.gluu.model.custom.script.conf.CustomScriptConfiguration)2 BaseExternalType (org.gluu.model.custom.script.type.BaseExternalType)2 PersistenceEntryManager (org.gluu.persist.PersistenceEntryManager)2 ApplicationInitializedEvent (org.gluu.service.cdi.event.ApplicationInitializedEvent)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 HashMap (java.util.HashMap)1 Filter (org.gluu.search.filter.Filter)1 GluuConfiguration (org.oxauth.persistence.model.configuration.GluuConfiguration)1 PyLong (org.python.core.PyLong)1 PyObject (org.python.core.PyObject)1