Skip to content

Commit

Permalink
Merge pull request #2328 from constantine2nd/develop
Browse files Browse the repository at this point in the history
Add props session_inactivity_timeout_in_seconds
  • Loading branch information
simonredfern authored Nov 16, 2023
2 parents fe3277b + 455a044 commit 5da518c
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion obp-api/src/main/resources/props/sample.props.template
Original file line number Diff line number Diff line change
Expand Up @@ -1237,7 +1237,7 @@ dynamic_code_compile_validate_dependencies=[\

# If you want to make the Lift inactivity timeout shorter than
# the container inactivity timeout, set the inactivity timeout here
session_inactivity_timeout_in_minutes = 30
session_inactivity_timeout_in_seconds = 300

# Defines redirect URL after user account is validated
# In case is not defined default value is the home page of this application
Expand Down
2 changes: 1 addition & 1 deletion obp-api/src/main/scala/bootstrap/liftweb/Boot.scala
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,7 @@ class Boot extends MdcLoggable {
createHydraClients()
}

Props.get("session_inactivity_timeout_in_minutes") match {
Props.get("session_inactivity_timeout_in_seconds") match {
case Full(x) if tryo(x.toLong).isDefined =>
LiftRules.sessionInactivityTimeout.default.set(Full((x.toLong.minutes): Long))
case _ =>
Expand Down
5 changes: 2 additions & 3 deletions obp-api/src/main/scala/code/api/v5_1_0/APIMethods510.scala
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,9 @@ trait APIMethods510 {
case "ui" :: "suggested-session-timeout" :: Nil JsonGet _ =>
cc => implicit val ec = EndpointContext(Some(cc))
for {
timeout: Int <- Future(APIUtil.getPropsAsIntValue("session_inactivity_timeout_in_minutes", 5))
timeoutInSeconds = (timeout * 60).toString
timeoutInSeconds: Int <- Future(APIUtil.getPropsAsIntValue("session_inactivity_timeout_in_seconds", 300))
} yield {
(SuggestedSessionTimeoutV510(timeoutInSeconds), HttpCode.`200`(cc.callContext))
(SuggestedSessionTimeoutV510(timeoutInSeconds.toString), HttpCode.`200`(cc.callContext))
}
}

Expand Down
10 changes: 5 additions & 5 deletions obp-api/src/main/webapp/media/js/inactivity.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,16 @@ function logout() {
async function makeObpApiCall() {
let response = await fetch('/obp/v5.1.0/ui/suggested-session-timeout');
let json = await response.json();
console.log(json.timeout_in_seconds);
localStorage.setItem("suggested-session-timeout-in-seconds", json.timeout_in_seconds);
return json.timeout_in_seconds;
}

function getSuggestedSessionTimeout() {
let timeoutInSeconds = localStorage.getItem("suggested-session-timeout-in-seconds");
if(!timeoutInSeconds) {
timeoutInSeconds = makeObpApiCall;
localStorage.setItem("suggested-session-timeout-in-seconds", timeoutInSeconds);
if(!localStorage.getItem("suggested-session-timeout-in-seconds")) {
makeObpApiCall();
}
return timeoutInSeconds * 1000 + 1000; // We need timeout in millis
return localStorage.getItem("suggested-session-timeout-in-seconds") * 1000 + 1000; // We need timeout in millis
}

// self executing function to trigger the operation on page load
Expand Down

0 comments on commit 5da518c

Please sign in to comment.