use of nl.knaw.huygens.security.client.model.SecurityInformation in project timbuctoo by HuygensING.
the class LoggedInUsers method userFor.
public Optional<User> userFor(String authHeader) {
if (authHeader == null || authHeader.isEmpty()) {
return Optional.empty();
} else {
User local = users.getIfPresent(authHeader);
if (local != null) {
return Optional.of(local);
} else {
try {
SecurityInformation securityInformation = authenticationHandler.getSecurityInformation(authHeader);
// get the one that was saved to the file
Optional<User> userFromFile = userStore.userFor(securityInformation.getPersistentID());
if (userFromFile.isPresent()) {
users.put(authHeader, userFromFile.get());
return userFromFile;
} else {
User nw = userStore.saveNew(securityInformation.getDisplayName(), securityInformation.getPersistentID());
users.put(authHeader, nw);
return Optional.of(nw);
}
} catch (UnauthorizedException e) {
LOG.warn("User is not retrievable", e);
return Optional.empty();
} catch (IOException | AuthenticationUnavailableException e) {
LOG.error("An exception is thrown while retrieving the user information.", e);
return Optional.empty();
}
}
}
}
Aggregations