We have a service setup that prepends the user name with a numerical code.
We do this with an inline groovy script:
"usernameAttributeProvider" : {
"@class" :
"org.apereo.cas.services.GroovyRegisteredServiceUsernameProvider",
"groovyScript" : "groovy { return '20115-'+attributes['cn'][0] }"
},
However, logins to this service are very slow and it appears that a lot of
time is spend executing the groovy script. From the debug logs, there is
an almost 7 second gap between executing the script and producing the value:
2019-03-05 11:39:22,003 DEBUG [org.apereo.cas.services.
GroovyRegisteredServiceUsernameProvider] - <Found groovy script to execute
[groovy
{ return '20115-'+attributes['cn'][0] }]>
2019-03-05 11:39:22,003 DEBUG [org.apereo.cas.util.ScriptingUtils] - <
Executing groovy script [return '20115-'+attributes['cn'][0] ] with
variables [{attributes={cn=[admin], givenName=[Admin], mail=[admin@host.
local], sn=[Admininstrator]}, [email protected], logger=org.apache.logging
.slf4j.Log4jLogger@6534b155}]>
2019-03-05 11:39:28,706 DEBUG [org.apereo.cas.services.
GroovyRegisteredServiceUsernameProvider] - <Found username [20115-admin]
from script [groovy { return '20115-'+attributes['cn'][0] }]>
2019-03-05 11:39:28,706 DEBUG [org.apereo.cas.services.
BaseRegisteredServiceUsernameAttributeProvider] - <Resolved username for [
https://localhost] is [20115-admin]>
It looks like the slow part is inside
ScriptingUtils.executeGroovyShellScript, most likely shell.evaluate.
public static <T> T executeGroovyShellScript(final String script,
final Map<String, Object>
variables,
final Class<T> clazz) {
try {
final Binding binding = new Binding();
final GroovyShell shell = new GroovyShell(binding);
if (variables != null && !variables.isEmpty()) {
variables.forEach(binding::setVariable);
}
if (!binding.hasVariable("logger")) {
binding.setVariable("logger", LOGGER);
}
LOGGER.debug("Executing groovy script [{}] with variables
[{}]", script, binding.getVariables());
final Object result = shell.evaluate(script);
if (result != null &&
!clazz.isAssignableFrom(result.getClass())) {
throw new ClassCastException("Result [" + result
+ " is of type " + result.getClass()
+ " when we were expecting " + clazz);
}
return (T) result;
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
}
return null;
}
I'm just curious if anyone else has run into slowness when executing inline
scripts and if so, is there any way to speed it up short of modifying
source code.
Abre
--
- Website: https://apereo.github.io/cas
- Gitter Chatroom: https://gitter.im/apereo/cas
- List Guidelines: https://goo.gl/1VRrw7
- Contributions: https://goo.gl/mh7qDG
---
You received this message because you are subscribed to the Google Groups "CAS
Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/a/apereo.org/d/msgid/cas-user/730e916c-cce0-4752-8069-1d39d13915fc%40apereo.org.