Skip to content

Commit

Permalink
feat(jans-config-api): config api interception script (#840)
Browse files Browse the repository at this point in the history
* feat: config-api interception script

* feat: config-api interception script

* feat: config-api interception script

* feat: config-api interception script
  • Loading branch information
pujavs authored Feb 17, 2022
1 parent 36458a1 commit 8e4c688
Show file tree
Hide file tree
Showing 20 changed files with 1,049 additions and 304 deletions.
1 change: 1 addition & 0 deletions jans-config-api/plugins/scim-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@

<build>
<filters>
<filter>../../profiles/${cfg}/config-build.properties</filter>
<filter>../../profiles/${cfg}/config-api-test.properties</filter>
</filters>

Expand Down
2 changes: 2 additions & 0 deletions jans-config-api/profiles/default/config-build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
log4j.default.log.level=INFO

11 changes: 11 additions & 0 deletions jans-config-api/server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@
<scope>provided</scope>
</dependency>

<!-- Quartz -->
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
</dependency>

<!-- Testing -->
<dependency>
<groupId>io.rest-assured</groupId>
Expand Down Expand Up @@ -187,6 +193,10 @@
<groupId>org.json</groupId>
<artifactId>json</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>jakarta.faces</artifactId>
</dependency>

<!-- jetty -->
<dependency>
Expand All @@ -207,6 +217,7 @@
<finalName>jans-config-api</finalName>

<filters>
<filter>../profiles/${cfg}/config-build.properties</filter>
<filter>../profiles/${cfg}/config-api-test.properties</filter>
</filters>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,21 @@
import io.jans.configapi.service.logger.LoggerService;
import io.jans.exception.ConfigurationException;
import io.jans.exception.OxIntializationException;
import io.jans.model.custom.script.CustomScriptType;
import io.jans.orm.PersistenceEntryManager;
import io.jans.orm.PersistenceEntryManagerFactory;
import io.jans.orm.service.PersistanceFactoryService;
import io.jans.service.PythonService;
import io.jans.service.cdi.event.LdapConfigurationReload;
import io.jans.service.cdi.util.CdiUtil;
import io.jans.service.custom.script.CustomScriptManager;
import io.jans.service.timer.QuartzSchedulerManager;
import io.jans.util.StringHelper;
import org.jboss.resteasy.plugins.server.servlet.ResteasyContextParameters;
import org.slf4j.Logger;
import java.util.ArrayList;

import java.util.List;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.context.BeforeDestroyed;
Expand Down Expand Up @@ -64,46 +70,63 @@ public class AppInitializer {

@Inject
private Instance<AuthorizationService> authorizationServiceInstance;

@Inject
StatusCheckerTimer statusCheckerTimer;

@Inject
private LoggerService loggerService;

@Inject
private QuartzSchedulerManager quartzSchedulerManager;

@Inject
private CustomScriptManager customScriptManager;

@Inject
private PythonService pythonService;

public void onStart(@Observes @Initialized(ApplicationScoped.class) Object init) {
log.info("========================== Initializing - App =======================================");
log.info("============= STARTING API APPLICATION ========================");
log.info("init:{}",init);
log.info("init:{}", init);

// Resteasy config - Turn off the default patch filter
System.setProperty(ResteasyContextParameters.RESTEASY_PATCH_FILTER_DISABLED, "true");
ResteasyProviderFactory instance = ResteasyProviderFactory.getInstance();
RegisterBuiltin.register(instance);
instance.registerProvider(ResteasyJackson2Provider.class);

// configuration
this.configurationFactory.create();
persistenceEntryManagerInstance.get();
this.createAuthorizationService();

// Initialize python interpreter
pythonService
.initPythonInterpreter(configurationFactory.getBaseConfiguration().getString("pythonModulesDir", null));

// Start timer
initSchedulerService();


// Initialize custom Script
initCustomScripts();

// Stats timer
statusCheckerTimer.initTimer();

// Schedule timer tasks
loggerService.initTimer();

ResteasyProviderFactory instance = ResteasyProviderFactory.getInstance();
RegisterBuiltin.register(instance);
instance.registerProvider(ResteasyJackson2Provider.class);

// Schedule timer tasks
configurationFactory.initTimer();

log.info("============== APPLICATION IS UP AND RUNNING ===================");
log.info("========================== App - Initialized =======================================");
}

public void destroy(@Observes @BeforeDestroyed(ApplicationScoped.class) ServletContext init) {
log.info("================================================================");
log.info("=========== API APPLICATION STOPPED ==========================");
log.info("init:{}",init);
log.info("init:{}", init);
log.info("================================================================");
}

Expand Down Expand Up @@ -143,8 +166,12 @@ private AuthorizationService createAuthorizationService() {
configurationFactory.getApiClientId());
return authorizationServiceInstance.select(OpenIdAuthorizationService.class).get();
} catch (Exception ex) {
log.error("Failed to create AuthorizationService instance", ex);
throw new ConfigurationException("Failed to create AuthorizationService instance", ex);
if (log.isErrorEnabled()) {
log.error("Failed to create AuthorizationService instance - apiProtectionType:{}, exception:{} ",
configurationFactory.getApiProtectionType(), ex);
}
throw new ConfigurationException("Failed to create AuthorizationService instance - apiProtectionType = "
+ configurationFactory.getApiProtectionType(), ex);
}
}

Expand All @@ -169,7 +196,7 @@ private void closePersistenceEntryManager() {
}

protected void initSchedulerService() {
log.debug(" \n\n initSchedulerService - Entry \n\n");
log.debug("Initializing Scheduler Service");
quartzSchedulerManager.start();

String disableScheduler = System.getProperties().getProperty("gluu.disable.scheduler");
Expand All @@ -178,4 +205,11 @@ protected void initSchedulerService() {
quartzSchedulerManager.standby();
}
}

private void initCustomScripts() {
List<CustomScriptType> supportedCustomScriptTypes = new ArrayList<>();
supportedCustomScriptTypes.add(CustomScriptType.CONFIG_API);
customScriptManager.initTimer(supportedCustomScriptTypes);
log.info("Initialized Custom Scripts!");
}
}
Loading

0 comments on commit 8e4c688

Please sign in to comment.