Search in sources :

Example 1 with AccessCredentialsDTO

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);
    }
}
Also used : AccessCredentialsDTO(io.hops.hopsworks.common.project.AccessCredentialsDTO) Project(io.hops.hopsworks.persistence.entity.project.Project) Users(io.hops.hopsworks.persistence.entity.user.Users) UserException(io.hops.hopsworks.exceptions.UserException) DatasetException(io.hops.hopsworks.exceptions.DatasetException) HopsSecurityException(io.hops.hopsworks.exceptions.HopsSecurityException) TransactionAttribute(javax.ejb.TransactionAttribute) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired) ApiOperation(io.swagger.annotations.ApiOperation)

Example 2 with AccessCredentialsDTO

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();
}
Also used : AccessCredentialsDTO(io.hops.hopsworks.common.project.AccessCredentialsDTO) Users(io.hops.hopsworks.persistence.entity.user.Users) HopsSecurityException(io.hops.hopsworks.exceptions.HopsSecurityException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles)

Example 3 with AccessCredentialsDTO

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();
}
Also used : AccessCredentialsDTO(io.hops.hopsworks.common.project.AccessCredentialsDTO) Users(io.hops.hopsworks.persistence.entity.user.Users) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiKeyRequired(io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles)

Aggregations

AccessCredentialsDTO (io.hops.hopsworks.common.project.AccessCredentialsDTO)3 Users (io.hops.hopsworks.persistence.entity.user.Users)3 Produces (javax.ws.rs.Produces)3 AllowedProjectRoles (io.hops.hopsworks.api.filter.AllowedProjectRoles)2 HopsSecurityException (io.hops.hopsworks.exceptions.HopsSecurityException)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 ApiKeyRequired (io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired)1 DatasetException (io.hops.hopsworks.exceptions.DatasetException)1 UserException (io.hops.hopsworks.exceptions.UserException)1 JWTRequired (io.hops.hopsworks.jwt.annotation.JWTRequired)1 Project (io.hops.hopsworks.persistence.entity.project.Project)1 ApiOperation (io.swagger.annotations.ApiOperation)1 TransactionAttribute (javax.ejb.TransactionAttribute)1 POST (javax.ws.rs.POST)1