use of eu.bcvsolutions.idm.core.security.api.domain.IdmJwtAuthentication in project CzechIdMng by bcvsolutions.
the class AuthenticationTestUtils method getAuth.
public static IdmJwtAuthentication getAuth(IdmIdentityDto identity, Collection<GrantedAuthority> authorities) {
DateTime iat = getIat();
DateTime exp = getExp();
return new IdmJwtAuthentication(identity, identity, exp, iat, authorities, "test");
}
use of eu.bcvsolutions.idm.core.security.api.domain.IdmJwtAuthentication in project CzechIdMng by bcvsolutions.
the class OAuthAuthenticationManagerTest method testAuthSuccess.
/**
* Successful authentication
*/
@Test
public void testAuthSuccess() {
IdmIdentityDto i = getTestIdentity();
IdmJwtAuthentication authentication = getAuthentication(USER_NAME, DateTime.now().plusHours(1), DateTime.now());
when(identityService.getByUsername(USER_NAME)).thenReturn(i);
doNothing().when(workflowIdentityService).setAuthenticatedUserId(USER_NAME);
doNothing().when(securityService).setAuthentication(authentication);
Authentication auth = authManager.authenticate(authentication);
Assert.assertEquals(USER_NAME, auth.getName());
Assert.assertEquals(USER_NAME, auth.getPrincipal());
Assert.assertTrue(auth.getAuthorities().isEmpty());
verify(identityService).getByUsername(USER_NAME);
verify(workflowIdentityService).setAuthenticatedUserId(USER_NAME);
verify(securityService).setAuthentication(authentication);
}
use of eu.bcvsolutions.idm.core.security.api.domain.IdmJwtAuthentication in project CzechIdMng by bcvsolutions.
the class OAuthAuthenticationManagerTest method testAuthExpired.
/**
* Expired tokens are not accepted.
*/
@Test(expected = ResultCodeException.class)
public void testAuthExpired() {
IdmIdentityDto i = getTestIdentity();
when(identityService.getByUsername(USER_NAME)).thenReturn(i);
IdmJwtAuthentication authentication = getAuthentication(USER_NAME, DateTime.now().minusHours(1), DateTime.now().plusHours(2));
authManager.authenticate(authentication);
Assert.fail("Cannot authenticate with expired token.");
}
use of eu.bcvsolutions.idm.core.security.api.domain.IdmJwtAuthentication in project CzechIdMng by bcvsolutions.
the class AbstractWorkflowIntegrationTest method loginAsNoAdmin.
public void loginAsNoAdmin(String user) {
Collection<GrantedAuthority> authorities = IdmAuthorityUtils.toAuthorities(moduleService.getAvailablePermissions()).stream().filter(authority -> {
return !IdmGroupPermission.APP_ADMIN.equals(authority.getAuthority());
}).collect(Collectors.toList());
IdmIdentityDto identity = (IdmIdentityDto) lookupService.getDtoLookup(IdmIdentityDto.class).lookup(user);
SecurityContextHolder.getContext().setAuthentication(new IdmJwtAuthentication(identity, null, authorities, "test"));
}
use of eu.bcvsolutions.idm.core.security.api.domain.IdmJwtAuthentication in project CzechIdMng by bcvsolutions.
the class DefaultIdmRoleRequestServiceIntegrationTest method notRightForExecuteImmediatelyExceptionTest.
@Test(expected = RoleRequestException.class)
@Transactional
public void notRightForExecuteImmediatelyExceptionTest() {
IdmIdentityDto testA = getHelper().createIdentity((GuardedString) null);
IdmRoleDto roleA = getHelper().createRole(100);
this.logout();
// Log as user without right for immediately execute role request (without
// approval)
Collection<GrantedAuthority> authorities = IdmAuthorityUtils.toAuthorities(moduleService.getAvailablePermissions()).stream().filter(authority -> {
return !CoreGroupPermission.ROLE_REQUEST_EXECUTE.equals(authority.getAuthority()) && !CoreGroupPermission.ROLE_REQUEST_ADMIN.equals(authority.getAuthority()) && !IdmGroupPermission.APP_ADMIN.equals(authority.getAuthority());
}).collect(Collectors.toList());
SecurityContextHolder.getContext().setAuthentication(new IdmJwtAuthentication(testA, null, authorities, "test"));
IdmIdentityContractDto contractA = identityContractService.getPrimeContract(testA.getId());
IdmRoleRequestDto request = new IdmRoleRequestDto();
request.setApplicant(testA.getId());
request.setExecuteImmediately(true);
request.setRequestedByType(RoleRequestedByType.MANUALLY);
request = roleRequestService.save(request);
Assert.assertEquals(RoleRequestState.CONCEPT, request.getState());
IdmConceptRoleRequestDto conceptA = new IdmConceptRoleRequestDto();
conceptA.setRoleRequest(request.getId());
conceptA.setOperation(ConceptRoleRequestOperation.ADD);
conceptA.setRole(roleA.getId());
conceptA.setIdentityContract(contractA.getId());
conceptA = conceptRoleRequestService.save(conceptA);
Assert.assertEquals(RoleRequestState.CONCEPT, conceptA.getState());
// We expect exception state (we don`t have right for execute without approval)
getHelper().startRequestInternal(request, true, true);
}
Aggregations