Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}

}