use of eu.bcvsolutions.idm.core.security.api.dto.LoginDto in project CzechIdMng by bcvsolutions.
the class BasicIdmAuthenticationFilterTest method testEnableIdmPasswordChange.
@Test
public void testEnableIdmPasswordChange() {
String testPassword = "testPassword";
String newTestPassword = "newTestPassword";
//
this.loginAsAdmin(TEST_ADMIN_USERNAME);
configurationService.setBooleanValue(IdentityConfiguration.PROPERTY_PUBLIC_CHANGE_PASSWORD_FOR_IDM_ENABLED, true);
//
// create identity
IdmIdentityDto identity = testHelper.createIdentity();
PasswordChangeDto passwordChangeDto = new PasswordChangeDto();
passwordChangeDto.setNewPassword(new GuardedString(testPassword));
passwordService.save(identity, passwordChangeDto);
this.logout();
//
LoginDto loginDto = new LoginDto();
loginDto.setUsername(identity.getUsername());
loginDto.setPassword(new GuardedString(testPassword));
LoginDto login = loginService.login(loginDto);
//
assertNotNull(login.getAuthentication());
//
passwordChangeDto = new PasswordChangeDto();
passwordChangeDto.setNewPassword(new GuardedString(newTestPassword));
passwordChangeDto.setOldPassword(new GuardedString(testPassword));
passwordChangeDto.setAll(true);
passwordChangeDto.setIdm(true);
//
List<OperationResult> passwordChangeResults = identityService.passwordChange(identity, passwordChangeDto);
//
assertEquals(1, passwordChangeResults.size());
OperationResult operationResult = passwordChangeResults.get(0);
assertEquals(OperationState.EXECUTED, operationResult.getState());
assertEquals(CoreResultCode.PASSWORD_CHANGE_ACCOUNT_SUCCESS.name(), operationResult.getModel().getStatusEnum());
assertEquals(HttpStatus.OK, operationResult.getModel().getStatus());
//
loginDto.setUsername(identity.getUsername());
loginDto.setPassword(new GuardedString(newTestPassword));
login = loginService.login(loginDto);
//
assertNotNull(login.getAuthentication());
}
use of eu.bcvsolutions.idm.core.security.api.dto.LoginDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmPasswordServiceIntegrationTest method testResetUsuccessfulAttemptsAfterPasswordChange.
@Test
@Transactional
public void testResetUsuccessfulAttemptsAfterPasswordChange() {
IdmIdentityDto identity = testHelper.createIdentity();
// login
LoginDto loginDto = new LoginDto();
loginDto.setUsername(identity.getUsername());
loginDto.setPassword(new GuardedString("wrong"));
try {
loginController.login(loginDto);
} catch (IdmAuthenticationException ex) {
// nothing
}
try {
loginController.login(loginDto);
} catch (IdmAuthenticationException ex) {
// nothing
}
IdmPasswordDto password = passwordService.findOneByIdentity(identity.getId());
//
Assert.assertEquals(2, password.getUnsuccessfulAttempts());
//
// password change
PasswordChangeDto passwordChange = new PasswordChangeDto();
passwordChange.setIdm(true);
passwordChange.setNewPassword(new GuardedString("new"));
passwordService.save(identity, passwordChange);
//
password = passwordService.findOneByIdentity(identity.getId());
//
Assert.assertEquals(0, password.getUnsuccessfulAttempts());
}
use of eu.bcvsolutions.idm.core.security.api.dto.LoginDto in project CzechIdMng by bcvsolutions.
the class CodeableEvaluatorIntegrationTest method testPermissionByUuid.
@Test
public void testPermissionByUuid() {
loginAsAdmin(InitTestData.TEST_ADMIN_USERNAME);
// prepare role
IdmRoleDto role = helper.createRole();
//
IdmAuthorizationPolicyDto dto = new IdmAuthorizationPolicyDto();
dto.setRole(role.getId());
dto.setEvaluator(CodeableEvaluator.class);
dto.setGroupPermission(CoreGroupPermission.ROLE.getName());
dto.setAuthorizableType(IdmRole.class.getCanonicalName());
dto.getEvaluatorProperties().put(CodeableEvaluator.PARAMETER_IDENTIFIER, role.getId().toString());
dto.setPermissions(IdmBasePermission.READ);
authorizationPolicyService.save(dto);
// prepare identity
IdmIdentityDto identity = helper.createIdentity();
identity.setPassword(new GuardedString("heslo"));
identityService.save(identity);
// assign role
helper.createIdentityRole(identity, role);
logout();
//
try {
loginService.login(new LoginDto(identity.getUsername(), identity.getPassword()));
//
// evaluate access
List<IdmRoleDto> roles = roleService.find(null, IdmBasePermission.READ).getContent();
assertEquals(1, roles.size());
assertEquals(role.getId(), roles.get(0).getId());
} finally {
logout();
}
}
use of eu.bcvsolutions.idm.core.security.api.dto.LoginDto in project CzechIdMng by bcvsolutions.
the class CodeableEvaluatorIntegrationTest method testPermissionByCode.
@Test
public void testPermissionByCode() {
loginAsAdmin(InitTestData.TEST_ADMIN_USERNAME);
// prepare role
IdmRoleDto role = helper.createRole();
//
IdmAuthorizationPolicyDto dto = new IdmAuthorizationPolicyDto();
dto.setRole(role.getId());
dto.setEvaluator(CodeableEvaluator.class);
dto.setGroupPermission(CoreGroupPermission.ROLE.getName());
dto.setAuthorizableType(IdmRole.class.getCanonicalName());
dto.getEvaluatorProperties().put(CodeableEvaluator.PARAMETER_IDENTIFIER, role.getCode());
dto.setPermissions(IdmBasePermission.READ);
authorizationPolicyService.save(dto);
// prepare identity
IdmIdentityDto identity = helper.createIdentity();
identity.setPassword(new GuardedString("heslo"));
identityService.save(identity);
// assign role
helper.createIdentityRole(identity, role);
logout();
//
try {
loginService.login(new LoginDto(identity.getUsername(), identity.getPassword()));
//
// evaluate access
List<IdmRoleDto> roles = roleService.find(null, IdmBasePermission.READ).getContent();
assertEquals(1, roles.size());
assertEquals(role.getId(), roles.get(0).getId());
} finally {
logout();
}
}
use of eu.bcvsolutions.idm.core.security.api.dto.LoginDto in project CzechIdMng by bcvsolutions.
the class ConfigurationEvaluatorIntegrationTest method testReadWithoutPermissions.
@Test
public void testReadWithoutPermissions() {
loginAsAdmin(InitTestData.TEST_ADMIN_USERNAME);
// prepare identity
IdmIdentityDto identity = helper.createIdentity();
identity.setPassword(new GuardedString("heslo"));
identityService.save(identity);
//
logout();
//
try {
loginService.login(new LoginDto(identity.getUsername(), identity.getPassword()));
//
// evaluate access
assertEquals(0, configurationService.find(null, IdmBasePermission.READ).getTotalElements());
} finally {
logout();
}
}
Aggregations