use of nl.knaw.huygens.timbuctoo.security.exceptions.LoginCreationException 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.exceptions.LoginCreationException in project timbuctoo by HuygensING.
the class LocalUserCreatorTest method createThrowsAUserCreationExceptionWhenTheLoginCreatorThrowsALoginCreationException.
@Test(expected = UserCreationException.class)
public void createThrowsAUserCreationExceptionWhenTheLoginCreatorThrowsALoginCreationException() throws Exception {
Mockito.doThrow(new LoginCreationException("")).when(loginCreator).createLogin(anyString(), anyString(), anyString(), anyString(), anyString(), anyString(), anyString());
instance.create(userInfo);
}
use of nl.knaw.huygens.timbuctoo.security.exceptions.LoginCreationException 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.exceptions.LoginCreationException in project timbuctoo by HuygensING.
the class LocalUserCreator method create.
public void create(Map<String, String> userInfo) throws UserCreationException {
String userPid = userInfo.get(USER_PID);
String userName = userInfo.get(USER_NAME);
String password = userInfo.get(PASSWORD);
String givenName = userInfo.get(GIVEN_NAME);
String surname = userInfo.get(SURNAME);
String emailAddress = userInfo.get(EMAIL_ADDRESS);
String organization = userInfo.get(ORGANIZATION);
String vreId = userInfo.get(VRE_ID);
String vreRole = userInfo.get(VRE_ROLE);
try {
loginCreator.createLogin(userPid, userName, password, givenName, surname, emailAddress, organization);
User user = userCreator.createUser(userPid, emailAddress, givenName, surname, organization);
authorizationCreator.createAuthorization(vreId, user, vreRole);
} catch (LoginCreationException e) {
throw new UserCreationException(e);
} catch (AuthorizationCreationException e) {
throw new UserCreationException(e);
}
}
Aggregations