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