use of eu.bcvsolutions.idm.core.security.api.dto.LoginDto in project CzechIdMng by bcvsolutions.
the class DefaultAuthenticationManager method cloneLoginDto.
/**
* Clone object {@link LoginDto} without inner class {@link IdmJwtAuthentication}
* @param loginDto
* @return
*/
private LoginDto cloneLoginDto(LoginDto loginDto) {
LoginDto clone = new LoginDto();
clone.setToken(loginDto.getToken());
clone.setUsername(loginDto.getUsername());
clone.setAuthenticationModule(loginDto.getAuthenticationModule());
clone.setSkipMustChange(loginDto.isSkipMustChange());
clone.setPassword(new GuardedString(loginDto.getPassword().asBytes()));
return clone;
}
use of eu.bcvsolutions.idm.core.security.api.dto.LoginDto in project CzechIdMng by bcvsolutions.
the class BasicIdmAuthenticationFilter method authorize.
@Override
public boolean authorize(String token, HttpServletRequest req, HttpServletResponse res) {
try {
LoginDto loginDto = createLoginDto(getBasicCredentials(token));
authManager.authenticate(loginDto);
LOG.debug("User [{}] successfully logged in.", loginDto.getUsername());
return true;
} catch (IdmAuthenticationException e) {
LOG.warn("Authentication exception raised during basic authentication: [{}].", e.getMessage());
} catch (Exception e) {
LOG.warn("Exception was raised during basic authentication: [{}].", e.getMessage());
}
return false;
}
use of eu.bcvsolutions.idm.core.security.api.dto.LoginDto in project CzechIdMng by bcvsolutions.
the class DefaultAccAuthenticatorTest method loginViaManagerBadCredentials.
@Test(expected = IdmAuthenticationException.class)
public void loginViaManagerBadCredentials() {
IdmIdentityDto identity = identityService.getByUsername(USERNAME);
PasswordChangeDto passwordChangeDto = new PasswordChangeDto();
passwordChangeDto.setAll(true);
passwordChangeDto.setIdm(false);
passwordChangeDto.setNewPassword(new GuardedString(PASSWORD));
// change password for system
provisioningService.changePassword(identity, passwordChangeDto);
LoginDto loginDto = new LoginDto();
loginDto.setUsername(USERNAME);
loginDto.setPassword(new GuardedString("test"));
authenticationManager.authenticate(loginDto);
}
use of eu.bcvsolutions.idm.core.security.api.dto.LoginDto in project CzechIdMng by bcvsolutions.
the class IdentityAccountByRoleEvaluatorIntegrationTest method testCanReadIdentityAccount.
@Test
public void testCanReadIdentityAccount() {
IdmIdentityDto identity;
AccIdentityAccountDto accountIdentityOne;
try {
loginAsAdmin(InitApplicationData.ADMIN_USERNAME);
//
identity = helper.createIdentity();
SysSystemDto system = helper.createTestResourceSystem(true);
AccAccountDto accountOne = new AccAccountDto();
accountOne.setSystem(system.getId());
accountOne.setUid(identity.getUsername());
accountOne.setAccountType(AccountType.PERSONAL);
accountOne = accountService.save(accountOne);
accountIdentityOne = new AccIdentityAccountDto();
accountIdentityOne.setIdentity(identity.getId());
accountIdentityOne.setOwnership(true);
accountIdentityOne.setAccount(accountOne.getId());
accountIdentityOne = identityAccountService.save(accountIdentityOne);
IdmRoleDto role = helper.createRole();
IdmRoleDto defaultRole = roleService.getByCode(InitDemoData.DEFAULT_ROLE_NAME);
IdmAuthorizationPolicyDto policy = new IdmAuthorizationPolicyDto();
policy.setRole(role.getId());
policy.setGroupPermission(AccGroupPermission.IDENTITYACCOUNT.getName());
policy.setAuthorizableType(AccIdentityAccount.class.getCanonicalName());
policy.setEvaluator(IdentityAccountByAccountEvaluator.class);
authorizationPolicyService.save(policy);
IdmAuthorizationPolicyDto policyAccount = new IdmAuthorizationPolicyDto();
policyAccount.setRole(role.getId());
policyAccount.setGroupPermission(AccGroupPermission.ACCOUNT.getName());
policyAccount.setAuthorizableType(AccAccount.class.getCanonicalName());
policyAccount.setEvaluator(ReadAccountByIdentityEvaluator.class);
authorizationPolicyService.save(policyAccount);
helper.createIdentityRole(identity, role);
helper.createIdentityRole(identity, defaultRole);
} finally {
logout();
}
// check
try {
loginService.login(new LoginDto(identity.getUsername(), identity.getPassword()));
AccIdentityAccountDto read = identityAccountService.get(accountIdentityOne.getId(), IdmBasePermission.READ);
Assert.assertEquals(accountIdentityOne, read);
} finally {
logout();
}
}
use of eu.bcvsolutions.idm.core.security.api.dto.LoginDto in project CzechIdMng by bcvsolutions.
the class RoleAccountByRoleEvaluatorIntegrationTest method testReadRoleWithEvaluator.
@Test
public void testReadRoleWithEvaluator() {
IdmIdentityDto identity = createIdentityWithRole(true);
try {
loginService.login(new LoginDto(identity.getUsername(), identity.getPassword()));
IdmRoleDto role = roleService.get(TEST_ROLE_ID, IdmBasePermission.READ);
assertEquals(TEST_ROLE_ID, role.getId());
assertEquals(1, roleService.find(null, IdmBasePermission.READ).getTotalElements());
assertEquals(3, authorizationPolicyService.find(null, IdmBasePermission.READ).getTotalElements());
} finally {
logout();
}
}
Aggregations