use of io.hops.hopsworks.common.project.AccessCredentialsDTO in project hopsworks by logicalclocks.
the class X509Resource method getx509.
@GET
@TransactionAttribute(TransactionAttributeType.NEVER)
@Produces(MediaType.APPLICATION_JSON)
@JWTRequired(acceptedTokens = { Audience.SERVICES, Audience.API }, allowedUserRoles = { "AGENT", "HOPS_ADMIN" })
@ApiOperation(value = "Get keystore, truststore and password of a project user", response = AccessCredentialsDTO.class)
public Response getx509(@QueryParam("username") String projectUsername, @Context SecurityContext sc) throws ProjectException, UserException, HopsSecurityException {
try {
String projectName = hdfsUsersController.getProjectName(projectUsername);
String username = hdfsUsersController.getUserName(projectUsername);
Project project = projectController.findProjectByName(projectName);
Users user = userFacade.findByUsername(username);
if (user == null) {
throw new UserException(RESTCodes.UserErrorCode.USER_DOES_NOT_EXIST, Level.FINE);
}
try {
AccessCredentialsDTO credentialsDTO = projectController.credentials(project.getId(), user);
return Response.ok(credentialsDTO).build();
} catch (DatasetException ex) {
throw new HopsSecurityException(RESTCodes.SecurityErrorCode.CERTIFICATE_NOT_FOUND, Level.FINE);
}
} catch (ArrayIndexOutOfBoundsException ex) {
throw new UserException(RESTCodes.UserErrorCode.USER_WAS_NOT_FOUND, Level.FINE, "Invalid project user format for username: " + projectUsername);
}
}
use of io.hops.hopsworks.common.project.AccessCredentialsDTO in project hopsworks by logicalclocks.
the class ProjectService method downloadCerts.
@POST
@Path("{projectId}/downloadCert")
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_SCIENTIST, AllowedProjectRoles.DATA_OWNER })
public Response downloadCerts(@PathParam("projectId") Integer id, @FormParam("password") String password, @Context SecurityContext sc) throws ProjectException, HopsSecurityException, DatasetException {
Users user = jWTHelper.getUserPrincipal(sc);
if (user.getEmail().equals(Settings.AGENT_EMAIL) || !authController.validatePassword(user, password)) {
throw new HopsSecurityException(RESTCodes.SecurityErrorCode.CERT_ACCESS_DENIED, Level.FINE);
}
AccessCredentialsDTO certsDTO = projectController.credentials(id, user);
return noCacheResponse.getNoCacheResponseBuilder(Response.Status.OK).entity(certsDTO).build();
}
use of io.hops.hopsworks.common.project.AccessCredentialsDTO in project hopsworks by logicalclocks.
the class ProjectService method credentials.
@GET
@Path("{projectId}/credentials")
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_SCIENTIST, AllowedProjectRoles.DATA_OWNER })
@ApiKeyRequired(acceptedScopes = { ApiScope.PROJECT }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response credentials(@PathParam("projectId") Integer id, @Context HttpServletRequest req, @Context SecurityContext sc) throws ProjectException, DatasetException {
Users user = jWTHelper.getUserPrincipal(sc);
AccessCredentialsDTO certsDTO = projectController.credentials(id, user);
return noCacheResponse.getNoCacheResponseBuilder(Response.Status.OK).entity(certsDTO).build();
}
Aggregations