use of org.platformlayer.auth.UserDatabase in project platformlayer by platformlayer.
the class ProjectNameAutoCompleter method doComplete.
@Override
public List<String> doComplete(CliContext context, String prefix) throws Exception {
if (prefix.length() <= 2) {
// Let's avoid returning thousands of projects
return null;
}
KeystoneCliContext keystoneContext = (KeystoneCliContext) context;
UserDatabase userRepository = keystoneContext.getUserRepository();
List<String> userIds = userRepository.listAllProjectNames(prefix);
addSuffix(userIds, " ");
return userIds;
}
use of org.platformlayer.auth.UserDatabase in project platformlayer by platformlayer.
the class CreateProject method runCommand.
@Override
public Object runCommand() throws RepositoryException {
UserDatabase userRepository = getContext().getUserRepository();
// We need to login to unlock the user key so we can encrypt the project key!
UserEntity me = getContext().loginDirect();
if (projectKey.contains("@@")) {
throw new CliException("Project names with @@ are reserved for system uses");
}
ProjectEntity project = userRepository.createProject(projectKey, me);
return project;
}
use of org.platformlayer.auth.UserDatabase in project platformlayer by platformlayer.
the class JoinProject method runCommand.
@Override
public Object runCommand() throws RepositoryException, IOException {
UserDatabase userRepository = getContext().getUserRepository();
UserEntity me = getContext().loginDirect();
ProjectEntity project = userRepository.findProjectByKey(projectKey.getKey());
if (project == null) {
throw new CliException("Project not found: " + projectKey.getKey());
}
SecretStore secretStore = new SecretStore(project.secretData);
CryptoKey projectSecret = secretStore.getSecretFromUser(me);
if (projectSecret == null) {
String msg = "Cannot retrieve project secret.";
msg += " Is " + me.key + " a member of " + project.getName() + "?";
throw new CliException(msg);
}
if (Strings.isNullOrEmpty(roleKey)) {
throw new CliException("Role is required");
}
RoleId role = new RoleId(roleKey);
userRepository.addUserToProject(username.getKey(), project.getName(), projectSecret, Collections.singletonList(role));
return project;
}
use of org.platformlayer.auth.UserDatabase in project platformlayer by platformlayer.
the class UserNameAutoCompleter method doComplete.
@Override
public List<String> doComplete(CliContext context, String prefix) throws Exception {
if (prefix.length() < 3) {
// Let's avoid returning thousands of users
return null;
}
KeystoneCliContext keystoneContext = (KeystoneCliContext) context;
UserDatabase userRepository = keystoneContext.getUserRepository();
List<String> userIds = userRepository.listAllUserNames(prefix);
addSuffix(userIds, " ");
return userIds;
}
use of org.platformlayer.auth.UserDatabase in project platformlayer by platformlayer.
the class CreateServiceAccount method runCommand.
@Override
public Object runCommand() throws Exception {
Certificate[] certificateChain = getContext().getCertificateChain(keystore, keystoreSecret, keyAlias);
X509Certificate cert;
if (certificateChain.length == 1) {
cert = (X509Certificate) certificateChain[0];
} else {
System.out.println("Certificate chain has length " + certificateChain.length + ", assuming entry 2 is CA");
cert = (X509Certificate) certificateChain[1];
}
UserDatabase userRepository = getContext().getUserRepository();
ServiceAccount account = userRepository.createServiceAccount(cert);
return account;
}
Aggregations