Search in sources :

Example 66 with JWTRequired

use of io.hops.hopsworks.jwt.annotation.JWTRequired in project hopsworks by logicalclocks.

the class TagSchemasResource method get.

@ApiOperation(value = "Get schema by name", response = SchemaDTO.class)
@GET
@Path("{name}")
@JWTRequired(acceptedTokens = { Audience.API, Audience.JOB }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiKeyRequired(acceptedScopes = { ApiScope.FEATURESTORE }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response get(@Context SecurityContext sc, @Context UriInfo uriInfo, @PathParam("name") String schemaName) throws SchematizedTagException {
    ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.TAG_SCHEMAS);
    SchemaDTO dto = tagSchemasBuilder.build(uriInfo, resourceRequest, schemaName);
    return Response.ok().entity(dto).build();
}
Also used : ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) SchemaDTO(io.hops.hopsworks.common.tags.SchemaDTO) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired) ApiOperation(io.swagger.annotations.ApiOperation) ApiKeyRequired(io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired)

Example 67 with JWTRequired

use of io.hops.hopsworks.jwt.annotation.JWTRequired in project hopsworks by logicalclocks.

the class ServingService method put.

@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST })
@JWTRequired(acceptedTokens = { Audience.API, Audience.JOB }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiKeyRequired(acceptedScopes = { ApiScope.SERVING }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiOperation(value = "Create or update a serving instance")
public Response put(@Context SecurityContext sc, @Context UriInfo uriInfo, @ApiParam(value = "serving specification", required = true) ServingView serving) throws ServingException, ServiceException, KafkaException, ProjectException, UserException, InterruptedException, ExecutionException, UnsupportedEncodingException {
    Users user = jWTHelper.getUserPrincipal(sc);
    if (serving == null) {
        throw new IllegalArgumentException("serving was not provided");
    }
    ServingWrapper servingWrapper = serving.getServingWrapper();
    servingUtil.validateUserInput(servingWrapper, project);
    servingController.put(project, user, servingWrapper);
    ServingView servingView = new ServingView(servingWrapper);
    UriBuilder builder = uriInfo.getAbsolutePathBuilder().path(String.valueOf(servingView.getId()));
    GenericEntity<ServingView> servingEntity = new GenericEntity<ServingView>(servingView) {
    };
    return Response.created(builder.build()).entity(servingEntity).build();
}
Also used : ServingWrapper(io.hops.hopsworks.common.serving.ServingWrapper) GenericEntity(javax.ws.rs.core.GenericEntity) Users(io.hops.hopsworks.persistence.entity.user.Users) UriBuilder(javax.ws.rs.core.UriBuilder) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired) ApiOperation(io.swagger.annotations.ApiOperation) ApiKeyRequired(io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles) PUT(javax.ws.rs.PUT)

Example 68 with JWTRequired

use of io.hops.hopsworks.jwt.annotation.JWTRequired in project hopsworks by logicalclocks.

the class ServingService method startOrStop.

@POST
@Path("/{servingId}")
@Consumes(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST })
@JWTRequired(acceptedTokens = { Audience.API, Audience.JOB }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiKeyRequired(acceptedScopes = { ApiScope.SERVING }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiOperation(value = "Start or stop a Serving instance")
public Response startOrStop(@Context SecurityContext sc, @ApiParam(value = "ID of the Serving instance to start/stop", required = true) @PathParam("servingId") Integer servingId, @ApiParam(value = "Action", required = true) @QueryParam("action") ServingCommands servingCommand) throws ServingException {
    Users user = jWTHelper.getUserPrincipal(sc);
    if (servingId == null) {
        throw new IllegalArgumentException("servingId was not provided");
    }
    if (servingCommand == null) {
        throw new IllegalArgumentException(RESTCodes.ServingErrorCode.COMMANDNOTPROVIDED.getMessage());
    }
    servingController.startOrStop(project, user, servingId, servingCommand);
    return Response.ok().build();
}
Also used : Users(io.hops.hopsworks.persistence.entity.user.Users) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired) ApiOperation(io.swagger.annotations.ApiOperation) ApiKeyRequired(io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles)

Example 69 with JWTRequired

use of io.hops.hopsworks.jwt.annotation.JWTRequired 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 70 with JWTRequired

use of io.hops.hopsworks.jwt.annotation.JWTRequired in project hopsworks by logicalclocks.

the class ReceiverResource method create.

@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Create a receiver.")
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response create(PostableReceiverDTO postableReceiverDTO, @QueryParam("defaultTemplate") @DefaultValue("false") Boolean defaultTemplate, @Context UriInfo uriInfo, @Context SecurityContext sc) throws AlertException, ProjectException {
    if (postableReceiverDTO == null) {
        throw new AlertException(RESTCodes.AlertErrorCode.ILLEGAL_ARGUMENT, Level.FINE, "No payload.");
    }
    Receiver receiver = receiverBuilder.build(postableReceiverDTO, defaultTemplate, true);
    validateReceiverOneConfig(receiver);
    try {
        alertManagerConfiguration.addReceiver(receiver, getProject());
    } catch (AlertManagerConfigCtrlCreateException | AlertManagerUnreachableException | AlertManagerConfigReadException e) {
        throw new AlertException(RESTCodes.AlertErrorCode.FAILED_TO_READ_CONFIGURATION, Level.FINE, e.getMessage());
    } catch (AlertManagerDuplicateEntryException e) {
        throw new AlertException(RESTCodes.AlertErrorCode.RECEIVER_EXIST, Level.FINE, e.getMessage());
    } catch (AlertManagerConfigUpdateException e) {
        throw new AlertException(RESTCodes.AlertErrorCode.FAILED_TO_UPDATE_AM_CONFIG, Level.FINE, e.getMessage());
    } catch (AlertManagerClientCreateException e) {
        throw new AlertException(RESTCodes.AlertErrorCode.FAILED_TO_CONNECT, Level.FINE, e.getMessage());
    } catch (IllegalArgumentException e) {
        throw new AlertException(RESTCodes.AlertErrorCode.ILLEGAL_ARGUMENT, Level.FINE, e.getMessage());
    }
    ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.RECEIVERS);
    ReceiverDTO dto = receiverBuilder.build(uriInfo, resourceRequest, receiver.getName(), getProject());
    dto.setHref(uriInfo.getAbsolutePathBuilder().path(receiver.getName()).build());
    return Response.created(dto.getHref()).entity(dto).build();
}
Also used : AlertManagerDuplicateEntryException(io.hops.hopsworks.alerting.exceptions.AlertManagerDuplicateEntryException) AlertManagerUnreachableException(io.hops.hopsworks.alert.exception.AlertManagerUnreachableException) Receiver(io.hops.hopsworks.alerting.config.dto.Receiver) AlertManagerConfigCtrlCreateException(io.hops.hopsworks.alerting.exceptions.AlertManagerConfigCtrlCreateException) AlertManagerConfigUpdateException(io.hops.hopsworks.alerting.exceptions.AlertManagerConfigUpdateException) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) AlertManagerConfigReadException(io.hops.hopsworks.alerting.exceptions.AlertManagerConfigReadException) AlertException(io.hops.hopsworks.exceptions.AlertException) AlertManagerClientCreateException(io.hops.hopsworks.alerting.exceptions.AlertManagerClientCreateException) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired) ApiOperation(io.swagger.annotations.ApiOperation) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles)

Aggregations

JWTRequired (io.hops.hopsworks.jwt.annotation.JWTRequired)292 Produces (javax.ws.rs.Produces)265 ApiOperation (io.swagger.annotations.ApiOperation)244 AllowedProjectRoles (io.hops.hopsworks.api.filter.AllowedProjectRoles)238 Path (javax.ws.rs.Path)203 ApiKeyRequired (io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired)171 Users (io.hops.hopsworks.persistence.entity.user.Users)169 ResourceRequest (io.hops.hopsworks.common.api.ResourceRequest)151 GET (javax.ws.rs.GET)150 Consumes (javax.ws.rs.Consumes)73 POST (javax.ws.rs.POST)62 DatasetPath (io.hops.hopsworks.common.dataset.util.DatasetPath)44 PUT (javax.ws.rs.PUT)42 DELETE (javax.ws.rs.DELETE)37 GenericEntity (javax.ws.rs.core.GenericEntity)30 Project (io.hops.hopsworks.persistence.entity.project.Project)24 AlertException (io.hops.hopsworks.exceptions.AlertException)20 AlertManagerUnreachableException (io.hops.hopsworks.alert.exception.AlertManagerUnreachableException)16 AlertManagerClientCreateException (io.hops.hopsworks.alerting.exceptions.AlertManagerClientCreateException)16 TagsDTO (io.hops.hopsworks.common.tags.TagsDTO)16