use of nl.knaw.huygens.security.client.UnauthorizedException 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();
}
}
}
}
use of nl.knaw.huygens.security.client.UnauthorizedException in project timbuctoo by HuygensING.
the class LoggedInUsersTest method setUp.
@Before
public void setUp() throws Exception {
Authenticator authenticator = AuthenticatorMockBuilder.authenticator().withPidFor("a", "b", "pid").build();
UserStore userStore = userStore().withUserFor("pid").build();
MockAuthenticationHandler authHandler = new MockAuthenticationHandler();
userStoreWithUserA = new LoggedInUsers(authenticator, userStore, ONE_SECOND_TIMEOUT, x -> {
throw new UnauthorizedException();
});
Authenticator authenticator1 = AuthenticatorMockBuilder.authenticator().withPidFor("a", "b", "pid").withPidFor("c", "d", "otherPid").build();
UserStore userStore1 = userStore().withUserFor("pid").withUserFor("otherPid").build();
userStoreWithUserAAndB = new LoggedInUsers(authenticator1, userStore1, ONE_SECOND_TIMEOUT, x -> {
throw new UnauthorizedException();
});
}
Aggregations