use of io.hops.hopsworks.common.dao.user.security.secrets.SecretPlaintext in project hopsworks by logicalclocks.
the class UsersResource method getSecret.
@GET
@Path("secrets/{secretName}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Gets the value of a private secret", response = SecretDTO.class)
@JWTRequired(acceptedTokens = { Audience.API, Audience.JOB }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiKeyRequired(acceptedScopes = { ApiScope.USER }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response getSecret(@PathParam("secretName") String name, @Context SecurityContext sc) throws UserException {
Users user = jWTHelper.getUserPrincipal(sc);
SecretPlaintext secret = secretsController.get(user, name);
SecretDTO dto = secretsBuilder.build(Arrays.asList(secret), true);
return Response.ok().entity(dto).build();
}
use of io.hops.hopsworks.common.dao.user.security.secrets.SecretPlaintext in project hopsworks by logicalclocks.
the class UsersResource method getAllSecrets.
@GET
@Path("secrets")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Retrieves all secrets' names of a user", response = SecretDTO.class)
@ApiKeyRequired(acceptedScopes = { ApiScope.USER }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response getAllSecrets(@Context SecurityContext sc) throws UserException {
Users user = jWTHelper.getUserPrincipal(sc);
List<SecretPlaintext> secrets = secretsController.getAllForUser(user);
SecretDTO dto = secretsBuilder.build(secrets, false);
return Response.ok().entity(dto).build();
}
use of io.hops.hopsworks.common.dao.user.security.secrets.SecretPlaintext in project hopsworks by logicalclocks.
the class UsersResource method getSharedSecret.
@GET
@Path("secrets/shared")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Gets the value of a shared secret", response = SecretDTO.class)
@JWTRequired(acceptedTokens = { Audience.API, Audience.JOB }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
@ApiKeyRequired(acceptedScopes = { ApiScope.USER }, allowedUserRoles = { "HOPS_ADMIN", "HOPS_USER" })
public Response getSharedSecret(@QueryParam("name") String secretName, @QueryParam("owner") String ownerUsername, @Context SecurityContext sc) throws UserException, ServiceException, ProjectException {
Users caller = jWTHelper.getUserPrincipal(sc);
SecretPlaintext secret = secretsController.getShared(caller, ownerUsername, secretName);
SecretDTO dto = secretsBuilder.build(Arrays.asList(secret), true);
return Response.ok().entity(dto).build();
}
use of io.hops.hopsworks.common.dao.user.security.secrets.SecretPlaintext in project hopsworks by logicalclocks.
the class StorageConnectorUtil method getSecret.
public <T> T getSecret(Secret secret, Class<T> valueType) throws FeaturestoreException {
T secretClass = null;
if (secret != null) {
try {
Users owner = userFacade.find(secret.getId().getUid());
// check if the calling user is part of the project with the shared feature store is done in feature store
// service, so we can get the secret here with owner/owner
SecretPlaintext plainText = secretsController.getShared(owner, owner, secret.getId().getName());
if (valueType == String.class) {
secretClass = (T) plainText.getPlaintext();
} else {
secretClass = objectMapper.readValue(plainText.getPlaintext(), valueType);
}
} catch (UserException | IOException | ServiceException | ProjectException e) {
throw new FeaturestoreException(RESTCodes.FeaturestoreErrorCode.STORAGE_CONNECTOR_GET_ERROR, Level.FINE, "Unable to retrieve Secret " + secret.getId().getName() + " for this storage connector.", e.getMessage());
}
}
return secretClass;
}
Aggregations