Skip to content

Commit

Permalink
chore(agama): place configuration inside AS configuration (#1405)
Browse files Browse the repository at this point in the history
* fix(agama): adjust pom version #1402 (#1403)

* fix(agama): adjust pom version #1402 (#1404)

* feat: add enabled config property; deny service when false #1388

* chore: remove fat jar generation #1388

* chore: include agama config in AS configuration #1388
  • Loading branch information
jgomer2001 committed May 20, 2022
1 parent 9644d1b commit 9b5bb0d
Show file tree
Hide file tree
Showing 15 changed files with 79 additions and 59 deletions.
48 changes: 4 additions & 44 deletions agama/engine/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,6 @@
</repository>
</repositories>

<!--build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build-->

<dependencies>

<dependency>
Expand All @@ -67,28 +43,24 @@
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<scope>provided</scope>
</dependency>

<!-- JSF -->
<dependency>
<groupId>jakarta.faces</groupId>
<artifactId>jakarta.faces-api</artifactId>
<scope>provided</scope>
<artifactId>jakarta.faces-api</artifactId>
</dependency>

<!-- JAX-RS -->
<dependency>
<groupId>org.jboss.spec.javax.ws.rs</groupId>
<artifactId>jboss-jaxrs-api_3.0_spec</artifactId>
<scope>provided</scope>
</dependency>

<!-- WELD -->
<dependency>
<groupId>org.jboss.weld.servlet</groupId>
<artifactId>weld-servlet-shaded</artifactId>
<scope>provided</scope>
<artifactId>weld-servlet-core</artifactId>
</dependency>

<!-- FREEMARKER -->
Expand All @@ -102,34 +74,28 @@
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<scope>provided</scope>
</dependency>

<!-- JACKSON -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<scope>provided</scope>
</dependency>

<!-- Mozilla Rhino -->
Expand All @@ -143,40 +109,34 @@
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy</artifactId>
<version>3.0.7</version>
<version>3.0.10</version>
</dependency>

<!-- JANS -->
<dependency>
<groupId>io.jans</groupId>
<artifactId>jans-core-util</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.jans</groupId>
<artifactId>jans-core-cdi</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.jans</groupId>
<artifactId>jans-core-service</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.jans</groupId>
<artifactId>jans-orm-core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.jans</groupId>
<artifactId>jans-auth-model</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
Expand All @@ -187,4 +147,4 @@

</dependencies>

</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ public int getEffectiveInterruptionTime() {
return effectiveInterruptionTime;
}

public boolean serviceEnabled() {
return engineConfig.isEnabled();
}

/**
* It is assumed that values in the map are String arrays with at least one element
* @param map
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.jans.agama.engine.servlet;

import io.jans.agama.engine.exception.TemplateProcessingException;
import io.jans.agama.engine.misc.FlowUtils;
import io.jans.agama.engine.page.BasicTemplateModel;
import io.jans.agama.engine.page.Page;
import io.jans.agama.engine.service.TemplatingService;
Expand All @@ -16,6 +17,9 @@

public abstract class BaseServlet extends HttpServlet {

@Inject
protected FlowUtils flowUtils;

@Inject
private TemplatingService templatingService;

Expand All @@ -28,6 +32,11 @@ public abstract class BaseServlet extends HttpServlet {
protected boolean isJsonRequest(HttpServletRequest request) {
return MediaType.APPLICATION_JSON.equals(request.getContentType());
}

protected void sendNotAvailable(HttpServletResponse response) throws IOException {
response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE,
"Flow engine not available. Check if Agama has been enabled in your configuration.");
}

protected void sendFlowTimeout(HttpServletResponse response, boolean jsonResponse, String message)
throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ public class ExecutionServlet extends BaseServlet {

@Inject
private FlowService flowService;

@Inject
private FlowUtils flowUtils;


@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
Expand Down Expand Up @@ -124,6 +121,11 @@ public void doPost(HttpServletRequest request, HttpServletResponse response)
public void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

if (!flowUtils.serviceEnabled()) {
sendNotAvailable(response);
return;
}

String method = request.getMethod();
String path = request.getServletPath();
boolean match = path.startsWith(URL_PREFIX);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ public class RestartServlet extends BaseServlet {
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

if (!flowUtils.serviceEnabled()) {
sendNotAvailable(response);
return;
}

logger.debug("Restart servlet");
try {
FlowStatus st = flowService.getRunningFlowStatus();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.jans.agama.timer;

import io.jans.agama.engine.misc.FlowUtils;
import io.jans.agama.engine.model.FlowRun;
import io.jans.orm.PersistenceEntryManager;
import io.jans.orm.search.filter.Filter;
Expand Down Expand Up @@ -32,11 +33,14 @@ public class FlowRunsCleaner {

@Inject
private PersistenceEntryManager entryManager;

private AtomicBoolean isActive;

@Inject
private Event<TimerEvent> timerEvent;

@Inject
private FlowUtils futils;

private AtomicBoolean isActive;

public void initTimer() {

Expand All @@ -50,6 +54,8 @@ public void initTimer() {
@Asynchronous
public void run(@Observes @Scheduled FlowRunsCleanerEvent event) {

if (!futils.serviceEnabled()) return;

if (isActive.get()) return;

if (!isActive.compareAndSet(false, true)) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ public void initTimer() {
@Asynchronous
public void run(@Observes @Scheduled TranspilationEvent event) {

if (!futils.serviceEnabled()) return;

if (isActive.get()) return;

if (!isActive.compareAndSet(false, true)) return;
Expand Down
6 changes: 6 additions & 0 deletions agama/misc/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Copyright (c) 2020, Janssen Project
#
from io.jans.agama import NativeJansFlowBridge
from io.jans.agama.engine.misc import FlowUtils
from io.jans.as.server.service import AuthenticationService, SessionIdService
from io.jans.jsf2.service import FacesService
from io.jans.jsf2.message import FacesMessages
Expand Down Expand Up @@ -84,6 +85,11 @@ def authenticate(self, configurationAttributes, requestParameters, step):


def prepareForStep(self, configurationAttributes, requestParameters, step):

if not CdiUtil.bean(FlowUtils).serviceEnabled():
print "Agama. Please ENABLE Agama engine in auth-server configuration"
return False

if step == 1:
print "Agama. Prepare for Step 1"

Expand Down
3 changes: 0 additions & 3 deletions agama/model/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,14 @@
<dependency>
<groupId>io.jans</groupId>
<artifactId>jans-orm-model</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.jans</groupId>
<artifactId>jans-core-util</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.ws.rs</groupId>
<artifactId>jboss-jaxrs-api_3.0_spec</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>

Expand Down
10 changes: 10 additions & 0 deletions agama/model/src/main/java/io/jans/agama/model/EngineConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
@JsonIgnoreProperties(ignoreUnknown = true)
public class EngineConfig {

private boolean enabled;

private String rootDir = Path.of(System.getProperty("server.base"), "agama").toString();
private String templatesPath = "/ftl";
private String scriptsPath = "/scripts";
Expand Down Expand Up @@ -55,6 +57,14 @@ public String getJsonFinishedFlowPage() {
return "json_"+ finishedFlowPage;
}

public boolean isEnabled() {
return enabled;
}

public void setEnabled(boolean enabled) {
this.enabled = enabled;
}

public String getRootDir() {
return rootDir;
}
Expand Down
4 changes: 0 additions & 4 deletions agama/transpiler/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,20 @@
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<scope>provided</scope>
</dependency>

<!-- JACKSON -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<scope>provided</scope>
</dependency>

</dependencies>
Expand Down
5 changes: 5 additions & 0 deletions jans-auth-server/model/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@
<groupId>io.jans</groupId>
<artifactId>jans-core-model</artifactId>
</dependency>
<dependency>
<groupId>io.jans</groupId>
<artifactId>agama-model</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.jboss.resteasy</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.google.common.collect.Lists;

import io.jans.agama.model.EngineConfig;
import io.jans.as.model.common.*;
import io.jans.as.model.error.ErrorHandlingMethod;
import io.jans.as.model.jwk.KeySelectionStrategy;
Expand Down Expand Up @@ -313,6 +315,8 @@ public class AppConfiguration implements Configuration {
private Boolean httpLoggingEnabled; // Used in ServletLoggingFilter to enable http request/response logging.
private Set<String> httpLoggingExcludePaths; // Used in ServletLoggingFilter to exclude some paths from logger. Paths example: ["/jans-auth/img", "/jans-auth/stylesheet"]
private String externalLoggerConfiguration; // Path to external log4j2 configuration file. This property might be configured from oxTrust: /identity/logviewer/configure

private EngineConfig agamaConfiguration;

public Boolean getRequireRequestObjectEncryption() {
if (requireRequestObjectEncryption == null) requireRequestObjectEncryption = false;
Expand Down Expand Up @@ -2502,4 +2506,12 @@ public Boolean getUseHighestLevelScriptIfAcrScriptNotFound() {
public void setUseHighestLevelScriptIfAcrScriptNotFound(Boolean useHighestLevelScriptIfAcrScriptNotFound) {
this.useHighestLevelScriptIfAcrScriptNotFound = useHighestLevelScriptIfAcrScriptNotFound;
}

public EngineConfig getAgamaConfiguration() {
return agamaConfiguration;
}

public void setAgamaConfiguration(EngineConfig agamaConfiguration) {
this.agamaConfiguration = agamaConfiguration;
}
}
Loading

0 comments on commit 9b5bb0d

Please sign in to comment.