use of org.xdi.model.SimpleExtendedCustomProperty in project oxTrust by GluuFederation.
the class ManageCustomScriptAction method modify.
public String modify() {
if (this.initialized) {
return OxTrustConstants.RESULT_SUCCESS;
}
CustomScriptType[] allowedCustomScriptTypes = this.applianceService.getCustomScriptTypes();
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.xdi.model.SimpleExtendedCustomProperty in project oxTrust by GluuFederation.
the class ManageCustomScriptAction 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);
}
use of org.xdi.model.SimpleExtendedCustomProperty in project oxTrust by GluuFederation.
the class PassportRestWebService method getPassportConfig.
@GET
@Produces({ MediaType.APPLICATION_JSON })
@ProtectedApi
public Response getPassportConfig() {
PassportConfigResponse passportConfigResponse = new PassportConfigResponse();
Map<String, Map> strategies = new HashMap<String, Map>();
LdapOxPassportConfiguration ldapOxPassportConfiguration = passportService.loadConfigurationFromLdap();
if (ldapOxPassportConfiguration != null) {
for (org.xdi.model.passport.PassportConfiguration passportConfiguration : ldapOxPassportConfiguration.getPassportConfigurations()) {
if (passportConfiguration != null) {
Map<String, String> map = new HashMap<String, String>();
List<SimpleExtendedCustomProperty> passList = passportConfiguration.getFieldset();
if (passList != null) {
for (SimpleExtendedCustomProperty fieldset : passList) {
map.put(fieldset.getValue1(), fieldset.getValue2());
}
}
strategies.put(passportConfiguration.getStrategy(), map);
}
}
}
passportConfigResponse.setPassportStrategies(strategies);
String passportConfigResponseJson;
try {
passportConfigResponseJson = jsonService.objectToPerttyJson(passportConfigResponse);
} catch (IOException ex) {
return getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Failed to prepare configuration");
}
return Response.status(Response.Status.OK).entity(passportConfigResponseJson).build();
}
use of org.xdi.model.SimpleExtendedCustomProperty 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<SimpleExtendedCustomProperty> simpleCustomProperties = loadedCustomScript.getConfigurationProperties();
if (simpleCustomProperties == null) {
simpleCustomProperties = new ArrayList<SimpleExtendedCustomProperty>(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);
}
}
}
// Load script
BaseExternalType newCustomScriptExternalType = createExternalType(loadedCustomScript, newConfigurationAttributes);
CustomScriptConfiguration newCustomScriptConfiguration = new CustomScriptConfiguration(loadedCustomScript, newCustomScriptExternalType, newConfigurationAttributes);
// Store configuration and script
newCustomScriptConfigurations.put(newSupportedCustomScriptInum, newCustomScriptConfiguration);
modified = true;
}
}
// Remove old external scripts 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);
}
Aggregations