Search in sources :

Example 21 with PasswordChangeDto

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

the class IdentityPasswordPreValidateDefinitionProcessor method process.

@Override
public EventResult<PasswordChangeDto> process(EntityEvent<PasswordChangeDto> event) {
    PasswordChangeDto passwordChangeDto = event.getContent();
    IdmPasswordValidationDto passwordValidationDto = new IdmPasswordValidationDto();
    List<IdmPasswordPolicyDto> passwordPolicyList = validateDefinition(passwordChangeDto);
    this.passwordPolicyService.preValidate(passwordValidationDto, passwordPolicyList);
    return new DefaultEventResult<>(event, this);
}
Also used : IdmPasswordValidationDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordValidationDto) IdmPasswordPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto) PasswordChangeDto(eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult)

Example 22 with PasswordChangeDto

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

the class IdentitySetPasswordProcessor method process.

@Override
public EventResult<IdmIdentityDto> process(EntityEvent<IdmIdentityDto> event) {
    IdmIdentityDto previousIdentity = event.getOriginalSource();
    IdmIdentityDto newIdentity = event.getContent();
    if (stateStarting(previousIdentity, newIdentity) && hasAccount(newIdentity)) {
        // change password for all systems
        PasswordChangeDto passwordChangeDto = new PasswordChangeDto();
        // 
        // public password change password for all system including idm
        passwordChangeDto.setAll(true);
        passwordChangeDto.setIdm(true);
        // TODO: how to generate password for all system policies
        GuardedString password = new GuardedString(passwordPolicyService.generatePasswordByDefault());
        passwordChangeDto.setNewPassword(password);
        // 
        List<OperationResult> results = identityService.passwordChange(newIdentity, passwordChangeDto);
        // 
        List<IdmAccountDto> successAccounts = new ArrayList<>();
        List<OperationResult> failureResults = new ArrayList<>();
        List<String> systemNames = new ArrayList<>();
        results.forEach(result -> {
            if (result.getModel() != null) {
                boolean success = result.getModel().getStatusEnum().equals(CoreResultCode.PASSWORD_CHANGE_ACCOUNT_SUCCESS.name());
                if (success) {
                    IdmAccountDto account = (IdmAccountDto) result.getModel().getParameters().get(IdmAccountDto.PARAMETER_NAME);
                    systemNames.add(account.getSystemName());
                    successAccounts.add(account);
                } else {
                    // exception is logged before
                    failureResults.add(result);
                }
            }
        });
        // send notification if at least one system success
        if (!successAccounts.isEmpty()) {
            notificationManager.send(CoreModuleDescriptor.TOPIC_PASSWORD_CHANGED, new IdmMessageDto.Builder().setLevel(NotificationLevel.SUCCESS).addParameter("successSystemNames", StringUtils.join(systemNames, ", ")).addParameter("successAccounts", successAccounts).addParameter("failureResults", failureResults).addParameter("name", identityService.getNiceLabel(newIdentity)).addParameter("password", password).build(), newIdentity);
        }
    }
    return new DefaultEventResult<>(event, this);
}
Also used : PasswordChangeDto(eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto) ArrayList(java.util.ArrayList) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmAccountDto(eu.bcvsolutions.idm.core.api.dto.IdmAccountDto) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)

Example 23 with PasswordChangeDto

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

the class AbstractProvisioningExecutor method changePassword.

@Override
public List<OperationResult> changePassword(DTO dto, PasswordChangeDto passwordChange) {
    Assert.notNull(dto);
    Assert.notNull(dto.getId(), "Password can be changed, when dto is already persisted.");
    Assert.notNull(passwordChange);
    List<SysProvisioningOperationDto> preparedOperations = new ArrayList<>();
    // 
    EntityAccountFilter filter = this.createEntityAccountFilter();
    filter.setEntityId(dto.getId());
    List<? extends EntityAccountDto> entityAccountList = getEntityAccountService().find(filter, null).getContent();
    if (entityAccountList == null) {
        return Collections.<OperationResult>emptyList();
    }
    // Distinct by accounts
    List<UUID> accountIds = new ArrayList<>();
    entityAccountList.stream().filter(entityAccount -> {
        if (!entityAccount.isOwnership()) {
            return false;
        }
        if (passwordChange.isAll()) {
            // Add all account supports change password
            if (entityAccount.getAccount() == null) {
                return false;
            }
            // Check if system for this account support change password
            AccAccountFilter accountFilter = new AccAccountFilter();
            accountFilter.setSupportChangePassword(Boolean.TRUE);
            accountFilter.setId(entityAccount.getAccount());
            List<AccAccountDto> accountsChecked = accountService.find(accountFilter, null).getContent();
            if (accountsChecked.size() == 1) {
                return true;
            }
            return false;
        } else {
            return passwordChange.getAccounts().contains(entityAccount.getAccount().toString());
        }
    }).forEach(entityAccount -> {
        if (!accountIds.contains(entityAccount.getAccount())) {
            accountIds.add(entityAccount.getAccount());
        }
    });
    // 
    List<AccAccountDto> accounts = new ArrayList<>();
    accountIds.forEach(accountId -> {
        AccAccountDto account = accountService.get(accountId);
        accounts.add(account);
        // find uid from system entity or from account
        String uid = account.getUid();
        SysSystemDto system = DtoUtils.getEmbedded(account, AccAccount_.system, SysSystemDto.class);
        SysSystemEntityDto systemEntity = systemEntityService.get(account.getSystemEntity());
        // 
        // Find mapped attributes (include overloaded attributes)
        List<AttributeMapping> finalAttributes = resolveMappedAttributes(account, dto, system, systemEntity.getEntityType());
        if (CollectionUtils.isEmpty(finalAttributes)) {
            return;
        }
        // We try find __PASSWORD__ attribute in mapped attributes
        Optional<? extends AttributeMapping> attriubuteHandlingOptional = finalAttributes.stream().filter((attribute) -> {
            SysSchemaAttributeDto schemaAttributeDto = getSchemaAttribute(attribute);
            return ProvisioningService.PASSWORD_SCHEMA_PROPERTY_NAME.equals(schemaAttributeDto.getName());
        }).findFirst();
        if (!attriubuteHandlingOptional.isPresent()) {
            throw new ProvisioningException(AccResultCode.PROVISIONING_PASSWORD_FIELD_NOT_FOUND, ImmutableMap.of("uid", uid, "system", system.getName()));
        }
        AttributeMapping mappedAttribute = attriubuteHandlingOptional.get();
        // 
        // add all account attributes => standard provisioning
        SysProvisioningOperationDto additionalProvisioningOperation = null;
        List<AttributeMapping> additionalPasswordChangeAttributes = resolveAdditionalPasswordChangeAttributes(account, dto, system, systemEntity.getEntityType());
        if (!additionalPasswordChangeAttributes.isEmpty()) {
            additionalProvisioningOperation = prepareProvisioning(systemEntity, dto, dto.getId(), ProvisioningOperationType.UPDATE, additionalPasswordChangeAttributes);
        }
        // 
        // password change operation
        SysProvisioningOperationDto operation;
        if (provisioningExecutor.getConfiguration().isSendPasswordAttributesTogether() && additionalProvisioningOperation != null) {
            // all attributes as start
            operation = additionalProvisioningOperation;
            // 
            // add wish for password
            ProvisioningAttributeDto passwordAttribute = ProvisioningAttributeDto.createProvisioningAttributeKey(mappedAttribute, schemaAttributeService.get(mappedAttribute.getSchemaAttribute()).getName());
            Object value = passwordChange.getNewPassword();
            if (!mappedAttribute.isEntityAttribute() && !mappedAttribute.isExtendedAttribute()) {
            // If is attribute handling resolve as constant, then we
            // don't want
            // do transformation again (was did in getAttributeValue)
            } else {
                value = attributeMappingService.transformValueToResource(systemEntity.getUid(), value, mappedAttribute, dto);
            }
            operation.getProvisioningContext().getAccountObject().put(passwordAttribute, value);
            // 
            // do provisioning for additional attributes and password
            // together
            preparedOperations.add(operation);
        } else {
            // Change password on target system - only
            // TODO: refactor password change - use account wish instead
            // filling connector object attributes directly
            operation = prepareProvisioningForAttribute(systemEntity, mappedAttribute, passwordChange.getNewPassword(), ProvisioningOperationType.UPDATE, dto);
            preparedOperations.add(operation);
            // do provisioning for additional attributes in second
            if (additionalProvisioningOperation != null) {
                preparedOperations.add(additionalProvisioningOperation);
            }
        }
    });
    // execute prepared operations
    return preparedOperations.stream().map(operation -> {
        SysProvisioningOperationDto result = provisioningExecutor.executeSync(operation);
        Map<String, Object> parameters = new LinkedHashMap<String, Object>();
        AccAccountDto account = accounts.stream().filter(a -> {
            return a.getUid().equals(result.getSystemEntityUid()) && a.getSystem().equals(operation.getSystem());
        }).findFirst().get();
        SysSystemDto system = DtoUtils.getEmbedded(account, AccAccount_.system, SysSystemDto.class);
        // 
        IdmAccountDto resultAccountDto = new IdmAccountDto();
        resultAccountDto.setId(account.getId());
        resultAccountDto.setUid(account.getUid());
        resultAccountDto.setRealUid(account.getRealUid());
        resultAccountDto.setSystemId(system.getId());
        resultAccountDto.setSystemName(system.getName());
        parameters.put(IdmAccountDto.PARAMETER_NAME, resultAccountDto);
        // 
        if (result.getResult().getState() == OperationState.EXECUTED) {
            // Add success changed password account
            return new OperationResult.Builder(OperationState.EXECUTED).setModel(new DefaultResultModel(CoreResultCode.PASSWORD_CHANGE_ACCOUNT_SUCCESS, parameters)).build();
        }
        OperationResult changeResult = new OperationResult.Builder(result.getResult().getState()).setModel(new DefaultResultModel(CoreResultCode.PASSWORD_CHANGE_ACCOUNT_FAILED, parameters)).build();
        changeResult.setCause(result.getResult().getCause());
        changeResult.setCode(result.getResult().getCode());
        return changeResult;
    }).collect(Collectors.toList());
}
Also used : ProvisioningExecutor(eu.bcvsolutions.idm.acc.service.api.ProvisioningExecutor) DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) SysSchemaAttributeDto(eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto) Autowired(org.springframework.beans.factory.annotation.Autowired) SysSystemEntityDto(eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto) EntityAccountDto(eu.bcvsolutions.idm.acc.dto.EntityAccountDto) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) SysRoleSystemService(eu.bcvsolutions.idm.acc.service.api.SysRoleSystemService) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) SysSystemEntity_(eu.bcvsolutions.idm.acc.entity.SysSystemEntity_) Map(java.util.Map) ProvisioningEntityExecutor(eu.bcvsolutions.idm.acc.service.api.ProvisioningEntityExecutor) SysSystemAttributeMapping(eu.bcvsolutions.idm.acc.entity.SysSystemAttributeMapping) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) SystemOperationType(eu.bcvsolutions.idm.acc.domain.SystemOperationType) ReadWriteDtoService(eu.bcvsolutions.idm.core.api.service.ReadWriteDtoService) Set(java.util.Set) ProvisioningAttributeDto(eu.bcvsolutions.idm.acc.dto.ProvisioningAttributeDto) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) AttributeMapping(eu.bcvsolutions.idm.acc.domain.AttributeMapping) List(java.util.List) EntityAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.EntityAccountFilter) AccAccountService(eu.bcvsolutions.idm.acc.service.api.AccAccountService) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) CollectionUtils(org.springframework.util.CollectionUtils) AccountType(eu.bcvsolutions.idm.acc.domain.AccountType) Optional(java.util.Optional) IcUidAttribute(eu.bcvsolutions.idm.ic.api.IcUidAttribute) SysRoleSystemDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemDto) AccAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccAccountFilter) SysSchemaObjectClassService(eu.bcvsolutions.idm.acc.service.api.SysSchemaObjectClassService) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) AccResultCode(eu.bcvsolutions.idm.acc.domain.AccResultCode) IcConnectorConfiguration(eu.bcvsolutions.idm.ic.api.IcConnectorConfiguration) IcConnectorFacade(eu.bcvsolutions.idm.ic.service.api.IcConnectorFacade) ProvisioningEvent(eu.bcvsolutions.idm.acc.event.ProvisioningEvent) AttributeMappingStrategyType(eu.bcvsolutions.idm.acc.domain.AttributeMappingStrategyType) ProvisioningEventType(eu.bcvsolutions.idm.acc.domain.ProvisioningEventType) SysSystemEntityService(eu.bcvsolutions.idm.acc.service.api.SysSystemEntityService) IdmAccountDto(eu.bcvsolutions.idm.core.api.dto.IdmAccountDto) HashMap(java.util.HashMap) IcObjectClassImpl(eu.bcvsolutions.idm.ic.impl.IcObjectClassImpl) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) SysSystemMappingService(eu.bcvsolutions.idm.acc.service.api.SysSystemMappingService) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) ImmutableList(com.google.common.collect.ImmutableList) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) IcConnectorObjectImpl(eu.bcvsolutions.idm.ic.impl.IcConnectorObjectImpl) ProvisioningOperationType(eu.bcvsolutions.idm.acc.domain.ProvisioningOperationType) LinkedHashSet(java.util.LinkedHashSet) SysProvisioningOperationDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto) ProvisioningContext(eu.bcvsolutions.idm.acc.domain.ProvisioningContext) Codeable(eu.bcvsolutions.idm.core.api.domain.Codeable) SysSystemMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemMappingFilter) SysRoleSystemAttributeService(eu.bcvsolutions.idm.acc.service.api.SysRoleSystemAttributeService) SysSchemaObjectClass_(eu.bcvsolutions.idm.acc.entity.SysSchemaObjectClass_) IcConnectorKey(eu.bcvsolutions.idm.ic.api.IcConnectorKey) SysSystemService(eu.bcvsolutions.idm.acc.service.api.SysSystemService) IdmRoleService(eu.bcvsolutions.idm.core.api.service.IdmRoleService) OperationState(eu.bcvsolutions.idm.core.api.domain.OperationState) IcAttribute(eu.bcvsolutions.idm.ic.api.IcAttribute) SysRoleSystemAttributeDto(eu.bcvsolutions.idm.acc.dto.SysRoleSystemAttributeDto) SysSchemaAttributeService(eu.bcvsolutions.idm.acc.service.api.SysSchemaAttributeService) SysSystemAttributeMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter) AccAccount_(eu.bcvsolutions.idm.acc.entity.AccAccount_) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) CoreResultCode(eu.bcvsolutions.idm.core.api.domain.CoreResultCode) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) ProvisioningService(eu.bcvsolutions.idm.acc.service.api.ProvisioningService) Collections(java.util.Collections) SysSystemAttributeMappingService(eu.bcvsolutions.idm.acc.service.api.SysSystemAttributeMappingService) PasswordChangeDto(eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto) EntityEventManager(eu.bcvsolutions.idm.core.api.service.EntityEventManager) Assert(org.springframework.util.Assert) SysSchemaAttributeDto(eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto) ArrayList(java.util.ArrayList) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) ProvisioningAttributeDto(eu.bcvsolutions.idm.acc.dto.ProvisioningAttributeDto) AccAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccAccountFilter) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) UUID(java.util.UUID) SysSystemEntityDto(eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto) SysProvisioningOperationDto(eu.bcvsolutions.idm.acc.dto.SysProvisioningOperationDto) DefaultResultModel(eu.bcvsolutions.idm.core.api.dto.DefaultResultModel) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) EntityAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.EntityAccountFilter) IdmAccountDto(eu.bcvsolutions.idm.core.api.dto.IdmAccountDto) SysSystemAttributeMapping(eu.bcvsolutions.idm.acc.entity.SysSystemAttributeMapping) AttributeMapping(eu.bcvsolutions.idm.acc.domain.AttributeMapping) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 24 with PasswordChangeDto

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

the class DefaultAccAuthenticatorTest method loginAgainstTwoAccount.

@Test
public void loginAgainstTwoAccount() {
    IdmIdentityDto identity = identityService.getByUsername(USERNAME);
    AccIdentityAccountFilter filter = new AccIdentityAccountFilter();
    filter.setIdentityId(identity.getId());
    List<AccIdentityAccountDto> identityAccounts = identityAccountService.find(filter, null).getContent();
    // get account distinct for identityAccounts
    List<String> accountIds = new ArrayList<>();
    for (AccIdentityAccountDto identityAccount : identityAccounts) {
        if (!accountIds.contains(identityAccount.getAccount().toString())) {
            accountIds.add(identityAccount.getAccount().toString());
        }
    }
    assertEquals(1, accountIds.size());
    assertEquals(1, identityAccounts.size());
    IdmRoleDto role2 = roleService.getByCode(ROLE_NAME + "2");
    IdmIdentityRoleDto irdto = new IdmIdentityRoleDto();
    irdto.setIdentityContract(identityContractService.findAllByIdentity(identity.getId()).get(0).getId());
    irdto.setRole(role2.getId());
    irdto = identityRoleService.save(irdto);
    identityAccounts = identityAccountService.find(filter, null).getContent();
    // get account distinct for identityAccounts
    accountIds = new ArrayList<>();
    for (AccIdentityAccountDto identityAccount : identityAccounts) {
        if (!accountIds.contains(identityAccount.getAccount().toString())) {
            accountIds.add(identityAccount.getAccount().toString());
        }
    }
    assertEquals(2, accountIds.size());
    assertEquals(2, identityAccounts.size());
    PasswordChangeDto passwordChangeDto = new PasswordChangeDto();
    List<String> accs = new ArrayList<>();
    accs.add(accountIds.get(0));
    passwordChangeDto.setAccounts(accs);
    passwordChangeDto.setAll(false);
    passwordChangeDto.setNewPassword(new GuardedString("1234"));
    // change password for system
    provisioningService.changePassword(identity, passwordChangeDto);
    passwordChangeDto = new PasswordChangeDto();
    accs = new ArrayList<>();
    accs.add(accountIds.get(1));
    passwordChangeDto.setAccounts(accs);
    passwordChangeDto.setAll(false);
    passwordChangeDto.setNewPassword(new GuardedString("4321"));
    // change password for system
    provisioningService.changePassword(identity, passwordChangeDto);
    // bough password are right
    LoginDto loginDto1 = new LoginDto();
    loginDto1.setUsername(USERNAME);
    loginDto1.setPassword(new GuardedString("1234"));
    loginDto1 = authenticationManager.authenticate(loginDto1);
    LoginDto loginDto2 = new LoginDto();
    loginDto2.setUsername(USERNAME);
    loginDto2.setPassword(new GuardedString("4321"));
    loginDto2 = authenticationManager.authenticate(loginDto2);
    assertNotNull(loginDto2);
    assertNotNull(loginDto2.getAuthentication());
    assertEquals("acc", loginDto2.getAuthenticationModule());
    assertNotNull(loginDto1);
    assertNotNull(loginDto1.getAuthentication());
    assertEquals("acc", loginDto1.getAuthenticationModule());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) PasswordChangeDto(eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto) ArrayList(java.util.ArrayList) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) AccIdentityAccountDto(eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto) AccIdentityAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) LoginDto(eu.bcvsolutions.idm.core.security.api.dto.LoginDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 25 with PasswordChangeDto

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

the class DefaultAccAuthenticatorTest method A_loginAgainstSystem.

@Test
public void A_loginAgainstSystem() {
    initData();
    IdmIdentityDto identity = identityService.getByUsername(USERNAME);
    IdmRoleDto role = roleService.getByCode(ROLE_NAME);
    IdmIdentityRoleDto irdto = new IdmIdentityRoleDto();
    irdto.setIdentityContract(identityContractService.findAllByIdentity(identity.getId()).get(0).getId());
    irdto.setRole(role.getId());
    // This evokes IdentityRole SAVE event. On this event will be start
    // account management and provisioning
    irdto = identityRoleService.save(irdto);
    // 
    AccIdentityAccountFilter filter = new AccIdentityAccountFilter();
    filter.setIdentityId(identity.getId());
    List<AccIdentityAccountDto> accounts = identityAccountService.find(filter, null).getContent();
    assertEquals(1, accounts.size());
    List<String> accs = new ArrayList<>();
    accs.add(accounts.get(0).getId().toString());
    PasswordChangeDto passwordChangeDto = new PasswordChangeDto();
    passwordChangeDto.setAccounts(accs);
    passwordChangeDto.setAll(true);
    passwordChangeDto.setNewPassword(new GuardedString("test"));
    // change password for system
    provisioningService.changePassword(identity, passwordChangeDto);
    LoginDto loginDto = new LoginDto();
    loginDto.setUsername(USERNAME);
    loginDto.setPassword(new GuardedString("test"));
    loginDto = authenticationManager.authenticate(loginDto);
    // 
    assertNotNull(loginDto);
    assertNotNull(loginDto.getAuthentication());
    assertEquals("acc", loginDto.getAuthenticationModule());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) PasswordChangeDto(eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto) AccIdentityAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter) ArrayList(java.util.ArrayList) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) LoginDto(eu.bcvsolutions.idm.core.security.api.dto.LoginDto) AccIdentityAccountDto(eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

PasswordChangeDto (eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto)36 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)30 Test (org.junit.Test)27 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)23 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)21 AccIdentityAccountDto (eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto)16 IdmPasswordPolicyDto (eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto)13 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)13 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)12 AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)11 AccIdentityAccountFilter (eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter)11 ArrayList (java.util.ArrayList)11 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)10 LoginDto (eu.bcvsolutions.idm.core.security.api.dto.LoginDto)9 OperationResult (eu.bcvsolutions.idm.core.api.entity.OperationResult)7 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)7 TestResource (eu.bcvsolutions.idm.acc.entity.TestResource)5 IdmPasswordDto (eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto)5 SysSystemAttributeMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto)4 IdmPasswordValidationDto (eu.bcvsolutions.idm.core.api.dto.IdmPasswordValidationDto)4