SimpleAuthenticator implements Authenticator<String, User> { @UnitOfWork @Override public Optional<User> authenticate(String credentials) { LOG.debug("SimpleAuthenticator called with {}", credentials); final Token token = dao.findByContent(credentials); if (token != null) { User byId = userDAO.findById(token.getUserId()); if (byId.isBanned()) { return Optional.empty(); } initializeUserProfiles(byId); return Optional.of(byId); } else { return userinfoPlusFromToken(credentials) .map(userinfoPlus -> { final String email = userinfoPlus.getEmail(); User user = userDAO.findByGoogleEmail(email); if (user == null) { user = createUser(userinfoPlus); } user.setTemporaryCredential(credentials); initializeUserProfiles(user); return Optional.of(user); }).filter(user -> !user.get().isBanned()) .orElse(Optional.empty()); } } SimpleAuthenticator(TokenDAO dao, UserDAO userDAO); @UnitOfWork @Override Optional<User> authenticate(String credentials);  }
@Test public void authenticateDockstoreToken() { when(token.getUserId()).thenReturn(USER_ID); when(tokenDAO.findByContent(credentials)).thenReturn(token); when(userDAO.findById(USER_ID)).thenReturn(user); final User authenticatedUser = simpleAuthenticator.authenticate(credentials).get(); Assert.assertNull(authenticatedUser.getTemporaryCredential()); }