Search in sources :

Example 61 with ResultCodeException

use of eu.bcvsolutions.idm.core.api.exception.ResultCodeException in project CzechIdMng by bcvsolutions.

the class DefaultIdmScriptServiceIntegrationTest method tryRedeployMissingScript.

@Test
public void tryRedeployMissingScript() {
    IdmScriptDto script = new IdmScriptDto();
    script.setCategory(IdmScriptCategory.SYSTEM);
    script.setCode("test_" + System.currentTimeMillis());
    script.setName("test_" + System.currentTimeMillis());
    script = scriptService.save(script);
    assertNotNull(script);
    assertNotNull(script.getId());
    try {
        scriptService.redeploy(script);
        fail();
    } catch (ResultCodeException e) {
        ResultCodeException resultCode = (ResultCodeException) e;
        assertEquals(resultCode.getError().getError().getStatusEnum(), CoreResultCode.SCRIPT_XML_FILE_NOT_FOUND.name());
    }
}
Also used : IdmScriptDto(eu.bcvsolutions.idm.core.api.dto.IdmScriptDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 62 with ResultCodeException

use of eu.bcvsolutions.idm.core.api.exception.ResultCodeException in project CzechIdMng by bcvsolutions.

the class DefaultIdmScriptServiceIntegrationTest method backupMissingFolderNewEntity.

@Test
public void backupMissingFolderNewEntity() {
    configurationService.setValue(Recoverable.BACKUP_FOLDER_CONFIG, null);
    IdmScriptDto script = new IdmScriptDto();
    script.setCategory(IdmScriptCategory.SYSTEM);
    script.setCode("test_" + System.currentTimeMillis());
    script.setName("test_" + System.currentTimeMillis());
    script = scriptService.save(script);
    assertNotNull(script);
    assertNotNull(script.getId());
    try {
        scriptService.backup(script);
        fail();
    } catch (ResultCodeException e) {
        ResultCodeException resultCode = (ResultCodeException) e;
        assertEquals(resultCode.getError().getError().getStatusEnum(), CoreResultCode.BACKUP_FOLDER_NOT_FOUND.name());
    }
}
Also used : IdmScriptDto(eu.bcvsolutions.idm.core.api.dto.IdmScriptDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 63 with ResultCodeException

use of eu.bcvsolutions.idm.core.api.exception.ResultCodeException in project CzechIdMng by bcvsolutions.

the class PasswordPreValidationIntegrationTest method testAdvancedEnabled.

@Test
public void testAdvancedEnabled() {
    IdmPasswordPolicyDto policy = new IdmPasswordPolicyDto();
    policy.setName(System.currentTimeMillis() + "");
    policy.setDefaultPolicy(true);
    policy.setMinPasswordLength(10);
    policy.setMaxPasswordLength(20);
    policy.setPasswordLengthRequired(true);
    policy.setMinUpperChar(5);
    policy.setUpperCharRequired(true);
    policy.setMinLowerChar(4);
    policy.setLowerCharRequired(true);
    policy.setEnchancedControl(true);
    policy.setMinRulesToFulfill(1);
    policy.setMinNumber(3);
    policy.setNumberRequired(false);
    policy.setMinSpecialChar(2);
    policy.setSpecialCharRequired(false);
    policy.setIdentityAttributeCheck("EMAIL, USERNAME");
    PasswordChangeDto passwordChange = new PasswordChangeDto();
    passwordChange.setIdm(true);
    policy = passwordPolicyService.save(policy);
    try {
        idmIdentityService.validatePassword(passwordChange);
    } catch (ResultCodeException ex) {
        Map<String, Object> parametrs = new HashMap<String, Object>();
        parametrs.put("minNumber", 3);
        parametrs.put("minSpecialChar", 2);
        assertEquals(10, ex.getError().getError().getParameters().get("minLength"));
        assertEquals(20, ex.getError().getError().getParameters().get("maxLength"));
        assertEquals(5, ex.getError().getError().getParameters().get("minUpperChar"));
        assertEquals(4, ex.getError().getError().getParameters().get("minLowerChar"));
        assertEquals(parametrs.toString(), ex.getError().getError().getParameters().get("minRulesToFulfill").toString());
        assertEquals(policy.getName(), ex.getError().getError().getParameters().get("policiesNamesPreValidation"));
        // special char base, passwordSimilarUsername, passwordSimilarEmail ->
        assertEquals(10, ex.getError().getError().getParameters().size());
        policy.setDefaultPolicy(false);
        passwordPolicyService.save(policy);
    }
}
Also used : IdmPasswordPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto) PasswordChangeDto(eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 64 with ResultCodeException

use of eu.bcvsolutions.idm.core.api.exception.ResultCodeException in project CzechIdMng by bcvsolutions.

the class DefaultIdmNotificationTemplateServiceIntegrationTest method redeployWithoutBackupFolder.

@Test
public void redeployWithoutBackupFolder() {
    String backupPath = configurationService.getValue(DefaultIdmNotificationTemplateService.BACKUP_FOLDER_CONFIG);
    if (backupPath != null) {
        configurationService.setValue(DefaultIdmNotificationTemplateService.BACKUP_FOLDER_CONFIG, null);
    }
    // 
    IdmNotificationTemplateDto testTemplate = notificationTemplateService.getByCode(TEST_TEMPLATE);
    Assert.assertNotNull(testTemplate);
    assertEquals(TEST_TEMPLATE, testTemplate.getCode());
    // 
    try {
        notificationTemplateService.redeploy(testTemplate);
        fail();
    } catch (Exception e) {
        assertTrue(e instanceof ResultCodeException);
        ResultCodeException resultCode = (ResultCodeException) e;
        assertEquals(resultCode.getError().getError().getStatusEnum(), CoreResultCode.BACKUP_FOLDER_NOT_FOUND.name());
    }
}
Also used : ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmNotificationTemplateDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto) IOException(java.io.IOException) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 65 with ResultCodeException

use of eu.bcvsolutions.idm.core.api.exception.ResultCodeException in project CzechIdMng by bcvsolutions.

the class DefaultRecaptchaServiceUnitTest method testNotValid2.

@Test()
public void testNotValid2() {
    RecaptchaResponse response = getRecaptchaResponse(TEST_HOSTNAME, false, "a");
    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)

Aggregations

ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)162 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)48 ApiOperation (io.swagger.annotations.ApiOperation)47 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)47 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)44 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)33 Test (org.junit.Test)31 ResponseEntity (org.springframework.http.ResponseEntity)22 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)20 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)17 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)17 Transactional (org.springframework.transaction.annotation.Transactional)17 IdmFormDefinitionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)15 UUID (java.util.UUID)15 ArrayList (java.util.ArrayList)14 IdmPasswordPolicyDto (eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto)13 PasswordChangeDto (eu.bcvsolutions.idm.core.api.dto.PasswordChangeDto)12 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)12 IOException (java.io.IOException)12 AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)10