private String getGluuSimplePersonAttributesWithValues(GluuSimplePerson gluuSimplePerson) { StringBuilder sb = new StringBuilder(); int index = 0; for (GluuCustomAttribute customAttribute : gluuSimplePerson.getCustomAttributes()) { // TODO: Do we need this? if (index > 0) { sb.append("\n"); } sb.append("\n").append(customAttribute.getName()).append(": '"); if ((customAttribute.getValues() != null) && (customAttribute.getValues().length > 1)) { sb.append(Arrays.toString(customAttribute.getValues())); } else { sb.append(customAttribute.getValue()); } sb.append("'"); index++; } return sb.toString(); }
public void validateInterceptorScript() { String result = update(); if (!OxTrustConstants.RESULT_SUCCESS.equals(result)) { return; } // Reinit dialog init(); this.showInterceptorValidationDialog = true; boolean loadedScripts = externalCacheRefreshService.getCustomScriptConfigurations().size() > 0; if (!loadedScripts) { String message = "Can't load Cache Refresh scripts. Using default script"; log.error(message); this.interceptorValidationMessage = message; return; } // Prepare data for dummy entry String targetInum = inumService.generateInums(OxTrustConstants.INUM_TYPE_PEOPLE_SLUG, false); String targetPersonDn = personService.getDnForPerson(targetInum); String[] targetCustomObjectClasses = applicationConfiguration.getPersonObjectClassTypes(); // Collect all attributes String[] keyAttributesWithoutValues = getCompoundKeyAttributesWithoutValues(cacheRefreshConfiguration); String[] sourceAttributes = getSourceAttributes(cacheRefreshConfiguration); // Merge all attributes into one set Set<String> allAttributes = new HashSet<String>(); for (String attribute : keyAttributesWithoutValues) { allAttributes.add(attribute); } for (String attribute : sourceAttributes) { allAttributes.add(attribute); } // Prepare source person entry with default attributes values GluuSimplePerson sourcePerson = new GluuSimplePerson(); List<GluuCustomAttribute> customAttributes = sourcePerson.getCustomAttributes(); for (String attribute : allAttributes) { customAttributes.add(new GluuCustomAttribute(attribute, "Test value")); } // Prepare target person GluuCustomPerson targetPerson = new GluuCustomPerson(); targetPerson.setDn(targetPersonDn); targetPerson.setInum(targetInum); targetPerson.setStatus(GluuStatus.ACTIVE); targetPerson.setCustomObjectClasses(targetCustomObjectClasses); // Execute mapping according to configuration Map<String, String> targetServerAttributesMapping = getTargetServerAttributesMapping(cacheRefreshConfiguration); cacheRefreshService.setTargetEntryAttributes( sourcePerson, targetServerAttributesMapping, targetPerson); // Execute interceptor script boolean executionResult = externalCacheRefreshService.executeExternalUpdateUserMethods(targetPerson); if (!executionResult) { String message = "Can't execute Cache Refresh scripts."; log.error(message); this.interceptorValidationMessage = message; return; } log.info( "Script has been executed successfully.\n\nSample source entry is:\n'{0}'.\n\nSample result entry is:\n'{1}'", getGluuSimplePersonAttributesWithValues(sourcePerson), getGluuCustomPersonAttributesWithValues(targetPerson)); this.interceptorValidationMessage = String.format( "Script has been executed successfully.\n\nSample source entry is:\n%s.\n\nSample result entry is:\n%s", getGluuSimplePersonAttributesWithValues(sourcePerson), getGluuCustomPersonAttributesWithValues(targetPerson)); }