Search in sources :

Example 36 with IdmTokenDto

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

the class DefaultTokenManagerIntegrationTest method testCrudToken.

@Test
public void testCrudToken() {
    IdmIdentityDto owner = new IdmIdentityDto(UUID.randomUUID());
    IdmTokenDto token = createToken(owner, null, null);
    // 
    Assert.assertNotNull(token.getId());
    Assert.assertEquals(owner.getId(), token.getOwnerId());
    Assert.assertEquals(manager.getOwnerType(owner), token.getOwnerType());
    // 
    IdmTokenDto getToken = manager.getToken(token.getId());
    // 
    Assert.assertEquals(token.getId(), getToken.getId());
    Assert.assertEquals(owner.getId(), getToken.getOwnerId());
    Assert.assertFalse(getToken.isDisabled());
    // 
    List<IdmTokenDto> tokens = manager.getTokens(owner);
    // 
    Assert.assertEquals(1, tokens.size());
    Assert.assertEquals(token.getId(), tokens.get(0).getId());
    // 
    manager.disableTokens(owner);
    // 
    getToken = manager.getToken(token.getId());
    Assert.assertEquals(token.getId(), getToken.getId());
    Assert.assertEquals(owner.getId(), getToken.getOwnerId());
    Assert.assertTrue(getToken.isDisabled());
    // 
    manager.deleteTokens(owner);
    // 
    tokens = manager.getTokens(owner);
    Assert.assertTrue(tokens.isEmpty());
    Assert.assertNull(manager.getToken(token.getId()));
}
Also used : IdmTokenDto(eu.bcvsolutions.idm.core.api.dto.IdmTokenDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 37 with IdmTokenDto

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

the class DefaultTokenManagerIntegrationTest method testEvictTokenCache.

@Test
public void testEvictTokenCache() {
    IdmIdentityDto owner = new IdmIdentityDto(UUID.randomUUID());
    IdmTokenDto token = createToken(owner, null, null);
    token = manager.getToken(token.getId());
    // 
    Assert.assertNotNull(cacheManager.getValue(TokenManager.TOKEN_CACHE_NAME, token.getId()));
    // 
    token.setDisabled(true);
    manager.saveToken(owner, token);
    // 
    Assert.assertNull(cacheManager.getValue(TokenManager.TOKEN_CACHE_NAME, token.getId()));
}
Also used : IdmTokenDto(eu.bcvsolutions.idm.core.api.dto.IdmTokenDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 38 with IdmTokenDto

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

the class DefaultTokenManagerIntegrationTest method testDisableTokenAfterIdentityIsDisabled.

@Test
public void testDisableTokenAfterIdentityIsDisabled() {
    IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
    IdmTokenDto token = createToken(identity, null, null);
    Assert.assertFalse(token.isDisabled());
    // 
    identityService.disable(identity.getId());
    // 
    token = manager.getToken(token.getId());
    // 
    Assert.assertTrue(token.isDisabled());
}
Also used : IdmTokenDto(eu.bcvsolutions.idm.core.api.dto.IdmTokenDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 39 with IdmTokenDto

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

the class DefaultTokenManagerIntegrationTest method testDisableTokenAfterIdentityIsDeleted.

@Test
public void testDisableTokenAfterIdentityIsDeleted() {
    IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
    IdmTokenDto token = createToken(identity, null, null);
    Assert.assertFalse(token.isDisabled());
    // 
    identityService.delete(identity);
    // 
    token = manager.getToken(token.getId());
    // 
    Assert.assertTrue(token.isDisabled());
}
Also used : IdmTokenDto(eu.bcvsolutions.idm.core.api.dto.IdmTokenDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 40 with IdmTokenDto

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

the class OAuthAuthenticationManagerUnitTest method testAuthSuccess.

/**
 * Successful authentication
 */
@Test
public void testAuthSuccess() {
    IdmIdentityDto i = getTestIdentity();
    IdmJwtAuthentication authentication = getAuthentication(UUID.randomUUID(), i, ZonedDateTime.now().plusHours(1), ZonedDateTime.now());
    doNothing().when(workflowIdentityService).setAuthenticatedUserId(USER_NAME);
    doNothing().when(securityService).setAuthentication(authentication);
    IdmTokenDto token = new IdmTokenDto(authentication.getId());
    token.setOwnerId(i.getId());
    when(tokenService.get(authentication.getId())).thenReturn(token);
    when(cacheManager.getValue(TokenManager.TOKEN_CACHE_NAME, token.getId())).thenReturn(null);
    Authentication auth = authManager.authenticate(authentication);
    Assert.assertEquals(USER_NAME, auth.getName());
    Assert.assertEquals(USER_NAME, auth.getPrincipal());
    Assert.assertTrue(auth.getAuthorities().isEmpty());
    verify(workflowIdentityService).setAuthenticatedUserId(USER_NAME);
    verify(securityService).setAuthentication(authentication);
    verify(tokenService).get(authentication.getId());
    verify(cacheManager).getValue(TokenManager.TOKEN_CACHE_NAME, token.getId());
}
Also used : IdmTokenDto(eu.bcvsolutions.idm.core.api.dto.IdmTokenDto) IdmJwtAuthentication(eu.bcvsolutions.idm.core.security.api.domain.IdmJwtAuthentication) Authentication(org.springframework.security.core.Authentication) IdmJwtAuthentication(eu.bcvsolutions.idm.core.security.api.domain.IdmJwtAuthentication) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Test(org.junit.Test) AbstractUnitTest(eu.bcvsolutions.idm.test.api.AbstractUnitTest)

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