use of nl.knaw.huygens.timbuctoo.security.dto.Login in project timbuctoo by HuygensING.
the class LocalFileLoginAccess method addLogin.
@Override
public void addLogin(Login login) throws LoginCreationException {
synchronized (loginsFile) {
try {
List<Login> logins = objectMapper.readValue(loginsFile.toFile(), new TypeReference<List<Login>>() {
});
if (containsLoginForUserName(logins, login.getUsername())) {
LOG.warn("Already contains a login for userName '{}'. No login added.", login.getUsername());
return;
}
if (logins.stream().anyMatch(itemLogin -> Objects.equals(itemLogin.getUserPid(), login.getUserPid()))) {
LOG.warn("Already contains a login for userPid '{}'. No login added", login.getUserPid());
return;
}
logins.add(login);
objectMapper.writeValue(loginsFile.toFile(), logins.toArray(new Login[logins.size()]));
} catch (IOException e) {
LOG.error("Could not read \"{}\"", loginsFile.toAbsolutePath());
LOG.error("Exception", e);
throw new LoginCreationException(e.getMessage());
}
}
}
use of nl.knaw.huygens.timbuctoo.security.dto.Login in project timbuctoo by HuygensING.
the class JsonBasedAuthenticatorTest method createLoginAddsALoginToTheLoginsFile.
@Test
public void createLoginAddsALoginToTheLoginsFile() throws Exception {
Login[] logins = new Login[0];
Path emptyLoginsFile = FileHelpers.makeTempFilePath(true);
new ObjectMapper().writeValue(emptyLoginsFile.toFile(), logins);
JsonBasedAuthenticator instance = backedByFile(emptyLoginsFile);
instance.createLogin("userPid", "userName", "password", "givenName", "surname", "email", "org");
Optional<String> authenticate = instance.authenticate("userName", "password");
assertThat(authenticate, is(present()));
Files.delete(emptyLoginsFile);
}
use of nl.knaw.huygens.timbuctoo.security.dto.Login in project timbuctoo by HuygensING.
the class JsonBasedAuthenticator method createLogin.
@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());
}
}
use of nl.knaw.huygens.timbuctoo.security.dto.Login in project timbuctoo by HuygensING.
the class AzureAccessTest method testLogin.
@Test
public void testLogin() throws Exception {
AzureLoginAccess instance = new AzureLoginAccess(tableClient);
Login login = Login.create("userName", "userPid", new byte[] { 'a' }, new byte[] { 'a' }, "", "", "", "");
instance.addLogin(login);
Optional<Login> retrievedLogin = instance.getLogin("userName");
assertThat(retrievedLogin, is(present()));
assertThat(retrievedLogin.get(), is(login));
}
use of nl.knaw.huygens.timbuctoo.security.dto.Login in project timbuctoo by HuygensING.
the class JsonBasedAuthenticatorTest method createLoginIgnoresTheAdditionOfLoginOfAKnownUserPid.
@Test
public void createLoginIgnoresTheAdditionOfLoginOfAKnownUserPid() 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 userPid = "userPid";
instance.createLogin(userPid, "userName", "password", "givenName", "surname", "email", "org");
instance.createLogin(userPid, "userName1", "password1", "givenName1", "surname1", "email1", "org1");
List<Login> loginList = objectMapper.readValue(emptyLoginsFile.toFile(), new TypeReference<List<Login>>() {
});
long count = loginList.stream().filter(login -> Objects.equals(login.getUserPid(), userPid)).count();
assertThat(count, is(1L));
Files.delete(emptyLoginsFile);
}
Aggregations