in sources/src/main/java/com/google/solutions/jitaccess/web/RequestContext.java [63:110]
void authenticate(
@NotNull EndUserId userId,
@NotNull Directory directory,
@NotNull Device device
) {
if (isAuthenticated()) {
throw new IllegalStateException(
"Request context has been authenticated before");
}
this.authenticationContext.subject = new Subject() {
private @Nullable Set<Principal> cachedPrincipals;
private final @NotNull Object cachedPrincipalsLock = new Object();
@Override
public @NotNull EndUserId user() {
return userId;
}
@Override
public @NotNull Directory directory() {
return directory;
}
@Override
public @NotNull Set<Principal> principals() {
//
// Resolve lazily.
//
synchronized (this.cachedPrincipalsLock)
{
if (this.cachedPrincipals == null) {
try {
this.cachedPrincipals = RequestContext.this
.subjectResolver
.resolvePrincipals(this.user(), directory);
}
catch (AccessException | IOException e) {
throw new UncheckedExecutionException(e);
}
}
return this.cachedPrincipals;
}
}
};
this.authenticationContext.device = device;
}