diff --git a/gateway-provider-security-pac4j/src/main/java/org/apache/knox/gateway/pac4j/filter/Pac4jDispatcherFilter.java b/gateway-provider-security-pac4j/src/main/java/org/apache/knox/gateway/pac4j/filter/Pac4jDispatcherFilter.java index 41642121e4..7f1670ed0f 100644 --- a/gateway-provider-security-pac4j/src/main/java/org/apache/knox/gateway/pac4j/filter/Pac4jDispatcherFilter.java +++ b/gateway-provider-security-pac4j/src/main/java/org/apache/knox/gateway/pac4j/filter/Pac4jDispatcherFilter.java @@ -122,6 +122,12 @@ public class Pac4jDispatcherFilter implements Filter, SessionInvalidator { private static final String PAC4J_OIDC_TYPE = "oidc.type"; + /* property for specifying pac4j cookies ttl */ + public static final String PAC4J_COOKIE_MAX_AGE = "pac4j.cookie.max.age"; + + /* default value is same is KNOXSSO token ttl default */ + private static final String PAC4J_COOKIE_MAX_AGE_DEFAULT = "-1"; + private CallbackFilter callbackFilter; private SecurityFilter securityFilter; @@ -216,6 +222,8 @@ public void init( FilterConfig filterConfig ) throws ServletException { setSessionStoreConfig(filterConfig, PAC4J_SESSION_STORE_EXCLUDE_PERMISSIONS, PAC4J_SESSION_STORE_EXCLUDE_PERMISSIONS_DEFAULT); /* do we need to exclude custom attributes? */ setSessionStoreConfig(filterConfig, PAC4J_SESSION_STORE_EXCLUDE_CUSTOM_ATTRIBUTES, PAC4J_SESSION_STORE_EXCLUDE_CUSTOM_ATTRIBUTES_DEFAULT); + /* add cookie expiry */ + setSessionStoreConfig(filterConfig, PAC4J_COOKIE_MAX_AGE, PAC4J_COOKIE_MAX_AGE_DEFAULT); //decorating client configuration (if needed) PAC4J_CLIENT_CONFIGURATION_DECORATOR.decorateClients(clients, properties); } diff --git a/gateway-provider-security-pac4j/src/main/java/org/apache/knox/gateway/pac4j/session/KnoxSessionStore.java b/gateway-provider-security-pac4j/src/main/java/org/apache/knox/gateway/pac4j/session/KnoxSessionStore.java index 040c82d3e3..94007954da 100644 --- a/gateway-provider-security-pac4j/src/main/java/org/apache/knox/gateway/pac4j/session/KnoxSessionStore.java +++ b/gateway-provider-security-pac4j/src/main/java/org/apache/knox/gateway/pac4j/session/KnoxSessionStore.java @@ -56,6 +56,7 @@ import static org.apache.knox.gateway.pac4j.filter.Pac4jDispatcherFilter.PAC4J_SESSION_STORE_EXCLUDE_PERMISSIONS_DEFAULT; import static org.apache.knox.gateway.pac4j.filter.Pac4jDispatcherFilter.PAC4J_SESSION_STORE_EXCLUDE_ROLES; import static org.apache.knox.gateway.pac4j.filter.Pac4jDispatcherFilter.PAC4J_SESSION_STORE_EXCLUDE_ROLES_DEFAULT; +import static org.apache.knox.gateway.pac4j.filter.Pac4jDispatcherFilter.PAC4J_COOKIE_MAX_AGE; /** * Specific session store where data are saved into cookies (and not in memory). @@ -201,6 +202,11 @@ public void set(WebContext context, String key, Object value) { cookie.setPath(parts[0]); } + + /* Set cookie max age */ + if(sessionStoreConfigs != null && sessionStoreConfigs.containsKey(PAC4J_COOKIE_MAX_AGE)) { + cookie.setMaxAge(Integer.parseInt(sessionStoreConfigs.get(PAC4J_COOKIE_MAX_AGE))); + } context.addResponseCookie(cookie); }