use of org.gluu.model.custom.script.CustomScriptType in project oxCore by GluuFederation.
the class CustomScriptManager method createExternalTypeFromStringWithPythonException.
public BaseExternalType createExternalTypeFromStringWithPythonException(CustomScript customScript, Map<String, SimpleCustomProperty> configurationAttributes) throws Exception {
String script = customScript.getScript();
String scriptName = StringHelper.toLowerCase(customScript.getName()) + ".py";
if (script == null) {
return null;
}
CustomScriptType customScriptType = customScript.getScriptType();
BaseExternalType externalType = null;
InputStream bis = null;
try {
bis = new ByteArrayInputStream(script.getBytes("UTF-8"));
externalType = pythonService.loadPythonScript(bis, scriptName, customScriptType.getPythonClass(), customScriptType.getCustomScriptType(), new PyObject[] { new PyLong(System.currentTimeMillis()) });
} catch (UnsupportedEncodingException e) {
log.error(String.format("%s. Script inum: %s", e.getMessage(), customScript.getInum()), e);
} finally {
IOUtils.closeQuietly(bis);
}
if (externalType == null) {
return null;
}
boolean initialized = false;
try {
if (externalType.getApiVersion() > 10) {
initialized = externalType.init(customScript, configurationAttributes);
} else {
initialized = externalType.init(configurationAttributes);
log.warn(" Update the script's init method to init(self, customScript, configurationAttributes)", customScript.getName());
}
} catch (Exception ex) {
log.error("Failed to initialize custom script: '{}'", ex, customScript.getName());
}
if (initialized) {
return externalType;
}
return null;
}
use of org.gluu.model.custom.script.CustomScriptType in project oxCore by GluuFederation.
the class CustomScriptManager method groupCustomScriptConfigurationsByScriptType.
private Map<CustomScriptType, List<CustomScriptConfiguration>> groupCustomScriptConfigurationsByScriptType(Map<String, CustomScriptConfiguration> customScriptConfigurations) {
Map<CustomScriptType, List<CustomScriptConfiguration>> newCustomScriptConfigurationsByScriptType = new HashMap<CustomScriptType, List<CustomScriptConfiguration>>();
for (CustomScriptType customScriptType : this.supportedCustomScriptTypes) {
List<CustomScriptConfiguration> customConfigurationsByScriptType = new ArrayList<CustomScriptConfiguration>();
newCustomScriptConfigurationsByScriptType.put(customScriptType, customConfigurationsByScriptType);
}
for (CustomScriptConfiguration customScriptConfiguration : customScriptConfigurations.values()) {
CustomScriptType customScriptType = customScriptConfiguration.getCustomScript().getScriptType();
List<CustomScriptConfiguration> customConfigurationsByScriptType = newCustomScriptConfigurationsByScriptType.get(customScriptType);
if (customConfigurationsByScriptType != null) {
customConfigurationsByScriptType.add(customScriptConfiguration);
}
}
return newCustomScriptConfigurationsByScriptType;
}
use of org.gluu.model.custom.script.CustomScriptType in project oxCore by GluuFederation.
the class AbstractCustomScriptService method findCustomScripts.
public List<CustomScript> findCustomScripts(List<CustomScriptType> customScriptTypes, String... returnAttributes) {
String baseDn = baseDn();
if ((customScriptTypes == null) || (customScriptTypes.size() == 0)) {
return findAllCustomScripts(returnAttributes);
}
List<Filter> customScriptTypeFilters = new ArrayList<Filter>();
for (CustomScriptType customScriptType : customScriptTypes) {
Filter customScriptTypeFilter = Filter.createEqualityFilter("oxScriptType", customScriptType.getValue());
customScriptTypeFilters.add(customScriptTypeFilter);
}
Filter filter = Filter.createORFilter(customScriptTypeFilters);
List<CustomScript> result = persistenceEntryManager.findEntries(baseDn, CustomScript.class, filter, returnAttributes);
return result;
}
use of org.gluu.model.custom.script.CustomScriptType in project oxTrust by GluuFederation.
the class ManageCustomScriptAction method modify.
public String modify() {
if (this.initialized) {
return OxTrustConstants.RESULT_SUCCESS;
}
CustomScriptType[] allowedCustomScriptTypes = getScriptType();
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;
}
use of org.gluu.model.custom.script.CustomScriptType in project oxTrust by GluuFederation.
the class UpdateGluuRadiusConfigAction method getRoPasswordScripts.
public List<String> getRoPasswordScripts() {
List<String> ret = new ArrayList<String>();
List<CustomScriptType> types = Arrays.asList(CustomScriptType.RESOURCE_OWNER_PASSWORD_CREDENTIALS);
List<CustomScript> scripts = customScriptService.findCustomScripts(types);
for (CustomScript script : scripts) {
if (script.isEnabled())
ret.add(script.getName());
}
return ret;
}
Aggregations