use of eu.bcvsolutions.idm.core.api.dto.IdmTokenDto in project CzechIdMng by bcvsolutions.
the class LoginControllerRestTest method testCasLoginResponse.
@Test
public void testCasLoginResponse() throws Exception {
// without login
getMockMvc().perform(get(BaseController.BASE_PATH + LoginController.AUTH_PATH + LoginController.CAS_LOGIN_RESPONSE_PATH).contentType(TestHelper.HAL_CONTENT_TYPE)).andExpect(status().isFound()).andExpect(MockMvcResultMatchers.redirectedUrl(LoginController.CAS_LOGIN_RESPONSE_PATH + "?status-code=" + CoreResultCode.LOG_IN_FAILED.getCode().toLowerCase()));
// with login
try {
loginAsAdmin();
IdmTokenDto currentToken = tokenManager.getCurrentToken();
IdmJwtAuthentication authentication = jwtTokenMapper.fromDto(currentToken);
String token = jwtTokenMapper.writeToken(authentication);
//
getMockMvc().perform(get(BaseController.BASE_PATH + LoginController.AUTH_PATH + LoginController.CAS_LOGIN_RESPONSE_PATH).header(JwtAuthenticationMapper.AUTHENTICATION_TOKEN_NAME, token).contentType(TestHelper.HAL_CONTENT_TYPE)).andExpect(status().isFound());
} finally {
logout();
}
}
use of eu.bcvsolutions.idm.core.api.dto.IdmTokenDto in project CzechIdMng by bcvsolutions.
the class DefaultTwoFactorAuthenticationManagerIntegrationTest method testRequireTwoFactorAuthenticationNotificationWithoutPassword.
@Test(expected = EntityNotFoundException.class)
public void testRequireTwoFactorAuthenticationNotificationWithoutPassword() {
// password is needed
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmProfileDto profile = getHelper().createProfile(identity);
// set without confirm, secret etc.
profile.setTwoFactorAuthenticationType(TwoFactorAuthenticationType.NOTIFICATION);
profileService.save(profile);
//
IdmTokenDto token = createToken(identity, false);
//
manager.requireTwoFactorAuthentication(identity.getId(), token.getId());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmTokenDto in project CzechIdMng by bcvsolutions.
the class DefaultTwoFactorAuthenticationManagerIntegrationTest method testRequireTwoFactorAuthenticationApplication.
@Test
public void testRequireTwoFactorAuthenticationApplication() {
// password is needed
IdmIdentityDto identity = getHelper().createIdentity();
//
TwoFactorRegistrationResponseDto initResponse = manager.init(identity.getId(), TwoFactorAuthenticationType.APPLICATION);
Assert.assertNotNull(initResponse);
Assert.assertNotNull(initResponse.getVerificationSecret());
Assert.assertEquals(identity.getUsername(), initResponse.getUsername());
Assert.assertNotNull(initResponse.getQrcode());
//
// confirm
TwoFactorRegistrationConfirmDto confirm = new TwoFactorRegistrationConfirmDto();
confirm.setVerificationSecret(new GuardedString(initResponse.getVerificationSecret()));
confirm.setVerificationCode(manager.generateCode(new GuardedString(initResponse.getVerificationSecret())));
confirm.setTwoFactorAuthenticationType(TwoFactorAuthenticationType.APPLICATION);
Assert.assertTrue(manager.confirm(identity.getId(), confirm));
Assert.assertEquals(initResponse.getVerificationSecret(), getHelper().getPassword(identity).getVerificationSecret());
//
IdmTokenDto token = createToken(identity, false);
//
Assert.assertTrue(manager.requireTwoFactorAuthentication(identity.getId(), token.getId()));
}
use of eu.bcvsolutions.idm.core.api.dto.IdmTokenDto in project CzechIdMng by bcvsolutions.
the class DefaultTwoFactorAuthenticationManagerIntegrationTest method testRequireTwoFactorAuthenticationNotification.
@Test
public void testRequireTwoFactorAuthenticationNotification() {
// password is needed
IdmIdentityDto identity = getHelper().createIdentity();
//
TwoFactorRegistrationResponseDto initResponse = manager.init(identity.getId(), TwoFactorAuthenticationType.NOTIFICATION);
Assert.assertNotNull(initResponse);
Assert.assertNotNull(initResponse.getVerificationSecret());
Assert.assertEquals(identity.getUsername(), initResponse.getUsername());
Assert.assertNull(initResponse.getQrcode());
//
// confirm
TwoFactorRegistrationConfirmDto confirm = new TwoFactorRegistrationConfirmDto();
confirm.setVerificationSecret(new GuardedString(initResponse.getVerificationSecret()));
confirm.setVerificationCode(manager.generateCode(new GuardedString(initResponse.getVerificationSecret())));
confirm.setTwoFactorAuthenticationType(TwoFactorAuthenticationType.NOTIFICATION);
Assert.assertTrue(manager.confirm(identity.getId(), confirm));
Assert.assertEquals(initResponse.getVerificationSecret(), getHelper().getPassword(identity).getVerificationSecret());
//
IdmTokenDto token = createToken(identity, false);
//
Assert.assertTrue(manager.requireTwoFactorAuthentication(identity.getId(), token.getId()));
}
use of eu.bcvsolutions.idm.core.api.dto.IdmTokenDto in project CzechIdMng by bcvsolutions.
the class DefaultTwoFactorAuthenticationManagerIntegrationTest method createToken.
private IdmTokenDto createToken(IdmIdentityDto owner, boolean secretVerified) {
IdmTokenDto dto = new IdmTokenDto();
dto.setTokenType("mock");
dto.setToken("mock");
dto.setIssuedAt(ZonedDateTime.now());
dto.setSecretVerified(secretVerified);
//
return tokenManager.saveToken(owner, dto);
}
Aggregations