use of javax.script.SimpleBindings in project OpenAM by OpenRock.
the class AbstractSandboxTests method shouldBeAllowedToAccessWhiteListedInstance.
@Test
public void shouldBeAllowedToAccessWhiteListedInstance() throws Exception {
// Given
Allowed allowed = new Allowed();
Bindings bindings = new SimpleBindings();
bindings.put("allowed", allowed);
// When
eval(bindings, "allowed.setDirty()");
// Then
assertThat(allowed.dirty).isTrue();
}
use of javax.script.SimpleBindings in project OpenAM by OpenRock.
the class ChainedBindingsTest method setupTestObjects.
@BeforeMethod
public void setupTestObjects() {
currentScope = new SimpleBindings();
parentScope = new SimpleBindings();
chainedBindings = new ChainedBindings(parentScope, currentScope);
}
use of javax.script.SimpleBindings in project OpenAM by OpenRock.
the class OpenAMScopeValidator method getUserInfo.
/**
* {@inheritDoc}
*/
public UserInfoClaims getUserInfo(AccessToken token, OAuth2Request request) throws UnauthorizedClientException, NotFoundException {
Map<String, Object> response = new HashMap<>();
Bindings scriptVariables = new SimpleBindings();
SSOToken ssoToken = getUsersSession(request);
String realm;
Set<String> scopes;
AMIdentity id;
OAuth2ProviderSettings providerSettings = providerSettingsFactory.get(request);
Map<String, Set<String>> requestedClaimsValues = gatherRequestedClaims(providerSettings, request, token);
try {
if (token != null) {
OpenIdConnectClientRegistration clientRegistration;
try {
clientRegistration = clientRegistrationStore.get(token.getClientId(), request);
} catch (InvalidClientException e) {
logger.message("Unable to retrieve client from store.");
throw new NotFoundException("No valid client registration found.");
}
final String subId = clientRegistration.getSubValue(token.getResourceOwnerId(), providerSettings);
//data comes from token when we have one
realm = token.getRealm();
scopes = token.getScope();
id = identityManager.getResourceOwnerIdentity(token.getResourceOwnerId(), realm);
response.put(OAuth2Constants.JWTTokenParams.SUB, subId);
response.put(OAuth2Constants.JWTTokenParams.UPDATED_AT, getUpdatedAt(token.getResourceOwnerId(), token.getRealm(), request));
} else {
//otherwise we're simply reading claims into the id_token, so grab it from the request/ssoToken
realm = DNMapper.orgNameToRealmName(ssoToken.getProperty(ISAuthConstants.ORGANIZATION));
id = identityManager.getResourceOwnerIdentity(ssoToken.getProperty(ISAuthConstants.USER_ID), realm);
String scopeStr = request.getParameter(OAuth2Constants.Params.SCOPE);
scopes = splitScope(scopeStr);
}
scriptVariables.put(OAuth2Constants.ScriptParams.SCOPES, getScriptFriendlyScopes(scopes));
scriptVariables.put(OAuth2Constants.ScriptParams.IDENTITY, id);
scriptVariables.put(OAuth2Constants.ScriptParams.LOGGER, logger);
scriptVariables.put(OAuth2Constants.ScriptParams.CLAIMS, response);
scriptVariables.put(OAuth2Constants.ScriptParams.SESSION, ssoToken);
scriptVariables.put(OAuth2Constants.ScriptParams.REQUESTED_CLAIMS, requestedClaimsValues);
ScriptObject script = getOIDCClaimsExtensionScript(realm);
try {
return scriptEvaluator.evaluateScript(script, scriptVariables);
} catch (ScriptException e) {
logger.message("Error running OIDC claims script", e);
throw new ServerException("Error running OIDC claims script: " + e.getMessage());
}
} catch (ServerException e) {
//API does not allow ServerExceptions to be thrown!
throw new NotFoundException(e.getMessage());
} catch (SSOException e) {
throw new NotFoundException(e.getMessage());
}
}
use of javax.script.SimpleBindings in project logging-log4j2 by apache.
the class ScriptCondition method selectFilesToDelete.
/**
* Executes the script
*
* @param baseDir
* @param candidates
* @return
*/
@SuppressWarnings("unchecked")
public List<PathWithAttributes> selectFilesToDelete(final Path basePath, final List<PathWithAttributes> candidates) {
final SimpleBindings bindings = new SimpleBindings();
bindings.put("basePath", basePath);
bindings.put("pathList", candidates);
bindings.putAll(configuration.getProperties());
bindings.put("configuration", configuration);
bindings.put("substitutor", configuration.getStrSubstitutor());
bindings.put("statusLogger", LOGGER);
final Object object = configuration.getScriptManager().execute(script.getName(), bindings);
return (List<PathWithAttributes>) object;
}
use of javax.script.SimpleBindings in project logging-log4j2 by apache.
the class ScriptFilter method filter.
@Override
public Result filter(final Logger logger, final Level level, final Marker marker, final Object msg, final Throwable t) {
final SimpleBindings bindings = new SimpleBindings();
bindings.put("logger", logger);
bindings.put("level", level);
bindings.put("marker", marker);
bindings.put("message", msg instanceof String ? new SimpleMessage((String) msg) : new ObjectMessage(msg));
bindings.put("parameters", null);
bindings.put("throwable", t);
bindings.putAll(configuration.getProperties());
bindings.put("substitutor", configuration.getStrSubstitutor());
final Object object = configuration.getScriptManager().execute(script.getName(), bindings);
return object == null || !Boolean.TRUE.equals(object) ? onMismatch : onMatch;
}
Aggregations