use of eu.bcvsolutions.idm.core.api.dto.IdmDelegationDefinitionDto in project CzechIdMng by bcvsolutions.
the class DelegationDefinitionDeleteNotificationProcessor method process.
@Override
public EventResult<IdmDelegationDefinitionDto> process(EntityEvent<IdmDelegationDefinitionDto> event) {
IdmDelegationDefinitionDto dto = event.getContent();
Assert.notNull(dto.getType(), "Delegate type cannot be null!");
Assert.notNull(dto.getDelegator(), "Delegator cannot be null!");
Assert.notNull(dto.getDelegate(), "Delegate cannot be null!");
// Transform dates
DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern(ConfigurationService.DEFAULT_APP_DATE_FORMAT);
LocalDate validFrom = dto.getValidFrom();
String from = "-∞";
if (validFrom != null) {
from = validFrom.format(dateFormat);
}
LocalDate validTill = dto.getValidTill();
String till = "∞";
if (validTill != null) {
till = validTill.format(dateFormat);
}
IdmIdentityDto delegator = identityService.get(dto.getDelegator());
IdmIdentityDto delegate = identityService.get(dto.getDelegate());
UUID currentUserId = securityService.getCurrentId();
// Send notification to the delegate (only if the delegate didn't delete the delegation).
if (!dto.getDelegate().equals(currentUserId)) {
senNotification(CoreModuleDescriptor.TOPIC_DELEGATION_DELETED_TO_DELEGATE, dto, delegator, delegate, from, till, delegate);
}
// Send notification to the delegator (only if the delegator didn't delete the delegation).
if (!dto.getDelegator().equals(currentUserId)) {
senNotification(CoreModuleDescriptor.TOPIC_DELEGATION_DELETED_TO_DELEGATOR, dto, delegator, delegate, from, till, delegator);
}
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmDelegationDefinitionDto in project CzechIdMng by bcvsolutions.
the class DelegationDefinitionSaveProcessor method process.
@Override
public EventResult<IdmDelegationDefinitionDto> process(EntityEvent<IdmDelegationDefinitionDto> event) {
IdmDelegationDefinitionDto dto = event.getContent();
if (!service.isNew(dto)) {
throw new ResultCodeException(CoreResultCode.DELEGATION_DEFINITION_CANNOT_BE_UPDATED);
}
// Validations
UUID delegateId = dto.getDelegate();
UUID delegatorId = dto.getDelegator();
Assert.notNull(delegateId, "Delegate ID cannot be null!");
Assert.notNull(delegatorId, "Delegator ID cannot be null!");
if (delegateId.equals(delegatorId)) {
throw new ResultCodeException(CoreResultCode.DELEGATION_DEFINITION_DELEGATOR_AND_DELEGATE_ARE_SAME, ImmutableMap.of("identity", delegateId));
}
dto = service.saveInternal(dto);
event.setContent(dto);
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmDelegationDefinitionDto in project CzechIdMng by bcvsolutions.
the class DelegationDefinitionCreateNotificationProcessor method process.
@Override
public EventResult<IdmDelegationDefinitionDto> process(EntityEvent<IdmDelegationDefinitionDto> event) {
IdmDelegationDefinitionDto dto = event.getContent();
Assert.notNull(dto.getType(), "Delegate type cannot be null!");
Assert.notNull(dto.getDelegator(), "Delegator cannot be null!");
Assert.notNull(dto.getDelegate(), "Delegate cannot be null!");
// Transform dates
DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern(ConfigurationService.DEFAULT_APP_DATE_FORMAT);
LocalDate validFrom = dto.getValidFrom();
String from = "-∞";
if (validFrom != null) {
from = validFrom.format(dateFormat);
}
LocalDate validTill = dto.getValidTill();
String till = "∞";
if (validTill != null) {
till = validTill.format(dateFormat);
}
IdmIdentityDto delegator = identityService.get(dto.getDelegator());
IdmIdentityDto delegate = identityService.get(dto.getDelegate());
UUID currentUserId = securityService.getCurrentId();
// Send notification to the delegate.
sendNotification(CoreModuleDescriptor.TOPIC_DELEGATION_CREATED_TO_DELEGATE, dto, delegator, delegate, from, till, delegate);
// Send notification to the delegator (only if the delegator didn't create the delegation).
if (!dto.getDelegator().equals(currentUserId)) {
sendNotification(CoreModuleDescriptor.TOPIC_DELEGATION_CREATED_TO_DELEGATOR, dto, delegator, delegate, from, till, delegator);
}
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmDelegationDefinitionDto in project CzechIdMng by bcvsolutions.
the class DelegationDefinitionDeleteProcessor method process.
@Override
public EventResult<IdmDelegationDefinitionDto> process(EntityEvent<IdmDelegationDefinitionDto> event) {
IdmDelegationDefinitionDto dto = event.getContent();
// Internal delete
service.deleteInternal(dto);
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmDelegationDefinitionDto in project CzechIdMng by bcvsolutions.
the class DelegationByDelegationDefinitionEvaluatorTest method testRead.
@Test
public void testRead() {
IdmIdentityDto delegatorOne = getHelper().createIdentity();
IdmIdentityDto delegatorTwo = getHelper().createIdentity();
IdmIdentityContractDto primeContactDelegatorOne = getHelper().getPrimeContract(delegatorOne);
IdmIdentityDto delegateOne = getHelper().createIdentity();
IdmIdentityDto delegateTwo = getHelper().createIdentity();
// Create default delegation One.
IdmDelegationDefinitionDto delegationDefOne = new IdmDelegationDefinitionDto();
delegationDefOne.setType(DefaultDelegationType.NAME);
delegationDefOne.setDelegator(delegatorOne.getId());
delegationDefOne.setDelegate(delegateOne.getId());
delegationDefOne = delegationDefinitionService.save(delegationDefOne);
// Create default delegation Two.
IdmDelegationDefinitionDto delegationDefTwo = new IdmDelegationDefinitionDto();
delegationDefTwo.setType(DefaultDelegationType.NAME);
delegationDefTwo.setDelegator(delegatorTwo.getId());
delegationDefTwo.setDelegate(delegateTwo.getId());
delegationDefTwo = delegationDefinitionService.save(delegationDefTwo);
IdmDelegationDto delegationOne = new IdmDelegationDto();
delegationOne.setDefinition(delegationDefOne.getId());
delegationOne.setOwnerId(UUID.randomUUID());
delegationOne.setOwnerType(WorkflowTaskInstanceDto.class.getCanonicalName());
delegationOne = delegationService.save(delegationOne);
IdmDelegationDto delegationTwo = new IdmDelegationDto();
delegationTwo.setDefinition(delegationDefTwo.getId());
delegationTwo.setOwnerId(UUID.randomUUID());
delegationTwo.setOwnerType(WorkflowTaskInstanceDto.class.getCanonicalName());
delegationService.save(delegationTwo);
List<IdmIdentityDto> identities;
List<IdmIdentityContractDto> contracts;
List<IdmDelegationDefinitionDto> delegationDefinitions;
List<IdmDelegationDto> delegations;
IdmRoleDto roleWithPermissions = getHelper().createRole();
getHelper().createIdentityRole(delegatorOne, roleWithPermissions);
getHelper().createIdentityRole(delegatorTwo, roleWithPermissions);
getHelper().createIdentityRole(delegateOne, roleWithPermissions);
getHelper().createIdentityRole(delegateTwo, roleWithPermissions);
// check - read without policy
try {
getHelper().login(delegateOne.getUsername(), delegateOne.getPassword());
//
identities = identityService.find(null, IdmBasePermission.READ).getContent();
Assert.assertTrue(identities.isEmpty());
contracts = contractService.find(null, IdmBasePermission.READ).getContent();
Assert.assertTrue(contracts.isEmpty());
delegationDefinitions = delegationDefinitionService.find(null, IdmBasePermission.READ).getContent();
Assert.assertTrue(delegationDefinitions.isEmpty());
delegations = delegationService.find(null, IdmBasePermission.READ).getContent();
Assert.assertTrue(delegations.isEmpty());
} finally {
logout();
}
// create authorization policy - assign to role
// identity
getHelper().createAuthorizationPolicy(roleWithPermissions.getId(), CoreGroupPermission.IDENTITY, IdmIdentity.class, SelfIdentityEvaluator.class, IdmBasePermission.READ);
// delegation definitions transitively
getHelper().createAuthorizationPolicy(roleWithPermissions.getId(), CoreGroupPermission.DELEGATIONDEFINITION, IdmDelegationDefinition.class, DelegationDefinitionByDelegateEvaluator.class);
// delegation transitively
getHelper().createAuthorizationPolicy(roleWithPermissions.getId(), CoreGroupPermission.DELEGATIONDEFINITION, IdmDelegation.class, DelegationByDelegationDefinitionEvaluator.class);
//
try {
getHelper().login(delegateOne.getUsername(), delegateOne.getPassword());
//
// without update permission
identities = identityService.find(null, IdmBasePermission.UPDATE).getContent();
Assert.assertTrue(identities.isEmpty());
contracts = contractService.find(null, IdmBasePermission.UPDATE).getContent();
Assert.assertTrue(contracts.isEmpty());
delegationDefinitions = delegationDefinitionService.find(null, IdmBasePermission.UPDATE).getContent();
Assert.assertTrue(delegationDefinitions.isEmpty());
//
// evaluate access
identities = identityService.find(null, IdmBasePermission.READ).getContent();
Assert.assertEquals(1, identities.size());
Assert.assertEquals(delegateOne.getId(), identities.get(0).getId());
contracts = contractService.find(null, IdmBasePermission.READ).getContent();
Assert.assertEquals(0, contracts.size());
delegationDefinitions = delegationDefinitionService.find(null, IdmBasePermission.READ).getContent();
Assert.assertEquals(1, delegationDefinitions.size());
Assert.assertEquals(delegationDefOne.getId(), delegationDefinitions.get(0).getId());
delegations = delegationService.find(null, IdmBasePermission.READ).getContent();
Assert.assertEquals(1, delegations.size());
Assert.assertEquals(delegationOne.getId(), delegations.get(0).getId());
//
Set<String> permissions = identityService.getPermissions(delegateOne);
Assert.assertEquals(1, permissions.size());
Assert.assertTrue(permissions.stream().anyMatch(p -> p.equals(IdmBasePermission.READ.name())));
permissions = contractService.getPermissions(primeContactDelegatorOne);
Assert.assertEquals(0, permissions.size());
permissions = delegationDefinitionService.getPermissions(delegationDefOne);
Assert.assertEquals(1, permissions.size());
Assert.assertTrue(permissions.stream().anyMatch(p -> p.equals(IdmBasePermission.READ.name())));
} finally {
logout();
}
}
Aggregations