use of io.hops.hopsworks.persistence.entity.user.security.apiKey.ApiScope in project hopsworks by logicalclocks.
the class ApiKeyResource method create.
@POST
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Create an api key.", response = ApiKeyDTO.class)
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER", "AGENT" })
public Response create(@QueryParam("name") String name, @QueryParam("scope") Set<ApiScope> scopes, @Context UriInfo uriInfo, @Context SecurityContext sc, @Context HttpServletRequest req) throws ApiKeyException, UserException {
Users user = jwtHelper.getUserPrincipal(sc);
Set<ApiScope> validatedScopes = validateScopes(user, scopes);
String apiKey = apikeyController.createNewKey(user, name, validatedScopes, false);
ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.APIKEY);
ApiKeyDTO dto = apikeyBuilder.build(uriInfo, resourceRequest, user, name);
dto.setKey(apiKey);
return Response.created(dto.getHref()).entity(dto).build();
}
use of io.hops.hopsworks.persistence.entity.user.security.apiKey.ApiScope in project hopsworks by logicalclocks.
the class ApiKeyResource method update.
@PUT
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Update an api key.", response = ApiKeyDTO.class)
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response update(@QueryParam("name") String name, @QueryParam("action") ApiKeyUpdateAction action, @QueryParam("scope") Set<ApiScope> scopes, @Context UriInfo uriInfo, @Context HttpServletRequest req, @Context SecurityContext sc) throws ApiKeyException {
Users user = jwtHelper.getUserPrincipal(sc);
Set<ApiScope> validatedScopes = validateScopes(user, scopes);
ApiKey apikey;
switch(action == null ? ApiKeyUpdateAction.ADD : action) {
case ADD:
apikey = apikeyController.addScope(user, name, validatedScopes);
break;
case DELETE:
apikey = apikeyController.removeScope(user, name, validatedScopes);
break;
case UPDATE:
apikey = apikeyController.update(user, name, validatedScopes);
break;
default:
throw new WebApplicationException("Action need to set a valid action, but found: " + action, Response.Status.NOT_FOUND);
}
ResourceRequest resourceRequest = new ResourceRequest(ResourceRequest.Name.APIKEY);
ApiKeyDTO dto = apikeyBuilder.build(uriInfo, resourceRequest, apikey);
return Response.ok().entity(dto).build();
}
use of io.hops.hopsworks.persistence.entity.user.security.apiKey.ApiScope in project hopsworks by logicalclocks.
the class ApiKeyResource method getScopes.
@GET
@Path("scopes")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Get all api key scopes.")
@JWTRequired(acceptedTokens = { Audience.API }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response getScopes(@Context SecurityContext sc) throws UserException {
Users user = jwtHelper.getUserPrincipal(sc);
if (user == null) {
throw new UserException(RESTCodes.UserErrorCode.USER_WAS_NOT_FOUND, Level.FINE);
}
Set<ApiScope> scopes = getScopesForUser(user);
GenericEntity<Set<ApiScope>> scopeEntity = new GenericEntity<Set<ApiScope>>(scopes) {
};
return Response.ok().entity(scopeEntity).build();
}
Aggregations