Search in sources :

Example 11 with CustomScript

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

the class UpdateScopeDescriptionAction method getInitialAuthorizationPolicies.

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

Example 12 with CustomScript

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

the class UpdateScopeDescriptionAction method searchAvailableAuthorizationPolicies.

public void searchAvailableAuthorizationPolicies() {
    if (this.availableAuthorizationPolicies != null) {
        selectAddedAuthorizationPolicies();
        return;
    }
    try {
        List<CustomScript> availableScripts = customScriptService.findCustomScripts(Arrays.asList(CustomScriptType.UMA_AUTHORIZATION_POLICY), CUSTOM_SCRIPT_RETURN_ATTRIBUTES);
        List<SelectableEntity<CustomScript>> tmpAvailableAuthorizationPolicies = new ArrayList<SelectableEntity<CustomScript>>();
        for (CustomScript authorizationPolicy : availableScripts) {
            tmpAvailableAuthorizationPolicies.add(new SelectableEntity<CustomScript>(authorizationPolicy));
        }
        this.availableAuthorizationPolicies = tmpAvailableAuthorizationPolicies;
        selectAddedAuthorizationPolicies();
    } catch (LdapMappingException ex) {
        log.error("Failed to find available authorization policies", ex);
    }
}
Also used : CustomScript(org.xdi.model.custom.script.model.CustomScript) SelectableEntity(org.xdi.model.SelectableEntity) LdapMappingException(org.gluu.site.ldap.persistence.exception.LdapMappingException) ArrayList(java.util.ArrayList)

Example 13 with CustomScript

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

the class UpdateScopeDescriptionAction method updateAuthorizationPolicies.

private void updateAuthorizationPolicies() {
    if (this.authorizationPolicies == null || this.authorizationPolicies.size() == 0) {
        this.scopeDescription.setAuthorizationPolicies(null);
        return;
    }
    List<String> tmpAuthorizationPolicies = new ArrayList<String>();
    for (CustomScript authorizationPolicy : this.authorizationPolicies) {
        tmpAuthorizationPolicies.add(authorizationPolicy.getDn());
    }
    this.scopeDescription.setAuthorizationPolicies(tmpAuthorizationPolicies);
}
Also used : CustomScript(org.xdi.model.custom.script.model.CustomScript) ArrayList(java.util.ArrayList)

Example 14 with CustomScript

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

the class UpdateScopeAction method updateDynamicScripts.

private void updateDynamicScripts() {
    if ((org.xdi.oxauth.model.common.ScopeType.DYNAMIC != this.scope.getScopeType()) || (this.dynamicScripts == null) || (this.dynamicScripts.size() == 0)) {
        this.scope.setDynamicScopeScripts(null);
        return;
    }
    List<String> resultDynamicScripts = new ArrayList<String>();
    for (CustomScript dynamicScript : this.dynamicScripts) {
        resultDynamicScripts.add(dynamicScript.getDn());
    }
    this.scope.setDynamicScopeScripts(resultDynamicScripts);
}
Also used : CustomScript(org.xdi.model.custom.script.model.CustomScript) ArrayList(java.util.ArrayList)

Example 15 with CustomScript

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

the class ManageCustomScriptAction method save.

public String save() {
    try {
        List<CustomScript> oldCustomScripts = customScriptService.findCustomScripts(Arrays.asList(this.applianceService.getCustomScriptTypes()), "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, "'{}' is reserved 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)) {
                    String basedInum = organizationService.getOrganizationInum();
                    customScriptId = basedInum + "!" + 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().size() == 0) {
                    customScript.setConfigurationProperties(null);
                }
                if (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 (LdapMappingException ex) {
        log.error("Failed to update custom scripts", ex);
        return OxTrustConstants.RESULT_FAILURE;
    }
    reset();
    return OxTrustConstants.RESULT_SUCCESS;
}
Also used : AuthenticationCustomScript(org.xdi.model.custom.script.model.auth.AuthenticationCustomScript) CustomScript(org.xdi.model.custom.script.model.CustomScript) CustomScriptType(org.xdi.model.custom.script.CustomScriptType) LdapMappingException(org.gluu.site.ldap.persistence.exception.LdapMappingException) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

CustomScript (org.xdi.model.custom.script.model.CustomScript)16 ArrayList (java.util.ArrayList)10 LdapMappingException (org.gluu.site.ldap.persistence.exception.LdapMappingException)4 SimpleCustomProperty (org.xdi.model.SimpleCustomProperty)4 AuthenticationCustomScript (org.xdi.model.custom.script.model.auth.AuthenticationCustomScript)4 CustomScriptType (org.xdi.model.custom.script.CustomScriptType)3 List (java.util.List)2 Test (org.testng.annotations.Test)2 DisplayNameEntry (org.xdi.model.DisplayNameEntry)2 SelectableEntity (org.xdi.model.SelectableEntity)2 CustomScriptConfiguration (org.xdi.model.custom.script.conf.CustomScriptConfiguration)2 BaseComponentTest (org.xdi.oxauth.BaseComponentTest)2 Filter (com.unboundid.ldap.sdk.Filter)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1 Entry (java.util.Map.Entry)1 BaseExternalType (org.xdi.model.custom.script.type.BaseExternalType)1