use of com.sequenceiq.freeipa.service.freeipa.user.model.EnvironmentAccessRights in project cloudbreak by hortonworks.
the class BulkUmsUsersStateProvider method addActorsToUmsUsersStateBuilder.
private void addActorsToUmsUsersStateBuilder(int environmentIndex, UserManagementProto.GetUserSyncStateModelResponse userSyncStateModel, ActorHandler actorHandler) {
// process actors - users and machine users are combined in the actor list
userSyncStateModel.getActorList().forEach(actor -> {
UserManagementProto.RightsCheckResult rightsCheckResult = actor.getRightsCheckResult(environmentIndex);
EnvironmentAccessRights environmentAccessRights = new EnvironmentAccessRights(rightsCheckResult.getHasRight(0), rightsCheckResult.getHasRight(1));
Supplier<Collection<String>> groupMembershipSupplier = () -> actor.getGroupIndexList().stream().map(groupIndex -> userSyncStateModel.getGroupList().get(groupIndex).getCrn()).collect(Collectors.toList());
Supplier<Collection<String>> wagMembershipSupplier = () -> actor.getWorkloadAdministrationGroupIndexList().stream().map(wagIndex -> userSyncStateModel.getWorkloadAdministrationGroupList().get(wagIndex).getWorkloadAdministrationGroupName()).collect(Collectors.toList());
Supplier<WorkloadCredential> workloadCredentialSupplier = () -> workloadCredentialConverter.toWorkloadCredential(actor.getCredentials());
actorHandler.handleActor(environmentAccessRights, fmsUserConverter.toFmsUser(actor.getActorDetails()), actor.getActorDetails().getCrn(), groupMembershipSupplier, wagMembershipSupplier, workloadCredentialSupplier, actor.getActorDetails().getCloudIdentityList());
});
}
use of com.sequenceiq.freeipa.service.freeipa.user.model.EnvironmentAccessRights in project cloudbreak by hortonworks.
the class EnvironmentAccessCheckerTest method testEnvironmentAccessCheckerCreatesRightEnvironmentAccessRights.
@Test
void testEnvironmentAccessCheckerCreatesRightEnvironmentAccessRights() {
EnvironmentAccessChecker underTest = environmentAccessCheckerFactory.create(ENV_CRN);
for (boolean hasAccess : new boolean[] { false, true }) {
for (boolean ipaAdmin : new boolean[] { false, true }) {
when(grpcUmsClient.hasRightsNoCache(eq(MEMBER_CRN), anyList(), any(Optional.class), any())).thenReturn(List.of(hasAccess, ipaAdmin));
EnvironmentAccessRights environmentAccessRights = underTest.hasAccess(MEMBER_CRN, Optional.empty());
assertEquals(hasAccess, environmentAccessRights.hasEnvironmentAccessRight());
assertEquals(ipaAdmin, environmentAccessRights.hasAdminFreeIpaRight());
}
}
}
use of com.sequenceiq.freeipa.service.freeipa.user.model.EnvironmentAccessRights in project cloudbreak by hortonworks.
the class EnvironmentAccessChecker method hasAccess.
public EnvironmentAccessRights hasAccess(String memberCrn, Optional<String> requestId) {
requireNonNull(memberCrn, "memberCrn is null");
requireNonNull(requestId, "requestId is null");
try {
List<Boolean> hasRights = grpcUmsClient.hasRightsNoCache(memberCrn, rightChecks, requestId, regionAwareInternalCrnGeneratorFactory);
return new EnvironmentAccessRights(hasRights.get(0), hasRights.get(1));
} catch (StatusRuntimeException e) {
// they do not have the right to access this environment and belong to no groups.
if (e.getStatus().getCode() == Code.NOT_FOUND) {
LOGGER.warn("Member CRN {} not found in UMS. Treating as if member has no rights to environment {}: {}", memberCrn, environmentCrn, e.getLocalizedMessage());
return new EnvironmentAccessRights(false, false);
} else {
throw e;
}
}
}
use of com.sequenceiq.freeipa.service.freeipa.user.model.EnvironmentAccessRights in project cloudbreak by hortonworks.
the class BulkUmsUsersStateProvider method addActorsToUmsUsersStateBuilder.
private void addActorsToUmsUsersStateBuilder(int environmentIndex, UserManagementProto.GetUserSyncStateModelResponse userSyncStateModel, ActorHandler actorHandler, Optional<String> requestIdOptional) {
// process actors - users and machine users are combined in the actor list
userSyncStateModel.getActorList().forEach(actor -> {
UserManagementProto.RightsCheckResult rightsCheckResult = actor.getRightsCheckResult(environmentIndex);
EnvironmentAccessRights environmentAccessRights = new EnvironmentAccessRights(rightsCheckResult.getHasRight(0), rightsCheckResult.getHasRight(1));
Supplier<Collection<String>> groupMembershipSupplier = () -> actor.getGroupIndexList().stream().map(groupIndex -> userSyncStateModel.getGroupList().get(groupIndex).getCrn()).collect(Collectors.toList());
Supplier<Collection<String>> wagMembershipSupplier = () -> actor.getWorkloadAdministrationGroupIndexList().stream().map(wagIndex -> userSyncStateModel.getWorkloadAdministrationGroupList().get(wagIndex).getWorkloadAdministrationGroupName()).collect(Collectors.toList());
Supplier<WorkloadCredential> workloadCredentialSupplier = () -> umsCredentialProvider.getCredentials(actor.getActorDetails().getCrn(), requestIdOptional);
try {
actorHandler.handleActor(environmentAccessRights, fmsUserConverter.toFmsUser(actor.getActorDetails()), actor.getActorDetails().getCrn(), groupMembershipSupplier, wagMembershipSupplier, workloadCredentialSupplier, actor.getActorDetails().getCloudIdentityList());
} catch (StatusRuntimeException e) {
if (e.getStatus().getCode() == Status.Code.NOT_FOUND) {
LOGGER.warn("Member CRN {} not found in UMS. NOT_FOUND errors indicate that a user/machineUser " + "has been deleted after we have retrieved the list of users/machineUsers from " + "the UMS. Member will not be added to the UMS Users State. {}", actor.getActorDetails().getCrn(), e.getLocalizedMessage());
} else {
throw e;
}
}
});
}
use of com.sequenceiq.freeipa.service.freeipa.user.model.EnvironmentAccessRights in project cloudbreak by hortonworks.
the class EnvironmentAccessCheckerTest method testEnvironmentAccessCheckerNoAccessIfMemberNotFound.
@Test
void testEnvironmentAccessCheckerNoAccessIfMemberNotFound() {
EnvironmentAccessChecker underTest = environmentAccessCheckerFactory.create(ENV_CRN);
Throwable ex = new StatusRuntimeException(Status.Code.NOT_FOUND.toStatus());
when(grpcUmsClient.hasRightsNoCache(eq(MEMBER_CRN), anyList(), any(Optional.class), any())).thenThrow(ex);
EnvironmentAccessRights environmentAccessRights = underTest.hasAccess(MEMBER_CRN, Optional.empty());
assertFalse(environmentAccessRights.hasEnvironmentAccessRight());
assertFalse(environmentAccessRights.hasAdminFreeIpaRight());
}
Aggregations