Skip to content

Commit

Permalink
KNOX-3077 - Add pac4j.cookie.max.age param
Browse files Browse the repository at this point in the history
  • Loading branch information
moresandeep committed Dec 12, 2024
1 parent 4748771 commit c4578b5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
public static final int PAC4J_COOKIE_MAX_AGE_DEFAULT = -1;

private CallbackFilter callbackFilter;

private SecurityFilter securityFilter;
Expand Down Expand Up @@ -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, Long.toString(PAC4J_COOKIE_MAX_AGE_DEFAULT));
//decorating client configuration (if needed)
PAC4J_CLIENT_CONFIGURATION_DECORATOR.decorateClients(clients, properties);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit c4578b5

Please sign in to comment.