public GroovyScriptInterruptInquirer(final Resource resource) { this.watchableScript = new WatchableGroovyScriptResource(resource); }
private void writeAccountToGroovyResource(final ConsentDecision decision) { watchableScript.execute("write", Boolean.class, decision, LOGGER); }
@Override public boolean shouldMultifactorAuthenticationProviderExecute(final Authentication authentication, final RegisteredService registeredService, final MultifactorAuthenticationProvider provider, final HttpServletRequest request) { try { val principal = authentication.getPrincipal(); LOGGER.debug("Evaluating multifactor authentication bypass properties for principal [{}], " + "service [{}] and provider [{}] via Groovy script [{}]", principal.getId(), registeredService, provider, watchableScript.getResource()); val args = new Object[]{authentication, principal, registeredService, provider, LOGGER, request}; return watchableScript.execute(args, Boolean.class); } catch (final Exception e) { LOGGER.error(e.getMessage(), e); return true; } } }
@SneakyThrows public WatchableGroovyScriptResource(final Resource script) { this.resource = script; if (ResourceUtils.doesResourceExist(script)) { this.watcherService = new FileWatcherService(script.getFile(), file -> { try { LOGGER.debug("Reloading script at [{}]", file); compileScriptResource(script); } catch (final Exception e) { LOGGER.error(e.getMessage(), e); } }); this.watcherService.start(script.getFilename()); compileScriptResource(script); } }
@Override public InterruptResponse inquireInternal(final Authentication authentication, final RegisteredService registeredService, final Service service, final Credential credential, final RequestContext requestContext) { if (ResourceUtils.doesResourceExist(watchableScript.getResource())) { val principal = authentication.getPrincipal(); val attributes = new HashMap<String, Object>(principal.getAttributes()); attributes.putAll(authentication.getAttributes()); final Object[] args = {principal.getId(), attributes, service != null ? service.getId() : null, LOGGER}; return watchableScript.execute(args, InterruptResponse.class); } return InterruptResponse.none(); } }
public GroovyConsentRepository(final Resource groovyResource) { this.watchableScript = new WatchableGroovyScriptResource(groovyResource); setConsentDecisions(readDecisionsFromGroovyResource()); }
@Override public boolean deleteConsentDecision(final long decisionId, final String principal) { super.deleteConsentDecision(decisionId, principal); return watchableScript.execute("delete", Boolean.class, decisionId, principal, LOGGER); }
public GroovyMultifactorAuthenticationProviderBypass(final MultifactorAuthenticationProviderBypassProperties bypass) { val groovyScript = bypass.getGroovy().getLocation(); this.watchableScript = new WatchableGroovyScriptResource(groovyScript); }
private Set<ConsentDecision> readDecisionsFromGroovyResource() { return watchableScript.execute("read", Set.class, getConsentDecisions(), LOGGER); } }
public GroovyScriptMultifactorAuthenticationTrigger(final CasConfigurationProperties casProperties) { this.casProperties = casProperties; val groovyScript = casProperties.getAuthn().getMfa().getGroovyScript(); this.watchableScript = new WatchableGroovyScriptResource(groovyScript); }
val provider = this.watchableScript.execute(args, String.class); LOGGER.debug("Groovy script run for [{}] returned the provider id [{}]", registeredService, provider); if (StringUtils.isBlank(provider)) {