Search in sources :

Example 1 with PasswordGenerator

use of eu.bcvsolutions.idm.core.api.utils.PasswordGenerator in project CzechIdMng by bcvsolutions.

the class DefaultIdmPasswordPolicyServiceIntegrationTest method testPolicyGeneratorValidator.

@Test
public void testPolicyGeneratorValidator() {
    IdmPasswordPolicyDto policy = new IdmPasswordPolicyDto();
    policy.setName("test_10_7");
    policy.setType(IdmPasswordPolicyType.GENERATE);
    policy.setGenerateType(IdmPasswordPolicyGenerateType.RANDOM);
    policy.setMaxPasswordLength(10);
    policy.setMinPasswordLength(8);
    policy.setMinLowerChar(2);
    policy.setMinNumber(2);
    policy.setMinUpperChar(2);
    policy.setMinSpecialChar(2);
    policy.setSpecialCharBase("!@#+$%&*");
    policy.setLowerCharBase("abcdefghijklmnopqrstuvwxyz");
    policy.setUpperCharBase("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
    policy.setNumberBase("0123456789");
    policy.setProhibitedCharacters("X");
    policy.setProhibitedBeginCharacters("a");
    policy.setProhibitedEndCharacters("z");
    PasswordGenerator generator = passwordPolicyService.getPasswordGenerator();
    // contains forbidden chars
    assertFalse(generator.testPasswordAgainstPolicy("a1@9X+loZs", policy));
    // contains forbidden chars at the beginning
    assertFalse(generator.testPasswordAgainstPolicy("a1@9Y+loZs", policy));
    // contains forbidden chars at the end
    assertFalse(generator.testPasswordAgainstPolicy("b1@9Y+loJz", policy));
    // does not contain min count from lower
    assertFalse(generator.testPasswordAgainstPolicy("A1@9Y+9*Zs", policy));
    // does not contain min count from upper
    assertFalse(generator.testPasswordAgainstPolicy("f1@9y+loZs", policy));
    // does not contain min count from special
    assertFalse(generator.testPasswordAgainstPolicy("f1#9yUloZs", policy));
    // does not contain min count from numbers
    assertFalse(generator.testPasswordAgainstPolicy("fG@9y+loZs", policy));
    // pass too long
    assertFalse(generator.testPasswordAgainstPolicy("h6%#ghGABDc*+369", policy));
    // pass too short
    assertFalse(generator.testPasswordAgainstPolicy("h6%G", policy));
}
Also used : IdmPasswordPolicyDto(eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto) PasswordGenerator(eu.bcvsolutions.idm.core.api.utils.PasswordGenerator) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 2 with PasswordGenerator

use of eu.bcvsolutions.idm.core.api.utils.PasswordGenerator in project CzechIdMng by bcvsolutions.

the class DefaultIdmLongRunningTaskServiceIntegrationTest method descriptionLengthTest2050.

@Test
public void descriptionLengthTest2050() {
    IdmLongRunningTaskDto task = new IdmLongRunningTaskDto();
    task.setTaskType(getHelper().createName());
    task.setInstanceId(getHelper().createName());
    task.setResult(new OperationResult.Builder(OperationState.EXECUTED).build());
    // this must also past, but description will be cutoff
    PasswordGenerator generator = new PasswordGenerator();
    String random = generator.generateRandom(2001, 2050, null, null, null, null);
    if (random.length() <= 2000) {
        fail();
    }
    task.setTaskDescription(random);
    IdmLongRunningTaskDto newSaved = service.save(task);
    assertNotNull(newSaved);
    assertNotEquals(random, newSaved.getTaskDescription());
    assertEquals(2000, newSaved.getTaskDescription().length());
    assertTrue(newSaved.getTaskDescription().endsWith("..."));
}
Also used : IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) PasswordGenerator(eu.bcvsolutions.idm.core.api.utils.PasswordGenerator) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 3 with PasswordGenerator

use of eu.bcvsolutions.idm.core.api.utils.PasswordGenerator in project CzechIdMng by bcvsolutions.

the class AbstractPasswordFilterIntegrationTest method createSystem.

protected SysSystemDto createSystem(boolean createPasswordFilter, boolean uidTransformation) {
    SysSystemDto system = this.getHelper().createTestResourceSystem(true);
    if (uidTransformation) {
        PasswordGenerator g = new PasswordGenerator();
        String uidSuffix = g.generateRandom(5, 5, 3, 2, 0, 0);
        SysSystemAttributeMappingFilter filter = new SysSystemAttributeMappingFilter();
        filter.setSystemId(system.getId());
        filter.setName(TestHelper.ATTRIBUTE_MAPPING_NAME);
        List<SysSystemAttributeMappingDto> attributes = systemAttributeMappingService.find(filter, null).getContent();
        assertEquals(1, attributes.size());
        SysSystemAttributeMappingDto uid = attributes.get(0);
        uid.setTransformToResourceScript("return entity.getUsername() + '_" + uidSuffix + "';");
        uid = systemAttributeMappingService.save(uid);
        system.setDescription(uidSuffix);
        system = systemService.save(system);
    }
    setPasswordFilter(system, createPasswordFilter);
    return system;
}
Also used : SysSystemAttributeMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) PasswordGenerator(eu.bcvsolutions.idm.core.api.utils.PasswordGenerator) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto)

Example 4 with PasswordGenerator

use of eu.bcvsolutions.idm.core.api.utils.PasswordGenerator in project CzechIdMng by bcvsolutions.

the class DefaultIdmLongRunningTaskServiceIntegrationTest method descriptionLengthTest2000.

@Test
public void descriptionLengthTest2000() {
    IdmLongRunningTaskDto task = new IdmLongRunningTaskDto();
    task.setTaskType(getHelper().createName());
    task.setInstanceId(getHelper().createName());
    task.setResult(new OperationResult.Builder(OperationState.EXECUTED).build());
    // this must past
    PasswordGenerator generator = new PasswordGenerator();
    String random = generator.generateRandom(2000, 2000, null, null, null, null);
    assertEquals(2000, random.length());
    task.setTaskDescription(random);
    IdmLongRunningTaskDto newSaved = service.save(task);
    assertNotNull(newSaved);
    assertEquals(random, newSaved.getTaskDescription());
    assertEquals(2000, newSaved.getTaskDescription().length());
}
Also used : IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) PasswordGenerator(eu.bcvsolutions.idm.core.api.utils.PasswordGenerator) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

PasswordGenerator (eu.bcvsolutions.idm.core.api.utils.PasswordGenerator)4 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)3 Test (org.junit.Test)3 IdmLongRunningTaskDto (eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto)2 SysSystemAttributeMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto)1 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)1 SysSystemAttributeMappingFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter)1 IdmPasswordPolicyDto (eu.bcvsolutions.idm.core.api.dto.IdmPasswordPolicyDto)1 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)1