Search in sources :

Example 26 with IdmTokenDto

use of eu.bcvsolutions.idm.core.api.dto.IdmTokenDto in project CzechIdMng by bcvsolutions.

the class PermissionsAuthorityChangeProcessorTest method testRemoveAuthorityUpdateUsers.

@Test
public void testRemoveAuthorityUpdateUsers() throws Exception {
    IdmRoleDto role = getTestRole();
    IdmIdentityDto i = getHelper().createIdentity();
    IdmIdentityContractDto c = getTestContract(i);
    getTestIdentityRole(role, c);
    // 
    List<IdmTokenDto> tokens = tokenManager.getTokens(i);
    // 
    Assert.assertTrue(tokens.isEmpty());
    // 
    // login - one token
    getHelper().login(i.getUsername(), i.getPassword());
    try {
        tokens = tokenManager.getTokens(i);
        Assert.assertEquals(1, tokens.size());
        Assert.assertFalse(tokens.get(0).isDisabled());
        clearAuthPolicies(role);
        tokens = tokenManager.getTokens(i);
        Assert.assertEquals(1, tokens.size());
        Assert.assertTrue(tokens.get(0).isDisabled());
    } finally {
        getHelper().logout();
    }
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmTokenDto(eu.bcvsolutions.idm.core.api.dto.IdmTokenDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) Test(org.junit.Test)

Example 27 with IdmTokenDto

use of eu.bcvsolutions.idm.core.api.dto.IdmTokenDto in project CzechIdMng by bcvsolutions.

the class IdmTokenControllerRestTest method testFindByDisabled.

@Test
public void testFindByDisabled() {
    UUID mockOwnerId = UUID.randomUUID();
    // 
    IdmTokenDto tokenOne = prepareDto();
    tokenOne.setOwnerId(mockOwnerId);
    tokenOne.setDisabled(true);
    tokenOne = createDto(tokenOne);
    IdmTokenDto tokenTwo = prepareDto();
    tokenTwo.setOwnerId(mockOwnerId);
    tokenTwo.setDisabled(false);
    tokenTwo = createDto(tokenTwo);
    // 
    IdmTokenFilter filter = new IdmTokenFilter();
    filter.setOwnerId(mockOwnerId);
    filter.setDisabled(true);
    List<IdmTokenDto> results = find(filter);
    // 
    Assert.assertEquals(1, results.size());
    Assert.assertEquals(tokenOne, results.get(0));
    // 
    filter.setDisabled(false);
    results = find(filter);
    // 
    Assert.assertEquals(1, results.size());
    Assert.assertEquals(tokenTwo, results.get(0));
}
Also used : IdmTokenFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmTokenFilter) IdmTokenDto(eu.bcvsolutions.idm.core.api.dto.IdmTokenDto) UUID(java.util.UUID) Test(org.junit.Test) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest)

Example 28 with IdmTokenDto

use of eu.bcvsolutions.idm.core.api.dto.IdmTokenDto in project CzechIdMng by bcvsolutions.

the class IdmTokenControllerRestTest method prepareDto.

@Override
protected IdmTokenDto prepareDto() {
    IdmIdentityDto owner = new IdmIdentityDto(UUID.randomUUID());
    IdmTokenDto dto = new IdmTokenDto();
    dto.setOwnerId(owner.getId());
    dto.setOwnerType(tokenManager.getOwnerType(owner));
    dto.setTokenType("mock");
    dto.setToken("mock");
    dto.setIssuedAt(ZonedDateTime.now());
    return dto;
}
Also used : IdmTokenDto(eu.bcvsolutions.idm.core.api.dto.IdmTokenDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)

Example 29 with IdmTokenDto

use of eu.bcvsolutions.idm.core.api.dto.IdmTokenDto in project CzechIdMng by bcvsolutions.

the class IdmTokenControllerRestTest method testGenerate.

@Test
public void testGenerate() throws Exception {
    IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
    IdmTokenDto token = new IdmTokenDto();
    token.setOwnerId(identity.getId());
    token.setOwnerType(tokenManager.getOwnerType(identity));
    token.setTokenType("custom");
    token.setExpiration(ZonedDateTime.now().plusDays(1));
    ObjectMapper mapper = getMapper();
    // 
    String response = getMockMvc().perform(post(getBaseUrl()).with(authentication(getAdminAuthentication())).content(mapper.writeValueAsString(token)).contentType(TestHelper.HAL_CONTENT_TYPE)).andExpect(status().isCreated()).andExpect(content().contentType(TestHelper.HAL_CONTENT_TYPE)).andReturn().getResponse().getContentAsString();
    IdmTokenDto createdToken = (IdmTokenDto) mapper.readValue(response, token.getClass());
    Assert.assertNotNull(createdToken);
    Assert.assertNotNull(createdToken.getId());
    Assert.assertTrue(token.getExpiration().isEqual(createdToken.getExpiration()));
    Assert.assertEquals(token.getTokenType(), createdToken.getTokenType());
    // 
    // token is filled
    String jwtToken = createdToken.getProperties().getString(IdmAuthenticationFilter.AUTHENTICATION_TOKEN_NAME);
    Assert.assertNotNull(jwtToken);
    IdmJwtAuthentication readToken = jwtTokenMapper.readToken(jwtToken);
    Assert.assertEquals(createdToken.getId(), readToken.getId());
    Assert.assertTrue(token.getExpiration().isEqual(readToken.getExpiration()));
    // 
    IdmTokenDto getToken = getDto(createdToken.getId());
    // token is not filled after get
    Assert.assertNull(getToken.getProperties().get(IdmAuthenticationFilter.AUTHENTICATION_TOKEN_NAME));
}
Also used : IdmTokenDto(eu.bcvsolutions.idm.core.api.dto.IdmTokenDto) IdmJwtAuthentication(eu.bcvsolutions.idm.core.security.api.domain.IdmJwtAuthentication) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest)

Example 30 with IdmTokenDto

use of eu.bcvsolutions.idm.core.api.dto.IdmTokenDto in project CzechIdMng by bcvsolutions.

the class LoginControllerRestTest method testLogoutWithHeader.

@Test
public void testLogoutWithHeader() throws Exception {
    IdmIdentityDto identity = getHelper().createIdentity();
    Map<String, String> login = new HashMap<>();
    login.put("username", identity.getUsername());
    login.put("password", identity.getPassword().asString());
    String response = getMockMvc().perform(post(BaseController.BASE_PATH + LoginController.AUTH_PATH).content(serialize(login)).contentType(TestHelper.HAL_CONTENT_TYPE)).andExpect(status().isOk()).andExpect(content().contentType(TestHelper.HAL_CONTENT_TYPE)).andReturn().getResponse().getContentAsString();
    UUID tokenId = getTokenId(response);
    String token = getToken(response);
    // 
    Assert.assertNotNull(tokenId);
    // 
    IdmTokenDto tokenDto = tokenManager.getToken(tokenId);
    Assert.assertFalse(tokenDto.isDisabled());
    // 
    getMockMvc().perform(delete(BaseController.BASE_PATH + "/logout").header(JwtAuthenticationMapper.AUTHENTICATION_TOKEN_NAME, token).contentType(TestHelper.HAL_CONTENT_TYPE)).andExpect(status().isNoContent());
    // 
    tokenDto = tokenManager.getToken(tokenId);
    Assert.assertTrue(tokenDto.isDisabled());
}
Also used : IdmTokenDto(eu.bcvsolutions.idm.core.api.dto.IdmTokenDto) HashMap(java.util.HashMap) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) UUID(java.util.UUID) AbstractRestTest(eu.bcvsolutions.idm.test.api.AbstractRestTest) Test(org.junit.Test)

Aggregations

IdmTokenDto (eu.bcvsolutions.idm.core.api.dto.IdmTokenDto)58 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)38 Test (org.junit.Test)34 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)16 UUID (java.util.UUID)16 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)15 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)9 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)8 IdmJwtAuthentication (eu.bcvsolutions.idm.core.security.api.domain.IdmJwtAuthentication)8 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)7 IdmJwtAuthenticationDto (eu.bcvsolutions.idm.core.security.api.dto.IdmJwtAuthenticationDto)7 LoginDto (eu.bcvsolutions.idm.core.security.api.dto.LoginDto)7 AbstractRestTest (eu.bcvsolutions.idm.test.api.AbstractRestTest)7 ConfigurationMap (eu.bcvsolutions.idm.core.api.domain.ConfigurationMap)6 Transactional (org.springframework.transaction.annotation.Transactional)6 ZonedDateTime (java.time.ZonedDateTime)5 IdmTokenFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmTokenFilter)4 EntityNotFoundException (eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException)4 AbstractReadWriteDtoControllerRestTest (eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest)4 TwoFactorRegistrationResponseDto (eu.bcvsolutions.idm.core.security.api.dto.TwoFactorRegistrationResponseDto)4