use of org.gluu.model.custom.script.CustomScriptType in project oxTrust by GluuFederation.
the class ManageOtherCustomScriptAction 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 AppInitializer method applicationInitialized.
/**
* Initialize components and schedule DS connection time checker
*/
public void applicationInitialized(@Observes @Initialized(ApplicationScoped.class) Object init) {
log.debug("Initializing application services");
showBuildInfo();
configurationFactory.create();
PersistenceEntryManager localLdapEntryManager = persistenceEntryManagerInstance.get();
initializeLdifArchiver(localLdapEntryManager);
// Initialize template engine
templateService.initTemplateEngine();
// Initialize python interpreter
pythonService.initPythonInterpreter(configurationFactory.getBaseConfiguration().getString("pythonModulesDir", null));
// Initialize Shibboleth
shibbolethInitializer.createShibbolethConfiguration();
// Initialize script manager
List<CustomScriptType> supportedCustomScriptTypes = Arrays.asList(CustomScriptType.CACHE_REFRESH, CustomScriptType.UPDATE_USER, CustomScriptType.USER_REGISTRATION, CustomScriptType.ID_GENERATOR, CustomScriptType.PERSISTENCE_EXTENSION);
// Start timer
initSchedulerService();
// Schedule timer tasks
metricService.initTimer();
configurationFactory.initTimer();
loggerService.initTimer();
ldapStatusTimer.initTimer();
metadataValidationTimer.initTimer();
entityIDMonitoringService.initTimer();
cacheRefreshTimer.initTimer();
customScriptManager.initTimer(supportedCustomScriptTypes);
cleanerTimer.initTimer();
statusCheckerDaily.initTimer();
statusCheckerTimer.initTimer();
logFileSizeChecker.initTimer();
updateChecker.initTimer();
transcodingRulesUpdater.initTimer();
// Notify other components/plugins about finish application initialization
eventApplicationInitialized.select(ApplicationInitialized.Literal.APPLICATION).fire(new ApplicationInitializedEvent());
}
use of org.gluu.model.custom.script.CustomScriptType 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;
}
use of org.gluu.model.custom.script.CustomScriptType in project oxTrust by GluuFederation.
the class GluuRadiusConfigWebResource method isValidAcrValue.
private final boolean isValidAcrValue(String acrValue) {
List<CustomScriptType> script_types = new ArrayList<CustomScriptType>();
script_types.add(CustomScriptType.RESOURCE_OWNER_PASSWORD_CREDENTIALS);
List<CustomScript> allowed_scripts = customScriptService.findCustomScripts(script_types);
for (CustomScript custom_script : allowed_scripts) {
if (!custom_script.isEnabled())
continue;
if (StringUtils.equals(custom_script.getName(), acrValue))
return true;
}
return false;
}
use of org.gluu.model.custom.script.CustomScriptType in project oxTrust by GluuFederation.
the class ManageCustomScriptAction 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);
}
if (ScriptLocationType.FILE == customScript.getLocationType()) {
customScript.setScript(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;
}
Aggregations