use of eu.bcvsolutions.idm.core.api.dto.IdmAuthorizationPolicyDto in project CzechIdMng by bcvsolutions.
the class DefaultTestHelper method createSpecificPolicy.
@Override
public IdmAuthorizationPolicyDto createSpecificPolicy(UUID role, GroupPermission groupPermission, Class<?> authorizableType, String evaluatorType, BasePermission... permission) {
IdmAuthorizationPolicyDto dto = new IdmAuthorizationPolicyDto();
dto.setRole(role);
dto.setEvaluatorType(evaluatorType);
dto.setGroupPermission(groupPermission == null ? null : groupPermission.getName());
dto.setAuthorizableType(authorizableType == null ? null : authorizableType.getCanonicalName());
dto.setPermissions(permission);
return authorizationPolicyService.save(dto);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmAuthorizationPolicyDto in project CzechIdMng by bcvsolutions.
the class DefaultTestHelper method createAuthorizationPolicy.
@Override
public IdmAuthorizationPolicyDto createAuthorizationPolicy(UUID role, GroupPermission groupPermission, Class<? extends AbstractEntity> authorizableType, Class<? extends AuthorizationEvaluator<? extends AbstractEntity>> evaluator, BasePermission... permission) {
IdmAuthorizationPolicyDto dto = new IdmAuthorizationPolicyDto();
dto.setRole(role);
dto.setEvaluator(evaluator);
dto.setGroupPermission(groupPermission == null ? null : groupPermission.getName());
dto.setAuthorizableType(authorizableType == null ? null : authorizableType.getCanonicalName());
dto.setPermissions(permission);
//
return authorizationPolicyService.save(dto);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmAuthorizationPolicyDto in project CzechIdMng by bcvsolutions.
the class InitAccApplicationData method init.
/**
* Initialize data for acc module
*/
protected void init() {
securityService.setSystemAuthentication();
//
try {
if (!configurationService.getBooleanValue(InitDemoData.PARAMETER_DEMO_DATA_CREATED, false)) {
LOG.info("Creating demo data for [{}] module...", AccModuleDescriptor.MODULE_ID);
// check if exist user role
IdmRoleDto defaultRole = createDefaultRole();
//
// create default evaluators for acc module
//
LOG.info("Crea authorization [{}] for default user role.", IdentityAccountByAccountEvaluator.class.getSimpleName());
IdmAuthorizationPolicyDto identityAccountByAccount = new IdmAuthorizationPolicyDto();
identityAccountByAccount.setAuthorizableType(AccIdentityAccount.class.getCanonicalName());
identityAccountByAccount.setEvaluator(IdentityAccountByAccountEvaluator.class);
identityAccountByAccount.setGroupPermission(AccGroupPermission.IDENTITYACCOUNT.getName());
identityAccountByAccount.setRole(defaultRole.getId());
identityAccountByAccount = authorizationPolicyService.save(identityAccountByAccount);
//
LOG.info("Create authorization [{}] for default user role.", ReadAccountByIdentityEvaluator.class.getSimpleName());
IdmAuthorizationPolicyDto accountByIdentity = new IdmAuthorizationPolicyDto();
accountByIdentity.setAuthorizableType(AccAccount.class.getCanonicalName());
accountByIdentity.setEvaluator(ReadAccountByIdentityEvaluator.class);
accountByIdentity.setGroupPermission(AccGroupPermission.ACCOUNT.getName());
accountByIdentity.setRole(defaultRole.getId());
accountByIdentity = authorizationPolicyService.save(accountByIdentity);
//
//
}
//
// Cancels all previously ran tasks
synchronizationService.init();
} catch (Exception ex) {
LOG.warn("Init data for ACC module, was not created!", ex);
} finally {
SecurityContextHolder.clearContext();
}
}
use of eu.bcvsolutions.idm.core.api.dto.IdmAuthorizationPolicyDto in project CzechIdMng by bcvsolutions.
the class RoleAccountByRoleEvaluatorIntegrationTest method createIdentityWithRole.
private IdmIdentityDto createIdentityWithRole(boolean transitive) {
loginAsAdmin(InitTestData.TEST_ADMIN_USERNAME);
IdmRoleDto role = helper.createRole();
TEST_ROLE_ID = role.getId();
// self policy
IdmAuthorizationPolicyDto readRolePolicy = new IdmAuthorizationPolicyDto();
readRolePolicy.setPermissions(IdmBasePermission.READ);
readRolePolicy.setRole(role.getId());
readRolePolicy.setGroupPermission(CoreGroupPermission.ROLE.getName());
readRolePolicy.setAuthorizableType(IdmRole.class.getCanonicalName());
readRolePolicy.setEvaluator(CodeableEvaluator.class);
readRolePolicy.getEvaluatorProperties().put(CodeableEvaluator.PARAMETER_IDENTIFIER, role.getId());
authorizationPolicyService.save(readRolePolicy);
if (transitive) {
// create transitive policies
IdmAuthorizationPolicyDto readAuthoritiesPolicy = new IdmAuthorizationPolicyDto();
readAuthoritiesPolicy.setRole(role.getId());
readAuthoritiesPolicy.setGroupPermission(CoreGroupPermission.AUTHORIZATIONPOLICY.getName());
readAuthoritiesPolicy.setAuthorizableType(IdmAuthorizationPolicy.class.getCanonicalName());
readAuthoritiesPolicy.setEvaluator(AuthorizationPolicyByRoleEvaluator.class);
authorizationPolicyService.save(readAuthoritiesPolicy);
IdmAuthorizationPolicyDto readRoleAccountPolicy = new IdmAuthorizationPolicyDto();
readRoleAccountPolicy.setRole(role.getId());
readRoleAccountPolicy.setGroupPermission(AccGroupPermission.ROLEACCOUNT.getName());
readRoleAccountPolicy.setAuthorizableType(AccRoleAccount.class.getCanonicalName());
readRoleAccountPolicy.setEvaluator(RoleAccountByRoleEvaluator.class);
authorizationPolicyService.save(readRoleAccountPolicy);
}
// prepare identity
IdmIdentityDto identity = helper.createIdentity();
identity.setPassword(new GuardedString("heslo"));
identity = identityService.save(identity);
// assign role
helper.createIdentityRole(identity, role);
logout();
//
return identity;
}
use of eu.bcvsolutions.idm.core.api.dto.IdmAuthorizationPolicyDto in project CzechIdMng by bcvsolutions.
the class DefaultAccAccountServiceTest method getConnectorObjectTest.
@Test
public void getConnectorObjectTest() {
String userOneName = "UserOne";
String eavAttributeName = "EAV_ATTRIBUTE";
SysSystemDto system = initData();
Assert.assertNotNull(system);
IdmIdentityDto identity = helper.createIdentity();
// Create role with evaluator
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);
// Change resources (set state on exclude) .. must be call in transaction
this.getBean().persistResource(createResource(userOneName, new LocalDateTime()));
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);
// Assign role with evaluator
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());
}
Aggregations