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();
}
}
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));
}
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;
}
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));
}
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());
}
Aggregations