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