Search in sources :

Example 26 with CustomScript

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

the class AbstractCustomScriptService method getCustomScriptByINum.

public Optional<CustomScript> getCustomScriptByINum(String baseDn, String inum, String... returnAttributes) {
    final List<Filter> customScriptTypeFilters = new ArrayList<Filter>();
    final Filter customScriptTypeFilter = Filter.createEqualityFilter("inum", inum);
    customScriptTypeFilters.add(customScriptTypeFilter);
    final Filter filter = Filter.createORFilter(customScriptTypeFilters);
    final List<CustomScript> result = persistenceEntryManager.findEntries(baseDn, CustomScript.class, filter, returnAttributes);
    if (result.isEmpty()) {
        return Optional.absent();
    }
    return Optional.of(result.get(0));
}
Also used : CustomScript(org.gluu.model.custom.script.model.CustomScript) Filter(org.gluu.search.filter.Filter) ArrayList(java.util.ArrayList)

Example 27 with CustomScript

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

the class UpdateUmaScopeAction method getInitialAuthorizationPolicies.

private List<CustomScript> getInitialAuthorizationPolicies() {
    List<CustomScript> result = new ArrayList<CustomScript>();
    if ((this.umaScope.getUmaAuthorizationPolicies() == null) || (this.umaScope.getUmaAuthorizationPolicies().size() == 0)) {
        return result;
    }
    List<DisplayNameEntry> displayNameEntries = lookupService.getDisplayNameEntries(customScriptService.baseDn(), this.umaScope.getUmaAuthorizationPolicies());
    if (displayNameEntries != null) {
        for (DisplayNameEntry displayNameEntry : displayNameEntries) {
            result.add(new CustomScript(displayNameEntry.getDn(), displayNameEntry.getInum(), displayNameEntry.getDisplayName()));
        }
    }
    return result;
}
Also used : CustomScript(org.gluu.model.custom.script.model.CustomScript) ArrayList(java.util.ArrayList) DisplayNameEntry(org.gluu.model.DisplayNameEntry)

Example 28 with CustomScript

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

the class ManageOtherCustomScriptAction method cleanAcrs.

private Set<String> cleanAcrs(String name) {
    Set<String> result = new HashSet<>();
    result.addAll(allAcrs);
    List<CustomScript> scripts = customScriptService.findCustomScripts(Arrays.asList(CustomScriptType.PERSON_AUTHENTICATION));
    for (CustomScript customScript : scripts) {
        if (null == customScript.getAliases())
            customScript.setAliases(new ArrayList<>());
        if (customScript.getName() != null) {
            if (!customScript.getName().equals(name)) {
                List<String> existing = customScript.getAliases();
                if (existing != null && existing.size() > 0) {
                    for (String value : existing) {
                        result.remove(value);
                    }
                }
            }
        }
    }
    return result;
}
Also used : CustomScript(org.gluu.model.custom.script.model.CustomScript) AuthenticationCustomScript(org.gluu.model.custom.script.model.auth.AuthenticationCustomScript) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 29 with CustomScript

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

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

the class UpdateClientAction method saveAttributesJson.

private void saveAttributesJson() {
    ClientAttributes clientAttributes = new ClientAttributes();
    try {
        clientAttributes = new ObjectMapper().readValue(this.oxAttributesJson, ClientAttributes.class);
    } catch (Exception e) {
        log.info("error parsing json:" + e);
    }
    clientAttributes.setPostAuthnScripts(postAuthnScripts.stream().map(CustomScript::getDn).collect(Collectors.toList()));
    clientAttributes.setRptClaimsScripts(rptClaimsScripts.stream().map(CustomScript::getDn).collect(Collectors.toList()));
    clientAttributes.setConsentGatheringScripts(consentScripts.stream().map(CustomScript::getDn).collect(Collectors.toList()));
    clientAttributes.setSpontaneousScopeScriptDns(spontaneousScopesScripts.stream().map(CustomScript::getDn).collect(Collectors.toList()));
    clientAttributes.setIntrospectionScripts(introspectionScripts.stream().map(CustomScript::getDn).collect(Collectors.toList()));
    this.client.setAttributes(clientAttributes);
}
Also used : CustomScript(org.gluu.model.custom.script.model.CustomScript) ClientAttributes(org.oxauth.persistence.model.ClientAttributes) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) EncryptionException(org.gluu.util.security.StringEncrypter.EncryptionException) BasePersistenceException(org.gluu.persist.exception.BasePersistenceException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) JSONException(org.codehaus.jettison.json.JSONException)

Aggregations

CustomScript (org.gluu.model.custom.script.model.CustomScript)42 ArrayList (java.util.ArrayList)20 AuthenticationCustomScript (org.gluu.model.custom.script.model.auth.AuthenticationCustomScript)11 CustomScriptType (org.gluu.model.custom.script.CustomScriptType)8 IOException (java.io.IOException)7 SimpleCustomProperty (org.gluu.model.SimpleCustomProperty)6 HttpEntity (org.apache.http.HttpEntity)5 HttpResponse (org.apache.http.HttpResponse)5 ParseException (org.apache.http.ParseException)5 SimpleExtendedCustomProperty (org.gluu.model.SimpleExtendedCustomProperty)5 Test (org.junit.Test)5 List (java.util.List)4 CustomScriptConfiguration (org.gluu.model.custom.script.conf.CustomScriptConfiguration)4 HttpGet (org.apache.http.client.methods.HttpGet)3 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)3 SelectableEntity (org.gluu.model.SelectableEntity)3 BasePersistenceException (org.gluu.persist.exception.BasePersistenceException)3 Filter (org.gluu.search.filter.Filter)3 Operation (io.swagger.v3.oas.annotations.Operation)2 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)2