/*
* The contents of this file are subject to the terms of the Common Development and
* Distribution License (the License). You may not use this file except in compliance with the
* License.
*
* You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
* specific language governing permission and limitations under the License.
*
* When distributing Covered Software, include this CDDL Header Notice in each file and include
* the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
* Header, with the fields enclosed by brackets [] replaced by your own identifying
* information: "Portions copyright [year] [name of copyright owner]".
*
* Copyright 2014-2015 ForgeRock AS.
*/
/**
* Responsible for executing any augment security context and providing the required parameters to the scripts.
*
* @since 3.0.0
*/
class AugmentationScriptExecutor {
/**
* Executes the specified augmentation script with the given properties and SecurityContextMapper.
*
* @param augmentScript The augment script entry.
* @param properties The properties to be provided to the script.
* @param securityContextMapper A SecurityContextMapper instance.
* @throws AuthenticationException If any problem occurs whilst executing the script.
*/
if (augmentScript == null) {
return;
}
try {
if (!augmentScript.isActive()) {
throw new ServiceUnavailableException("Failed to execute inactive script: "
}
// Create internal Context chain for script-call
// Pass auth module properties and SecurityContextWrapper details to augmentation script
// expect updated security context
// if security context is updated; update the SecurityContextMapper backing store
securityContextMapper.setAuthenticationId(updatedSecurityContext.get(SecurityContextMapper.AUTHENTICATION_ID).asString());
}
securityContextMapper.setAuthorizationId((updatedSecurityContext.get(SecurityContextMapper.AUTHORIZATION).asMap()));
}
} catch (ScriptThrownException e) {
final ResourceException re = e.toResourceException(ResourceException.INTERNAL_ERROR, e.getMessage());
logger.error("{} when attempting to execute script {}", re.toString(), augmentScript.getName(), re);
} catch (ScriptException e) {
throw new AuthenticationException(e.getMessage(), e);
} catch (ResourceException e) {
throw new AuthenticationException(e.getMessage(), e);
}
}
}