You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by jl...@apache.org on 2025/03/07 15:53:46 UTC
(ofbiz-framework) branch trunk updated: Implemented: Modified JWTManager.java to generate and validate refresh token (OFBIZ-13212)
This is an automated email from the ASF dual-hosted git repository.
jleroux pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git
The following commit(s) were added to refs/heads/trunk by this push:
new e7aaa24078 Implemented: Modified JWTManager.java to generate and validate refresh token (OFBIZ-13212)
e7aaa24078 is described below
commit e7aaa240787fd2280cb253431b6e4ee0ee3bb710
Author: ArashPreet <66...@users.noreply.github.com>
AuthorDate: Fri Mar 7 21:23:40 2025 +0530
Implemented: Modified JWTManager.java to generate and validate refresh token (OFBIZ-13212)
This implementation will allow user to get refresh token while login.
* OFBIZ-13212-framework-update
- Modified framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/JWTManager.java to generate and validate refresh token.
* OFBIZ-13212-framework-update
- Added security.jwt.refresh.token.expireTime property in security for refresh token.
---------
Co-authored-by: ArashPreet Singh <ar...@insonix.com>
---
framework/security/config/security.properties | 3 +++
.../java/org/apache/ofbiz/webapp/control/JWTManager.java | 14 ++++++++++++++
2 files changed, 17 insertions(+)
diff --git a/framework/security/config/security.properties b/framework/security/config/security.properties
index 6fbc9b9ea8..21d584bca0 100644
--- a/framework/security/config/security.properties
+++ b/framework/security/config/security.properties
@@ -149,6 +149,9 @@ login.secret_key_string=p2s5u8x/A?D(G+KbPeShVmYq3t6w9z$B&E)H@McQfTjWnZr4u7x!A%D*
# -- Time To Live of the token send to the external server in seconds
security.jwt.token.expireTime=1800
+# -- Time To Live of the refresh token send to the external server in seconds
+security.jwt.refresh.token.expireTime=84600
+
# -- Enables the internal Single Sign On feature which allows a token based login between OFBiz instances
# To make this work you also have to configure a secret key with security.token.key
security.internal.sso.enabled=false
diff --git a/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/JWTManager.java b/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/JWTManager.java
index 758ec1e571..8e3f339f23 100644
--- a/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/JWTManager.java
+++ b/framework/webapp/src/main/java/org/apache/ofbiz/webapp/control/JWTManager.java
@@ -404,4 +404,18 @@ public class JWTManager {
}
return result;
}
+
+ public static String createRefreshToken(Delegator delegator, String userLoginId) {
+ int refreshTokenExpireTime = Integer.parseInt(EntityUtilProperties.getPropertyValue("security",
+ "security.jwt.refresh.token.expireTime", "86400", delegator));
+ return createJwt(delegator, UtilMisc.toMap("userLoginId", userLoginId, "type", "refresh"), refreshTokenExpireTime);
+ }
+
+ public static Map<String, Object> validateRefreshToken(String refreshToken, String key) {
+ Map<String, Object> claims = validateToken(refreshToken, key);
+ if (!claims.containsKey("type") || !"refresh".equals(claims.get("type"))) {
+ return ServiceUtil.returnError("Invalid refresh token.");
+ }
+ return claims;
+ }
}