Search in sources :

Example 1 with PolicyModel

use of bio.terra.model.PolicyModel in project jade-data-repo by DataBiosphere.

the class SamIam method addPolicyMemberInner.

private PolicyModel addPolicyMemberInner(AuthenticatedUserRequest userReq, IamResourceType iamResourceType, UUID resourceId, String policyName, String userEmail) throws ApiException {
    ResourcesApi samResourceApi = samResourcesApi(userReq.getRequiredToken());
    samResourceApi.addUserToPolicy(iamResourceType.toString(), resourceId.toString(), policyName, userEmail);
    AccessPolicyMembership result = samResourceApi.getPolicy(iamResourceType.toString(), resourceId.toString(), policyName);
    return new PolicyModel().name(policyName).members(result.getMemberEmails());
}
Also used : PolicyModel(bio.terra.model.PolicyModel) ResourcesApi(org.broadinstitute.dsde.workbench.client.sam.api.ResourcesApi) AccessPolicyMembership(org.broadinstitute.dsde.workbench.client.sam.model.AccessPolicyMembership)

Example 2 with PolicyModel

use of bio.terra.model.PolicyModel in project jade-data-repo by DataBiosphere.

the class RepositoryApiController method deleteDatasetPolicyMember.

@Override
public ResponseEntity<PolicyResponse> deleteDatasetPolicyMember(@PathVariable("id") String id, @PathVariable("policyName") String policyName, @PathVariable("memberEmail") String memberEmail) {
    // member email can't be null since it is part of the URL
    if (!ValidationUtils.isValidEmail(memberEmail)) {
        throw new ValidationException("InvalidMemberEmail");
    }
    PolicyModel policy = iamService.deletePolicyMember(getAuthenticatedInfo(), IamResourceType.DATASET, UUID.fromString(id), policyName, memberEmail);
    PolicyResponse response = new PolicyResponse().policies(Collections.singletonList(policy));
    return new ResponseEntity<>(response, HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ValidationException(bio.terra.app.controller.exception.ValidationException) PolicyModel(bio.terra.model.PolicyModel) PolicyResponse(bio.terra.model.PolicyResponse)

Example 3 with PolicyModel

use of bio.terra.model.PolicyModel in project jade-data-repo by DataBiosphere.

the class RepositoryApiController method retrieveDatasetPolicies.

@Override
public ResponseEntity<PolicyResponse> retrieveDatasetPolicies(@PathVariable("id") String id) {
    List<PolicyModel> policies = iamService.retrievePolicies(getAuthenticatedInfo(), IamResourceType.DATASET, UUID.fromString(id));
    PolicyResponse response = new PolicyResponse().policies(policies);
    return new ResponseEntity<>(response, HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) PolicyModel(bio.terra.model.PolicyModel) PolicyResponse(bio.terra.model.PolicyResponse)

Example 4 with PolicyModel

use of bio.terra.model.PolicyModel in project jade-data-repo by DataBiosphere.

the class RepositoryApiController method deleteSnapshotPolicyMember.

@Override
public ResponseEntity<PolicyResponse> deleteSnapshotPolicyMember(@PathVariable("id") String id, @PathVariable("policyName") String policyName, @PathVariable("memberEmail") String memberEmail) {
    // member email can't be null since it is part of the URL
    if (!ValidationUtils.isValidEmail(memberEmail)) {
        throw new ValidationException("InvalidMemberEmail");
    }
    PolicyModel policy = iamService.deletePolicyMember(getAuthenticatedInfo(), IamResourceType.DATASNAPSHOT, UUID.fromString(id), policyName, memberEmail);
    PolicyResponse response = new PolicyResponse().policies(Collections.singletonList(policy));
    return new ResponseEntity<>(response, HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ValidationException(bio.terra.app.controller.exception.ValidationException) PolicyModel(bio.terra.model.PolicyModel) PolicyResponse(bio.terra.model.PolicyResponse)

Example 5 with PolicyModel

use of bio.terra.model.PolicyModel in project jade-data-repo by DataBiosphere.

the class SamIam method retrievePoliciesInner.

private List<PolicyModel> retrievePoliciesInner(AuthenticatedUserRequest userReq, IamResourceType iamResourceType, UUID resourceId) throws ApiException {
    ResourcesApi samResourceApi = samResourcesApi(userReq.getRequiredToken());
    List<AccessPolicyResponseEntry> results = samResourceApi.listResourcePolicies(iamResourceType.toString(), resourceId.toString());
    return results.stream().map(entry -> new PolicyModel().name(entry.getPolicyName()).members(entry.getPolicy().getMemberEmails())).collect(Collectors.toList());
}
Also used : DataRepoException(bio.terra.common.exception.DataRepoException) Arrays(java.util.Arrays) IamResourceType(bio.terra.service.iam.IamResourceType) AccessPolicyMembership(org.broadinstitute.dsde.workbench.client.sam.model.AccessPolicyMembership) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) IamUnauthorizedException(bio.terra.service.iam.exception.IamUnauthorizedException) HashMap(java.util.HashMap) ApiException(org.broadinstitute.dsde.workbench.client.sam.ApiException) IamInternalServerErrorException(bio.terra.service.iam.exception.IamInternalServerErrorException) ArrayList(java.util.ArrayList) IamAction(bio.terra.service.iam.IamAction) GoogleApi(org.broadinstitute.dsde.workbench.client.sam.api.GoogleApi) Map(java.util.Map) ResourcesApi(org.broadinstitute.dsde.workbench.client.sam.api.ResourcesApi) Pair(org.broadinstitute.dsde.workbench.client.sam.Pair) AccessPolicyResponseEntry(org.broadinstitute.dsde.workbench.client.sam.model.AccessPolicyResponseEntry) PolicyModel(bio.terra.model.PolicyModel) Logger(org.slf4j.Logger) ApiClient(org.broadinstitute.dsde.workbench.client.sam.ApiClient) IamBadRequestException(bio.terra.service.iam.exception.IamBadRequestException) ResourceAndAccessPolicy(org.broadinstitute.dsde.workbench.client.sam.model.ResourceAndAccessPolicy) IamProviderInterface(bio.terra.service.iam.IamProviderInterface) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) IamRole(bio.terra.service.iam.IamRole) Component(org.springframework.stereotype.Component) List(java.util.List) HttpStatusCodes(com.google.api.client.http.HttpStatusCodes) UserStatusInfo(bio.terra.model.UserStatusInfo) UsersApi(org.broadinstitute.dsde.workbench.client.sam.api.UsersApi) AuthenticatedUserRequest(bio.terra.service.iam.AuthenticatedUserRequest) ConfigurationService(bio.terra.service.configuration.ConfigurationService) Collections(java.util.Collections) IamNotFoundException(bio.terra.service.iam.exception.IamNotFoundException) AccessPolicyResponseEntry(org.broadinstitute.dsde.workbench.client.sam.model.AccessPolicyResponseEntry) PolicyModel(bio.terra.model.PolicyModel) ResourcesApi(org.broadinstitute.dsde.workbench.client.sam.api.ResourcesApi)

Aggregations

PolicyModel (bio.terra.model.PolicyModel)8 PolicyResponse (bio.terra.model.PolicyResponse)5 ResponseEntity (org.springframework.http.ResponseEntity)5 ResourcesApi (org.broadinstitute.dsde.workbench.client.sam.api.ResourcesApi)3 AccessPolicyMembership (org.broadinstitute.dsde.workbench.client.sam.model.AccessPolicyMembership)3 ValidationException (bio.terra.app.controller.exception.ValidationException)2 DataRepoException (bio.terra.common.exception.DataRepoException)1 UserStatusInfo (bio.terra.model.UserStatusInfo)1 ConfigurationService (bio.terra.service.configuration.ConfigurationService)1 AuthenticatedUserRequest (bio.terra.service.iam.AuthenticatedUserRequest)1 IamAction (bio.terra.service.iam.IamAction)1 IamProviderInterface (bio.terra.service.iam.IamProviderInterface)1 IamResourceType (bio.terra.service.iam.IamResourceType)1 IamRole (bio.terra.service.iam.IamRole)1 IamBadRequestException (bio.terra.service.iam.exception.IamBadRequestException)1 IamInternalServerErrorException (bio.terra.service.iam.exception.IamInternalServerErrorException)1 IamNotFoundException (bio.terra.service.iam.exception.IamNotFoundException)1 IamUnauthorizedException (bio.terra.service.iam.exception.IamUnauthorizedException)1 HttpStatusCodes (com.google.api.client.http.HttpStatusCodes)1 ArrayList (java.util.ArrayList)1