Skip to content

Commit

Permalink
feat: healt-check should check script manager initialization status (#…
Browse files Browse the repository at this point in the history
…8220)

feat: healt-check should check script manager initialization status #8219

Signed-off-by: Yuriy Movchan <Yuriy.Movchan@gmail.com>
  • Loading branch information
yurem committed Apr 3, 2024
1 parent 853d9f1 commit 02d4cd1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ def processOtpAuthentication(self, requestParameters, user, identity, otp_auth_m
validation_result = self.validateHotpKey(otp_secret_key, moving_factor, otpCode)
if (validation_result != None) and validation_result["result"]:
print "OTP. Process HOTP authentication during authentication. otpCode is valid"

# Update current moving factor in user entry
enrolledAuthenticator.addCustom("movingFactor", moving_factor)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import io.jans.as.server.service.external.ExternalDynamicScopeService;
import io.jans.as.server.service.external.ExternalHealthCheckService;
import io.jans.orm.PersistenceEntryManager;
import io.jans.service.custom.script.CustomScriptManager;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.servlet.http.HttpServletRequest;
Expand Down Expand Up @@ -50,6 +51,9 @@ public class HealthCheckController {
@Inject
private ExternalHealthCheckService externalHealthCheckService;

@Inject
private CustomScriptManager сustomScriptManager;

@GET
@POST
@Path("/health-check")
Expand All @@ -74,7 +78,7 @@ public String healthCheckController(@Context HttpServletRequest httpRequest, @Co
}

public String getAppStatus() {
if (externalAuthenticationService.isLoaded() && externalDynamicScopeService.isLoaded()) {
if (externalAuthenticationService.isLoaded() && externalDynamicScopeService.isLoaded() && сustomScriptManager.isInitialized()) {
return "running";
} else {
return "starting";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,9 @@
import java.util.Map.Entry;
import java.util.concurrent.atomic.AtomicBoolean;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.context.BeforeDestroyed;
import jakarta.enterprise.event.Event;
import jakarta.enterprise.event.Observes;
import jakarta.enterprise.inject.Instance;
import jakarta.inject.Inject;
import jakarta.servlet.ServletContext;

import io.jans.service.custom.inject.ReloadScript;
import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;

import io.jans.model.ScriptLocationType;
import io.jans.model.SimpleCustomProperty;
import io.jans.model.SimpleExtendedCustomProperty;
Expand All @@ -39,10 +32,17 @@
import io.jans.service.cdi.async.Asynchronous;
import io.jans.service.cdi.event.Scheduled;
import io.jans.service.cdi.event.UpdateScriptEvent;
import io.jans.service.custom.inject.ReloadScript;
import io.jans.service.timer.event.TimerEvent;
import io.jans.service.timer.schedule.TimerSchedule;
import io.jans.util.StringHelper;
import org.slf4j.Logger;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.context.BeforeDestroyed;
import jakarta.enterprise.event.Event;
import jakarta.enterprise.event.Observes;
import jakarta.enterprise.inject.Instance;
import jakarta.inject.Inject;
import jakarta.servlet.ServletContext;

/**
* Provides actual versions of scripts
Expand Down Expand Up @@ -84,6 +84,8 @@ public class CustomScriptManager {
private long lastFinishedTime;

private Map<CustomScriptType, List<CustomScriptConfiguration>> customScriptConfigurationsByScriptType;

private boolean initialized = false;

@Asynchronous
public void initTimer(List<CustomScriptType> supportedCustomScriptTypes) {
Expand All @@ -97,6 +99,8 @@ public void initTimer(List<CustomScriptType> supportedCustomScriptTypes) {

timerEvent.fire(new TimerEvent(new TimerSchedule(delay, DEFAULT_INTERVAL), new UpdateScriptEvent(),
Scheduled.Literal.INSTANCE));

initialized = true;
}

protected void configure() {
Expand Down Expand Up @@ -261,7 +265,7 @@ private ReloadResult reloadCustomScriptConfigurations(
// Add to script revision file modification time. This should allow to
// reload script automatically after changing location_type
long fileModifiactionTime = getFileModificationTime(loadedCustomScript.getLocationPath());
loadedCustomScript.setRevision(newCustomScript.getRevision() + fileModifiactionTime);
loadedCustomScript.setRevision(loadedCustomScript.getRevision() + fileModifiactionTime);

if (fileModifiactionTime != 0) {
String scriptFromFile = loadFromFile(loadedCustomScript.getLocationPath());
Expand Down Expand Up @@ -411,4 +415,8 @@ public void clearScriptError(CustomScript customScript) {
externalTypeCreator.clearScriptError(customScript);
}

public boolean isInitialized() {
return initialized;
}

}

0 comments on commit 02d4cd1

Please sign in to comment.