Search in sources :

Example 26 with SimpleCustomProperty

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

the class ExternalUserRegistrationService method executeExternalInitRegistrationMethod.

public boolean executeExternalInitRegistrationMethod(CustomScriptConfiguration customScriptConfiguration, GluuCustomPerson user, Map<String, String[]> requestParameters) {
    try {
        log.debug("Executing python 'initRegistration' method");
        UserRegistrationType externalType = (UserRegistrationType) customScriptConfiguration.getExternalType();
        Map<String, SimpleCustomProperty> configurationAttributes = customScriptConfiguration.getConfigurationAttributes();
        return externalType.initRegistration(user, requestParameters, configurationAttributes);
    } catch (Exception ex) {
        log.error(ex.getMessage(), ex);
    }
    return false;
}
Also used : UserRegistrationType(org.xdi.model.custom.script.type.user.UserRegistrationType) SimpleCustomProperty(org.xdi.model.SimpleCustomProperty)

Example 27 with SimpleCustomProperty

use of org.xdi.model.SimpleCustomProperty 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<SimpleCustomProperty> simpleCustomProperties = loadedCustomScript.getConfigurationProperties();
            if (simpleCustomProperties == null) {
                simpleCustomProperties = new ArrayList<SimpleCustomProperty>(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);
                    }
                }
            }
            // Create authenticator
            BaseExternalType newCustomScriptExternalType = createExternalType(loadedCustomScript, newConfigurationAttributes);
            CustomScriptConfiguration newCustomScriptConfiguration = new CustomScriptConfiguration(loadedCustomScript, newCustomScriptExternalType, newConfigurationAttributes);
            // Store configuration and authenticator
            newCustomScriptConfigurations.put(newSupportedCustomScriptInum, newCustomScriptConfiguration);
            modified = true;
        }
    }
    // Remove old external authenticator 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) 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)

Example 28 with SimpleCustomProperty

use of org.xdi.model.SimpleCustomProperty in project oxCore by GluuFederation.

the class CustomScript method addModuleProperty.

public void addModuleProperty(final String name, final String value) {
    SimpleCustomProperty usageTypeModuleProperties = new SimpleCustomProperty(name, value);
    getModuleProperties().add(usageTypeModuleProperties);
}
Also used : SimpleCustomProperty(org.xdi.model.SimpleCustomProperty)

Example 29 with SimpleCustomProperty

use of org.xdi.model.SimpleCustomProperty in project oxAuth by GluuFederation.

the class ExternalUmaAuthorizationPolicyService method executeExternalAuthorizeMethod.

public boolean executeExternalAuthorizeMethod(CustomScriptConfiguration customScriptConfiguration, AuthorizationContext authorizationContext) {
    try {
        log.debug("Executing python 'authorize' method");
        AuthorizationPolicyType externalType = (AuthorizationPolicyType) customScriptConfiguration.getExternalType();
        Map<String, SimpleCustomProperty> configurationAttributes = customScriptConfiguration.getConfigurationAttributes();
        return externalType.authorize(authorizationContext, configurationAttributes);
    } catch (Exception ex) {
        log.error(ex.getMessage(), ex);
    }
    return false;
}
Also used : AuthorizationPolicyType(org.xdi.model.custom.script.type.uma.AuthorizationPolicyType) SimpleCustomProperty(org.xdi.model.SimpleCustomProperty)

Example 30 with SimpleCustomProperty

use of org.xdi.model.SimpleCustomProperty in project oxAuth by GluuFederation.

the class ExternalAuthenticationService method getInternalCustomScriptConfiguration.

private CustomScriptConfiguration getInternalCustomScriptConfiguration() {
    CustomScript customScript = new AuthenticationCustomScript() {

        @Override
        public AuthenticationScriptUsageType getUsageType() {
            return AuthenticationScriptUsageType.INTERACTIVE;
        }
    };
    customScript.setName(OxConstants.SCRIPT_TYPE_INTERNAL_RESERVED_NAME);
    customScript.setLevel(-1);
    return new CustomScriptConfiguration(customScript, internalDefaultPersonAuthenticationType, new HashMap<String, SimpleCustomProperty>(0));
}
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) SimpleCustomProperty(org.xdi.model.SimpleCustomProperty) CustomScriptConfiguration(org.xdi.model.custom.script.conf.CustomScriptConfiguration)

Aggregations

SimpleCustomProperty (org.xdi.model.SimpleCustomProperty)41 PersonAuthenticationType (org.xdi.model.custom.script.type.auth.PersonAuthenticationType)10 InternalDefaultPersonAuthenticationType (org.xdi.oxauth.service.external.internal.InternalDefaultPersonAuthenticationType)10 ScimType (org.xdi.model.custom.script.type.scim.ScimType)6 CustomScript (org.xdi.model.custom.script.model.CustomScript)4 UpdateUserType (org.xdi.model.custom.script.type.user.UpdateUserType)4 UserRegistrationType (org.xdi.model.custom.script.type.user.UserRegistrationType)4 AuthenticationCustomScript (org.xdi.model.custom.script.model.auth.AuthenticationCustomScript)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 AuthenticationScriptUsageType (org.xdi.model.AuthenticationScriptUsageType)2 CustomScriptConfiguration (org.xdi.model.custom.script.conf.CustomScriptConfiguration)2 BaseExternalType (org.xdi.model.custom.script.type.BaseExternalType)2 IdGeneratorType (org.xdi.model.custom.script.type.id.IdGeneratorType)2 File (java.io.File)1 FileFilter (java.io.FileFilter)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 List (java.util.List)1 Entry (java.util.Map.Entry)1