@Test public void canLoginAsOtherUserShouldReturnAllowedWhenAdminAndUserIsInRepository() throws Exception { when(usersRepository.isAdministrator(ADMIN)) .thenReturn(true); when(usersRepository.contains(USER)) .thenReturn(true); assertThat(testee.canLoginAsOtherUser(ADMIN, USER)).isEqualTo(Authorizator.AuthorizationState.ALLOWED); }
@Override public AuthorizationState canLoginAsOtherUser(Username userId, Username otherUserId) throws MailboxException { try { if (!repos.isAdministrator(userId)) { return AuthorizationState.NOT_ADMIN; } if (!repos.contains(otherUserId)) { return AuthorizationState.UNKNOWN_USER; } return AuthorizationState.ALLOWED; } catch (UsersRepositoryException e) { throw new MailboxException("Unable to access usersRepository", e); } }
UserRepositoryAuthorizator implements Authorizator { @Override public AuthorizationState canLoginAsOtherUser(Username userId, Username otherUserId) throws MailboxException { try { if (!repos.isAdministrator(userId)) { return AuthorizationState.NOT_ADMIN; } if (!repos.contains(otherUserId)) { return AuthorizationState.UNKNOWN_USER; } return AuthorizationState.ALLOWED; } catch (UsersRepositoryException e) { throw new MailboxException("Unable to access usersRepository", e); } } }
UserRepositoryAuthorizator implements Authorizator { @Override public AuthorizationState canLoginAsOtherUser(Username userId, Username otherUserId) throws MailboxException { try { if (!repos.isAdministrator(userId)) { return AuthorizationState.NOT_ADMIN; } if (!repos.contains(otherUserId)) { return AuthorizationState.UNKNOWN_USER; } return AuthorizationState.ALLOWED; } catch (UsersRepositoryException e) { throw new MailboxException("Unable to access usersRepository", e); } } @Inject  UserRepositoryAuthorizator(UsersRepository repos); }
UserRepositoryAuthorizator implements Authorizator { @Override public AuthorizationState canLoginAsOtherUser(Username userId, Username otherUserId) throws MailboxException { try { if (!repos.isAdministrator(userId)) { return AuthorizationState.NOT_ADMIN; } if (!repos.contains(otherUserId)) { return AuthorizationState.UNKNOWN_USER; } return AuthorizationState.ALLOWED; } catch (UsersRepositoryException e) { throw new MailboxException("Unable to access usersRepository", e); } } @Inject  UserRepositoryAuthorizator(UsersRepository repos); @Override AuthorizationState canLoginAsOtherUser(Username userId, Username otherUserId); }
UserRepositoryAuthorizator implements Authorizator { @Override public AuthorizationState canLoginAsOtherUser(Username userId, Username otherUserId) throws MailboxException { try { if (!repos.isAdministrator(userId)) { return AuthorizationState.NOT_ADMIN; } if (!repos.contains(otherUserId)) { return AuthorizationState.UNKNOWN_USER; } return AuthorizationState.ALLOWED; } catch (UsersRepositoryException e) { throw new MailboxException("Unable to access usersRepository", e); } } @Inject  UserRepositoryAuthorizator(UsersRepository repos); @Override AuthorizationState canLoginAsOtherUser(Username userId, Username otherUserId);  }