Search in sources :

Example 26 with JWTRequired

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

the class ModelsResource method getAll.

@ApiOperation(value = "Get a list of all models for this project", response = ModelDTO.class)
@GET
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_SCIENTIST, AllowedProjectRoles.DATA_OWNER })
@JWTRequired(acceptedTokens = { Audience.API, Audience.JOB }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiKeyRequired(acceptedScopes = { ApiScope.MODELREGISTRY }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response getAll(@BeanParam Pagination pagination, @BeanParam ModelsBeanParam modelsBeanParam, @Context UriInfo uriInfo, @Context SecurityContext sc) throws ModelRegistryException, GenericException, SchematizedTagException, MetadataException {
    Users user = jwtHelper.getUserPrincipal(sc);
    ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.MODELS);
    resourceRequest.setOffset(pagination.getOffset());
    resourceRequest.setLimit(pagination.getLimit());
    resourceRequest.setFilter(modelsBeanParam.getFilter());
    resourceRequest.setSort(modelsBeanParam.getSortBySet());
    resourceRequest.setExpansions(modelsBeanParam.getExpansions().getResources());
    ModelDTO dto = modelsBuilder.build(uriInfo, resourceRequest, user, userProject, modelRegistryProject);
    return Response.ok().entity(dto).build();
}
Also used : ModelDTO(io.hops.hopsworks.api.modelregistry.models.dto.ModelDTO) Users(io.hops.hopsworks.persistence.entity.user.Users) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) Produces(javax.ws.rs.Produces) 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) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles)

Example 27 with JWTRequired

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

the class ModelsResource method getTags.

@ApiOperation(value = "Get all tags attached to a model", response = TagsDTO.class)
@GET
@Path("/{id}/tags")
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_SCIENTIST, AllowedProjectRoles.DATA_OWNER })
@JWTRequired(acceptedTokens = { Audience.API, Audience.JOB }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiKeyRequired(acceptedScopes = { ApiScope.MODELREGISTRY }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response getTags(@Context SecurityContext sc, @Context UriInfo uriInfo, @ApiParam(value = "Id of the model", required = true) @PathParam("id") String id, @BeanParam TagsExpansionBeanParam tagsExpansionBeanParam) throws DatasetException, MetadataException, SchematizedTagException, ProvenanceException, ModelRegistryException {
    Users user = jwtHelper.getUserPrincipal(sc);
    ProvStateDTO fileState = modelsController.getModel(modelRegistryProject, id);
    ModelDTO model = modelUtils.convertProvenanceHitToModel(fileState);
    Map<String, String> result = tagController.getAll(userProject, user, modelUtils.getModelFullPath(modelRegistryProject, model.getName(), model.getVersion()));
    ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.TAGS);
    resourceRequest.setExpansions(tagsExpansionBeanParam.getResources());
    TagsDTO dto = tagBuilder.build(uriInfo, resourceRequest, userProject, modelRegistryProject, fileState.getMlId(), result);
    return Response.status(Response.Status.OK).entity(dto).build();
}
Also used : ModelDTO(io.hops.hopsworks.api.modelregistry.models.dto.ModelDTO) TagsDTO(io.hops.hopsworks.common.tags.TagsDTO) Users(io.hops.hopsworks.persistence.entity.user.Users) ResourceRequest(io.hops.hopsworks.common.api.ResourceRequest) ProvStateDTO(io.hops.hopsworks.common.provenance.state.dto.ProvStateDTO) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) 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) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles)

Example 28 with JWTRequired

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

the class AuthFilter method allowedRoles.

@Override
public Set<String> allowedRoles() {
    Class<?> resourceClass = resourceInfo.getResourceClass();
    Method method = resourceInfo.getResourceMethod();
    JWTRequired methodRolesAnnotation = method.getAnnotation(JWTRequired.class);
    JWTRequired classRolesAnnotation = resourceClass.getAnnotation(JWTRequired.class);
    JWTRequired rolesAnnotation = methodRolesAnnotation != null ? methodRolesAnnotation : classRolesAnnotation;
    if (rolesAnnotation == null) {
        return null;
    }
    return new HashSet<>(Arrays.asList(rolesAnnotation.allowedUserRoles()));
}
Also used : JWTRequired(io.hops.hopsworks.jwt.annotation.JWTRequired) Method(java.lang.reflect.Method) HashSet(java.util.HashSet)

Example 29 with JWTRequired

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

the class FeaturestoreService method getFeaturestoreByName.

/**
 * Endpoint for getting a featurestore by name.
 *
 * @param name
 *   the name of the featurestore
 * @return JSON representation of the featurestore
 */
@GET
// Anything else that is not just number should use this endpoint
@Path("/{name: [a-z0-9_]*(?=[a-z])[a-z0-9_]+}")
@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.FEATURESTORE }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiOperation(value = "Get featurestore with a specific name", response = FeaturestoreDTO.class)
public Response getFeaturestoreByName(@ApiParam(value = "Id of the featurestore", required = true) @PathParam("name") String name, @Context SecurityContext sc) throws FeaturestoreException {
    verifyNameProvided(name);
    FeaturestoreDTO featurestoreDTO = featurestoreController.getFeaturestoreForProjectWithName(project, name);
    GenericEntity<FeaturestoreDTO> featurestoreDTOGeneric = new GenericEntity<FeaturestoreDTO>(featurestoreDTO) {
    };
    return noCacheResponse.getNoCacheResponseBuilder(Response.Status.OK).entity(featurestoreDTOGeneric).build();
}
Also used : FeaturestoreDTO(io.hops.hopsworks.common.featurestore.FeaturestoreDTO) GenericEntity(javax.ws.rs.core.GenericEntity) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) 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) AllowedProjectRoles(io.hops.hopsworks.api.filter.AllowedProjectRoles)

Example 30 with JWTRequired

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

the class FeaturestoreService method getFeaturestoreSettings.

/**
 * Endpoint for getting a featurestore's settings
 **
 * @return JSON representation of the featurestore settings
 */
@GET
@Path("/settings")
@Produces(MediaType.APPLICATION_JSON)
@AllowedProjectRoles({ AllowedProjectRoles.DATA_OWNER, AllowedProjectRoles.DATA_SCIENTIST })
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiKeyRequired(acceptedScopes = { ApiScope.FEATURESTORE }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiOperation(value = "Get featurestore settings", response = FeaturestoreClientSettingsDTO.class)
public Response getFeaturestoreSettings(@Context SecurityContext sc) {
    FeaturestoreClientSettingsDTO featurestoreClientSettingsDTO = new FeaturestoreClientSettingsDTO();
    featurestoreClientSettingsDTO.setOnlineFeaturestoreEnabled(settings.isOnlineFeaturestore());
    featurestoreClientSettingsDTO.setS3IAMRole(settings.isIAMRoleConfigured());
    GenericEntity<FeaturestoreClientSettingsDTO> featurestoreClientSettingsDTOGeneric = new GenericEntity<FeaturestoreClientSettingsDTO>(featurestoreClientSettingsDTO) {
    };
    return noCacheResponse.getNoCacheResponseBuilder(Response.Status.OK).entity(featurestoreClientSettingsDTOGeneric).build();
}
Also used : GenericEntity(javax.ws.rs.core.GenericEntity) FeaturestoreClientSettingsDTO(io.hops.hopsworks.common.featurestore.settings.FeaturestoreClientSettingsDTO) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) 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) 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