use of io.jans.model.custom.script.model.CustomScript in project jans by JanssenProject.
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;
}
use of io.jans.model.custom.script.model.CustomScript in project jans by JanssenProject.
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);
}
use of io.jans.model.custom.script.model.CustomScript in project jans by JanssenProject.
the class CustomScriptManager method saveScriptErrorImpl.
protected void saveScriptErrorImpl(CustomScript customScript, Exception exception, boolean overwrite) {
// Load entry from DN
String customScriptDn = customScript.getDn();
Class<? extends CustomScript> scriptType = customScript.getScriptType().getCustomScriptModel();
CustomScript loadedCustomScript = customScriptService.getCustomScriptByDn(scriptType, customScriptDn);
// Check if there is error value already
ScriptError currError = loadedCustomScript.getScriptError();
if (!overwrite && (currError != null)) {
return;
}
// Save error into script entry
StringBuilder builder = new StringBuilder();
builder.append(ExceptionUtils.getStackTrace(exception));
String message = exception.getMessage();
if (message != null && !StringUtils.isEmpty(message)) {
builder.append("\n==================Further details============================\n");
builder.append(message);
}
loadedCustomScript.setScriptError(new ScriptError(new Date(), builder.toString()));
customScriptService.update(loadedCustomScript);
}
use of io.jans.model.custom.script.model.CustomScript in project jans by JanssenProject.
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("jansScrTyp", customScriptType.getValue());
customScriptTypeFilters.add(customScriptTypeFilter);
}
Filter filter = Filter.createORFilter(customScriptTypeFilters);
List<CustomScript> result = persistenceEntryManager.findEntries(baseDn, CustomScript.class, filter, returnAttributes);
return result;
}
use of io.jans.model.custom.script.model.CustomScript in project jans by JanssenProject.
the class AbstractCustomScriptService method getScriptByDisplayName.
public CustomScript getScriptByDisplayName(String name) {
Filter searchFilter = Filter.createEqualityFilter("displayName", name);
List<CustomScript> result = persistenceEntryManager.findEntries(baseDn(), CustomScript.class, searchFilter, 1);
if (result != null && !result.isEmpty()) {
return result.get(0);
}
return null;
}
Aggregations