Search in sources :

Example 1 with SecretPlaintext

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();
}
Also used : Users(io.hops.hopsworks.persistence.entity.user.Users) SecretPlaintext(io.hops.hopsworks.common.dao.user.security.secrets.SecretPlaintext) 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)

Example 2 with SecretPlaintext

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();
}
Also used : Users(io.hops.hopsworks.persistence.entity.user.Users) SecretPlaintext(io.hops.hopsworks.common.dao.user.security.secrets.SecretPlaintext) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiKeyRequired(io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired)

Example 3 with SecretPlaintext

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();
}
Also used : Users(io.hops.hopsworks.persistence.entity.user.Users) SecretPlaintext(io.hops.hopsworks.common.dao.user.security.secrets.SecretPlaintext) 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)

Example 4 with SecretPlaintext

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;
}
Also used : ProjectException(io.hops.hopsworks.exceptions.ProjectException) ServiceException(io.hops.hopsworks.exceptions.ServiceException) Users(io.hops.hopsworks.persistence.entity.user.Users) SecretPlaintext(io.hops.hopsworks.common.dao.user.security.secrets.SecretPlaintext) UserException(io.hops.hopsworks.exceptions.UserException) IOException(java.io.IOException) FeaturestoreException(io.hops.hopsworks.exceptions.FeaturestoreException)

Aggregations

SecretPlaintext (io.hops.hopsworks.common.dao.user.security.secrets.SecretPlaintext)4 Users (io.hops.hopsworks.persistence.entity.user.Users)4 ApiKeyRequired (io.hops.hopsworks.api.filter.apiKey.ApiKeyRequired)3 ApiOperation (io.swagger.annotations.ApiOperation)3 GET (javax.ws.rs.GET)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 JWTRequired (io.hops.hopsworks.jwt.annotation.JWTRequired)2 FeaturestoreException (io.hops.hopsworks.exceptions.FeaturestoreException)1 ProjectException (io.hops.hopsworks.exceptions.ProjectException)1 ServiceException (io.hops.hopsworks.exceptions.ServiceException)1 UserException (io.hops.hopsworks.exceptions.UserException)1 IOException (java.io.IOException)1