Search in sources :

Example 1 with SimpleExtendedCustomProperty

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

the class ManageCustomScriptAction method modify.

public String modify() {
    if (this.initialized) {
        return OxTrustConstants.RESULT_SUCCESS;
    }
    CustomScriptType[] allowedCustomScriptTypes = this.applianceService.getCustomScriptTypes();
    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 : AuthenticationCustomScript(org.xdi.model.custom.script.model.auth.AuthenticationCustomScript) CustomScript(org.xdi.model.custom.script.model.CustomScript) AuthenticationCustomScript(org.xdi.model.custom.script.model.auth.AuthenticationCustomScript) BaseMappingException(org.gluu.persist.exception.mapping.BaseMappingException) SimpleExtendedCustomProperty(org.xdi.model.SimpleExtendedCustomProperty) CustomScriptType(org.xdi.model.custom.script.CustomScriptType) ArrayList(java.util.ArrayList) List(java.util.List) SimpleCustomProperty(org.xdi.model.SimpleCustomProperty)

Example 2 with SimpleExtendedCustomProperty

use of org.xdi.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.xdi.model.SimpleExtendedCustomProperty) AuthenticationCustomScript(org.xdi.model.custom.script.model.auth.AuthenticationCustomScript) CustomScript(org.xdi.model.custom.script.model.CustomScript) AuthenticationCustomScript(org.xdi.model.custom.script.model.auth.AuthenticationCustomScript) SimpleCustomProperty(org.xdi.model.SimpleCustomProperty)

Example 3 with SimpleExtendedCustomProperty

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

the class PassportRestWebService method getPassportConfig.

@GET
@Produces({ MediaType.APPLICATION_JSON })
@ProtectedApi
public Response getPassportConfig() {
    PassportConfigResponse passportConfigResponse = new PassportConfigResponse();
    Map<String, Map> strategies = new HashMap<String, Map>();
    LdapOxPassportConfiguration ldapOxPassportConfiguration = passportService.loadConfigurationFromLdap();
    if (ldapOxPassportConfiguration != null) {
        for (org.xdi.model.passport.PassportConfiguration passportConfiguration : ldapOxPassportConfiguration.getPassportConfigurations()) {
            if (passportConfiguration != null) {
                Map<String, String> map = new HashMap<String, String>();
                List<SimpleExtendedCustomProperty> passList = passportConfiguration.getFieldset();
                if (passList != null) {
                    for (SimpleExtendedCustomProperty fieldset : passList) {
                        map.put(fieldset.getValue1(), fieldset.getValue2());
                    }
                }
                strategies.put(passportConfiguration.getStrategy(), map);
            }
        }
    }
    passportConfigResponse.setPassportStrategies(strategies);
    String passportConfigResponseJson;
    try {
        passportConfigResponseJson = jsonService.objectToPerttyJson(passportConfigResponse);
    } catch (IOException ex) {
        return getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Failed to prepare configuration");
    }
    return Response.status(Response.Status.OK).entity(passportConfigResponseJson).build();
}
Also used : LdapOxPassportConfiguration(org.xdi.config.oxtrust.LdapOxPassportConfiguration) HashMap(java.util.HashMap) IOException(java.io.IOException) SimpleExtendedCustomProperty(org.xdi.model.SimpleExtendedCustomProperty) PassportConfigResponse(org.gluu.oxtrust.model.passport.PassportConfigResponse) HashMap(java.util.HashMap) Map(java.util.Map) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ProtectedApi(org.gluu.oxtrust.service.filter.ProtectedApi)

Example 4 with SimpleExtendedCustomProperty

use of org.xdi.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);
                    }
                }
            }
            // 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.xdi.model.custom.script.model.CustomScript) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SimpleExtendedCustomProperty(org.xdi.model.SimpleExtendedCustomProperty) Entry(java.util.Map.Entry) BaseExternalType(org.xdi.model.custom.script.type.BaseExternalType) SimpleCustomProperty(org.xdi.model.SimpleCustomProperty) CustomScriptConfiguration(org.xdi.model.custom.script.conf.CustomScriptConfiguration)

Aggregations

SimpleExtendedCustomProperty (org.xdi.model.SimpleExtendedCustomProperty)4 SimpleCustomProperty (org.xdi.model.SimpleCustomProperty)3 CustomScript (org.xdi.model.custom.script.model.CustomScript)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 AuthenticationCustomScript (org.xdi.model.custom.script.model.auth.AuthenticationCustomScript)2 IOException (java.io.IOException)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 GET (javax.ws.rs.GET)1 Produces (javax.ws.rs.Produces)1 PassportConfigResponse (org.gluu.oxtrust.model.passport.PassportConfigResponse)1 ProtectedApi (org.gluu.oxtrust.service.filter.ProtectedApi)1 BaseMappingException (org.gluu.persist.exception.mapping.BaseMappingException)1 LdapOxPassportConfiguration (org.xdi.config.oxtrust.LdapOxPassportConfiguration)1 CustomScriptType (org.xdi.model.custom.script.CustomScriptType)1 CustomScriptConfiguration (org.xdi.model.custom.script.conf.CustomScriptConfiguration)1 BaseExternalType (org.xdi.model.custom.script.type.BaseExternalType)1