@Override public Principal createPrincipal(final String id, final Map<String, Object> attributes) { return ScriptingUtils.executeGroovyScript(this.groovyResource, new Object[]{id, attributes, LOGGER}, Principal.class, true); } }
@Override public Map<String, String> getSecurityQuestions(final String username) { return ScriptingUtils.executeGroovyScript(this.groovyResource, "getSecurityQuestions", new Object[]{username, LOGGER}, Map.class, true); } }
@Override public boolean send(final String from, final String to, final String message) { return ScriptingUtils.executeGroovyScript(this.groovyResource, new Object[]{from, to, message, LOGGER}, Boolean.class, true); } }
@Override public String transform(final String formUserId) { return ScriptingUtils.executeGroovyScript(this.script, new Object[]{formUserId, LOGGER}, String.class, true); } }
@Override public boolean supports(final Credential credential) { return ScriptingUtils.executeGroovyScript(this.groovyResource, "supports", new Object[]{credential, LOGGER}, Boolean.class, true); } }
@Override public void decorate(final RequestContext requestContext, final ApplicationContext applicationContext) { ScriptingUtils.executeGroovyScript(groovyScript, new Object[]{requestContext, applicationContext, LOGGER}, Void.class, true); } }
@Override public boolean process(final AuthenticationTransaction transaction) throws AuthenticationException { return ScriptingUtils.executeGroovyScript(this.groovyResource, new Object[]{transaction, LOGGER}, Boolean.class, true); }
/** * Execute. * * @param <T> the type parameter * @param args the args * @param clazz the clazz * @return the result */ public <T> T execute(final Object[] args, final Class<T> clazz) { if (this.groovyScript != null) { return ScriptingUtils.executeGroovyScript(this.groovyScript, args, clazz, true); } return null; }
@Override public String findUsername(final String email) { return ScriptingUtils.executeGroovyScript(this.groovyResource, "findUsername", new Object[]{email, LOGGER}, String.class, true); }
/** * Execute groovy script. * * @param <T> the type parameter * @param groovyScript the groovy script * @param methodName the method name * @param clazz the clazz * @return the t */ public static <T> T executeGroovyScript(final Resource groovyScript, final String methodName, final Class<T> clazz) { return executeGroovyScript(groovyScript, methodName, ArrayUtils.EMPTY_OBJECT_ARRAY, clazz, false); }
@Override public String findEmail(final String username) { return ScriptingUtils.executeGroovyScript(this.groovyResource, "findEmail", new Object[]{username, LOGGER}, String.class, true); }
@Override public boolean changeInternal(final @NonNull Credential credential, final @NonNull PasswordChangeBean bean) { return ScriptingUtils.executeGroovyScript(this.groovyResource, "change", new Object[]{credential, bean, LOGGER}, Boolean.class, true); }
@Override public Map<String, List<Object>> modifyAttributes(final Map<String, List<Object>> attributes) { val map = ScriptingUtils.executeGroovyScript(this.groovyScript, new Object[]{attributes, LOGGER}, Map.class, true); LOGGER.debug("Attributes mutated by [{}] are calculated as [{}]", getClass().getSimpleName(), map); return map; } }
@Override public List<MessageDescriptor> handle(final AuthenticationResponse response, final PasswordPolicyConfiguration configuration) { val applicationContext = ApplicationContextProvider.getApplicationContext(); return ScriptingUtils.executeGroovyScript(groovyResource, new Object[]{response, configuration, LOGGER, applicationContext}, List.class, true); } }
@Override public Map<String, Object> getAttributesInternal(final Principal principal, final Map<String, Object> attributes, final RegisteredService service) { try { final Object[] args = {attributes, LOGGER, principal, service}; val resource = ResourceUtils.getResourceFrom(this.groovyScript); return ScriptingUtils.executeGroovyScript(resource, args, Map.class, true); } catch (final Exception e) { LOGGER.error(e.getMessage(), e); } LOGGER.warn("Groovy script [{}] does not exist or cannot be loaded", groovyScript); return new HashMap<>(0); } }
@Override protected byte[] encode(final CharSequence rawPassword, final byte[] salt) { val resource = ApplicationContextProvider.getResourceLoader().getResource(this.scriptFile); final Object[] args = {rawPassword, salt, LOGGER, ApplicationContextProvider.getApplicationContext()}; return ScriptingUtils.executeGroovyScript(resource, args, byte[].class, true); } }
private Optional<Exception> getScriptExecutionResult(final Authentication auth, final Matcher matcherInline) { if (matcherInline.find()) { val args = CollectionUtils.wrap("principal", auth.getPrincipal(), "logger", LOGGER); val inlineScript = matcherInline.group(1); return ScriptingUtils.executeGroovyShellScript(inlineScript, args, Optional.class); } val res = this.resourceLoader.getResource(script); final Object[] args = {auth.getPrincipal(), LOGGER}; return ScriptingUtils.executeGroovyScript(res, args, Optional.class, true); } }
@Override public Map<String, Object> getAttributesForUser(final String uid) { val finalAttributes = new HashMap<String, Object>(); casProperties.getAuthn().getAttributeRepository().getGroovy() .forEach(groovy -> { val args = new Object[] {uid, LOGGER, casProperties, applicationContext}; val personAttributesMap = ScriptingUtils.executeGroovyScript(groovy.getLocation(), args, Map.class, true); finalAttributes.putAll(personAttributesMap); }); return finalAttributes; } }
@Override public void doInitialize() { val script = casProperties.getWebflow().getGroovy().getLocation(); if (script != null) { val args = new Object[]{this, applicationContext, LOGGER}; LOGGER.debug("Executing Groovy script [{}] to auto-configure the webflow context", script); ScriptingUtils.executeGroovyScript(script, args, Object.class, true); } } }
@Override public IPAddressIntelligenceResponse examineInternal(final RequestContext context, final String clientIpAddress) { val groovyResource = adaptiveAuthenticationProperties.getIpIntel().getGroovy().getLocation(); return ScriptingUtils.executeGroovyScript(groovyResource, new Object[]{context, clientIpAddress, LOGGER}, IPAddressIntelligenceResponse.class, true); } }