use of eu.bcvsolutions.idm.core.security.api.domain.GuardedString in project CzechIdMng by bcvsolutions.
the class DefaultRecaptchaServiceUnitTest method testNotValid.
@Test()
public void testNotValid() {
RecaptchaResponse response = getRecaptchaResponse(TEST_HOSTNAME, false, "a", "b");
when(config.getSecretKey()).thenReturn(new GuardedString(TEST_SECRET_KEY));
when(template.postForEntity(anyString(), any(), eq(RecaptchaResponse.class))).thenReturn(getResponse(response, HttpStatus.OK));
try {
service.checkRecaptcha(getRecaptchaRequest(TEST_REMOTE_IP, TEST_REQUEST));
} catch (ResultCodeException O_o) {
Assert.assertEquals(O_o.getStatus(), CoreResultCode.RECAPTCHA_CHECK_FAILED.getStatus());
}
verify(template).postForEntity(anyString(), any(), eq(RecaptchaResponse.class));
verifyNoMoreInteractions(template);
}
use of eu.bcvsolutions.idm.core.security.api.domain.GuardedString in project CzechIdMng by bcvsolutions.
the class SendNotificationToApplicantAndImplementerTest method createTestUser.
/**
* Creates testUser with working position and contract
*
* @return IdmIdentityDto
*/
private IdmIdentityDto createTestUser() {
IdmIdentityDto testUser = new IdmIdentityDto();
testUser.setUsername("" + System.currentTimeMillis());
testUser.setPassword(new GuardedString("heslo"));
testUser.setFirstName("Test");
testUser.setLastName("User");
testUser.setEmail(testUser.getUsername() + "@bscsolutions.eu");
testUser = this.identityService.save(testUser);
IdmIdentityContractDto identityWorkPosition2 = new IdmIdentityContractDto();
identityWorkPosition2.setIdentity(testUser.getId());
identityWorkPosition2.setWorkPosition(organization.getId());
identityWorkPosition2 = identityContractService.save(identityWorkPosition2);
IdmContractGuaranteeDto contractGuarantee = new IdmContractGuaranteeDto();
contractGuarantee.setIdentityContract(identityWorkPosition2.getId());
contractGuarantee.setGuarantee(testUser2.getId());
contractGuaranteeService.save(contractGuarantee);
return testUser;
}
use of eu.bcvsolutions.idm.core.security.api.domain.GuardedString in project CzechIdMng by bcvsolutions.
the class BasicIdmAuthenticationFilterTest method testDisableIdmPasswordChange.
@Test
public void testDisableIdmPasswordChange() {
String testPassword = "testPassword";
String newTestPassword = "newTestPassword";
//
this.loginAsAdmin(TEST_ADMIN_USERNAME);
configurationService.setBooleanValue(IdentityConfiguration.PROPERTY_PUBLIC_CHANGE_PASSWORD_FOR_IDM_ENABLED, false);
//
// 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());
}
use of eu.bcvsolutions.idm.core.security.api.domain.GuardedString in project CzechIdMng by bcvsolutions.
the class BasicIdmAuthenticationFilterTest method testEnableIdmPasswordChangeViaRest.
@Test
public void testEnableIdmPasswordChangeViaRest() throws JsonProcessingException {
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 = createIdentityInTransaction(testPassword);
// allow password change
IdmRoleDto roleWithPermission = testHelper.createRole();
testHelper.createAuthorizationPolicy(roleWithPermission.getId(), CoreGroupPermission.IDENTITY, IdmIdentity.class, SelfIdentityEvaluator.class, IdentityBasePermission.PASSWORDCHANGE);
testHelper.assignRoles(testHelper.getPrimeContract(identity.getId()), roleWithPermission);
this.logout();
authorizationPolicyService.getDefaultAuthorities(identity.getId());
PasswordChangeDto passwordChangeDto = new PasswordChangeDto();
passwordChangeDto.setAll(true);
passwordChangeDto.setIdm(true);
passwordChangeDto.setNewPassword(new GuardedString(newTestPassword));
passwordChangeDto.setOldPassword(new GuardedString(testPassword));
List<OperationResult> passwordChangeResults = passwordChangeController.passwordChange(identity.getUsername(), 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 loginDto = new LoginDto();
loginDto.setUsername(identity.getUsername());
loginDto.setPassword(new GuardedString(newTestPassword));
LoginDto login = loginService.login(loginDto);
assertNotNull(login.getAuthentication());
}
use of eu.bcvsolutions.idm.core.security.api.domain.GuardedString in project CzechIdMng by bcvsolutions.
the class ConnIdIcConnectorService method authenticateObject.
@Override
public IcUidAttribute authenticateObject(IcConnectorInstance connectorInstance, IcConnectorConfiguration connectorConfiguration, IcObjectClass objectClass, String username, GuardedString password) {
Assert.notNull(connectorInstance);
Assert.notNull(connectorInstance.getConnectorKey());
Assert.notNull(connectorConfiguration);
Assert.notNull(username);
LOG.debug("Authenticate object - ConnId (username= {} {})", username, connectorInstance.getConnectorKey().toString());
ConnectorFacade conn = getConnectorFacade(connectorInstance, connectorConfiguration);
ObjectClass objectClassConnId = ConnIdIcConvertUtil.convertIcObjectClass(objectClass);
if (objectClassConnId == null) {
objectClassConnId = ObjectClass.ACCOUNT;
}
try {
IcUidAttribute uid = ConnIdIcConvertUtil.convertConnIdUid(conn.authenticate(objectClassConnId, username, new org.identityconnectors.common.security.GuardedString(password.asString().toCharArray()), null));
LOG.debug("Authenticated object - ConnId (Uid= {})", uid);
return uid;
} catch (InvalidCredentialException ex) {
throw new ResultCodeException(IcResultCode.AUTH_FAILED, ex);
}
}
Aggregations