Search in sources :

Example 1 with UserDatabase

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;
}
Also used : KeystoneCliContext(org.platformlayer.keystone.cli.KeystoneCliContext) UserDatabase(org.platformlayer.auth.UserDatabase)

Example 2 with UserDatabase

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;
}
Also used : CliException(com.fathomdb.cli.CliException) ProjectEntity(org.platformlayer.auth.ProjectEntity) UserDatabase(org.platformlayer.auth.UserDatabase) UserEntity(org.platformlayer.auth.UserEntity)

Example 3 with UserDatabase

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;
}
Also used : CliException(com.fathomdb.cli.CliException) ProjectEntity(org.platformlayer.auth.ProjectEntity) UserDatabase(org.platformlayer.auth.UserDatabase) CryptoKey(com.fathomdb.crypto.CryptoKey) SecretStore(org.platformlayer.auth.crypto.SecretStore) RoleId(org.platformlayer.model.RoleId) UserEntity(org.platformlayer.auth.UserEntity)

Example 4 with UserDatabase

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;
}
Also used : KeystoneCliContext(org.platformlayer.keystone.cli.KeystoneCliContext) UserDatabase(org.platformlayer.auth.UserDatabase)

Example 5 with UserDatabase

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;
}
Also used : ServiceAccount(org.platformlayer.auth.ServiceAccount) UserDatabase(org.platformlayer.auth.UserDatabase) X509Certificate(java.security.cert.X509Certificate) X509Certificate(java.security.cert.X509Certificate) Certificate(java.security.cert.Certificate)

Aggregations

UserDatabase (org.platformlayer.auth.UserDatabase)9 CliException (com.fathomdb.cli.CliException)3 UserEntity (org.platformlayer.auth.UserEntity)3 Certificate (java.security.cert.Certificate)2 ProjectEntity (org.platformlayer.auth.ProjectEntity)2 KeystoneCliContext (org.platformlayer.keystone.cli.KeystoneCliContext)2 CryptoKey (com.fathomdb.crypto.CryptoKey)1 X509Certificate (java.security.cert.X509Certificate)1 OpsUser (org.platformlayer.auth.OpsUser)1 ServiceAccount (org.platformlayer.auth.ServiceAccount)1 ServiceAccountEntity (org.platformlayer.auth.ServiceAccountEntity)1 SecretStore (org.platformlayer.auth.crypto.SecretStore)1 RoleId (org.platformlayer.model.RoleId)1