Skip to content

Commit

Permalink
fix(frontend): auth session ttl specified in hours instead of days. M… (
Browse files Browse the repository at this point in the history
#2695)

Fixes: #2680

Co-authored-by: thomas.larsson <thomas.larsson@klarna.com>
  • Loading branch information
thomasplarsson and thomas.larsson authored Jun 25, 2021
1 parent 64a5ea5 commit c04f856
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
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 @@ -144,7 +144,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 = 720;
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
4 changes: 4 additions & 0 deletions datahub-frontend/conf/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ auth.jaas.enabled = ${?AUTH_JAAS_ENABLED}
# auth.jaas.enabled = false
# auth.oidc.enabled = false # (or simply omit oidc configurations)

# Login session expiration time
# auth.session.ttlInHours = ${?AUTH_SESSION_TTL_HOURS}


analytics.enabled = ${?DATAHUB_ANALYTICS_ENABLED}

# Kafka Producer Configuration
Expand Down

0 comments on commit c04f856

Please sign in to comment.