use of eu.bcvsolutions.idm.core.security.api.domain.GuardedString in project CzechIdMng by bcvsolutions.
the class AbstractHrProcessIntegrationTest method createTestIdentity.
protected IdmIdentityDto createTestIdentity(String username, boolean disabled) {
IdmIdentityDto identity = new IdmIdentityDto();
identity.setUsername(username);
identity.setPassword(new GuardedString("password"));
identity.setFirstName("Test");
identity.setLastName("User");
identity.setEmail("test.user@example.tl");
identity.setState(disabled ? IdentityState.DISABLED : null);
identity = this.identityService.save(identity);
// make sure default contract is not created
identityContractService.findAllByIdentity(identity.getId()).forEach(c -> identityContractService.deleteInternal(c));
return identity;
}
use of eu.bcvsolutions.idm.core.security.api.domain.GuardedString in project CzechIdMng by bcvsolutions.
the class AuthenticationManagerTest method loginViaManagerBadCredentials.
@Transactional
@Test(expected = AuthenticationException.class)
public void loginViaManagerBadCredentials() {
IdmIdentityDto identity = new IdmIdentityDto();
identity.setUsername("test_login_1");
identity.setLastName("test_login_1");
identity.setPassword(new GuardedString("test1234"));
identity = this.identityService.save(identity);
LoginDto loginDto = new LoginDto();
loginDto.setPassword(new GuardedString("test12345"));
loginDto.setUsername("test_login_1");
authenticationManager.authenticate(loginDto);
fail();
}
use of eu.bcvsolutions.idm.core.security.api.domain.GuardedString in project CzechIdMng by bcvsolutions.
the class AuthenticationManagerTest method loginViaManagerSuccesful.
@Test
@Transactional
public void loginViaManagerSuccesful() {
IdmIdentityDto identity = new IdmIdentityDto();
identity.setUsername("test_login_2");
identity.setLastName("test_login_2");
identity.setPassword(new GuardedString("test1234"));
identity = this.identityService.save(identity);
LoginDto loginDto = new LoginDto();
loginDto.setPassword(new GuardedString("test1234"));
loginDto.setUsername("test_login_2");
loginDto = authenticationManager.authenticate(loginDto);
assertNotNull(loginDto);
assertNotNull(loginDto.getAuthentication());
assertEquals("core", loginDto.getAuthenticationModule());
}
use of eu.bcvsolutions.idm.core.security.api.domain.GuardedString in project CzechIdMng by bcvsolutions.
the class DefaultAuthorizationManagerIntegrationTest method testPredicate.
@Test
public void testPredicate() {
loginAsAdmin(InitTestData.TEST_USER_1);
// prepare role
IdmRoleDto role = helper.createRole();
helper.createUuidPolicy(role.getId(), role.getId(), IdmBasePermission.READ);
helper.createBasePolicy(role.getId(), IdmBasePermission.AUTOCOMPLETE);
// prepare identity
IdmIdentityDto identity = helper.createIdentity();
identity.setPassword(new GuardedString("heslo"));
identityService.save(identity);
// assign role
helper.createIdentityRole(identity, role);
logout();
//
// empty without login
IdmRoleFilter filter = new IdmRoleFilter();
assertEquals(0, roleService.find(filter, null, IdmBasePermission.READ).getTotalElements());
assertEquals(0, roleService.find(filter, null, IdmBasePermission.AUTOCOMPLETE).getTotalElements());
//
try {
loginService.login(new LoginDto(identity.getUsername(), identity.getPassword()));
//
// evaluate access
assertEquals(1, roleService.find(filter, null, IdmBasePermission.READ).getTotalElements());
assertEquals(roleService.find(null).getTotalElements(), roleService.find(filter, null, IdmBasePermission.AUTOCOMPLETE).getTotalElements());
} finally {
logout();
}
}
use of eu.bcvsolutions.idm.core.security.api.domain.GuardedString in project CzechIdMng by bcvsolutions.
the class DefaultAuthorizationManagerIntegrationTest method testEvaluate.
@Test
public void testEvaluate() {
loginAsAdmin(InitTestData.TEST_USER_1);
// prepare role
IdmRoleDto role = helper.createRole();
helper.createBasePolicy(role.getId(), IdmBasePermission.READ);
// prepare identity
IdmIdentityDto identity = helper.createIdentity();
identity.setPassword(new GuardedString("heslo"));
identityService.save(identity);
// assign role
helper.createIdentityRole(identity, role);
logout();
//
// without login
assertFalse(manager.evaluate(role, IdmBasePermission.READ));
assertFalse(manager.evaluate(role, IdmBasePermission.UPDATE));
assertFalse(manager.evaluate(role, IdmBasePermission.ADMIN));
assertFalse(manager.evaluate(role, IdmBasePermission.AUTOCOMPLETE));
//
try {
loginService.login(new LoginDto(identity.getUsername(), identity.getPassword()));
//
// evaluate access
assertTrue(manager.evaluate(role, IdmBasePermission.READ));
assertFalse(manager.evaluate(role, IdmBasePermission.UPDATE));
assertFalse(manager.evaluate(role, IdmBasePermission.ADMIN));
assertFalse(manager.evaluate(role, IdmBasePermission.AUTOCOMPLETE));
} finally {
logout();
}
}
Aggregations