Search in sources :

Example 1 with CustomScriptType

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

the class CustomScriptManager method createExternalTypeFromStringWithPythonException.

public BaseExternalType createExternalTypeFromStringWithPythonException(CustomScript customScript, Map<String, SimpleCustomProperty> configurationAttributes) throws Exception {
    String script = customScript.getScript();
    String scriptName = StringHelper.toLowerCase(customScript.getName()) + ".py";
    if (script == null) {
        return null;
    }
    CustomScriptType customScriptType = customScript.getScriptType();
    BaseExternalType externalType = null;
    InputStream bis = null;
    try {
        bis = new ByteArrayInputStream(script.getBytes("UTF-8"));
        externalType = pythonService.loadPythonScript(bis, scriptName, customScriptType.getPythonClass(), customScriptType.getCustomScriptType(), new PyObject[] { new PyLong(System.currentTimeMillis()) });
    } catch (UnsupportedEncodingException e) {
        log.error(String.format("%s. Script inum: %s", e.getMessage(), customScript.getInum()), e);
    } finally {
        IOUtils.closeQuietly(bis);
    }
    if (externalType == null) {
        return null;
    }
    boolean initialized = false;
    try {
        if (externalType.getApiVersion() > 10) {
            initialized = externalType.init(customScript, configurationAttributes);
        } else {
            initialized = externalType.init(configurationAttributes);
            log.warn(" Update the script's init method to init(self, customScript, configurationAttributes)", customScript.getName());
        }
    } catch (Exception ex) {
        log.error("Failed to initialize custom script: '{}'", ex, customScript.getName());
    }
    if (initialized) {
        return externalType;
    }
    return null;
}
Also used : PyLong(org.python.core.PyLong) ByteArrayInputStream(java.io.ByteArrayInputStream) CustomScriptType(org.gluu.model.custom.script.CustomScriptType) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) BaseExternalType(org.gluu.model.custom.script.type.BaseExternalType) UnsupportedEncodingException(java.io.UnsupportedEncodingException) PyObject(org.python.core.PyObject) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 2 with CustomScriptType

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

the class CustomScriptManager method groupCustomScriptConfigurationsByScriptType.

private Map<CustomScriptType, List<CustomScriptConfiguration>> groupCustomScriptConfigurationsByScriptType(Map<String, CustomScriptConfiguration> customScriptConfigurations) {
    Map<CustomScriptType, List<CustomScriptConfiguration>> newCustomScriptConfigurationsByScriptType = new HashMap<CustomScriptType, List<CustomScriptConfiguration>>();
    for (CustomScriptType customScriptType : this.supportedCustomScriptTypes) {
        List<CustomScriptConfiguration> customConfigurationsByScriptType = new ArrayList<CustomScriptConfiguration>();
        newCustomScriptConfigurationsByScriptType.put(customScriptType, customConfigurationsByScriptType);
    }
    for (CustomScriptConfiguration customScriptConfiguration : customScriptConfigurations.values()) {
        CustomScriptType customScriptType = customScriptConfiguration.getCustomScript().getScriptType();
        List<CustomScriptConfiguration> customConfigurationsByScriptType = newCustomScriptConfigurationsByScriptType.get(customScriptType);
        if (customConfigurationsByScriptType != null) {
            customConfigurationsByScriptType.add(customScriptConfiguration);
        }
    }
    return newCustomScriptConfigurationsByScriptType;
}
Also used : HashMap(java.util.HashMap) CustomScriptType(org.gluu.model.custom.script.CustomScriptType) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) CustomScriptConfiguration(org.gluu.model.custom.script.conf.CustomScriptConfiguration)

Example 3 with CustomScriptType

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

the class AbstractCustomScriptService method findCustomScripts.

public List<CustomScript> findCustomScripts(List<CustomScriptType> customScriptTypes, String... returnAttributes) {
    String baseDn = baseDn();
    if ((customScriptTypes == null) || (customScriptTypes.size() == 0)) {
        return findAllCustomScripts(returnAttributes);
    }
    List<Filter> customScriptTypeFilters = new ArrayList<Filter>();
    for (CustomScriptType customScriptType : customScriptTypes) {
        Filter customScriptTypeFilter = Filter.createEqualityFilter("oxScriptType", customScriptType.getValue());
        customScriptTypeFilters.add(customScriptTypeFilter);
    }
    Filter filter = Filter.createORFilter(customScriptTypeFilters);
    List<CustomScript> result = persistenceEntryManager.findEntries(baseDn, CustomScript.class, filter, returnAttributes);
    return result;
}
Also used : CustomScript(org.gluu.model.custom.script.model.CustomScript) Filter(org.gluu.search.filter.Filter) CustomScriptType(org.gluu.model.custom.script.CustomScriptType) ArrayList(java.util.ArrayList)

Example 4 with CustomScriptType

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

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

the class UpdateGluuRadiusConfigAction method getRoPasswordScripts.

public List<String> getRoPasswordScripts() {
    List<String> ret = new ArrayList<String>();
    List<CustomScriptType> types = Arrays.asList(CustomScriptType.RESOURCE_OWNER_PASSWORD_CREDENTIALS);
    List<CustomScript> scripts = customScriptService.findCustomScripts(types);
    for (CustomScript script : scripts) {
        if (script.isEnabled())
            ret.add(script.getName());
    }
    return ret;
}
Also used : CustomScript(org.gluu.model.custom.script.model.CustomScript) CustomScriptType(org.gluu.model.custom.script.CustomScriptType) ArrayList(java.util.ArrayList)

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