Search in sources :

Example 6 with IdmIdentityRoleDto

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

the class InitApplicationData method init.

protected void init() {
    securityService.setSystemAuthentication();
    // 
    try {
        // prepare default form definitions
        if (formService.getDefinition(IdmIdentity.class) == null) {
            formService.createDefinition(IdmIdentity.class, new ArrayList<>());
        }
        if (formService.getDefinition(IdmRole.class) == null) {
            formService.createDefinition(IdmRole.class, new ArrayList<>());
        }
        if (formService.getDefinition(IdmTreeNode.class) == null) {
            formService.createDefinition(IdmTreeNode.class, new ArrayList<>());
        }
        if (formService.getDefinition(IdmIdentityContract.class) == null) {
            formService.createDefinition(IdmIdentityContract.class, new ArrayList<>());
        }
        // 
        // create super admin role
        IdmRoleDto existsSuperAdminRole = this.roleService.getByCode(ADMIN_ROLE);
        if (existsSuperAdminRole == null && this.roleService.find(new PageRequest(0, 1)).getTotalElements() == 0) {
            // 
            final IdmRoleDto superAdminRole = new IdmRoleDto();
            superAdminRole.setName(ADMIN_ROLE);
            superAdminRole.setRoleType(RoleType.SYSTEM);
            existsSuperAdminRole = this.roleService.save(superAdminRole);
            // super admin authorization policy
            IdmAuthorizationPolicyDto policy = new IdmAuthorizationPolicyDto();
            policy.setGroupPermission(IdmGroupPermission.APP.getName());
            policy.setPermissions(IdmBasePermission.ADMIN);
            policy.setRole(existsSuperAdminRole.getId());
            policy.setEvaluator(BasePermissionEvaluator.class);
            authorizationPolicyService.save(policy);
            // 
            LOG.info(MessageFormat.format("Super admin Role created [id: {0}]", superAdminRole.getId()));
        }
        // 
        // create super admin
        IdmIdentityDto existsSuperAdmin = this.identityService.getByUsername(ADMIN_USERNAME);
        if (existsSuperAdmin == null || this.identityService.find(new PageRequest(0, 1)).getTotalElements() == 0) {
            // 
            IdmIdentityDto identityAdmin = new IdmIdentityDto();
            identityAdmin.setUsername(ADMIN_USERNAME);
            identityAdmin.setPassword(new GuardedString(ADMIN_PASSWORD));
            identityAdmin.setLastName("Administrator");
            identityAdmin = this.identityService.save(identityAdmin);
            LOG.info(MessageFormat.format("Super admin identity created [id: {0}]", identityAdmin.getId()));
            // 
            // create prime contract
            IdmIdentityContractDto contract = identityContractService.getPrimeContract(identityAdmin.getId());
            if (contract == null) {
                contract = identityContractService.prepareMainContract(identityAdmin.getId());
                contract = identityContractService.save(contract);
            }
            // 
            // assign super admin role
            IdmIdentityRoleDto identityRole = new IdmIdentityRoleDto();
            identityRole.setIdentityContract(contract.getId());
            identityRole.setRole(existsSuperAdminRole.getId());
            identityRoleService.save(identityRole);
        }
        // 
        // create Node type for organization
        IdmTreeTypeDto treeType = treeTypeService.getByCode(DEFAULT_TREE_TYPE);
        if (treeType == null && this.treeTypeService.find(new PageRequest(0, 1)).getTotalElements() == 0) {
            treeType = new IdmTreeTypeDto();
            treeType.setCode(DEFAULT_TREE_TYPE);
            treeType.setName("Organization structure");
            treeType = this.treeTypeService.save(treeType);
            treeConfiguration.setDefaultType(treeType.getId());
            // create organization root
            if (treeNodeService.findRoots(treeType.getId(), new PageRequest(0, 1)).getTotalElements() == 0) {
                IdmTreeNodeDto organizationRoot = new IdmTreeNodeDto();
                organizationRoot.setCode("root");
                organizationRoot.setName("Root organization");
                organizationRoot.setTreeType(treeType.getId());
                organizationRoot = this.treeNodeService.save(organizationRoot);
            }
        }
        // 
        // initial missing scripts, current scripts isn't redploy
        scriptService.init();
        // save only missing templates, current templates is not redeploys
        notificationTemplateService.init();
        // 
        // init notification configuration, initialization topic need exists system templates!
        notificationConfigurationService.initDefaultTopics();
        // 
        // Cancels all previously ran tasks
        longRunningTaskManager.init();
        // 
        // Cancels all previously ran events
        entityEventManager.init();
    } finally {
        SecurityContextHolder.clearContext();
    }
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmAuthorizationPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmAuthorizationPolicyDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) PageRequest(org.springframework.data.domain.PageRequest) IdmTreeNode(eu.bcvsolutions.idm.core.model.entity.IdmTreeNode) IdmRole(eu.bcvsolutions.idm.core.model.entity.IdmRole) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmIdentityContract(eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract)

Example 7 with IdmIdentityRoleDto

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

the class InitDemoData method init.

protected void init() {
    // we need to be ensured admin and and admin role exists.
    initApplicationData.init();
    // 
    securityService.setSystemAuthentication();
    // 
    try {
        IdmIdentityDto identityAdmin = this.identityService.getByUsername(InitApplicationData.ADMIN_USERNAME);
        // 
        Page<IdmTreeNodeDto> rootsList = treeNodeService.findRoots((UUID) null, new PageRequest(0, 1));
        IdmTreeNodeDto rootOrganization = null;
        if (!rootsList.getContent().isEmpty()) {
            rootOrganization = rootsList.getContent().get(0);
        } else {
            IdmTreeNodeDto organizationRoot = new IdmTreeNodeDto();
            organizationRoot.setCode("root");
            organizationRoot.setName("Organization ROOT");
            organizationRoot.setTreeType(treeTypeService.getByCode(InitApplicationData.DEFAULT_TREE_TYPE).getId());
            organizationRoot = this.treeNodeService.save(organizationRoot);
        }
        // 
        if (!configurationService.getBooleanValue(PARAMETER_DEMO_DATA_CREATED, false)) {
            LOG.info("Creating demo data ...");
            // 
            // create default password policy for validate
            IdmPasswordPolicyDto passValidate = null;
            try {
                passValidate = this.passwordPolicyService.getDefaultPasswordPolicy(IdmPasswordPolicyType.VALIDATE);
            } catch (ResultCodeException e) {
            // nothing, password policy for validate not exist
            }
            // default password policy not exist, try to found by name
            if (passValidate == null) {
                passValidate = this.passwordPolicyService.findOneByName("DEFAULT_VALIDATE_POLICY");
            }
            // if password policy still not exist create default password policy
            if (passValidate == null) {
                passValidate = new IdmPasswordPolicyDto();
                passValidate.setName("DEFAULT_VALIDATE_POLICY");
                passValidate.setDefaultPolicy(true);
                passValidate.setType(IdmPasswordPolicyType.VALIDATE);
                passwordPolicyService.save(passValidate);
            }
            // 
            // create default password policy for generate
            IdmPasswordPolicyDto passGenerate = null;
            try {
                passGenerate = this.passwordPolicyService.getDefaultPasswordPolicy(IdmPasswordPolicyType.GENERATE);
            } catch (ResultCodeException e) {
            // nothing, password policy for generate password not exist
            }
            // try to found password policy by name
            if (passGenerate == null) {
                passGenerate = this.passwordPolicyService.findOneByName("DEFAULT_GENERATE_POLICY");
            }
            // if still not exist create default generate password policy
            if (passGenerate == null) {
                passGenerate = new IdmPasswordPolicyDto();
                passGenerate.setName("DEFAULT_GENERATE_POLICY");
                passGenerate.setDefaultPolicy(true);
                passGenerate.setType(IdmPasswordPolicyType.GENERATE);
                passGenerate.setMinLowerChar(2);
                passGenerate.setMinNumber(2);
                passGenerate.setMinSpecialChar(2);
                passGenerate.setMinUpperChar(2);
                passGenerate.setMinPasswordLength(8);
                passGenerate.setMaxPasswordLength(12);
                passwordPolicyService.save(passGenerate);
            }
            // 
            // role may exists from another module initialization
            IdmRoleDto role1 = this.roleService.getByCode(DEFAULT_ROLE_NAME);
            if (role1 == null) {
                role1 = new IdmRoleDto();
                role1.setName(DEFAULT_ROLE_NAME);
                role1 = this.roleService.save(role1);
            }
            // self policy
            IdmAuthorizationPolicyDto selfPolicy = new IdmAuthorizationPolicyDto();
            selfPolicy.setPermissions(IdmBasePermission.AUTOCOMPLETE, IdmBasePermission.READ, IdentityBasePermission.PASSWORDCHANGE, IdentityBasePermission.CHANGEPERMISSION);
            selfPolicy.setRole(role1.getId());
            selfPolicy.setGroupPermission(CoreGroupPermission.IDENTITY.getName());
            selfPolicy.setAuthorizableType(IdmIdentity.class.getCanonicalName());
            selfPolicy.setEvaluator(SelfIdentityEvaluator.class);
            authorizationPolicyService.save(selfPolicy);
            // read identity roles by identity
            IdmAuthorizationPolicyDto identityRolePolicy = new IdmAuthorizationPolicyDto();
            identityRolePolicy.setRole(role1.getId());
            identityRolePolicy.setGroupPermission(CoreGroupPermission.IDENTITYROLE.getName());
            identityRolePolicy.setAuthorizableType(IdmIdentityRole.class.getCanonicalName());
            identityRolePolicy.setEvaluator(IdentityRoleByIdentityEvaluator.class);
            authorizationPolicyService.save(identityRolePolicy);
            // read identity contracts by identity
            IdmAuthorizationPolicyDto identityContractPolicy = new IdmAuthorizationPolicyDto();
            identityContractPolicy.setRole(role1.getId());
            identityContractPolicy.setGroupPermission(CoreGroupPermission.IDENTITYCONTRACT.getName());
            identityContractPolicy.setAuthorizableType(IdmIdentityContract.class.getCanonicalName());
            identityContractPolicy.setEvaluator(IdentityContractByIdentityEvaluator.class);
            authorizationPolicyService.save(identityContractPolicy);
            // read contract guarantees by identity contract
            IdmAuthorizationPolicyDto contractGuaranteePolicy = new IdmAuthorizationPolicyDto();
            contractGuaranteePolicy.setRole(role1.getId());
            contractGuaranteePolicy.setGroupPermission(CoreGroupPermission.CONTRACTGUARANTEE.getName());
            contractGuaranteePolicy.setAuthorizableType(IdmContractGuarantee.class.getCanonicalName());
            contractGuaranteePolicy.setEvaluator(ContractGuaranteeByIdentityContractEvaluator.class);
            authorizationPolicyService.save(contractGuaranteePolicy);
            // only autocomplete roles that can be requested
            IdmAuthorizationPolicyDto applyForPolicy = new IdmAuthorizationPolicyDto();
            applyForPolicy.setPermissions(IdmBasePermission.AUTOCOMPLETE);
            applyForPolicy.setRole(role1.getId());
            applyForPolicy.setGroupPermission(CoreGroupPermission.ROLE.getName());
            applyForPolicy.setAuthorizableType(IdmRole.class.getCanonicalName());
            applyForPolicy.setEvaluator(RoleCanBeRequestedEvaluator.class);
            authorizationPolicyService.save(applyForPolicy);
            // role requests by identity
            IdmAuthorizationPolicyDto roleRequestByIdentityPolicy = new IdmAuthorizationPolicyDto();
            roleRequestByIdentityPolicy.setRole(role1.getId());
            roleRequestByIdentityPolicy.setGroupPermission(CoreGroupPermission.ROLEREQUEST.getName());
            roleRequestByIdentityPolicy.setAuthorizableType(IdmRoleRequest.class.getCanonicalName());
            roleRequestByIdentityPolicy.setEvaluator(RoleRequestByIdentityEvaluator.class);
            authorizationPolicyService.save(roleRequestByIdentityPolicy);
            // self role requests
            IdmAuthorizationPolicyDto selfRoleRequestPolicy = new IdmAuthorizationPolicyDto();
            selfRoleRequestPolicy.setPermissions(IdmBasePermission.READ, IdmBasePermission.UPDATE, IdmBasePermission.CREATE, IdmBasePermission.DELETE);
            selfRoleRequestPolicy.setRole(role1.getId());
            selfRoleRequestPolicy.setGroupPermission(CoreGroupPermission.ROLEREQUEST.getName());
            selfRoleRequestPolicy.setAuthorizableType(IdmRoleRequest.class.getCanonicalName());
            selfRoleRequestPolicy.setEvaluator(SelfRoleRequestEvaluator.class);
            authorizationPolicyService.save(selfRoleRequestPolicy);
            // role rerquests in approval
            IdmAuthorizationPolicyDto roleRequestByWfPolicy = new IdmAuthorizationPolicyDto();
            roleRequestByWfPolicy.setPermissions(IdmBasePermission.READ, IdmBasePermission.UPDATE);
            roleRequestByWfPolicy.setRole(role1.getId());
            roleRequestByWfPolicy.setGroupPermission(CoreGroupPermission.ROLEREQUEST.getName());
            roleRequestByWfPolicy.setAuthorizableType(IdmRoleRequest.class.getCanonicalName());
            roleRequestByWfPolicy.setEvaluator(RoleRequestByWfInvolvedIdentityEvaluator.class);
            authorizationPolicyService.save(roleRequestByWfPolicy);
            // tree node - autocomplete
            IdmAuthorizationPolicyDto treeNodePolicy = new IdmAuthorizationPolicyDto();
            treeNodePolicy.setPermissions(IdmBasePermission.AUTOCOMPLETE);
            treeNodePolicy.setRole(role1.getId());
            treeNodePolicy.setGroupPermission(CoreGroupPermission.TREENODE.getName());
            treeNodePolicy.setAuthorizableType(IdmTreeNode.class.getCanonicalName());
            treeNodePolicy.setEvaluator(BasePermissionEvaluator.class);
            authorizationPolicyService.save(treeNodePolicy);
            // tree type - autocomplete all
            IdmAuthorizationPolicyDto treeTypePolicy = new IdmAuthorizationPolicyDto();
            treeTypePolicy.setPermissions(IdmBasePermission.AUTOCOMPLETE);
            treeTypePolicy.setRole(role1.getId());
            treeTypePolicy.setGroupPermission(CoreGroupPermission.TREETYPE.getName());
            treeTypePolicy.setAuthorizableType(IdmTreeType.class.getCanonicalName());
            treeTypePolicy.setEvaluator(BasePermissionEvaluator.class);
            authorizationPolicyService.save(treeTypePolicy);
            // workflow task read and execute
            IdmAuthorizationPolicyDto workflowTaskPolicy = new IdmAuthorizationPolicyDto();
            workflowTaskPolicy.setPermissions(IdmBasePermission.READ, IdmBasePermission.EXECUTE);
            workflowTaskPolicy.setRole(role1.getId());
            workflowTaskPolicy.setGroupPermission(CoreGroupPermission.WORKFLOWTASK.getName());
            workflowTaskPolicy.setEvaluator(BasePermissionEvaluator.class);
            authorizationPolicyService.save(workflowTaskPolicy);
            // 
            LOG.info(MessageFormat.format("Role created [id: {0}]", role1.getId()));
            // 
            IdmRoleDto role2 = new IdmRoleDto();
            role2.setName("customRole");
            // TODO: subroles are disabled for now
            // List<IdmRoleComposition> subRoles = new ArrayList<>();
            // subRoles.add(new IdmRoleComposition(role2, superAdminRole));
            // role2.setSubRoles(subRoles);
            role2 = this.roleService.save(role2);
            LOG.info(MessageFormat.format("Role created [id: {0}]", role2.getId()));
            // 
            IdmRoleDto roleManager = new IdmRoleDto();
            roleManager.setName("manager");
            roleManager = this.roleService.save(roleManager);
            LOG.info(MessageFormat.format("Role created [id: {0}]", roleManager.getId()));
            // 
            // 
            IdmIdentityDto identity = new IdmIdentityDto();
            identity.setUsername("tomiska");
            identity.setPassword(new GuardedString("heslo"));
            identity.setFirstName("Radek");
            identity.setLastName("Tomiška");
            identity.setEmail("radek.tomiska@bcvsolutions.eu");
            identity = this.identityService.save(identity);
            LOG.info(MessageFormat.format("Identity created [id: {0}]", identity.getId()));
            // 
            // create prime contract
            IdmIdentityContractDto identityContract = identityContractService.getPrimeContract(identity.getId());
            if (identityContract == null) {
                identityContract = identityContractService.prepareMainContract(identity.getId());
                identityContract = identityContractService.save(identityContract);
            }
            // 
            IdmIdentityRoleDto identityRole1 = new IdmIdentityRoleDto();
            identityRole1.setIdentityContract(identityContract.getId());
            identityRole1.setRole(role1.getId());
            identityRole1 = identityRoleService.save(identityRole1);
            // 
            IdmIdentityRoleDto identityRole2 = new IdmIdentityRoleDto();
            identityRole2.setIdentityContract(identityContract.getId());
            identityRole2.setRole(role2.getId());
            identityRole2 = identityRoleService.save(identityRole2);
            // 
            IdmIdentityDto identity2 = new IdmIdentityDto();
            identity2.setUsername("svanda");
            identity2.setFirstName("Vít");
            identity2.setPassword(new GuardedString("heslo"));
            identity2.setLastName("Švanda");
            identity2.setEmail("vit.svanda@bcvsolutions.eu");
            identity2 = this.identityService.save(identity2);
            LOG.info(MessageFormat.format("Identity created [id: {0}]", identity2.getId()));
            // 
            IdmIdentityDto identity3 = new IdmIdentityDto();
            identity3.setUsername("kopr");
            identity3.setFirstName("Ondrej");
            identity3.setPassword(new GuardedString("heslo"));
            identity3.setLastName("Kopr");
            identity3.setEmail("ondrej.kopr@bcvsolutions.eu");
            identity3 = this.identityService.save(identity3);
            LOG.info(MessageFormat.format("Identity created [id: {0}]", identity3.getId()));
            // 
            // get tree type for organization
            IdmTreeTypeDto treeType = treeTypeService.getByCode(InitApplicationData.DEFAULT_TREE_TYPE);
            // 
            IdmTreeNodeDto organization1 = new IdmTreeNodeDto();
            organization1.setCode("one");
            organization1.setName("Organization One");
            organization1.setParent(rootOrganization.getId());
            organization1.setTreeType(treeType.getId());
            organization1 = this.treeNodeService.save(organization1);
            // 
            IdmTreeNodeDto organization2 = new IdmTreeNodeDto();
            organization2.setCode("two");
            organization2.setName("Organization Two");
            organization2.setCreator("ja");
            organization2.setParent(rootOrganization.getId());
            organization2.setTreeType(treeType.getId());
            organization2 = this.treeNodeService.save(organization2);
            // 
            IdmIdentityContractDto identityWorkPosition = new IdmIdentityContractDto();
            identityWorkPosition.setIdentity(identityAdmin.getId());
            identityWorkPosition.setWorkPosition(organization2.getId());
            identityWorkPosition = identityContractService.save(identityWorkPosition);
            IdmContractGuaranteeDto contractGuarantee = new IdmContractGuaranteeDto();
            contractGuarantee.setIdentityContract(identityWorkPosition.getId());
            contractGuarantee.setGuarantee(identity2.getId());
            contractGuaranteeService.save(contractGuarantee);
            // 
            LOG.info("Demo data was created.");
            // 
            configurationService.setBooleanValue(PARAMETER_DEMO_DATA_CREATED, true);
            // 
            // demo eav identity form
            IdmFormAttributeDto letter = new IdmFormAttributeDto();
            letter.setCode("letter");
            letter.setName("Favorite letter");
            letter.setPlaceholder("Character");
            letter.setDescription("Some favorite character");
            letter.setPersistentType(PersistentType.CHAR);
            letter.setRequired(true);
            letter = formService.saveAttribute(IdmIdentity.class, letter);
            IdmFormAttributeDto phone = new IdmFormAttributeDto();
            phone.setCode(FORM_ATTRIBUTE_PHONE);
            phone.setName("Phone");
            phone.setDescription("Additional identitiy's phone");
            phone.setPersistentType(PersistentType.TEXT);
            phone = formService.saveAttribute(IdmIdentity.class, phone);
            IdmFormAttributeDto description = new IdmFormAttributeDto();
            description.setCode("description");
            description.setName("Description");
            description.setDescription("Some longer optional text (2000 characters)");
            description.setPersistentType(PersistentType.TEXT);
            description.setFaceType(BaseFaceType.TEXTAREA);
            description = formService.saveAttribute(IdmIdentity.class, description);
            IdmFormAttributeDto rich = new IdmFormAttributeDto();
            rich.setCode("rich");
            rich.setName("RichText");
            rich.setDescription("Some rich text (2000 characters)");
            rich.setPersistentType(PersistentType.TEXT);
            description.setFaceType(BaseFaceType.RICHTEXTAREA);
            rich = formService.saveAttribute(IdmIdentity.class, rich);
            IdmFormAttributeDto sure = new IdmFormAttributeDto();
            sure.setCode("sure");
            sure.setName("Registration");
            sure.setPersistentType(PersistentType.BOOLEAN);
            sure.setDefaultValue(Boolean.TRUE.toString());
            sure = formService.saveAttribute(IdmIdentity.class, sure);
            IdmFormAttributeDto intNumber = new IdmFormAttributeDto();
            intNumber.setCode("intNumber");
            intNumber.setName("Int number");
            intNumber.setPersistentType(PersistentType.INT);
            intNumber = formService.saveAttribute(IdmIdentity.class, intNumber);
            IdmFormAttributeDto longNumber = new IdmFormAttributeDto();
            longNumber.setCode("longNumber");
            longNumber.setName("Long number");
            longNumber.setPersistentType(PersistentType.LONG);
            longNumber = formService.saveAttribute(IdmIdentity.class, longNumber);
            IdmFormAttributeDto doubleNumber = new IdmFormAttributeDto();
            doubleNumber.setCode("doubleNumber");
            doubleNumber.setName("Double number");
            doubleNumber.setPersistentType(PersistentType.DOUBLE);
            doubleNumber = formService.saveAttribute(IdmIdentity.class, doubleNumber);
            IdmFormAttributeDto currency = new IdmFormAttributeDto();
            currency.setCode("currency");
            currency.setName("Price");
            currency.setPersistentType(PersistentType.DOUBLE);
            currency.setFaceType(BaseFaceType.CURRENCY);
            currency = formService.saveAttribute(IdmIdentity.class, currency);
            IdmFormAttributeDto date = new IdmFormAttributeDto();
            date.setCode("date");
            date.setName("Date");
            date.setPersistentType(PersistentType.DATE);
            date.setRequired(true);
            date.setDescription("Important date");
            date = formService.saveAttribute(IdmIdentity.class, date);
            IdmFormAttributeDto datetime = new IdmFormAttributeDto();
            datetime.setCode(FORM_ATTRIBUTE_DATETIME);
            datetime.setName("Date and time");
            datetime.setPersistentType(PersistentType.DATETIME);
            datetime = formService.saveAttribute(IdmIdentity.class, datetime);
            IdmFormAttributeDto uuid = new IdmFormAttributeDto();
            uuid.setCode(FORM_ATTRIBUTE_UUID);
            uuid.setName("UUID");
            uuid.setDescription("Some uuid value");
            uuid.setPersistentType(PersistentType.UUID);
            uuid = formService.saveAttribute(IdmIdentity.class, uuid);
            IdmFormAttributeDto webPages = new IdmFormAttributeDto();
            webPages.setCode(FORM_ATTRIBUTE_WWW);
            webPages.setName("WWW");
            webPages.setDescription("Favorite web pages (every line in new value)");
            webPages.setPersistentType(PersistentType.TEXT);
            webPages.setMultiple(true);
            webPages = formService.saveAttribute(IdmIdentity.class, webPages);
            IdmFormAttributeDto password = new IdmFormAttributeDto();
            password.setCode(FORM_ATTRIBUTE_PASSWORD);
            password.setName("Custom password");
            password.setPersistentType(PersistentType.TEXT);
            password.setConfidential(true);
            password.setDescription("Test password");
            password = formService.saveAttribute(IdmIdentity.class, password);
            IdmFormAttributeDto byteArray = new IdmFormAttributeDto();
            byteArray.setCode("byteArray");
            byteArray.setName("Byte array");
            byteArray.setPersistentType(PersistentType.BYTEARRAY);
            byteArray.setConfidential(false);
            byteArray.setDescription("Test byte array");
            byteArray.setPlaceholder("or image :-)");
            byteArray = formService.saveAttribute(IdmIdentity.class, byteArray);
            List<IdmFormValueDto> values = new ArrayList<>();
            IdmFormValueDto phoneValue = new IdmFormValueDto();
            phoneValue.setFormAttribute(phone.getId());
            phoneValue.setStringValue("12345679");
            values.add(phoneValue);
            formService.saveValues(identity.getId(), IdmIdentity.class, null, values);
            // 
            // demo eav role form
            IdmFormAttributeDto roleExt = new IdmFormAttributeDto();
            roleExt.setCode("extAttr");
            roleExt.setName("Ext.attr");
            roleExt.setPersistentType(PersistentType.TEXT);
            roleExt.setConfidential(false);
            roleExt.setDescription("Role's custom extended attribute");
            roleExt = formService.saveAttribute(IdmRole.class, roleExt);
            // 
            // demo eav tree node form
            IdmFormAttributeDto treeNodeExt = new IdmFormAttributeDto();
            treeNodeExt.setCode("extAttr");
            treeNodeExt.setName("Ext.attr");
            treeNodeExt.setPersistentType(PersistentType.TEXT);
            treeNodeExt.setConfidential(false);
            treeNodeExt.setDescription("Tree node's custom extended attribute");
            treeNodeExt = formService.saveAttribute(IdmTreeNode.class, treeNodeExt);
            // 
            // demo eav identity contract's form
            IdmFormAttributeDto identityContractExt = new IdmFormAttributeDto();
            identityContractExt.setCode("extAttr");
            identityContractExt.setName("Ext.attr");
            identityContractExt.setPersistentType(PersistentType.TEXT);
            identityContractExt.setConfidential(false);
            identityContractExt.setDescription("Identity contract's custom extended attribute");
            identityContractExt = formService.saveAttribute(IdmIdentityContract.class, identityContractExt);
        }
    } catch (Exception ex) {
        LOG.warn("Demo data was not created", ex);
    } finally {
        SecurityContextHolder.clearContext();
    }
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmContractGuarantee(eu.bcvsolutions.idm.core.model.entity.IdmContractGuarantee) ArrayList(java.util.ArrayList) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmTreeTypeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto) PageRequest(org.springframework.data.domain.PageRequest) IdmPasswordPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto) IdmIdentityRole(eu.bcvsolutions.idm.core.model.entity.IdmIdentityRole) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmRole(eu.bcvsolutions.idm.core.model.entity.IdmRole) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContract(eu.bcvsolutions.idm.core.model.entity.IdmIdentityContract) IdmRoleRequest(eu.bcvsolutions.idm.core.model.entity.IdmRoleRequest) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmAuthorizationPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmAuthorizationPolicyDto) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) IdmTreeType(eu.bcvsolutions.idm.core.model.entity.IdmTreeType) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmContractGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto) IdmTreeNode(eu.bcvsolutions.idm.core.model.entity.IdmTreeNode) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentity(eu.bcvsolutions.idm.core.model.entity.IdmIdentity) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)

Example 8 with IdmIdentityRoleDto

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

the class IdentitySyncTest method updateIdentityPropagateValidityTest.

@Test
public void updateIdentityPropagateValidityTest() {
    SysSystemDto system = initData();
    Assert.assertNotNull(system);
    SysSyncIdentityConfigDto config = doCreateSyncConfig(system);
    IdmRoleDto defaultRole = helper.createRole();
    // Set default role to sync configuration
    config.setDefaultRole(defaultRole.getId());
    config = (SysSyncIdentityConfigDto) syncConfigService.save(config);
    IdmIdentityDto identityOne = helper.createIdentity(IDENTITY_ONE);
    IdmIdentityContractDto primeContract = contractService.getPrimeContract(identityOne.getId());
    Assert.assertNotNull(primeContract);
    LocalDate validTill = LocalDate.now().plusDays(10);
    LocalDate validFrom = LocalDate.now().plusDays(-10);
    primeContract.setValidFrom(validFrom);
    primeContract.setValidTill(validTill);
    primeContract = contractService.save(primeContract);
    IdmIdentityFilter identityFilter = new IdmIdentityFilter();
    identityFilter.setUsername(IDENTITY_ONE);
    synchornizationService.setSynchronizationConfigId(config.getId());
    synchornizationService.process();
    SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.LINK, 1, OperationResultType.SUCCESS);
    Assert.assertFalse(log.isRunning());
    Assert.assertFalse(log.isContainsError());
    List<IdmIdentityRoleDto> roles = identityRoleService.findAllByIdentity(identityOne.getId());
    Assert.assertEquals(1, roles.size());
    IdmIdentityRoleDto identityRole = roles.get(0);
    Assert.assertEquals(defaultRole.getId(), identityRole.getRole());
    Assert.assertEquals(identityRole.getValidFrom(), validFrom);
    Assert.assertEquals(identityRole.getValidTill(), validTill);
    AccIdentityAccountFilter identityAccountFilter = new AccIdentityAccountFilter();
    identityAccountFilter.setIdentityRoleId(identityRole.getId());
    Assert.assertEquals(1, identityAccountService.find(identityAccountFilter, null).getContent().size());
    // Delete log
    syncLogService.delete(log);
}
Also used : SysSyncIdentityConfigDto(eu.bcvsolutions.idm.acc.dto.SysSyncIdentityConfigDto) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmIdentityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter) AccIdentityAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) LocalDate(org.joda.time.LocalDate) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test) DefaultSynchronizationServiceTest(eu.bcvsolutions.idm.acc.service.impl.DefaultSynchronizationServiceTest)

Example 9 with IdmIdentityRoleDto

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

the class IdentitySyncTest method updateIdentityWithDefaultRoleTest.

@Test
public void updateIdentityWithDefaultRoleTest() {
    SysSystemDto system = initData();
    Assert.assertNotNull(system);
    SysSyncIdentityConfigDto config = doCreateSyncConfig(system);
    IdmRoleDto defaultRole = helper.createRole();
    // Set default role to sync configuration
    config.setDefaultRole(defaultRole.getId());
    config = (SysSyncIdentityConfigDto) syncConfigService.save(config);
    IdmIdentityDto identityOne = helper.createIdentity(IDENTITY_ONE);
    IdmIdentityFilter identityFilter = new IdmIdentityFilter();
    identityFilter.setUsername(IDENTITY_ONE);
    synchornizationService.setSynchronizationConfigId(config.getId());
    synchornizationService.process();
    SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.LINK, 1, OperationResultType.SUCCESS);
    Assert.assertFalse(log.isRunning());
    Assert.assertFalse(log.isContainsError());
    List<IdmIdentityRoleDto> roles = identityRoleService.findAllByIdentity(identityOne.getId());
    Assert.assertEquals(1, roles.size());
    Assert.assertEquals(defaultRole.getId(), roles.get(0).getRole());
    // Delete log
    syncLogService.delete(log);
}
Also used : SysSyncIdentityConfigDto(eu.bcvsolutions.idm.acc.dto.SysSyncIdentityConfigDto) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmIdentityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test) DefaultSynchronizationServiceTest(eu.bcvsolutions.idm.acc.service.impl.DefaultSynchronizationServiceTest)

Example 10 with IdmIdentityRoleDto

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

the class IdentitySyncTest method createIdentityWithDefaultRoleTest.

@Test
public void createIdentityWithDefaultRoleTest() {
    SysSystemDto system = initData();
    Assert.assertNotNull(system);
    SysSyncIdentityConfigDto config = doCreateSyncConfig(system);
    IdmRoleDto defaultRole = helper.createRole();
    // Set default role to sync configuration
    config.setDefaultRole(defaultRole.getId());
    config = (SysSyncIdentityConfigDto) syncConfigService.save(config);
    IdmIdentityFilter identityFilter = new IdmIdentityFilter();
    identityFilter.setUsername(IDENTITY_ONE);
    List<IdmIdentityDto> identities = identityService.find(identityFilter, null).getContent();
    Assert.assertEquals(0, identities.size());
    synchornizationService.setSynchronizationConfigId(config.getId());
    synchornizationService.process();
    // Have to be in the warning state, because default role cannot be assigned for
    // new identity, because sync do not creates the default contract. See
    // IdmIdentityContractService.SKIP_CREATION_OF_DEFAULT_POSITION.
    SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.CREATE_ENTITY, 1, OperationResultType.WARNING);
    Assert.assertFalse(log.isRunning());
    Assert.assertFalse(log.isContainsError());
    identities = identityService.find(identityFilter, null).getContent();
    Assert.assertEquals(1, identities.size());
    List<IdmIdentityRoleDto> roles = identityRoleService.findAllByIdentity(identities.get(0).getId());
    Assert.assertEquals(0, roles.size());
    // Delete log
    syncLogService.delete(log);
}
Also used : SysSyncIdentityConfigDto(eu.bcvsolutions.idm.acc.dto.SysSyncIdentityConfigDto) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmIdentityFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test) DefaultSynchronizationServiceTest(eu.bcvsolutions.idm.acc.service.impl.DefaultSynchronizationServiceTest)

Aggregations

IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)122 Test (org.junit.Test)94 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)90 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)72 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)71 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)54 IdmAutomaticRoleAttributeDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto)30 LocalDate (org.joda.time.LocalDate)21 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)19 TestResource (eu.bcvsolutions.idm.acc.entity.TestResource)16 IdmFormAttributeDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto)15 AccIdentityAccountFilter (eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter)13 UUID (java.util.UUID)13 AbstractUnitTest (eu.bcvsolutions.idm.test.api.AbstractUnitTest)12 AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)11 SysSystemMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto)10 Transactional (org.springframework.transaction.annotation.Transactional)10 AccIdentityAccountDto (eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto)9 IdmIdentityRoleFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter)8 AbstractCoreWorkflowIntegrationTest (eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest)7