Search in sources :

Example 1 with OpsUser

use of org.platformlayer.auth.OpsUser in project platformlayer by platformlayer.

the class RegisterResource method register.

private RegistrationResponse register(RegistrationRequest request) {
    RegistrationResponse response = new RegistrationResponse();
    String username = request.username;
    String password = request.password;
    UserEntity userEntity;
    try {
        OpsUser user = registrationService.registerUser(username, password);
        userEntity = (UserEntity) user;
    } catch (CustomerFacingException e) {
        response.errorMessage = e.getMessage();
        return response;
    }
    if (userEntity == null) {
        log.warn("Authentication request failed immediately after registration.  Username=" + username);
        throw new IllegalStateException();
    }
    response.access = tokenHelpers.buildAccess(userEntity);
    return response;
}
Also used : CustomerFacingException(org.platformlayer.CustomerFacingException) OpsUser(org.platformlayer.auth.OpsUser) RegistrationResponse(org.platformlayer.auth.model.RegistrationResponse) UserEntity(org.platformlayer.auth.UserEntity)

Example 2 with OpsUser

use of org.platformlayer.auth.OpsUser in project platformlayer by platformlayer.

the class RegistrationServiceImpl method registerUser.

@Override
public OpsUser registerUser(String username, String password) throws CustomerFacingException {
    if (Strings.isNullOrEmpty(username)) {
        throw CustomerFacingException.buildRequiredField("username");
    }
    if (Strings.isNullOrEmpty(password)) {
        throw CustomerFacingException.buildRequiredField("password");
    }
    password = password.trim();
    username = username.trim();
    checkPassword(password);
    checkUsername(username);
    OpsUser user;
    try {
        user = repository.findUser(username);
        if (user != null) {
            // TODO: Should we hide this fact?
            throw CustomerFacingException.buildFieldError("username", "duplicate", "Username is already registered");
        }
        user = repository.createUser(username, password, null);
        // TODO: We reserve @@, to prevent collisions
        // TODO: Is this good enough? What if project already exists?
        String projectKey = "user@@" + username.toLowerCase();
        repository.createProject(projectKey, user);
    } catch (RepositoryException e) {
        log.warn("Repository error creating user", e);
        throw CustomerFacingException.wrap(e);
    }
    return user;
}
Also used : OpsUser(org.platformlayer.auth.OpsUser) RepositoryException(org.platformlayer.RepositoryException)

Example 3 with OpsUser

use of org.platformlayer.auth.OpsUser in project platformlayer by platformlayer.

the class CreateUser method runCommand.

@Override
public Object runCommand() throws RepositoryException, GeneralSecurityException, IOException, OpsException {
    if (password == null && keystore == null && certPath == null) {
        throw new CliException("Either key or password or cert is required");
    }
    UserDatabase userRepository = getContext().getUserRepository();
    Certificate[] certificateChain = null;
    if (keystore != null) {
        certificateChain = getContext().getCertificateChain(keystore, keystoreSecret, keyAlias);
    } else if (certPath != null) {
        certificateChain = getContext().loadCertificateChain(certPath);
    }
    OpsUser user = userRepository.createUser(username, password, certificateChain);
    return user;
}
Also used : CliException(com.fathomdb.cli.CliException) UserDatabase(org.platformlayer.auth.UserDatabase) OpsUser(org.platformlayer.auth.OpsUser) Certificate(java.security.cert.Certificate)

Aggregations

OpsUser (org.platformlayer.auth.OpsUser)3 CliException (com.fathomdb.cli.CliException)1 Certificate (java.security.cert.Certificate)1 CustomerFacingException (org.platformlayer.CustomerFacingException)1 RepositoryException (org.platformlayer.RepositoryException)1 UserDatabase (org.platformlayer.auth.UserDatabase)1 UserEntity (org.platformlayer.auth.UserEntity)1 RegistrationResponse (org.platformlayer.auth.model.RegistrationResponse)1