use of org.xdi.model.custom.script.model.CustomScript in project oxTrust by GluuFederation.
the class UpdateScopeAction method searchAvailableDynamicScripts.
public void searchAvailableDynamicScripts() {
if (this.availableDynamicScripts != null) {
selectAddedDynamicScripts();
return;
}
try {
List<CustomScript> availableScripts = customScriptService.findCustomScripts(Arrays.asList(CustomScriptType.DYNAMIC_SCOPE), CUSTOM_SCRIPT_RETURN_ATTRIBUTES);
List<SelectableEntity<CustomScript>> tmpAvailableDynamicScripts = new ArrayList<SelectableEntity<CustomScript>>();
for (CustomScript dynamicScript : availableScripts) {
if (dynamicScript.isEnabled()) {
tmpAvailableDynamicScripts.add(new SelectableEntity<CustomScript>(dynamicScript));
}
}
this.availableDynamicScripts = tmpAvailableDynamicScripts;
selectAddedDynamicScripts();
} catch (LdapMappingException ex) {
log.error("Failed to find available authorization policies", ex);
}
}
use of org.xdi.model.custom.script.model.CustomScript in project oxTrust by GluuFederation.
the class ManagePersonAuthenticationAction method getPersonAuthenticationConfigurationNames.
public List<String> getPersonAuthenticationConfigurationNames() {
if (this.customAuthenticationConfigNames == null) {
this.customAuthenticationConfigNames = new ArrayList<String>();
for (CustomScript customScript : this.customScripts) {
if (customScript.isEnabled()) {
String name = customScript.getName();
if (StringHelper.isEmpty(name)) {
continue;
}
this.customAuthenticationConfigNames.add(customScript.getName());
}
}
if ((ldapConfig != null) && StringHelper.isNotEmpty(ldapConfig.getConfigId())) {
this.customAuthenticationConfigNames.add(ldapConfig.getConfigId());
} else {
this.customAuthenticationConfigNames.add(OxConstants.SCRIPT_TYPE_INTERNAL_RESERVED_NAME);
}
}
return this.customAuthenticationConfigNames;
}
use of org.xdi.model.custom.script.model.CustomScript 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<SimpleCustomProperty> simpleCustomProperties = loadedCustomScript.getConfigurationProperties();
if (simpleCustomProperties == null) {
simpleCustomProperties = new ArrayList<SimpleCustomProperty>(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);
}
}
}
// Create authenticator
BaseExternalType newCustomScriptExternalType = createExternalType(loadedCustomScript, newConfigurationAttributes);
CustomScriptConfiguration newCustomScriptConfiguration = new CustomScriptConfiguration(loadedCustomScript, newCustomScriptExternalType, newConfigurationAttributes);
// Store configuration and authenticator
newCustomScriptConfigurations.put(newSupportedCustomScriptInum, newCustomScriptConfiguration);
modified = true;
}
}
// Remove old external authenticator 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 org.xdi.model.custom.script.model.CustomScript 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 = ldapEntryManager.findEntries(baseDn, CustomScript.class, returnAttributes, filter);
return result;
}
use of org.xdi.model.custom.script.model.CustomScript in project oxAuth by GluuFederation.
the class ExternalAuthenticationService method getInternalCustomScriptConfiguration.
private CustomScriptConfiguration getInternalCustomScriptConfiguration() {
CustomScript customScript = new AuthenticationCustomScript() {
@Override
public AuthenticationScriptUsageType getUsageType() {
return AuthenticationScriptUsageType.INTERACTIVE;
}
};
customScript.setName(OxConstants.SCRIPT_TYPE_INTERNAL_RESERVED_NAME);
customScript.setLevel(-1);
return new CustomScriptConfiguration(customScript, internalDefaultPersonAuthenticationType, new HashMap<String, SimpleCustomProperty>(0));
}
Aggregations