Search in sources :

Example 1 with SecurityInformation

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();
            }
        }
    }
}
Also used : AuthenticationUnavailableException(nl.knaw.huygens.timbuctoo.security.exceptions.AuthenticationUnavailableException) User(nl.knaw.huygens.timbuctoo.v5.security.dto.User) SecurityInformation(nl.knaw.huygens.security.client.model.SecurityInformation) UnauthorizedException(nl.knaw.huygens.security.client.UnauthorizedException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 UnauthorizedException (nl.knaw.huygens.security.client.UnauthorizedException)1 SecurityInformation (nl.knaw.huygens.security.client.model.SecurityInformation)1 AuthenticationUnavailableException (nl.knaw.huygens.timbuctoo.security.exceptions.AuthenticationUnavailableException)1 User (nl.knaw.huygens.timbuctoo.v5.security.dto.User)1