Search in sources :

Example 16 with CustomScript

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

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

the class UpdateUmaScopeAction method searchAvailableAuthorizationPolicies.

public void searchAvailableAuthorizationPolicies() {
    if (this.availableAuthorizationPolicies != null) {
        selectAddedAuthorizationPolicies();
        return;
    }
    try {
        List<CustomScript> availableScripts = customScriptService.findCustomScripts(Arrays.asList(CustomScriptType.UMA_RPT_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 (BasePersistenceException ex) {
        log.error("Failed to find available authorization policies", ex);
    }
}
Also used : CustomScript(org.gluu.model.custom.script.model.CustomScript) BasePersistenceException(org.gluu.persist.exception.BasePersistenceException) SelectableEntity(org.gluu.model.SelectableEntity) ArrayList(java.util.ArrayList)

Example 18 with CustomScript

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

the class UpdateUmaScopeAction method updateAuthorizationPolicies.

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

Example 19 with CustomScript

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

the class CustomScriptWebResourceTest method getCustomScript.

private CustomScript getCustomScript(String name) {
    CustomScript customScript = new CustomScript();
    customScript.setName(name);
    customScript.setDescription(name);
    customScript.setEnabled(false);
    customScript.setLevel(20);
    customScript.setConfigurationProperties(new ArrayList<>());
    customScript.setModuleProperties(new ArrayList<>());
    customScript.setLocationType(ScriptLocationType.LDAP);
    customScript.setProgrammingLanguage(ProgrammingLanguage.PYTHON);
    customScript.setScript("I'm a custom script added via oxtrust api");
    customScript.setScriptType(CustomScriptType.PERSON_AUTHENTICATION);
    return customScript;
}
Also used : CustomScript(org.gluu.model.custom.script.model.CustomScript)

Example 20 with CustomScript

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

the class CustomScriptWebResourceTest method listCustomScriptsTest.

@Test
public void listCustomScriptsTest() {
    HttpUriRequest request = new HttpGet(BASE_URL + ApiConstants.BASE_API_URL + ApiConstants.CONFIGURATION + ApiConstants.SCRIPTS);
    HttpResponse response = handle(request);
    Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
    HttpEntity entity = response.getEntity();
    try {
        String content = EntityUtils.toString(entity);
        CustomScript[] scripts = mapper.readValue(content, CustomScript[].class);
        Assert.assertTrue(scripts.length > 5);
    } catch (ParseException | IOException e) {
        e.printStackTrace();
        Assert.assertTrue(false);
    }
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) HttpEntity(org.apache.http.HttpEntity) CustomScript(org.gluu.model.custom.script.model.CustomScript) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) ParseException(org.apache.http.ParseException) IOException(java.io.IOException) Test(org.junit.Test)

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