Search in sources :

Example 86 with GuardedString

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);
}
Also used : ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) RecaptchaTestUtil.getRecaptchaResponse(eu.bcvsolutions.idm.core.security.service.impl.RecaptchaTestUtil.getRecaptchaResponse) RecaptchaResponse(eu.bcvsolutions.idm.core.security.api.dto.RecaptchaResponse) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) Test(org.junit.Test) AbstractUnitTest(eu.bcvsolutions.idm.test.api.AbstractUnitTest)

Example 87 with GuardedString

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;
}
Also used : IdmContractGuaranteeDto(eu.bcvsolutions.idm.core.api.dto.IdmContractGuaranteeDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)

Example 88 with GuardedString

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());
}
Also used : PasswordChangeDto(eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto) 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) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) LoginDto(eu.bcvsolutions.idm.core.security.api.dto.LoginDto) AbstractRestTest(eu.bcvsolutions.idm.test.api.AbstractRestTest) Test(org.junit.Test)

Example 89 with GuardedString

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());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) PasswordChangeDto(eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto) 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) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) LoginDto(eu.bcvsolutions.idm.core.security.api.dto.LoginDto) AbstractRestTest(eu.bcvsolutions.idm.test.api.AbstractRestTest) Test(org.junit.Test)

Example 90 with GuardedString

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);
    }
}
Also used : IcObjectClass(eu.bcvsolutions.idm.ic.api.IcObjectClass) ObjectClass(org.identityconnectors.framework.common.objects.ObjectClass) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IcConnectorFacade(eu.bcvsolutions.idm.ic.service.api.IcConnectorFacade) ConnectorFacade(org.identityconnectors.framework.api.ConnectorFacade) InvalidCredentialException(org.identityconnectors.framework.common.exceptions.InvalidCredentialException) IcUidAttribute(eu.bcvsolutions.idm.ic.api.IcUidAttribute) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString)

Aggregations

GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)97 Test (org.junit.Test)61 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)59 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)49 LoginDto (eu.bcvsolutions.idm.core.security.api.dto.LoginDto)40 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)30 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)26 PasswordChangeDto (eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto)20 ArrayList (java.util.ArrayList)13 IdmAuthorizationPolicyDto (eu.bcvsolutions.idm.core.api.dto.IdmAuthorizationPolicyDto)11 IcConnectorObject (eu.bcvsolutions.idm.ic.api.IcConnectorObject)11 AccIdentityAccountDto (eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto)10 AccIdentityAccountFilter (eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter)9 HashMap (java.util.HashMap)9 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)8 Transactional (org.springframework.transaction.annotation.Transactional)8 ProvisioningAttributeDto (eu.bcvsolutions.idm.acc.dto.ProvisioningAttributeDto)7 SysSystemAttributeMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto)7 IdmRole (eu.bcvsolutions.idm.core.model.entity.IdmRole)7 List (java.util.List)7