@Test public void throwsLocalLoginUnavailableExceptionWhenTheUserCouldNotBeAuthenticatedLocallyDueToASystemError() throws Exception { Authenticator authenticator = mock(JsonBasedAuthenticator.class); given(authenticator.authenticate(anyString(), anyString())).willThrow(new LocalLoginUnavailableException("")); LoggedInUsers instance = new LoggedInUsers(authenticator, null, ONE_SECOND_TIMEOUT, null); expectedException.expect(LocalLoginUnavailableException.class); instance.userTokenFor("", ""); }
public synchronized Optional<String> userTokenFor(String username, String password) throws LocalLoginUnavailableException, AuthenticationUnavailableException { Optional<String> id; Optional<String> token = Optional.empty(); id = authenticator.authenticate(username, password); if (id.isPresent()) { Optional<User> user = userStore.userFor(id.get()); if (user.isPresent()) { String uuid = UUID.randomUUID().toString(); token = Optional.of(uuid); users.put(uuid, user.get()); } } return token; }
LoggedInUsers { public synchronized Optional<String> userTokenFor(String username, String password) throws LocalLoginUnavailableException, AuthenticationUnavailableException { Optional<String> id; Optional<String> token = Optional.empty(); id = authenticator.authenticate(username, password); if (id.isPresent()) { Optional<User> user = userStore.userFor(id.get()); if (user.isPresent()) { String uuid = UUID.randomUUID().toString(); token = Optional.of(uuid); users.put(uuid, user.get()); } } return token; } }
LoggedInUsers { public synchronized Optional<String> userTokenFor(String username, String password) throws LocalLoginUnavailableException, AuthenticationUnavailableException { Optional<String> id; Optional<String> token = Optional.empty(); id = authenticator.authenticate(username, password); if (id.isPresent()) { Optional<User> user = userStore.userFor(id.get()); if (user.isPresent()) { String uuid = UUID.randomUUID().toString(); token = Optional.of(uuid); users.put(uuid, user.get()); } } return token; } LoggedInUsers(Authenticator authenticator, UserStore userStore,
                       Timeout inactivityTimeout, AuthenticationHandler authenticationHandler); }
LoggedInUsers { public synchronized Optional<String> userTokenFor(String username, String password) throws LocalLoginUnavailableException, AuthenticationUnavailableException { Optional<String> id; Optional<String> token = Optional.empty(); id = authenticator.authenticate(username, password); if (id.isPresent()) { Optional<User> user = userStore.userFor(id.get()); if (user.isPresent()) { String uuid = UUID.randomUUID().toString(); token = Optional.of(uuid); users.put(uuid, user.get()); } } return token; } LoggedInUsers(Authenticator authenticator, UserStore userStore,
                       Timeout inactivityTimeout, AuthenticationHandler authenticationHandler); synchronized Optional<User> userFor(String authHeader); synchronized Optional<String> userTokenFor(String username, String password); }
LoggedInUsers { public synchronized Optional<String> userTokenFor(String username, String password) throws LocalLoginUnavailableException, AuthenticationUnavailableException { Optional<String> id; Optional<String> token = Optional.empty(); id = authenticator.authenticate(username, password); if (id.isPresent()) { Optional<User> user = userStore.userFor(id.get()); if (user.isPresent()) { String uuid = UUID.randomUUID().toString(); token = Optional.of(uuid); users.put(uuid, user.get()); } } return token; } LoggedInUsers(Authenticator authenticator, UserStore userStore,
                       Timeout inactivityTimeout, AuthenticationHandler authenticationHandler); synchronized Optional<User> userFor(String authHeader); synchronized Optional<String> userTokenFor(String username, String password); static final Logger LOG; }