Search in sources :

Example 1 with SimpleExtendedCustomProperty

use of org.gluu.model.SimpleExtendedCustomProperty in project oxTrust by GluuFederation.

the class ManageCustomScriptAction 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 2 with SimpleExtendedCustomProperty

use of org.gluu.model.SimpleExtendedCustomProperty in project oxTrust by GluuFederation.

the class ManageCustomScriptAction method addCustomScript.

public void addCustomScript(CustomScriptType scriptType) {
    List<CustomScript> customScriptsByType = this.customScriptsByTypes.get(scriptType);
    CustomScript customScript;
    if (CustomScriptType.PERSON_AUTHENTICATION == scriptType) {
        AuthenticationCustomScript authenticationCustomScript = new AuthenticationCustomScript();
        authenticationCustomScript.setModuleProperties(new ArrayList<SimpleCustomProperty>());
        authenticationCustomScript.setUsageType(AuthenticationScriptUsageType.INTERACTIVE);
        customScript = authenticationCustomScript;
    } else {
        customScript = new CustomScript();
        customScript.setModuleProperties(new ArrayList<SimpleCustomProperty>());
    }
    customScript.setLocationType(ScriptLocationType.LDAP);
    customScript.setScriptType(scriptType);
    customScript.setProgrammingLanguage(ProgrammingLanguage.PYTHON);
    customScript.setConfigurationProperties(new ArrayList<SimpleExtendedCustomProperty>());
    customScriptsByType.add(customScript);
}
Also used : SimpleExtendedCustomProperty(org.gluu.model.SimpleExtendedCustomProperty) 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) SimpleCustomProperty(org.gluu.model.SimpleCustomProperty)

Example 3 with SimpleExtendedCustomProperty

use of org.gluu.model.SimpleExtendedCustomProperty 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 4 with SimpleExtendedCustomProperty

use of org.gluu.model.SimpleExtendedCustomProperty in project oxTrust by GluuFederation.

the class ManageOtherCustomScriptAction method addCustomScript.

public void addCustomScript(CustomScriptType scriptType) {
    List<CustomScript> customScriptsByType = this.customScriptsByTypes.get(scriptType);
    CustomScript customScript;
    if (CustomScriptType.PERSON_AUTHENTICATION == scriptType) {
        AuthenticationCustomScript authenticationCustomScript = new AuthenticationCustomScript();
        authenticationCustomScript.setModuleProperties(new ArrayList<SimpleCustomProperty>());
        authenticationCustomScript.setUsageType(AuthenticationScriptUsageType.INTERACTIVE);
        customScript = authenticationCustomScript;
    } else {
        customScript = new CustomScript();
        customScript.setModuleProperties(new ArrayList<SimpleCustomProperty>());
    }
    customScript.setLocationType(ScriptLocationType.LDAP);
    customScript.setScriptType(scriptType);
    customScript.setProgrammingLanguage(ProgrammingLanguage.PYTHON);
    customScript.setConfigurationProperties(new ArrayList<SimpleExtendedCustomProperty>());
    customScriptsByType.add(customScript);
}
Also used : SimpleExtendedCustomProperty(org.gluu.model.SimpleExtendedCustomProperty) 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) SimpleCustomProperty(org.gluu.model.SimpleCustomProperty)

Example 5 with SimpleExtendedCustomProperty

use of org.gluu.model.SimpleExtendedCustomProperty in project oxCore by GluuFederation.

the class CustomScriptManager method reloadCustomScriptConfigurations.

private ReloadResult reloadCustomScriptConfigurations(Map<String, CustomScriptConfiguration> customScriptConfigurations, List<CustomScript> newCustomScripts) {
    Map<String, CustomScriptConfiguration> newCustomScriptConfigurations;
    boolean modified = false;
    if (customScriptConfigurations == null) {
        newCustomScriptConfigurations = new HashMap<String, CustomScriptConfiguration>();
        modified = true;
    } else {
        // Clone old map to avoid reload not changed scripts because it's time and CPU
        // consuming process
        newCustomScriptConfigurations = new HashMap<String, CustomScriptConfiguration>(customScriptConfigurations);
    }
    List<String> newSupportedCustomScriptInums = new ArrayList<String>();
    for (CustomScript newCustomScript : newCustomScripts) {
        if (!newCustomScript.isEnabled()) {
            continue;
        }
        if (ScriptLocationType.FILE == newCustomScript.getLocationType()) {
            // Replace script revision with file modification time. This should allow to
            // reload script automatically after changing location_type
            long fileModifiactionTime = getFileModificationTime(newCustomScript.getLocationPath());
            newCustomScript.setRevision(fileModifiactionTime);
        }
        String newSupportedCustomScriptInum = StringHelper.toLowerCase(newCustomScript.getInum());
        newSupportedCustomScriptInums.add(newSupportedCustomScriptInum);
        CustomScriptConfiguration prevCustomScriptConfiguration = newCustomScriptConfigurations.get(newSupportedCustomScriptInum);
        if (prevCustomScriptConfiguration == null || prevCustomScriptConfiguration.getCustomScript().getRevision() != newCustomScript.getRevision()) {
            // Destroy old version properly before creating new one
            if (prevCustomScriptConfiguration != null) {
                destroyCustomScript(prevCustomScriptConfiguration);
            }
            // Load script entry with all attributes
            CustomScript loadedCustomScript = customScriptService.getCustomScriptByDn(newCustomScript.getScriptType().getCustomScriptModel(), newCustomScript.getDn());
            // Prepare configuration attributes
            Map<String, SimpleCustomProperty> newConfigurationAttributes = new HashMap<String, SimpleCustomProperty>();
            List<SimpleExtendedCustomProperty> simpleCustomProperties = loadedCustomScript.getConfigurationProperties();
            if (simpleCustomProperties == null) {
                simpleCustomProperties = new ArrayList<SimpleExtendedCustomProperty>(0);
            }
            for (SimpleCustomProperty simpleCustomProperty : simpleCustomProperties) {
                newConfigurationAttributes.put(simpleCustomProperty.getValue1(), simpleCustomProperty);
            }
            if (ScriptLocationType.FILE == loadedCustomScript.getLocationType()) {
                // Replace script revision with file modification time. This should allow to
                // reload script automatically after changing location_type
                long fileModifiactionTime = getFileModificationTime(loadedCustomScript.getLocationPath());
                loadedCustomScript.setRevision(fileModifiactionTime);
                if (fileModifiactionTime != 0) {
                    String scriptFromFile = loadFromFile(loadedCustomScript.getLocationPath());
                    if (StringHelper.isNotEmpty(scriptFromFile)) {
                        loadedCustomScript.setScript(scriptFromFile);
                    }
                }
            }
            // Automatic package update '.xdi' --> '.org'
            // TODO: Remove in CE 5.0
            String scriptCode = loadedCustomScript.getScript();
            if (scriptCode != null) {
                scriptCode = scriptCode.replaceAll(".xdi", ".gluu");
                loadedCustomScript.setScript(scriptCode);
            }
            // Load script
            BaseExternalType newCustomScriptExternalType = createExternalType(loadedCustomScript, newConfigurationAttributes);
            CustomScriptConfiguration newCustomScriptConfiguration = new CustomScriptConfiguration(loadedCustomScript, newCustomScriptExternalType, newConfigurationAttributes);
            // Store configuration and script
            newCustomScriptConfigurations.put(newSupportedCustomScriptInum, newCustomScriptConfiguration);
            modified = true;
        }
    }
    // Remove old external scripts configurations
    for (Iterator<Entry<String, CustomScriptConfiguration>> it = newCustomScriptConfigurations.entrySet().iterator(); it.hasNext(); ) {
        Entry<String, CustomScriptConfiguration> externalAuthenticatorConfigurationEntry = it.next();
        String prevSupportedCustomScriptInum = externalAuthenticatorConfigurationEntry.getKey();
        if (!newSupportedCustomScriptInums.contains(prevSupportedCustomScriptInum)) {
            // Destroy old authentication method
            destroyCustomScript(externalAuthenticatorConfigurationEntry.getValue());
            it.remove();
            modified = true;
        }
    }
    return new ReloadResult(newCustomScriptConfigurations, modified);
}
Also used : CustomScript(org.gluu.model.custom.script.model.CustomScript) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SimpleExtendedCustomProperty(org.gluu.model.SimpleExtendedCustomProperty) Entry(java.util.Map.Entry) BaseExternalType(org.gluu.model.custom.script.type.BaseExternalType) SimpleCustomProperty(org.gluu.model.SimpleCustomProperty) CustomScriptConfiguration(org.gluu.model.custom.script.conf.CustomScriptConfiguration)

Aggregations

SimpleCustomProperty (org.gluu.model.SimpleCustomProperty)5 SimpleExtendedCustomProperty (org.gluu.model.SimpleExtendedCustomProperty)5 CustomScript (org.gluu.model.custom.script.model.CustomScript)5 AuthenticationCustomScript (org.gluu.model.custom.script.model.auth.AuthenticationCustomScript)4 ArrayList (java.util.ArrayList)3 List (java.util.List)2 CustomScriptType (org.gluu.model.custom.script.CustomScriptType)2 HashMap (java.util.HashMap)1 Entry (java.util.Map.Entry)1 CustomScriptConfiguration (org.gluu.model.custom.script.conf.CustomScriptConfiguration)1 BaseExternalType (org.gluu.model.custom.script.type.BaseExternalType)1