Skip to content

Commit 517b804

Browse files
author
Dennis Labordus
committed
Added 2 timeout settings to UserInfo.
Signed-off-by: Dennis Labordus <[email protected]>
1 parent 8b56f58 commit 517b804

File tree

6 files changed

+49
-8
lines changed

6 files changed

+49
-8
lines changed

README.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,15 @@ Below environment variable(s) can be used to configure the connection to BaseX,
8383
| BASEX_USERNAME | basex.username | Username under which the application logs in. | admin |
8484
| BASEX_PASSWORD | basex.password | Password of the username used above. | admin |
8585

86-
Below environment variable(s) can be used to configure which claims are used to fill the UserInfo response.
87-
88-
| Environment variable | Java Property | Description | Example |
89-
| -------------------------------- | ------------------------------ | --------------------------------------------- | ---------------- |
90-
| USERINFO_NAME_CLAIMNAME | compas.userinfo.name.claimname | The Name of the user logged in. | name |
91-
| USERINFO_WHO_CLAIMNAME | compas.userinfo.who.claimname | The Name of the user used in the Who History. | name |
86+
Below environment variable(s) can be used to configure which claims and information are used to fill the UserInfo
87+
response.
88+
89+
| Environment variable | Java Property | Description | Example |
90+
| -------------------------------- | ------------------------------- | ----------------------------------------------------------- | ---------------- |
91+
| USERINFO_NAME_CLAIMNAME | compas.userinfo.name.claimname | The Name of the user logged in. | name |
92+
| USERINFO_WHO_CLAIMNAME | compas.userinfo.who.claimname | The Name of the user used in the Who History. | name |
93+
| USERINFO_SESSION_WARNING | compas.userinfo.session.warning | Number of minutes a Session Warning can be displayed. | 20 |
94+
| USERINFO_SESSION_EXPIRES | compas.userinfo.session.expires | Number of minutes a Session Expires to display in Frontend. | 30 |
9295

9396
## Security
9497

app/src/main/java/org/lfenergy/compas/scl/data/rest/UserInfoProperties.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,10 @@ public interface UserInfoProperties {
1313

1414
@WithName("who.claimname")
1515
String who();
16+
17+
@WithName("session.warning")
18+
int sessionWarning();
19+
20+
@WithName("session.expires")
21+
int sessionExpires();
1622
}

app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/CompasCommonResource.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ public UserInfoResponse getUserInfo(@HeaderParam("Authorization") String authHea
6666

6767
var response = new UserInfoResponse();
6868
response.setName(jsonWebToken.getClaim(userInfoProperties.name()));
69+
response.setSessionWarning(userInfoProperties.sessionWarning());
70+
response.setSessionExpires(userInfoProperties.sessionExpires());
6971
return response;
7072
}
7173
}

app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/model/UserInfoResponse.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// SPDX-License-Identifier: Apache-2.0
44
package org.lfenergy.compas.scl.data.rest.v1.model;
55

6+
import org.eclipse.microprofile.openapi.annotations.media.Schema;
7+
68
import javax.xml.bind.annotation.XmlAccessType;
79
import javax.xml.bind.annotation.XmlAccessorType;
810
import javax.xml.bind.annotation.XmlElement;
@@ -13,14 +15,39 @@
1315
@XmlRootElement(name = "UserInfoResponse", namespace = SCL_DATA_SERVICE_V1_NS_URI)
1416
@XmlAccessorType(XmlAccessType.FIELD)
1517
public class UserInfoResponse {
18+
@Schema(description = "The name of the user retrieved from the JWT Claim.")
1619
@XmlElement(name = "Name", namespace = SCL_DATA_SERVICE_V1_NS_URI)
1720
private String name;
1821

22+
@Schema(description = "The number of minutes when the frontend isn't used and a warning message will be shown.")
23+
@XmlElement(name = "SessionWarning", namespace = SCL_DATA_SERVICE_V1_NS_URI)
24+
private int sessionWarning;
25+
26+
@Schema(description = "The number of minutes when the session will expire and a expired message will be shown if the frontend isn't used.")
27+
@XmlElement(name = "SessionExpires", namespace = SCL_DATA_SERVICE_V1_NS_URI)
28+
private int sessionExpires;
29+
1930
public String getName() {
2031
return name;
2132
}
2233

2334
public void setName(String name) {
2435
this.name = name;
2536
}
37+
38+
public int getSessionWarning() {
39+
return sessionWarning;
40+
}
41+
42+
public void setSessionWarning(int sessionWarning) {
43+
this.sessionWarning = sessionWarning;
44+
}
45+
46+
public int getSessionExpires() {
47+
return sessionExpires;
48+
}
49+
50+
public void setSessionExpires(int sessionExpires) {
51+
this.sessionExpires = sessionExpires;
52+
}
2653
}

app/src/main/resources/application.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
compas.userinfo.name.claimname = ${USERINFO_NAME_CLAIMNAME:name}
66
compas.userinfo.who.claimname = ${USERINFO_WHO_CLAIMNAME:name}
7+
compas.userinfo.session.warning = ${USERINFO_SESSION_WARNING:10}
8+
compas.userinfo.session.expires = ${USERINFO_SESSION_EXPIRES:15}
79

810
quarkus.http.cors = false
911
quarkus.http.root-path = /compas-scl-data-service/

app/src/test/java/org/lfenergy/compas/scl/data/rest/v1/CompasCommonResourceTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ void getUserInfo_WhenCalled_ThenUserInfoResponseRetrieved() {
8484
.response();
8585

8686
var xmlPath = response.xmlPath();
87-
var name = xmlPath.get("UserInfoResponse.Name");
88-
assertEquals("Test User", name);
87+
assertEquals("Test User", xmlPath.get("UserInfoResponse.Name"));
88+
assertEquals(10, xmlPath.getInt("UserInfoResponse.SessionWarning"));
89+
assertEquals(15, xmlPath.getInt("UserInfoResponse.SessionExpires"));
8990
}
9091
}

0 commit comments

Comments
 (0)