Search in sources :

Example 1 with ScriptingService

use of org.forgerock.openam.scripting.service.ScriptingService in project OpenAM by OpenRock.

the class ScriptedAuthModulesStep method upgradeScriptedAuthModules.

private void upgradeScriptedAuthModules(String realm, Set<ScriptData> scriptDataSet) throws AMConfigurationException, ScriptException, SSOException, SMSException {
    ScriptingService service = serviceFactory.create(getAdminSubject(), realm);
    AMAuthenticationManager authManager = new AMAuthenticationManager(getAdminToken(), realm);
    for (ScriptData scriptData : scriptDataSet) {
        Map<String, Set<String>> attributes = new HashMap<>();
        UpgradeProgress.reportStart("upgrade.scripted.auth.server.script.start", scriptData.serverSideScript.getName(), realm);
        service.create(scriptData.serverSideScript);
        attributes.put(SERVER_SCRIPT, Collections.singleton(scriptData.serverSideScript.getId()));
        UpgradeProgress.reportEnd("upgrade.success");
        if (scriptData.clientSideScript != null) {
            UpgradeProgress.reportStart("upgrade.scripted.auth.client.script.start", scriptData.clientSideScript.getName(), realm);
            service.create(scriptData.clientSideScript);
            attributes.put(CLIENT_SCRIPT, Collections.singleton(scriptData.clientSideScript.getId()));
            UpgradeProgress.reportEnd("upgrade.success");
        } else {
            attributes.put(CLIENT_SCRIPT, Collections.singleton(EMPTY_SCRIPT_SELECTION));
        }
        UpgradeProgress.reportStart("upgrade.scripted.auth.module.script.start", scriptData.moduleName, realm);
        AMAuthenticationInstance instance = authManager.getAuthenticationInstance(scriptData.moduleName);
        if (instance != null) {
            instance.setAttributeValues(attributes);
            UpgradeProgress.reportEnd("upgrade.success");
        } else {
            DEBUG.error("Scripted module {} in realm {} could not be found", scriptData.moduleName, realm);
            UpgradeProgress.reportEnd("upgrade.failed");
        }
    }
}
Also used : ScriptingService(org.forgerock.openam.scripting.service.ScriptingService) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) AMAuthenticationInstance(com.sun.identity.authentication.config.AMAuthenticationInstance) AMAuthenticationManager(com.sun.identity.authentication.config.AMAuthenticationManager)

Example 2 with ScriptingService

use of org.forgerock.openam.scripting.service.ScriptingService in project OpenAM by OpenRock.

the class ScriptingGuiceModule method configure.

@Override
protected void configure() {
    bind(ScriptValidator.class).to(StandardScriptValidator.class);
    bind(Logger.class).annotatedWith(Names.named("ScriptLogger")).toInstance(logger);
    install(new FactoryModuleBuilder().implement(new TypeLiteral<ScriptingService>() {
    }, ScriptConfigurationService.class).build(new TypeLiteral<ScriptingServiceFactory>() {
    }));
    install(new FactoryModuleBuilder().implement(new TypeLiteral<ScriptingDataStore>() {
    }, ScriptConfigurationDataStore.class).build(new TypeLiteral<ScriptingDataStoreFactory>() {
    }));
    bind(StandardScriptEngineManager.class).annotatedWith(Names.named(AUTHENTICATION_SERVER_SIDE.name())).toInstance(new StandardScriptEngineManager());
    bind(StandardScriptEngineManager.class).annotatedWith(Names.named(POLICY_CONDITION.name())).toInstance(new StandardScriptEngineManager());
    bind(StandardScriptEngineManager.class).annotatedWith(Names.named(OIDC_CLAIMS.name())).toInstance(new StandardScriptEngineManager());
    bind(RestletHttpClient.class).annotatedWith(Names.named(SupportedScriptingLanguage.JAVASCRIPT.name())).to(JavaScriptHttpClient.class);
    bind(RestletHttpClient.class).annotatedWith(Names.named(SupportedScriptingLanguage.GROOVY.name())).to(GroovyHttpClient.class);
    try {
        bind(Client.class).annotatedWith(Names.named("ScriptingHttpClient")).toInstance(new Client(new HttpClientHandler()));
    } catch (HttpApplicationException e) {
        logger.error("Failed to create HttpClientHandler", e);
    }
}
Also used : StandardScriptEngineManager(org.forgerock.openam.scripting.StandardScriptEngineManager) ScriptingService(org.forgerock.openam.scripting.service.ScriptingService) TypeLiteral(com.google.inject.TypeLiteral) FactoryModuleBuilder(com.google.inject.assistedinject.FactoryModuleBuilder) ScriptingDataStore(org.forgerock.openam.scripting.datastore.ScriptingDataStore) StandardScriptValidator(org.forgerock.openam.scripting.StandardScriptValidator) ScriptValidator(org.forgerock.openam.scripting.ScriptValidator) RestletHttpClient(org.forgerock.http.client.RestletHttpClient) JavaScriptHttpClient(org.forgerock.openam.scripting.api.http.JavaScriptHttpClient) Client(org.forgerock.http.Client) GroovyHttpClient(org.forgerock.openam.scripting.api.http.GroovyHttpClient) HttpClientHandler(org.forgerock.http.handler.HttpClientHandler) HttpApplicationException(org.forgerock.http.HttpApplicationException)

Example 3 with ScriptingService

use of org.forgerock.openam.scripting.service.ScriptingService in project OpenAM by OpenRock.

the class ScriptResourceTest method setUp.

@BeforeMethod
public void setUp() throws ResourceException {
    Logger logger = mock(Logger.class);
    ScriptingService scriptingService = new MockScriptingService();
    ScriptingServiceFactory serviceFactory = mock(ScriptingServiceFactory.class);
    when(serviceFactory.create(any(Subject.class), anyString())).thenReturn(scriptingService);
    ExceptionMappingHandler<ScriptException, ResourceException> errorHandler = new ScriptExceptionMappingHandler();
    scriptResource = new ScriptResource(logger, serviceFactory, errorHandler, new StandardScriptValidator(new StandardScriptEngineManager()));
    context = mock(Context.class);
    given(context.asContext(HttpContext.class)).willReturn(new HttpContext(json(object(field("headers", Collections.emptyMap()), field("parameters", Collections.emptyMap()))), null));
}
Also used : StandardScriptEngineManager(org.forgerock.openam.scripting.StandardScriptEngineManager) HttpContext(org.forgerock.json.resource.http.HttpContext) ScriptContext(org.forgerock.openam.scripting.ScriptConstants.ScriptContext) Context(org.forgerock.services.context.Context) ScriptingService(org.forgerock.openam.scripting.service.ScriptingService) HttpContext(org.forgerock.json.resource.http.HttpContext) StandardScriptValidator(org.forgerock.openam.scripting.StandardScriptValidator) Logger(org.slf4j.Logger) ScriptingServiceFactory(org.forgerock.openam.scripting.service.ScriptingServiceFactory) Subject(javax.security.auth.Subject) ScriptException(org.forgerock.openam.scripting.ScriptException) ResourceException(org.forgerock.json.resource.ResourceException) ScriptExceptionMappingHandler(org.forgerock.openam.scripting.rest.ScriptExceptionMappingHandler) ScriptResource(org.forgerock.openam.scripting.rest.ScriptResource) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

ScriptingService (org.forgerock.openam.scripting.service.ScriptingService)3 StandardScriptEngineManager (org.forgerock.openam.scripting.StandardScriptEngineManager)2 StandardScriptValidator (org.forgerock.openam.scripting.StandardScriptValidator)2 TypeLiteral (com.google.inject.TypeLiteral)1 FactoryModuleBuilder (com.google.inject.assistedinject.FactoryModuleBuilder)1 AMAuthenticationInstance (com.sun.identity.authentication.config.AMAuthenticationInstance)1 AMAuthenticationManager (com.sun.identity.authentication.config.AMAuthenticationManager)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Subject (javax.security.auth.Subject)1 Client (org.forgerock.http.Client)1 HttpApplicationException (org.forgerock.http.HttpApplicationException)1 RestletHttpClient (org.forgerock.http.client.RestletHttpClient)1 HttpClientHandler (org.forgerock.http.handler.HttpClientHandler)1 ResourceException (org.forgerock.json.resource.ResourceException)1 HttpContext (org.forgerock.json.resource.http.HttpContext)1 ScriptContext (org.forgerock.openam.scripting.ScriptConstants.ScriptContext)1 ScriptException (org.forgerock.openam.scripting.ScriptException)1 ScriptValidator (org.forgerock.openam.scripting.ScriptValidator)1