Search in sources :

Example 1 with RoleId

use of org.platformlayer.model.RoleId in project platformlayer by platformlayer.

the class PlatformLayerAuthAdminClient method buildPlatformlayerProjectAuthorization.

private PlatformlayerProjectAuthorization buildPlatformlayerProjectAuthorization(PlatformlayerUserAuthentication user, ProjectValidation project) {
    String name = project.getName();
    int projectId = Integer.parseInt(project.getId());
    List<RoleId> roles = Lists.newArrayList();
    for (Role role : project.getRoles()) {
        roles.add(new RoleId(role.getName()));
    }
    CryptoKey projectSecret = FathomdbCrypto.deserializeKey(project.getSecret());
    return new PlatformlayerProjectAuthorization(user, name, projectSecret, roles, projectId);
}
Also used : Role(org.platformlayer.auth.v1.Role) CryptoKey(com.fathomdb.crypto.CryptoKey) RoleId(org.platformlayer.model.RoleId)

Example 2 with RoleId

use of org.platformlayer.model.RoleId 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 3 with RoleId

use of org.platformlayer.model.RoleId in project platformlayer by platformlayer.

the class RootResource method retrieveServiceList.

@Path("{projectId}")
public ServicesCollectionResource retrieveServiceList(@PathParam("projectId") String projectKey) {
    ProjectAuthorization authz = AuthenticationFilter.authorizeProject(getAuthenticationCredentials(), authTokenValidator, projectKey);
    if (authz == null) {
        throw new WebApplicationException(HttpServletResponse.SC_UNAUTHORIZED);
    }
    List<RoleId> roles = authz.getRoles();
    if (roles == null || !roles.contains(RoleId.OWNER)) {
        throw new WebApplicationException(HttpServletResponse.SC_UNAUTHORIZED);
    }
    // Note that we have a different notion of project id from the auth system
    // TODO: I think this is not needed for direct authentication? Fix? Cleanup?
    authz = new XaasProjectAuthorization(repository, authz);
    getScope().put(new ProjectId(projectKey));
    getScope().put(ProjectAuthorization.class, authz);
    ServicesCollectionResource resources = objectInjector.getInstance(ServicesCollectionResource.class);
    return resources;
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) ProjectAuthorization(org.platformlayer.model.ProjectAuthorization) ProjectId(org.platformlayer.ids.ProjectId) RoleId(org.platformlayer.model.RoleId) Path(javax.ws.rs.Path)

Example 4 with RoleId

use of org.platformlayer.model.RoleId in project platformlayer by platformlayer.

the class Mapping method mapToRoles.

// public static RoleList mapToRoles(List<Role> roles) {
// RoleList roleList = new RoleList();
// roleList.roles = roles;
// return roleList;
// }
public static List<Role> mapToRoles(List<RoleId> roles) {
    List<Role> roleList = Lists.newArrayList();
    for (RoleId role : roles) {
        Role xmlRole = new Role();
        xmlRole.name = role.getKey();
        roleList.add(xmlRole);
    }
    return roleList;
}
Also used : Role(org.platformlayer.auth.model.Role) RoleId(org.platformlayer.model.RoleId)

Example 5 with RoleId

use of org.platformlayer.model.RoleId in project platformlayer by platformlayer.

the class UserProjectEntity method setRoles.

public void setRoles(List<RoleId> roles) {
    StringBuilder sb = new StringBuilder();
    for (RoleId role : roles) {
        if (sb.length() != 0) {
            sb.append(",");
        }
        sb.append(role.getKey());
    }
    this.joinedRoles = sb.toString();
}
Also used : RoleId(org.platformlayer.model.RoleId)

Aggregations

RoleId (org.platformlayer.model.RoleId)5 CryptoKey (com.fathomdb.crypto.CryptoKey)2 CliException (com.fathomdb.cli.CliException)1 Path (javax.ws.rs.Path)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 ProjectEntity (org.platformlayer.auth.ProjectEntity)1 UserDatabase (org.platformlayer.auth.UserDatabase)1 UserEntity (org.platformlayer.auth.UserEntity)1 SecretStore (org.platformlayer.auth.crypto.SecretStore)1 Role (org.platformlayer.auth.model.Role)1 Role (org.platformlayer.auth.v1.Role)1 ProjectId (org.platformlayer.ids.ProjectId)1 ProjectAuthorization (org.platformlayer.model.ProjectAuthorization)1