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;
}
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;
}
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;
}
Aggregations