use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto in project CzechIdMng by bcvsolutions.
the class TestAppAuthenticationFilter method authorize.
@Override
public boolean authorize(String token, HttpServletRequest request, HttpServletResponse response) {
try {
Optional<Jwt> jwt = HttpFilterUtils.parseToken(token);
if (!jwt.isPresent()) {
return false;
}
Map<String, Object> claims = verifyTokenAndGetClaims(jwt.get());
String userName = (String) claims.get(HttpFilterUtils.JWT_USER_NAME);
IdmIdentityDto identity = identityService.getByUsername(userName);
// not important - either new refreshed token or data are returned to user
DateTime expiration = null;
Collection<GrantedAuthority> authorities = null;
if (shouldGrantAuthoritiesForPath(request.getServletPath())) {
authorities = grantedAuthoritiesFactory.getGrantedAuthoritiesForIdentity(identity.getId());
} else {
authorities = new ArrayList<>();
}
IdmJwtAuthentication ija = new IdmJwtAuthentication(identity, expiration, authorities, EntityUtils.getModule(this.getClass()));
SecurityContextHolder.getContext().setAuthentication(ija);
return true;
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto in project CzechIdMng by bcvsolutions.
the class JwtAuthenticationMapper method fromDto.
/**
* Converts dto to authentication.
*
* @param dto
* @return
*/
public IdmJwtAuthentication fromDto(IdmJwtAuthenticationDto dto) {
Assert.notNull(dto);
//
Collection<DefaultGrantedAuthorityDto> authorities = dto.getAuthorities();
List<GrantedAuthority> grantedAuthorities = new ArrayList<>();
if (authorities != null) {
for (DefaultGrantedAuthorityDto a : authorities) {
grantedAuthorities.add(new DefaultGrantedAuthority(a.getAuthority()));
}
}
IdmJwtAuthentication authentication = new IdmJwtAuthentication(new IdmIdentityDto(dto.getCurrentIdentityId(), dto.getCurrentUsername()), new IdmIdentityDto(dto.getOriginalIdentityId(), dto.getOriginalUsername()), dto.getExpiration(), dto.getIssuedAt(), grantedAuthorities, dto.getFromModule());
return authentication;
}
use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto in project CzechIdMng by bcvsolutions.
the class DefaultWorkflowTaskInstanceService method internalSearch.
private PageImpl<WorkflowTaskInstanceDto> internalSearch(WorkflowFilterDto filter, Pageable pageable) {
// if currently logged user can read all task continue
if (!canReadAllTask()) {
// if user can't read all task check filter
if (filter.getCandidateOrAssigned() == null) {
filter.setCandidateOrAssigned(securityService.getCurrentId().toString());
} else {
IdmIdentityDto identity = (IdmIdentityDto) lookupService.lookupDto(IdmIdentityDto.class, filter.getCandidateOrAssigned());
if (!identity.getId().equals(securityService.getCurrentId())) {
throw new ResultCodeException(CoreResultCode.FORBIDDEN, "You do not have permission for access to all tasks!");
}
}
// else is filled candidate and it is equals currently logged user
}
String processDefinitionId = filter.getProcessDefinitionId();
Map<String, Object> equalsVariables = filter.getEqualsVariables();
TaskQuery query = taskService.createTaskQuery();
query.active();
query.includeProcessVariables();
if (processDefinitionId != null) {
query.processDefinitionId(processDefinitionId);
}
if (filter.getProcessDefinitionKey() != null) {
query.processDefinitionKey(filter.getProcessDefinitionKey());
}
if (filter.getProcessInstanceId() != null) {
query.processInstanceId(filter.getProcessInstanceId());
}
if (filter.getId() != null) {
query.taskId(filter.getId().toString());
}
if (filter.getCreatedAfter() != null) {
query.taskCreatedAfter(filter.getCreatedAfter().toDate());
}
if (filter.getCreatedBefore() != null) {
query.taskCreatedBefore(filter.getCreatedBefore().toDate());
}
if (equalsVariables != null) {
for (Entry<String, Object> entry : equalsVariables.entrySet()) {
query.processVariableValueEquals(entry.getKey(), entry.getValue());
}
}
if (filter.getCandidateOrAssigned() != null) {
BaseDto dto = lookupService.lookupDto(IdmIdentityDto.class, filter.getCandidateOrAssigned());
Assert.notNull(dto);
query.taskCandidateOrAssigned(String.valueOf(dto.getId()));
}
query.orderByTaskCreateTime();
query.desc();
long count = query.count();
// it's possible that pageable is null
List<Task> tasks = null;
if (pageable == null) {
tasks = query.list();
} else {
tasks = query.listPage((pageable.getPageNumber()) * pageable.getPageSize(), pageable.getPageSize());
}
List<WorkflowTaskInstanceDto> dtos = new ArrayList<>();
if (tasks != null) {
for (Task task : tasks) {
dtos.add(toResource(task));
}
}
return new PageImpl<WorkflowTaskInstanceDto>(dtos, pageable, count);
}
use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto in project CzechIdMng by bcvsolutions.
the class CreatedComparatorUnitTest method testCompareEquals.
@Test
public void testCompareEquals() {
List<IdmIdentityDto> identities = new ArrayList<>();
DateTime created = new DateTime();
IdmIdentityDto one = new IdmIdentityDto(UUID.randomUUID());
one.setCreated(created);
IdmIdentityDto two = new IdmIdentityDto(UUID.randomUUID());
two.setCreated(created);
identities.add(one);
identities.add(two);
identities.sort(new CreatedComparator());
Assert.assertEquals(one.getId(), identities.get(0).getId());
Assert.assertEquals(two.getId(), identities.get(1).getId());
identities.sort(new CreatedComparator(false));
Assert.assertEquals(one.getId(), identities.get(0).getId());
Assert.assertEquals(two.getId(), identities.get(1).getId());
}
use of eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto in project CzechIdMng by bcvsolutions.
the class IdmIdentityController method getFormValues.
/**
* Returns filled form values
*
* @param backendId
* @return
*/
@ResponseBody
@RequestMapping(value = "/{backendId}/form-values", method = RequestMethod.GET)
@PreAuthorize("hasAuthority('" + CoreGroupPermission.IDENTITY_READ + "')")
@ApiOperation(value = "Identity form definition - read values", nickname = "getIdentityFormValues", tags = { IdmIdentityController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.IDENTITY_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.IDENTITY_READ, description = "") }) })
public Resource<?> getFormValues(@ApiParam(value = "Identity's uuid identifier or username.", required = true) @PathVariable @NotNull String backendId, @ApiParam(value = "Code of form definition (default will be used if no code is given).", required = false, defaultValue = FormService.DEFAULT_DEFINITION_CODE) @RequestParam(name = "definitionCode", required = false) String definitionCode) {
IdmIdentityDto entity = getDto(backendId);
if (entity == null) {
throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("entity", backendId));
}
//
IdmFormDefinitionDto formDefinition = formDefinitionController.getDefinition(IdmIdentity.class, definitionCode);
//
return formDefinitionController.getFormValues(entity, formDefinition);
}
Aggregations