DefaultAccAccountService extends AbstractEventableDtoService<AccAccountDto, AccAccount, AccAccountFilter> implements AccAccountService { @Override public IcConnectorObject getConnectorObject(AccAccountDto account, BasePermission... permissions) { Assert.notNull(account, "Account cannot be null!"); this.checkAccess(account, permissions); List<SysSchemaAttributeDto> schemaAttributes = this.getSchemaAttributes(account.getSystem(), null); if (schemaAttributes == null) { return null; } try { IcConnectorObject fullObject = this.systemService.readConnectorObject(account.getSystem(), account.getRealUid(), null); return this.getConnectorObjectForSchema(fullObject, schemaAttributes); } catch (Exception ex) { SysSystemDto system = DtoUtils.getEmbedded(account, AccAccount_.system, SysSystemDto.class); throw new ResultCodeException(AccResultCode.ACCOUNT_CANNOT_BE_READ_FROM_TARGET, ImmutableMap.of("account", account.getUid(), "system", system != null ? system.getName() : account.getSystem()), ex); } } @Autowired  DefaultAccAccountService(AccAccountRepository accountRepository,
			AccIdentityAccountService identityAccountService, SysSystemService systemService,
			SysSchemaObjectClassService schemaObjectClassService, SysSchemaAttributeService schemaAttributeService,
			EntityEventManager entityEventManager); @Override AuthorizableType getAuthorizableType(); @Override @Transactional void delete(AccAccountDto account, BasePermission... permission); @Override List<AccAccountDto> getAccounts(UUID systemId, UUID identityId); @Override AccAccountDto getAccount(String uid, UUID systemId); @Override @Transactional(readOnly = true) Page<AccAccountDto> findExpired(ZonedDateTime expirationDate, Pageable pageable); @Override IcConnectorObject getConnectorObject(AccAccountDto account, BasePermission... permissions); @Override SynchronizationEntityExecutor getSyncExecutor(SystemEntityType entityType);  }
@Test public void getConnectorObjectTest() { String userOneName = "UserOne"; String eavAttributeName = helper.getSchemaColumnName("EAV_ATTRIBUTE"); SysSystemDto system = initData(); Assert.assertNotNull(system); IdmIdentityDto identity = helper.createIdentity(); IdmRoleDto role = helper.createRole(); IdmAuthorizationPolicyDto policyAccount = new IdmAuthorizationPolicyDto(); policyAccount.setRole(role.getId()); policyAccount.setGroupPermission(AccGroupPermission.ACCOUNT.getName()); policyAccount.setAuthorizableType(AccAccount.class.getCanonicalName()); policyAccount.setEvaluator(ReadAccountByIdentityEvaluator.class); authorizationPolicyService.save(policyAccount); this.getBean().persistResource(createResource(userOneName, ZonedDateTime.now())); AccAccountDto account = new AccAccountDto(); account.setEntityType(SystemEntityType.IDENTITY); account.setSystem(system.getId()); account.setAccountType(AccountType.PERSONAL); account.setUid(userOneName); account = accountService.save(account); AccIdentityAccountDto accountIdentityOne = new AccIdentityAccountDto(); accountIdentityOne.setIdentity(identity.getId()); accountIdentityOne.setOwnership(true); accountIdentityOne.setAccount(account.getId()); accountIdentityOne = identityAccountService.save(accountIdentityOne); helper.createIdentityRole(identity, role); logout(); loginService.login(new LoginDto(identity.getUsername(), identity.getPassword())); IcConnectorObject connectorObject = accountService.getConnectorObject(account, IdmBasePermission.READ); Assert.assertNotNull(connectorObject); Assert.assertEquals(userOneName, connectorObject.getUidValue()); Assert.assertNotNull(connectorObject.getAttributeByName(eavAttributeName)); Assert.assertEquals(userOneName, connectorObject.getAttributeByName(eavAttributeName).getValue()); }
@Test(expected = ForbiddenEntityException.class) public void getConnectorObjectForbiddenTest() { String userOneName = "UserOne"; String eavAttributeName = "EAV_ATTRIBUTE"; SysSystemDto system = initData(); Assert.assertNotNull(system); IdmIdentityDto identity = helper.createIdentity(); IdmRoleDto role = helper.createRole(); IdmAuthorizationPolicyDto policyAccount = new IdmAuthorizationPolicyDto(); policyAccount.setRole(role.getId()); policyAccount.setGroupPermission(AccGroupPermission.ACCOUNT.getName()); policyAccount.setAuthorizableType(AccAccount.class.getCanonicalName()); policyAccount.setEvaluator(ReadAccountByIdentityEvaluator.class); authorizationPolicyService.save(policyAccount); this.getBean().persistResource(createResource(userOneName, ZonedDateTime.now())); AccAccountDto account = new AccAccountDto(); account.setEntityType(SystemEntityType.IDENTITY); account.setSystem(system.getId()); account.setAccountType(AccountType.PERSONAL); account.setUid(userOneName); account = accountService.save(account); helper.createIdentityRole(identity, role); logout(); loginService.login(new LoginDto(identity.getUsername(), identity.getPassword())); IcConnectorObject connectorObject = accountService.getConnectorObject(account, IdmBasePermission.READ); Assert.assertNotNull(connectorObject); Assert.assertEquals(userOneName, connectorObject.getUidValue()); Assert.assertNotNull(connectorObject.getAttributeByName(eavAttributeName)); Assert.assertEquals(userOneName, connectorObject.getAttributeByName(eavAttributeName).getValue()); }