use of eu.bcvsolutions.idm.core.security.api.dto.IdmJwtAuthenticationDto in project CzechIdMng by bcvsolutions.
the class JwtAuthenticationMapper method toDto.
/**
* Converts authentication.
*
* @param authentication to dto
* @return
*/
public IdmJwtAuthenticationDto toDto(IdmJwtAuthentication authentication) {
Assert.notNull(authentication);
//
IdmJwtAuthenticationDto authenticationDto = new IdmJwtAuthenticationDto();
authenticationDto.setCurrentUsername(authentication.getCurrentUsername());
authenticationDto.setCurrentIdentityId(getIdentityId(authentication.getCurrentIdentity()));
authenticationDto.setOriginalUsername(authentication.getOriginalUsername());
authenticationDto.setOriginalIdentityId(getIdentityId(authentication.getOriginalIdentity()));
authenticationDto.setExpiration(authentication.getExpiration());
authenticationDto.setFromModule(authentication.getFromModule());
authenticationDto.setIssuedAt(DateTime.now());
authenticationDto.setAuthorities(getDtoAuthorities(authentication));
return authenticationDto;
}
use of eu.bcvsolutions.idm.core.security.api.dto.IdmJwtAuthenticationDto in project CzechIdMng by bcvsolutions.
the class LoginControllerTest method testSuccesfulLogIn.
@Test
public void testSuccesfulLogIn() throws Exception {
LoginDto loginDto = new LoginDto();
loginDto.setUsername(InitTestData.TEST_ADMIN_USERNAME);
loginDto.setPassword(new GuardedString(InitTestData.TEST_ADMIN_PASSWORD));
Resource<LoginDto> response = loginController.login(loginDto);
IdmJwtAuthenticationDto authentication = response.getContent().getAuthentication();
assertNotNull(authentication);
assertEquals(InitTestData.TEST_ADMIN_USERNAME, authentication.getCurrentUsername());
assertEquals(InitTestData.TEST_ADMIN_USERNAME, authentication.getOriginalUsername());
}
use of eu.bcvsolutions.idm.core.security.api.dto.IdmJwtAuthenticationDto in project CzechIdMng by bcvsolutions.
the class ExtendExpirationFilterTest method testSuccessfulTokenExtension.
@Test
public void testSuccessfulTokenExtension() throws Exception {
IdmJwtAuthenticationDto authDto = AuthenticationTestUtils.getAuthDto(identityService.getByUsername(TEST_ADMIN_USERNAME), Lists.newArrayList(IdmAuthorityUtils.getAdminAuthority()));
String token = getAuthToken(authDto);
sleep();
MvcResult result = getMockMvc().perform(get(AuthenticationTestUtils.getSelfPath(TEST_ADMIN_USERNAME)).header(JwtAuthenticationMapper.AUTHENTICATION_TOKEN_NAME, token).contentType(HAL_CONTENT_TYPE)).andExpect(status().isOk()).andExpect(content().contentType(HAL_CONTENT_TYPE)).andExpect(jsonPath("$.username", equalTo(TEST_ADMIN_USERNAME))).andReturn();
IdmJwtAuthenticationDto extendedDto = getIdmJwtDto(result);
checkSuccessfulTokenExtension(authDto, extendedDto);
}
use of eu.bcvsolutions.idm.core.security.api.dto.IdmJwtAuthenticationDto in project CzechIdMng by bcvsolutions.
the class ExtendExpirationFilterTest method getIdmJwtDto.
private IdmJwtAuthenticationDto getIdmJwtDto(MvcResult result) throws IOException {
String extended = result.getResponse().getHeader(JwtAuthenticationMapper.AUTHENTICATION_TOKEN_NAME);
Assert.assertNotNull(extended);
Jwt decoded = JwtHelper.decode(extended);
decoded.verifySignature(jwtMapper.getVerifier());
IdmJwtAuthenticationDto extendedDto = jwtMapper.getClaims(decoded);
return extendedDto;
}
use of eu.bcvsolutions.idm.core.security.api.dto.IdmJwtAuthenticationDto in project CzechIdMng by bcvsolutions.
the class JwtIdmAuthenticationFilterTest method testTokenModified.
@Test
public void testTokenModified() throws Exception {
IdmJwtAuthenticationDto authDto = AuthenticationTestUtils.getAuthDto(identityService.getByUsername(TEST_ADMIN_USERNAME), Lists.newArrayList(IdmAuthorityUtils.getAdminAuthority()));
String tokenOriginal = getAuthToken(authDto);
// mix two different tokens - payload from second, signature from first
authDto.setExpiration(DateTime.now().plus(10000000));
String[] token2Split = getAuthToken(authDto).split("\\.");
String[] tokenOrigSplit = tokenOriginal.split("\\.");
String token = token2Split[0] + "." + token2Split[1] + "." + tokenOrigSplit[2];
getMockMvc().perform(get(AuthenticationTestUtils.getSelfPath(TEST_ADMIN_USERNAME)).header(JwtAuthenticationMapper.AUTHENTICATION_TOKEN_NAME, token).contentType(HAL_CONTENT_TYPE)).andExpect(status().is(403));
}
Aggregations