use of org.gluu.model.custom.script.model.CustomScript in project oxTrust by GluuFederation.
the class CustomScriptWebResourceTest method updateScriptTest.
@Test
public void updateScriptTest() {
String name = "AnotherMyScript";
CustomScript script = getCustomScript(name);
HttpPost request = new HttpPost(BASE_URL + ApiConstants.BASE_API_URL + ApiConstants.CONFIGURATION + ApiConstants.SCRIPTS);
try {
String json = mapper.writeValueAsString(script);
HttpEntity entity = new ByteArrayEntity(json.toString().getBytes("UTF-8"), ContentType.APPLICATION_FORM_URLENCODED);
request.setEntity(entity);
String CONTENT_TYPE = "Content-Type";
request.setHeader(CONTENT_TYPE, MediaType.APPLICATION_JSON);
HttpResponse response = handle(request);
Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
HttpEntity result = response.getEntity();
CustomScript myScript = mapper.readValue(EntityUtils.toString(result), CustomScript.class);
Assert.assertEquals(myScript.getName(), name);
myScript.setDescription(myScript.getDescription() + " Updated");
HttpPut second = new HttpPut(BASE_URL + ApiConstants.BASE_API_URL + ApiConstants.CONFIGURATION + ApiConstants.SCRIPTS);
json = mapper.writeValueAsString(myScript);
entity = new ByteArrayEntity(json.toString().getBytes("UTF-8"), ContentType.APPLICATION_FORM_URLENCODED);
second.setEntity(entity);
second.setHeader(CONTENT_TYPE, MediaType.APPLICATION_JSON);
response = handle(second);
Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
} catch (ParseException | IOException e) {
e.printStackTrace();
Assert.assertTrue(false);
}
}
use of org.gluu.model.custom.script.model.CustomScript in project oxTrust by GluuFederation.
the class CustomScriptWebResourceTest method listUpdateUserCustomScriptsTest.
@Test
public void listUpdateUserCustomScriptsTest() {
String type = "update_user";
HttpUriRequest request = new HttpGet(BASE_URL + ApiConstants.BASE_API_URL + ApiConstants.CONFIGURATION + ApiConstants.SCRIPTS + ApiConstants.TYPE_PATH + "/" + type);
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 >= 1);
} catch (ParseException | IOException e) {
e.printStackTrace();
Assert.assertTrue(false);
}
}
use of org.gluu.model.custom.script.model.CustomScript in project oxTrust by GluuFederation.
the class CustomScriptWebResourceTest method getScriptByInumTest.
@Test
public void getScriptByInumTest() {
String inum = "5018-AF9C";
HttpUriRequest request = new HttpGet(BASE_URL + ApiConstants.BASE_API_URL + ApiConstants.CONFIGURATION + ApiConstants.SCRIPTS + "/" + inum);
HttpResponse response = handle(request);
Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
HttpEntity entity = response.getEntity();
try {
String content = EntityUtils.toString(entity);
CustomScript script = mapper.readValue(content, CustomScript.class);
Assert.assertNotNull(script);
} catch (ParseException | IOException e) {
e.printStackTrace();
Assert.assertTrue(false);
}
}
use of org.gluu.model.custom.script.model.CustomScript 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;
}
use of org.gluu.model.custom.script.model.CustomScript in project oxAuth by GluuFederation.
the class ExternalAuthenticationService method getAuthModesByAcrValues.
public List<String> getAuthModesByAcrValues(List<String> acrValues) {
List<String> authModes = new ArrayList<String>();
for (String acrValue : acrValues) {
if (StringHelper.isNotEmpty(acrValue)) {
String customScriptName = StringHelper.toLowerCase(scriptName(acrValue));
if (customScriptConfigurationsNameMap.containsKey(customScriptName)) {
CustomScriptConfiguration customScriptConfiguration = customScriptConfigurationsNameMap.get(customScriptName);
CustomScript customScript = customScriptConfiguration.getCustomScript();
// Handle internal authentication method
if (customScript.isInternal()) {
authModes.add(scriptName(acrValue));
continue;
}
CustomScriptType customScriptType = customScriptConfiguration.getCustomScript().getScriptType();
BaseExternalType defaultImplementation = customScriptType.getDefaultImplementation();
BaseExternalType pythonImplementation = customScriptConfiguration.getExternalType();
if ((pythonImplementation != null) && (defaultImplementation != pythonImplementation)) {
authModes.add(scriptName(acrValue));
}
}
}
}
return authModes;
}
Aggregations