Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix(frontend): auth session ttl specified in hours instead of days. M…
…ore reasonable default 24 hours instead of 30 days.

Fixes: #2680
  • Loading branch information
thomas.larsson committed Jun 11, 2021
commit 48a223b27e1f641c26d12840112911731a4547dc
2 changes: 1 addition & 1 deletion datahub-frontend/app/react/auth/AuthModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ private Result handleOidcCallback(final Result result, final PlayWebContext cont
context.getJavaSession().put(ACTOR, actorUrn);
return result.withCookies(createActorCookie(actorUrn, _configs.hasPath(SESSION_TTL_CONFIG_PATH)
? _configs.getInt(SESSION_TTL_CONFIG_PATH)
: DEFAULT_SESSION_TTL_DAYS));
: DEFAULT_SESSION_TTL_HOURS));
} else {
throw new RuntimeException(
String.format("Failed to extract DataHub username from username claim %s using regex %s",
Expand Down
12 changes: 6 additions & 6 deletions datahub-frontend/app/react/auth/AuthUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

public class AuthUtils {

public static final String SESSION_TTL_CONFIG_PATH = "auth.session.ttlInDays";
public static final Integer DEFAULT_SESSION_TTL_DAYS = 30;
public static final String SESSION_TTL_CONFIG_PATH = "auth.session.ttlInHours";
public static final Integer DEFAULT_SESSION_TTL_HOURS = 24;
public static final CorpuserUrn DEFAULT_ACTOR_URN = new CorpuserUrn("datahub");

public static final String LOGIN_ROUTE = "/login";
Expand All @@ -30,15 +30,15 @@ public static boolean isAuthenticated(final Http.Context ctx) {
}

/**
* Creates a client authentication cookie (actor cookie) with a specified TTL in days.
* Creates a client authentication cookie (actor cookie) with a specified TTL in hours.
*
* @param actorUrn the urn of the authenticated actor, e.g. "urn:li:corpuser:datahub"
* @param ttlInDays the number of days until the actor cookie expires after being set
* @param ttlInHours the number of hours until the actor cookie expires after being set
*/
public static Http.Cookie createActorCookie(final String actorUrn, final Integer ttlInDays) {
public static Http.Cookie createActorCookie(final String actorUrn, final Integer ttlInHours) {
return Http.Cookie.builder(ACTOR, actorUrn)
.withHttpOnly(false)
.withMaxAge(Duration.of(ttlInDays, ChronoUnit.DAYS))
.withMaxAge(Duration.of(ttlInHours, ChronoUnit.HOURS))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public Result authenticate() {
session().put(ACTOR, DEFAULT_ACTOR_URN.toString());
return redirect("/").withCookies(createActorCookie(DEFAULT_ACTOR_URN.toString(), _configs.hasPath(SESSION_TTL_CONFIG_PATH)
? _configs.getInt(SESSION_TTL_CONFIG_PATH)
: DEFAULT_SESSION_TTL_DAYS));
: DEFAULT_SESSION_TTL_HOURS));
}

/**
Expand Down