Search in sources :

Example 1 with IdmDelegationDefinitionDto

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);
}
Also used : IdmDelegationDefinitionDto(eu.bcvsolutions.idm.core.api.dto.IdmDelegationDefinitionDto) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) UUID(java.util.UUID) DateTimeFormatter(java.time.format.DateTimeFormatter) LocalDate(java.time.LocalDate)

Example 2 with IdmDelegationDefinitionDto

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);
}
Also used : IdmDelegationDefinitionDto(eu.bcvsolutions.idm.core.api.dto.IdmDelegationDefinitionDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) UUID(java.util.UUID)

Example 3 with IdmDelegationDefinitionDto

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);
}
Also used : IdmDelegationDefinitionDto(eu.bcvsolutions.idm.core.api.dto.IdmDelegationDefinitionDto) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) UUID(java.util.UUID) DateTimeFormatter(java.time.format.DateTimeFormatter) LocalDate(java.time.LocalDate)

Example 4 with IdmDelegationDefinitionDto

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);
}
Also used : IdmDelegationDefinitionDto(eu.bcvsolutions.idm.core.api.dto.IdmDelegationDefinitionDto) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult)

Example 5 with IdmDelegationDefinitionDto

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();
    }
}
Also used : DefaultDelegationType(eu.bcvsolutions.idm.core.model.delegation.type.DefaultDelegationType) IdmDelegation(eu.bcvsolutions.idm.core.model.entity.IdmDelegation) Autowired(org.springframework.beans.factory.annotation.Autowired) WorkflowTaskInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto) CoreGroupPermission(eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission) IdmBasePermission(eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission) DelegationDefinitionByDelegateEvaluator(eu.bcvsolutions.idm.core.security.evaluator.delegation.DelegationDefinitionByDelegateEvaluator) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) IdmIdentityContractService(eu.bcvsolutions.idm.core.api.service.IdmIdentityContractService) IdmDelegationDto(eu.bcvsolutions.idm.core.api.dto.IdmDelegationDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmDelegationDefinition(eu.bcvsolutions.idm.core.model.entity.IdmDelegationDefinition) Set(java.util.Set) Test(org.junit.Test) IdmDelegationService(eu.bcvsolutions.idm.core.api.service.IdmDelegationService) UUID(java.util.UUID) List(java.util.List) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) SelfIdentityEvaluator(eu.bcvsolutions.idm.core.security.evaluator.identity.SelfIdentityEvaluator) AbstractEvaluatorIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractEvaluatorIntegrationTest) IdmDelegationDefinitionService(eu.bcvsolutions.idm.core.api.service.IdmDelegationDefinitionService) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) Assert(org.junit.Assert) IdmDelegationDefinitionDto(eu.bcvsolutions.idm.core.api.dto.IdmDelegationDefinitionDto) DelegationByDelegationDefinitionEvaluator(eu.bcvsolutions.idm.core.security.evaluator.delegation.DelegationByDelegationDefinitionEvaluator) Transactional(org.springframework.transaction.annotation.Transactional) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmDelegationDefinitionDto(eu.bcvsolutions.idm.core.api.dto.IdmDelegationDefinitionDto) WorkflowTaskInstanceDto(eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto) IdmDelegationDto(eu.bcvsolutions.idm.core.api.dto.IdmDelegationDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) Test(org.junit.Test) AbstractEvaluatorIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractEvaluatorIntegrationTest)

Aggregations

IdmDelegationDefinitionDto (eu.bcvsolutions.idm.core.api.dto.IdmDelegationDefinitionDto)28 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)18 Test (org.junit.Test)14 UUID (java.util.UUID)11 WorkflowTaskInstanceDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto)10 List (java.util.List)10 Autowired (org.springframework.beans.factory.annotation.Autowired)10 IdmDelegationDto (eu.bcvsolutions.idm.core.api.dto.IdmDelegationDto)9 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)9 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)8 IdmDelegationDefinitionService (eu.bcvsolutions.idm.core.api.service.IdmDelegationDefinitionService)8 IdmIdentityService (eu.bcvsolutions.idm.core.api.service.IdmIdentityService)8 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)7 DefaultDelegationType (eu.bcvsolutions.idm.core.model.delegation.type.DefaultDelegationType)7 ChangeIdentityPermissionTest (eu.bcvsolutions.idm.core.workflow.permissions.ChangeIdentityPermissionTest)7 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)7 Assert (org.junit.Assert)7 CoreGroupPermission (eu.bcvsolutions.idm.core.model.domain.CoreGroupPermission)6 IdmBasePermission (eu.bcvsolutions.idm.core.security.api.domain.IdmBasePermission)6 AbstractEvaluatorIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractEvaluatorIntegrationTest)6