Search in sources :

Example 11 with IdmIdentityDto

use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto in project CzechIdMng by bcvsolutions.

the class IdmIdentityController method findRevision.

@ResponseBody
@RequestMapping(value = "/{backendId}/revisions/{revId}", method = RequestMethod.GET)
@PreAuthorize("hasAuthority('" + CoreGroupPermission.IDENTITY_READ + "')")
@ApiOperation(value = "Identity audit - read revision detail", nickname = "getIdentityRevision", tags = { IdmIdentityController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.IDENTITY_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.IDENTITY_READ, description = "") }) })
public ResponseEntity<?> findRevision(@ApiParam(value = "Identity's uuid identifier or username.", required = true) @PathVariable("backendId") String backendId, @ApiParam(value = "Revision identifier.", required = true) @PathVariable("revId") Long revId) {
    IdmIdentityDto originalEntity = getDto(backendId);
    if (originalEntity == null) {
        throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", backendId));
    }
    checkAccess(originalEntity, IdmBasePermission.READ);
    // 
    IdmIdentity revisionIdentity;
    try {
        revisionIdentity = this.auditService.findRevision(IdmIdentity.class, originalEntity.getId(), revId);
    // checkAccess(revisionIdentity, IdmBasePermission.READ);
    } catch (RevisionDoesNotExistException ex) {
        throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("revision", revId), ex);
    }
    // TODO: dto
    return new ResponseEntity<>(revisionIdentity, HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) RevisionDoesNotExistException(org.hibernate.envers.exception.RevisionDoesNotExistException) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 12 with IdmIdentityDto

use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto in project CzechIdMng by bcvsolutions.

the class IdmIdentityController method getGrantedAuthotrities.

/**
 * Returns given identity's granted authorities
 *
 * @param backendId
 * @return list of granted authorities
 */
@ResponseBody
@RequestMapping(value = "/{backendId}/authorities", method = RequestMethod.GET)
@PreAuthorize("hasAuthority('" + CoreGroupPermission.IDENTITY_READ + "')")
@ApiOperation(value = "Identity granted authorities", nickname = "getIdentityAuthorities", tags = { IdmIdentityController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.IDENTITY_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.IDENTITY_READ, description = "") }) })
public List<? extends GrantedAuthority> getGrantedAuthotrities(@ApiParam(value = "Identity's uuid identifier or username.", required = true) @PathVariable String backendId) {
    IdmIdentityDto identity = getDto(backendId);
    if (identity == null) {
        throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", backendId));
    }
    checkAccess(identity, IdmBasePermission.READ);
    // 
    return grantedAuthoritiesFactory.getGrantedAuthorities(identity.getUsername());
}
Also used : ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 13 with IdmIdentityDto

use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto in project CzechIdMng by bcvsolutions.

the class AddNewAutomaticRoleTaskExecutor method processItem.

@Override
public Optional<OperationResult> processItem(IdmIdentityContractDto identityContract) {
    try {
        if (!identityContract.isValidNowOrInFuture()) {
            IdmIdentityDto identity = DtoUtils.getEmbedded(identityContract, IdmIdentityContract_.identity, IdmIdentityDto.class);
            IdmRoleDto role = DtoUtils.getEmbedded(getRoleTreeNode(), IdmRoleTreeNode_.role, IdmRoleDto.class);
            return Optional.of(new OperationResult.Builder(OperationState.NOT_EXECUTED).setModel(new DefaultResultModel(CoreResultCode.AUTOMATIC_ROLE_CONTRACT_IS_NOT_VALID, ImmutableMap.of("role", role.getCode(), "roleTreeNode", getRoleTreeNode().getId(), "identity", identity.getUsername()))).build());
        }
        List<IdmIdentityRoleDto> allByContract = identityRoleService.findAllByContract(identityContract.getId());
        // skip already assigned automatic roles
        for (IdmIdentityRoleDto roleByContract : allByContract) {
            if (ObjectUtils.equals(roleByContract.getRoleTreeNode(), getRoleTreeNode().getId())) {
                IdmIdentityDto identity = DtoUtils.getEmbedded(identityContract, IdmIdentityContract_.identity, IdmIdentityDto.class);
                IdmRoleDto role = DtoUtils.getEmbedded(getRoleTreeNode(), IdmRoleTreeNode_.role, IdmRoleDto.class);
                return Optional.of(new OperationResult.Builder(OperationState.NOT_EXECUTED).setModel(new DefaultResultModel(CoreResultCode.AUTOMATIC_ROLE_ALREADY_ASSIGNED, ImmutableMap.of("role", role.getCode(), "roleTreeNode", getRoleTreeNode().getId(), "identity", identity.getUsername()))).build());
            }
        }
        // 
        // automatic role by tree node is added directly trough identity role
        // TODO: why is role attribute service used? Role tree node service should be used.
        automaticRoleAttributeService.addAutomaticRoles(identityContract, Sets.newHashSet(getRoleTreeNode()));
        return Optional.of(new OperationResult.Builder(OperationState.EXECUTED).build());
    } catch (Exception ex) {
        IdmIdentityDto identity = DtoUtils.getEmbedded(identityContract, IdmIdentityContract_.identity, IdmIdentityDto.class);
        IdmRoleDto role = DtoUtils.getEmbedded(getRoleTreeNode(), IdmRoleTreeNode_.role, IdmRoleDto.class);
        // 
        LOG.error("Adding role [{}] by automatic role [{}] for identity [{}] failed", role.getCode(), getRoleTreeNode().getId(), identity.getUsername(), ex);
        // 
        return Optional.of(new OperationResult.Builder(OperationState.EXCEPTION).setModel(new DefaultResultModel(CoreResultCode.AUTOMATIC_ROLE_ASSIGN_TASK_NOT_COMPLETE, ImmutableMap.of("role", role.getCode(), "roleTreeNode", getRoleTreeNode().getId(), "identity", identity.getUsername()))).setCause(ex).build());
    }
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException)

Example 14 with IdmIdentityDto

use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto in project CzechIdMng by bcvsolutions.

the class DefaultSynchronizationServiceTest method doStartSyncC_Unlinked_doLink.

@Test
public void doStartSyncC_Unlinked_doLink() {
    SysSyncConfigFilter configFilter = new SysSyncConfigFilter();
    configFilter.setName(SYNC_CONFIG_NAME);
    List<AbstractSysSyncConfigDto> syncConfigs = syncConfigService.find(configFilter, null).getContent();
    Assert.assertEquals(1, syncConfigs.size());
    AbstractSysSyncConfigDto syncConfigCustom = syncConfigs.get(0);
    Assert.assertFalse(syncConfigService.isRunning(syncConfigCustom));
    // Set sync config
    syncConfigCustom.setLinkedAction(SynchronizationLinkedActionType.IGNORE);
    syncConfigCustom.setUnlinkedAction(SynchronizationUnlinkedActionType.LINK);
    syncConfigCustom.setMissingEntityAction(SynchronizationMissingEntityActionType.IGNORE);
    syncConfigCustom.setMissingAccountAction(ReconciliationMissingAccountActionType.IGNORE);
    syncConfigCustom.setReconciliation(true);
    syncConfigService.save(syncConfigCustom);
    // Check state before sync
    IdmIdentityDto identityOne = identityService.getByUsername("x" + IDENTITY_USERNAME_ONE);
    IdmIdentityDto identityTwo = identityService.getByUsername("x" + IDENTITY_USERNAME_TWO);
    AccIdentityAccountFilter identityAccountFilterOne = new AccIdentityAccountFilter();
    identityAccountFilterOne.setIdentityId(identityOne.getId());
    Assert.assertEquals(0, identityAccoutnService.find(identityAccountFilterOne, null).getTotalElements());
    AccIdentityAccountFilter identityAccountFilterTwo = new AccIdentityAccountFilter();
    identityAccountFilterTwo.setIdentityId(identityTwo.getId());
    Assert.assertEquals(0, identityAccoutnService.find(identityAccountFilterTwo, null).getTotalElements());
    // Start synchronization
    synchornizationService.setSynchronizationConfigId(syncConfigCustom.getId());
    synchornizationService.process();
    // 
    SysSyncLogFilter logFilter = new SysSyncLogFilter();
    logFilter.setSynchronizationConfigId(syncConfigCustom.getId());
    List<SysSyncLogDto> logs = syncLogService.find(logFilter, null).getContent();
    Assert.assertEquals(1, logs.size());
    SysSyncLogDto log = logs.get(0);
    // log.getSyncActionLogs();
    Assert.assertFalse(log.isRunning());
    Assert.assertFalse(log.isContainsError());
    SysSyncActionLogFilter actionLogFilter = new SysSyncActionLogFilter();
    actionLogFilter.setSynchronizationLogId(log.getId());
    List<SysSyncActionLogDto> actions = syncActionLogService.find(actionLogFilter, null).getContent();
    Assert.assertEquals(1, actions.size());
    SysSyncActionLogDto actionLog = actions.stream().filter(action -> {
        return SynchronizationActionType.LINK == action.getSyncAction();
    }).findFirst().get();
    SysSyncItemLogFilter itemLogFilter = new SysSyncItemLogFilter();
    itemLogFilter.setSyncActionLogId(actionLog.getId());
    List<SysSyncItemLogDto> items = syncItemLogService.find(itemLogFilter, null).getContent();
    Assert.assertEquals(2, items.size());
    // Check state after sync
    Assert.assertEquals(1, identityAccoutnService.find(identityAccountFilterOne, null).getTotalElements());
    Assert.assertEquals(1, identityAccoutnService.find(identityAccountFilterTwo, null).getTotalElements());
    // Delete log
    syncLogService.delete(log);
}
Also used : SysSyncActionLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto) AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) SysSyncLogFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncLogFilter) SysSyncItemLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto) AccIdentityAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter) SysSyncItemLogFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncItemLogFilter) SysSyncActionLogFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncActionLogFilter) SysSyncConfigFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncConfigFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 15 with IdmIdentityDto

use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto in project CzechIdMng by bcvsolutions.

the class DefaultSynchronizationServiceTest method doStartSyncD_Missing_Account_doCreateAccount.

@Test
public void doStartSyncD_Missing_Account_doCreateAccount() {
    SysSyncConfigFilter configFilter = new SysSyncConfigFilter();
    configFilter.setName(SYNC_CONFIG_NAME);
    List<AbstractSysSyncConfigDto> syncConfigs = syncConfigService.find(configFilter, null).getContent();
    Assert.assertEquals(1, syncConfigs.size());
    AbstractSysSyncConfigDto syncConfigCustom = syncConfigs.get(0);
    Assert.assertFalse(syncConfigService.isRunning(syncConfigCustom));
    // Create new identity THREE, with account
    IdmIdentityDto identity = new IdmIdentityDto();
    identity.setUsername("x" + IDENTITY_USERNAME_THREE);
    identity.setFirstName(IDENTITY_USERNAME_THREE);
    identity.setLastName(IDENTITY_USERNAME_THREE);
    identity = identityService.save(identity);
    AccAccountDto accountOne = new AccAccountDto();
    SysSystemMappingDto systemMapping = systemMappingService.get(syncConfigCustom.getSystemMapping());
    SysSystemDto system = systemService.get(schemaObjectClassService.get(systemMapping.getObjectClass()).getSystem());
    accountOne.setSystem(system.getId());
    accountOne.setUid("x" + IDENTITY_USERNAME_THREE);
    accountOne.setAccountType(AccountType.PERSONAL);
    accountOne.setEntityType(SystemEntityType.IDENTITY);
    accountOne = accountService.save(accountOne);
    AccIdentityAccountDto accountIdentityOne = new AccIdentityAccountDto();
    accountIdentityOne.setIdentity(identity.getId());
    accountIdentityOne.setOwnership(true);
    accountIdentityOne.setAccount(accountOne.getId());
    accountIdentityOne = identityAccoutnService.save(accountIdentityOne);
    // Set sync config
    syncConfigCustom.setLinkedAction(SynchronizationLinkedActionType.IGNORE);
    syncConfigCustom.setUnlinkedAction(SynchronizationUnlinkedActionType.IGNORE);
    syncConfigCustom.setMissingEntityAction(SynchronizationMissingEntityActionType.IGNORE);
    syncConfigCustom.setMissingAccountAction(ReconciliationMissingAccountActionType.CREATE_ACCOUNT);
    syncConfigCustom.setReconciliation(true);
    syncConfigService.save(syncConfigCustom);
    // Check state before sync
    Assert.assertNull(entityManager.find(TestResource.class, "x" + IDENTITY_USERNAME_THREE));
    // Start synchronization
    synchornizationService.setSynchronizationConfigId(syncConfigCustom.getId());
    synchornizationService.process();
    // 
    SysSyncLogFilter logFilter = new SysSyncLogFilter();
    logFilter.setSynchronizationConfigId(syncConfigCustom.getId());
    List<SysSyncLogDto> logs = syncLogService.find(logFilter, null).getContent();
    Assert.assertEquals(1, logs.size());
    SysSyncLogDto log = logs.get(0);
    Assert.assertFalse(log.isRunning());
    Assert.assertFalse(log.isContainsError());
    SysSyncActionLogFilter actionLogFilter = new SysSyncActionLogFilter();
    actionLogFilter.setSynchronizationLogId(log.getId());
    List<SysSyncActionLogDto> actions = syncActionLogService.find(actionLogFilter, null).getContent();
    Assert.assertEquals(2, actions.size());
    SysSyncActionLogDto actionLog = actions.stream().filter(action -> {
        return SynchronizationActionType.CREATE_ACCOUNT == action.getSyncAction();
    }).findFirst().get();
    SysSyncItemLogFilter itemLogFilter = new SysSyncItemLogFilter();
    itemLogFilter.setSyncActionLogId(actionLog.getId());
    List<SysSyncItemLogDto> items = syncItemLogService.find(itemLogFilter, null).getContent();
    Assert.assertEquals(1, items.size());
    // Check state after sync
    Assert.assertNotNull(entityManager.find(TestResource.class, "x" + IDENTITY_USERNAME_THREE));
    // Delete log
    syncLogService.delete(log);
}
Also used : SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) TestResource(eu.bcvsolutions.idm.acc.entity.TestResource) AccIdentityAccountDto(eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) SysSyncActionLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto) AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) SysSyncLogFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncLogFilter) SysSyncItemLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto) SysSyncItemLogFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncItemLogFilter) SysSyncActionLogFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncActionLogFilter) SysSyncConfigFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncConfigFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)568 Test (org.junit.Test)433 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)328 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)206 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)157 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)99 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)95 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)69 ArrayList (java.util.ArrayList)63 LoginDto (eu.bcvsolutions.idm.core.security.api.dto.LoginDto)61 UUID (java.util.UUID)59 AbstractCoreWorkflowIntegrationTest (eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest)58 AccIdentityAccountDto (eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto)55 IdmRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)54 IdmNotificationLogDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto)54 Transactional (org.springframework.transaction.annotation.Transactional)53 IdmNotificationFilter (eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter)51 AccIdentityAccountFilter (eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter)50 IdmConceptRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto)49 AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)48