Search in sources :

Example 56 with CoreException

use of eu.bcvsolutions.idm.core.api.exception.CoreException in project CzechIdMng by bcvsolutions.

the class UuidToEntityConverter method convert.

@Override
public BaseEntity convert(MappingContext<UUID, BaseEntity> context) {
    Class<BaseEntity> entityClass = context.getDestinationType();
    UUID sourceUuid = context.getSource();
    // 
    if (sourceUuid != null) {
        MappingContext<?, ?> parentContext = context.getParent();
        PropertyMapping propertyMapping = (PropertyMapping) context.getMapping();
        // Find name of field by property mapping
        String field = propertyMapping.getLastDestinationProperty().getName();
        try {
            // Find field in DTO class
            Field fieldTyp = getFirstFieldInClassHierarchy(parentContext.getSourceType(), field);
            if (fieldTyp.isAnnotationPresent(Embedded.class)) {
                Embedded embeddedAnnotation = fieldTyp.getAnnotation(Embedded.class);
                if (embeddedAnnotation.enabled()) {
                    EntityLookup<?> lookup = getLookupService().getEntityLookup(embeddedAnnotation.dtoClass());
                    if (lookup != null) {
                        return lookup.lookup(sourceUuid);
                    }
                }
            }
        } catch (NoSuchFieldException | SecurityException e) {
            throw new CoreException(e);
        }
        // We do not have lookup by embedded annotation. We try load service for entity
        EntityLookup<?> lookup = getLookupService().getEntityLookup(entityClass);
        if (lookup != null) {
            return lookup.lookup(sourceUuid);
        }
    }
    return null;
}
Also used : BaseEntity(eu.bcvsolutions.idm.core.api.entity.BaseEntity) Field(java.lang.reflect.Field) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) PropertyMapping(org.modelmapper.spi.PropertyMapping) Embedded(eu.bcvsolutions.idm.core.api.domain.Embedded) UUID(java.util.UUID)

Example 57 with CoreException

use of eu.bcvsolutions.idm.core.api.exception.CoreException in project CzechIdMng by bcvsolutions.

the class UuidToEntityConditionalConverter method convert.

@Override
public BaseEntity convert(MappingContext<UUID, BaseEntity> context) {
    Class<BaseEntity> entityClass = context.getDestinationType();
    UUID sourceUuid = context.getSource();
    // 
    if (sourceUuid == null) {
        return null;
    }
    MappingContext<?, ?> parentContext = context.getParent();
    PropertyMapping propertyMapping = (PropertyMapping) context.getMapping();
    // Find name of field by property mapping
    String field = propertyMapping.getLastDestinationProperty().getName();
    try {
        // Find field in DTO class
        Field fieldTyp = getFirstFieldInClassHierarchy(parentContext.getSourceType(), field);
        if (fieldTyp.isAnnotationPresent(Embedded.class)) {
            Embedded embeddedAnnotation = fieldTyp.getAnnotation(Embedded.class);
            if (embeddedAnnotation.enabled()) {
                EntityLookup<?> lookup = getLookupService().getEntityLookup(embeddedAnnotation.dtoClass());
                if (lookup != null) {
                    return lookup.lookup(sourceUuid);
                }
            }
        }
    } catch (NoSuchFieldException | SecurityException e) {
        throw new CoreException(e);
    }
    // We do not have lookup by embedded annotation. We try load service for entity
    EntityLookup<?> lookup = getLookupService().getEntityLookup(entityClass);
    if (lookup != null) {
        return lookup.lookup(sourceUuid);
    }
    // 
    return null;
}
Also used : BaseEntity(eu.bcvsolutions.idm.core.api.entity.BaseEntity) Field(java.lang.reflect.Field) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) PropertyMapping(org.modelmapper.spi.PropertyMapping) Embedded(eu.bcvsolutions.idm.core.api.domain.Embedded) UUID(java.util.UUID)

Example 58 with CoreException

use of eu.bcvsolutions.idm.core.api.exception.CoreException in project CzechIdMng by bcvsolutions.

the class DefaultAutomaticRoleManager method changeAutomaticRoleRules.

@Override
public IdmAutomaticRoleAttributeDto changeAutomaticRoleRules(IdmAutomaticRoleAttributeDto automaticRole, boolean executeImmediately, IdmAutomaticRoleAttributeRuleDto... newRules) {
    Assert.notNull(automaticRole, "Automatic role is required.");
    Assert.notNull(automaticRole.getId(), "Automatic role must exists!");
    IdmAutomaticRoleRequestDto request = new IdmAutomaticRoleRequestDto();
    request.setOperation(RequestOperationType.UPDATE);
    request.setRequestType(AutomaticRoleRequestType.ATTRIBUTE);
    request.setExecuteImmediately(executeImmediately);
    request.setAutomaticRole(automaticRole.getId());
    request.setName(automaticRole.getName());
    request.setRole(automaticRole.getRole());
    final IdmAutomaticRoleRequestDto createdRequest = roleRequestService.save(request);
    ArrayList<IdmAutomaticRoleAttributeRuleDto> rules = Lists.newArrayList(newRules);
    if (rules != null) {
        // Creates request for change or add rule
        rules.forEach(rule -> {
            IdmAutomaticRoleAttributeRuleRequestDto ruleRequest = new IdmAutomaticRoleAttributeRuleRequestDto();
            ruleRequest.setRequest(createdRequest.getId());
            ruleRequest.setOperation(rule.getId() != null ? RequestOperationType.UPDATE : RequestOperationType.ADD);
            ruleRequest.setAttributeName(rule.getAttributeName());
            ruleRequest.setComparison(rule.getComparison());
            ruleRequest.setType(rule.getType());
            ruleRequest.setFormAttribute(rule.getFormAttribute());
            ruleRequest.setValue(rule.getValue());
            ruleRequest.setRule(rule.getId());
            ruleRequest = ruleRequestService.save(ruleRequest);
        });
    }
    IdmAutomaticRoleAttributeRuleFilter ruleFilter = new IdmAutomaticRoleAttributeRuleFilter();
    ruleFilter.setAutomaticRoleAttributeId(automaticRole.getId());
    List<IdmAutomaticRoleAttributeRuleDto> currentRules = ruleService.find(ruleFilter, null).getContent();
    currentRules.stream().filter(currentRule -> {
        return rules == null || !rules.contains(currentRule);
    }).forEach(ruleToDelete -> {
        // Creates request for remove rule
        IdmAutomaticRoleAttributeRuleRequestDto ruleRequest = new IdmAutomaticRoleAttributeRuleRequestDto();
        ruleRequest.setRequest(createdRequest.getId());
        ruleRequest.setOperation(RequestOperationType.REMOVE);
        ruleRequest.setAttributeName(ruleToDelete.getAttributeName());
        ruleRequest.setComparison(ruleToDelete.getComparison());
        ruleRequest.setType(ruleToDelete.getType());
        ruleRequest.setFormAttribute(ruleToDelete.getFormAttribute());
        ruleRequest.setValue(ruleToDelete.getValue());
        ruleRequest.setRule(ruleToDelete.getId());
        ruleRequest = ruleRequestService.save(ruleRequest);
    });
    IdmAutomaticRoleRequestDto executedRequest = roleRequestService.startRequestInternal(createdRequest.getId(), true);
    if (RequestState.EXECUTED == executedRequest.getState()) {
        UUID createdAutomaticRoleId = executedRequest.getAutomaticRole();
        Assert.notNull(createdAutomaticRoleId, "Automatic role identifier is required.");
        return automaticRoleAttributeService.get(executedRequest.getAutomaticRole());
    }
    if (RequestState.IN_PROGRESS == executedRequest.getState()) {
        throw new AcceptedException(executedRequest.getId().toString());
    }
    if (RequestState.EXCEPTION == executedRequest.getState()) {
        throw new CoreException(executedRequest.getResult().getCause());
    }
    return null;
}
Also used : RequestOperationType(eu.bcvsolutions.idm.core.api.domain.RequestOperationType) AbstractIdmAutomaticRoleDto(eu.bcvsolutions.idm.core.api.dto.AbstractIdmAutomaticRoleDto) RequestState(eu.bcvsolutions.idm.core.api.domain.RequestState) IdmRoleTreeNodeService(eu.bcvsolutions.idm.core.api.service.IdmRoleTreeNodeService) Autowired(org.springframework.beans.factory.annotation.Autowired) IdmAutomaticRoleAttributeRuleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleAttributeRuleFilter) ArrayList(java.util.ArrayList) IdmAutomaticRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleRequestDto) AutomaticRoleManager(eu.bcvsolutions.idm.core.api.service.AutomaticRoleManager) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) IdmAutomaticRoleAttributeRuleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleRequestDto) Lists(com.google.common.collect.Lists) IdmAutomaticRoleRequestService(eu.bcvsolutions.idm.core.api.service.IdmAutomaticRoleRequestService) IdmAutomaticRoleAttributeRuleDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto) Service(org.springframework.stereotype.Service) AutomaticRoleRequestType(eu.bcvsolutions.idm.core.api.domain.AutomaticRoleRequestType) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) IdmAutomaticRoleAttributeRuleRequestService(eu.bcvsolutions.idm.core.api.service.IdmAutomaticRoleAttributeRuleRequestService) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) UUID(java.util.UUID) IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) List(java.util.List) IdmAutomaticRoleAttributeRuleService(eu.bcvsolutions.idm.core.api.service.IdmAutomaticRoleAttributeRuleService) IdmAutomaticRoleAttributeService(eu.bcvsolutions.idm.core.api.service.IdmAutomaticRoleAttributeService) Assert(org.springframework.util.Assert) IdmAutomaticRoleAttributeRuleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleRequestDto) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) IdmAutomaticRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleRequestDto) IdmAutomaticRoleAttributeRuleDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) IdmAutomaticRoleAttributeRuleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleAttributeRuleFilter) UUID(java.util.UUID)

Example 59 with CoreException

use of eu.bcvsolutions.idm.core.api.exception.CoreException in project CzechIdMng by bcvsolutions.

the class AbstractNotificationLogService method deleteInternal.

@Override
@Transactional
public void deleteInternal(DTO dto) {
    Assert.notNull(dto, "Notification is required.");
    UUID notificationId = dto.getId();
    Assert.notNull(notificationId, "Notification identifier is required.");
    // 
    try {
        // 
        // delete recipients is done by hiberante mapping - see IdmNotification
        // 
        // delete notification attachments
        IdmNotificationAttachmentFilter notificationAttachmentFilter = new IdmNotificationAttachmentFilter();
        notificationAttachmentFilter.setNotification(notificationId);
        notificationAttachmentService.find(notificationAttachmentFilter, null).forEach(notificationAttachmentService::delete);
        // 
        // delete attachments - owned by notification only
        attachmentManager.deleteAttachments(dto);
        // 
        // delete child notifications ...
        F filter = getFilterClass().getDeclaredConstructor().newInstance();
        filter.setParent(notificationId);
        find(filter, null).getContent().forEach(this::delete);
        // 
        super.deleteInternal(dto);
    } catch (ReflectiveOperationException ex) {
        throw new CoreException(String.format("Service [%s] has wrong filter, fix implemented filter class [%s] (add default constructor).", this.getClass(), getFilterClass()), ex);
    }
}
Also used : CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) IdmNotificationAttachmentFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationAttachmentFilter) UUID(java.util.UUID) Transactional(org.springframework.transaction.annotation.Transactional)

Example 60 with CoreException

use of eu.bcvsolutions.idm.core.api.exception.CoreException in project CzechIdMng by bcvsolutions.

the class TestAppAuthenticationFilter method getClaimsAsMap.

@SuppressWarnings("unchecked")
private Map<String, Object> getClaimsAsMap(Jwt jwt) {
    try {
        Map<String, Object> map = (Map<String, Object>) mapper.readValue(jwt.getClaims(), Map.class);
        // 
        if (map.containsKey(HttpFilterUtils.JWT_EXP) && map.get(HttpFilterUtils.JWT_EXP) instanceof Integer) {
            Integer intValue = (Integer) map.get(HttpFilterUtils.JWT_EXP);
            map.put(HttpFilterUtils.JWT_EXP, Long.valueOf(intValue));
        }
        return map;
    } catch (IOException ex) {
        throw new CoreException(ex);
    }
}
Also used : CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) IOException(java.io.IOException) Map(java.util.Map)

Aggregations

CoreException (eu.bcvsolutions.idm.core.api.exception.CoreException)64 UUID (java.util.UUID)16 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)15 Test (org.junit.Test)14 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)13 IOException (java.io.IOException)12 ArrayList (java.util.ArrayList)11 AcceptedException (eu.bcvsolutions.idm.core.api.exception.AcceptedException)10 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)9 Field (java.lang.reflect.Field)9 Embedded (eu.bcvsolutions.idm.core.api.domain.Embedded)8 AbstractDto (eu.bcvsolutions.idm.core.api.dto.AbstractDto)8 BaseEntity (eu.bcvsolutions.idm.core.api.entity.BaseEntity)8 List (java.util.List)8 Requestable (eu.bcvsolutions.idm.core.api.domain.Requestable)7 BaseDto (eu.bcvsolutions.idm.core.api.dto.BaseDto)7 IdmRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRequestDto)7 IdmLongRunningTaskDto (eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto)7 RequestOperationType (eu.bcvsolutions.idm.core.api.domain.RequestOperationType)6 IntrospectionException (java.beans.IntrospectionException)6