@Test public void createLoginIgnoresTheAdditionOfLoginOfAKnownUserName() throws Exception { Login[] logins = new Login[0]; Path emptyLoginsFile = FileHelpers.makeTempFilePath(true); ObjectMapper objectMapper = new ObjectMapper(); objectMapper.writeValue(emptyLoginsFile.toFile(), logins); JsonBasedAuthenticator instance = backedByFile(emptyLoginsFile); String userName = "userName"; instance.createLogin("userPid", userName, "password", "givenName", "surname", "email", "org"); instance.createLogin("userPid2", userName, "password1", "givenName2", "surname2", "email2", "org2"); List<Login> loginList = objectMapper.readValue(emptyLoginsFile.toFile(), new TypeReference<List<Login>>() { }); long count = loginList.stream().filter(login -> Objects.equals(login.getUsername(), userName)).count(); assertThat(count, is(1L)); Files.delete(emptyLoginsFile); }
@Override public void createLogin(String userPid, String userName, String password, String givenName, String surname, String email, String organization) throws LoginCreationException { try { Login login = create(userPid, userName, password, givenName, surname, email, organization); loginAccess.addLogin(login); } catch (NoSuchAlgorithmException e) { LOG.error("Encryption algorithm can not be found.", e); throw new LoginCreationException(e.getMessage()); } }
JsonBasedAuthenticator implements Authenticator, LoginCreator { @Override public void createLogin(String userPid, String userName, String password, String givenName, String surname, String email, String organization) throws LoginCreationException { try { Login login = create(userPid, userName, password, givenName, surname, email, organization); loginAccess.addLogin(login); } catch (NoSuchAlgorithmException e) { LOG.error("Encryption algorithm can not be found.", e); throw new LoginCreationException(e.getMessage()); } } }
JsonBasedAuthenticator implements Authenticator, LoginCreator { @Override public void createLogin(String userPid, String userName, String password, String givenName, String surname, String email, String organization) throws LoginCreationException { try { Login login = create(userPid, userName, password, givenName, surname, email, organization); loginAccess.addLogin(login); } catch (NoSuchAlgorithmException e) { LOG.error("Encryption algorithm can not be found.", e); throw new LoginCreationException(e.getMessage()); } } JsonBasedAuthenticator(LoginAccess loginAccess, String encryptionAlgorithm); }
JsonBasedAuthenticator implements Authenticator, LoginCreator { @Override public void createLogin(String userPid, String userName, String password, String givenName, String surname, String email, String organization) throws LoginCreationException { try { Login login = create(userPid, userName, password, givenName, surname, email, organization); loginAccess.addLogin(login); } catch (NoSuchAlgorithmException e) { LOG.error("Encryption algorithm can not be found.", e); throw new LoginCreationException(e.getMessage()); } } JsonBasedAuthenticator(LoginAccess loginAccess, String encryptionAlgorithm); @Override Optional<String> authenticate(String username, String password); @Override void createLogin(String userPid, String userName, String password, String givenName, String surname,
                          String email, String organization); Login create(String userPid, String userName, String password, String givenName, String surname, String email,
                      String organization); }
JsonBasedAuthenticator implements Authenticator, LoginCreator { @Override public void createLogin(String userPid, String userName, String password, String givenName, String surname, String email, String organization) throws LoginCreationException { try { Login login = create(userPid, userName, password, givenName, surname, email, organization); loginAccess.addLogin(login); } catch (NoSuchAlgorithmException e) { LOG.error("Encryption algorithm can not be found.", e); throw new LoginCreationException(e.getMessage()); } } JsonBasedAuthenticator(LoginAccess loginAccess, String encryptionAlgorithm); @Override Optional<String> authenticate(String username, String password); @Override void createLogin(String userPid, String userName, String password, String givenName, String surname,
                          String email, String organization); Login create(String userPid, String userName, String password, String givenName, String surname, String email,
                      String organization); static final Logger LOG; }