Search in sources :

Example 1 with LoginCreationException

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());
        }
    }
}
Also used : LoginCreationException(nl.knaw.huygens.timbuctoo.security.exceptions.LoginCreationException) List(java.util.List) Login(nl.knaw.huygens.timbuctoo.security.dto.Login) IOException(java.io.IOException)

Example 2 with LoginCreationException

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);
}
Also used : LoginCreationException(nl.knaw.huygens.timbuctoo.security.exceptions.LoginCreationException) Test(org.junit.Test)

Example 3 with LoginCreationException

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());
    }
}
Also used : LoginCreationException(nl.knaw.huygens.timbuctoo.security.exceptions.LoginCreationException) Login(nl.knaw.huygens.timbuctoo.security.dto.Login) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 4 with LoginCreationException

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);
    }
}
Also used : User(nl.knaw.huygens.timbuctoo.v5.security.dto.User) UserCreationException(nl.knaw.huygens.timbuctoo.security.exceptions.UserCreationException) LoginCreationException(nl.knaw.huygens.timbuctoo.security.exceptions.LoginCreationException) AuthorizationCreationException(nl.knaw.huygens.timbuctoo.v5.security.exceptions.AuthorizationCreationException)

Aggregations

LoginCreationException (nl.knaw.huygens.timbuctoo.security.exceptions.LoginCreationException)4 Login (nl.knaw.huygens.timbuctoo.security.dto.Login)2 IOException (java.io.IOException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 List (java.util.List)1 UserCreationException (nl.knaw.huygens.timbuctoo.security.exceptions.UserCreationException)1 User (nl.knaw.huygens.timbuctoo.v5.security.dto.User)1 AuthorizationCreationException (nl.knaw.huygens.timbuctoo.v5.security.exceptions.AuthorizationCreationException)1 Test (org.junit.Test)1