Search in sources :

Example 1 with IdmPasswordDto

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

the class DefaultIdmPasswordService method setLastSuccessfulLogin.

@Override
public void setLastSuccessfulLogin(String username) {
    IdmPasswordDto passwordDto = getPasswordByIdentityUsername(username);
    if (passwordDto != null) {
        passwordDto.setLastSuccessfulLogin(new DateTime());
        passwordDto.resetUnsuccessfulAttempts();
        passwordDto = save(passwordDto);
    }
}
Also used : IdmPasswordDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto) DateTime(org.joda.time.DateTime)

Example 2 with IdmPasswordDto

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

the class PasswordExpirationWarningIntegrationTest method testSimpleWarningMessageDry.

@Test
public void testSimpleWarningMessageDry() {
    // prepare date
    IdmIdentityDto identity = helper.createIdentity();
    // 
    try {
        IdmPasswordDto password = passwordService.findOneByIdentity(identity.getId());
        password.setValidTill(new LocalDate().plusDays(1));
        passwordService.save(password);
        // prepare task
        IdmScheduledTaskDto scheduledTask = scheduledTaskService.save(SchedulerTestUtils.createIdmScheduledTask(UUID.randomUUID().toString()));
        IdmLongRunningTaskDto longRunningTask = longRunningService.save(SchedulerTestUtils.createIdmLongRunningTask(scheduledTask, PasswordExpirationWarningTaskExecutor.class));
        PasswordExpirationWarningTaskExecutor executor = AutowireHelper.autowireBean(new PasswordExpirationWarningTaskExecutor());
        executor.setLongRunningTaskId(longRunningTask.getId());
        executor.init(ImmutableMap.of(PasswordExpirationWarningTaskExecutor.PARAMETER_DAYS_BEFORE, "2"));
        // first process
        Boolean result = executor.process();
        Page<IdmProcessedTaskItemDto> queueItems = itemService.findQueueItems(scheduledTask, null);
        Page<IdmProcessedTaskItemDto> logItems = itemService.findLogItems(longRunningTask, null);
        // first check
        Assert.assertTrue(result);
        Assert.assertTrue(executor.getCount() > 0);
        Assert.assertTrue(queueItems.getTotalElements() > 0);
        Assert.assertTrue(logItems.getTotalElements() > 0);
        Assert.assertTrue(logItems.getContent().stream().map(IdmProcessedTaskItemDto::getReferencedEntityId).anyMatch(password.getId()::equals));
        // second process
        longRunningTask = longRunningService.save(SchedulerTestUtils.createIdmLongRunningTask(scheduledTask, PasswordExpirationWarningTaskExecutor.class));
        executor.setLongRunningTaskId(longRunningTask.getId());
        executor.init(ImmutableMap.of(PasswordExpirationWarningTaskExecutor.PARAMETER_DAYS_BEFORE, "2"));
        result = executor.process();
        itemService.findQueueItems(scheduledTask, null);
        logItems = itemService.findLogItems(longRunningTask, null);
        // second check
        Assert.assertTrue(result);
        Assert.assertEquals(Long.valueOf(0), executor.getCount());
        Assert.assertTrue(queueItems.getTotalElements() > 0);
        Assert.assertEquals(0, logItems.getTotalElements());
    } finally {
        identityService.delete(identity);
    }
}
Also used : IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) IdmScheduledTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmScheduledTaskDto) IdmPasswordDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto) IdmProcessedTaskItemDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmProcessedTaskItemDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) LocalDate(org.joda.time.LocalDate) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 3 with IdmPasswordDto

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

the class PasswordExpiredIntegrationTest method testNotSendWarningMessageToDisabledIdentity.

@Test
public void testNotSendWarningMessageToDisabledIdentity() {
    // prepare date
    IdmIdentityDto identity = helper.createIdentity();
    // 
    try {
        IdmPasswordDto password = passwordService.findOneByIdentity(identity.getId());
        password.setValidTill(new LocalDate().minusDays(1));
        passwordService.save(password);
        // disable identity
        identity.setDisabled(true);
        identityService.save(identity);
        // prepare task
        IdmScheduledTaskDto scheduledTask = scheduledTaskService.save(SchedulerTestUtils.createIdmScheduledTask(UUID.randomUUID().toString()));
        IdmLongRunningTaskDto longRunningTask = longRunningService.save(SchedulerTestUtils.createIdmLongRunningTask(scheduledTask, PasswordExpiredTaskExecutor.class));
        PasswordExpiredTaskExecutor executor = AutowireHelper.autowireBean(new PasswordExpiredTaskExecutor());
        executor.setLongRunningTaskId(longRunningTask.getId());
        executor.init(ImmutableMap.of(PasswordExpirationWarningTaskExecutor.PARAMETER_DAYS_BEFORE, "2"));
        // first process
        Boolean result = executor.process();
        Page<IdmProcessedTaskItemDto> logItems = itemService.findLogItems(longRunningTask, null);
        // check
        Assert.assertTrue(result);
        Assert.assertFalse(logItems.getContent().stream().map(IdmProcessedTaskItemDto::getReferencedEntityId).anyMatch(password.getId()::equals));
    } finally {
        identityService.delete(identity);
    }
}
Also used : IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) IdmScheduledTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmScheduledTaskDto) IdmPasswordDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto) IdmProcessedTaskItemDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmProcessedTaskItemDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) LocalDate(org.joda.time.LocalDate) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 4 with IdmPasswordDto

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

the class IdmIdentityController method getPassword.

@ResponseBody
@PreAuthorize("hasAuthority('" + CoreGroupPermission.PASSWORD_READ + "')")
@RequestMapping(value = "/{backendId}/password", method = RequestMethod.GET)
@ApiOperation(value = "Get password by identity", nickname = "getIdentityPassword", response = IdmPasswordDto.class, tags = { IdmPasswordController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.PASSWORD_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.PASSWORD_READ, description = "") }) })
public ResponseEntity<?> getPassword(@ApiParam(value = "Identity's uuid identifier or username.", required = true) @PathVariable @NotNull String backendId) {
    IdmIdentityDto dto = getDto(backendId);
    if (dto == null) {
        throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", backendId));
    }
    IdmPasswordDto passwordDto = passwordService.findOneByIdentity(dto.getId());
    if (passwordDto == null) {
        return new ResponseEntity<InputStreamResource>(HttpStatus.NO_CONTENT);
    }
    return new ResponseEntity<>(passwordController.toResource(passwordDto), HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) IdmPasswordDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto) 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 5 with IdmPasswordDto

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

the class DefaultIdmPasswordPolicyServiceIntegrationTest method testValidateMinPasswordAgeFailedSameUser.

@Test(expected = PasswordChangeException.class)
public void testValidateMinPasswordAgeFailedSameUser() {
    IdmIdentityDto identity = getHelper().createIdentity();
    IdmPasswordDto password = getHelper().getPassword(identity);
    password.setValidFrom(LocalDate.now());
    password = passwordService.save(password);
    // 
    IdmPasswordPolicyDto policy = new IdmPasswordPolicyDto();
    policy.setType(IdmPasswordPolicyType.VALIDATE);
    policy.setMinPasswordAge(1);
    // 
    IdmPasswordValidationDto validation = new IdmPasswordValidationDto();
    validation.setIdentity(identity);
    validation.setPassword(getHelper().createName());
    // 
    try {
        getHelper().login(identity);
        // 
        passwordPolicyService.validate(validation, Lists.newArrayList(policy));
    } finally {
        getHelper().logout();
    }
}
Also used : IdmPasswordPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto) IdmPasswordValidationDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordValidationDto) IdmPasswordDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

IdmPasswordDto (eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto)88 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)71 Test (org.junit.Test)65 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)53 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)52 IdmPasswordPolicyDto (eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto)28 PasswordChangeDto (eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto)20 LoginDto (eu.bcvsolutions.idm.core.security.api.dto.LoginDto)19 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)11 Transactional (org.springframework.transaction.annotation.Transactional)11 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)10 AbstractPasswordFilterIntegrationTest (eu.bcvsolutions.idm.acc.AbstractPasswordFilterIntegrationTest)9 IdmLongRunningTaskDto (eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto)9 IdmProcessedTaskItemDto (eu.bcvsolutions.idm.core.scheduler.api.dto.IdmProcessedTaskItemDto)9 IdmScheduledTaskDto (eu.bcvsolutions.idm.core.scheduler.api.dto.IdmScheduledTaskDto)9 ZonedDateTime (java.time.ZonedDateTime)9 UUID (java.util.UUID)9 IdmPasswordFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmPasswordFilter)8 IdmAuthenticationException (eu.bcvsolutions.idm.core.security.api.exception.IdmAuthenticationException)8 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)7