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