use of pro.taskana.exceptions.SystemException in project taskana by Taskana.
the class WorkbasketServiceImpl method checkAuthorization.
private void checkAuthorization(String workbasketKey, String domain, String workbasketId, WorkbasketPermission workbasketPermission) throws NotAuthorizedException {
LOGGER.debug("entry to checkAuthorization(workbasketId = {}, workbasketPermission = {})", workbasketKey, workbasketPermission);
if (workbasketPermission == null) {
throw new SystemException("checkAuthorization was called with an invalid parameter combination");
}
// Skip permission check is security is not enabled
if (!taskanaEngine.getConfiguration().isSecurityEnabled()) {
LOGGER.debug("Skipping permissions check since security is disabled.");
return;
}
if (taskanaEngine.isUserInRole(TaskanaRole.ADMIN)) {
LOGGER.debug("Skipping permissions check since user is in role ADMIN.");
return;
}
boolean isAuthorized = false;
try {
taskanaEngine.openConnection();
List<String> accessIds = CurrentUserContext.getAccessIds();
LOGGER.debug("checkAuthorization: Verifying that {} has the permission {} on workbasket {}", CurrentUserContext.getUserid(), workbasketPermission.name(), workbasketKey);
List<WorkbasketAccessItemImpl> accessItems;
if (workbasketKey != null) {
accessItems = workbasketAccessMapper.findByWorkbasketAccessByWorkbasketKeyDomainAndAuthorization(workbasketKey, domain, accessIds, workbasketPermission.name());
} else if (workbasketId != null) {
accessItems = workbasketAccessMapper.findByWorkbasketAndAccessIdAndAuthorizationsById(workbasketId, accessIds, workbasketPermission.name());
} else {
LOGGER.error("Throwing SystemException because an internal error occurred. Workbasket key and id were null in checkAuthorization");
throw new SystemException("checkAuthorizationImpl was called with both workbasketKey and workbasketId set to null");
}
if (accessItems.isEmpty()) {
if (workbasketId != null) {
LOGGER.error("AccessIds {} do not have permission {} on workbasket with id {}. Throwing NotAuthorizedException.", LoggerUtils.listToString(accessIds), workbasketPermission.name(), workbasketId);
throw new NotAuthorizedException("Not authorized. Permission '" + workbasketPermission.name() + "' on workbasket '" + workbasketId + "' is needed.");
} else {
LOGGER.error("AccessIds {} do not have permission {} on workbasket with key {} and domain {}. Throwing NotAuthorizedException.", LoggerUtils.listToString(accessIds), workbasketPermission.name(), workbasketKey, domain);
throw new NotAuthorizedException("Not authorized. Permission '" + workbasketPermission.name() + "' on workbasket with key '" + workbasketKey + "' and domain '" + domain + "' is needed.");
}
}
isAuthorized = true;
} finally {
taskanaEngine.returnConnection();
LOGGER.debug("exit from checkAuthorization(). User is authorized = {}.", isAuthorized);
}
}
use of pro.taskana.exceptions.SystemException in project taskana by Taskana.
the class ClassificationServiceImpl method deleteClassification.
@Override
public void deleteClassification(String classificationKey, String domain) throws ClassificationInUseException, ClassificationNotFoundException, NotAuthorizedException {
LOGGER.debug("entry to deleteClassification(key = {}, domain = {})", classificationKey, domain);
taskanaEngine.checkRoleMembership(TaskanaRole.BUSINESS_ADMIN, TaskanaRole.ADMIN);
try {
taskanaEngine.openConnection();
Classification classification = this.classificationMapper.findByKeyAndDomain(classificationKey, domain);
if (classification == null) {
throw new ClassificationNotFoundException(classificationKey, domain, "The classification " + classificationKey + "wasn't found in the domain " + domain);
}
List<AttachmentSummaryImpl> attachments = taskanaEngine.getSqlSession().getMapper(AttachmentMapper.class).findAttachmentSummariesByClassificationId(classification.getId());
if (!attachments.isEmpty()) {
throw new ClassificationInUseException("Classification " + classification.getId() + " is used by Attachment " + attachments.get(0).getId());
}
if (domain.equals("")) {
// master mode - delete all associated classifications in every domain.
List<String> domains = this.classificationMapper.getDomainsForClassification(classificationKey);
domains.remove("");
for (String classificationDomain : domains) {
deleteClassification(classificationKey, classificationDomain);
}
}
TaskServiceImpl taskService = (TaskServiceImpl) taskanaEngine.getTaskService();
try {
List<TaskSummary> classificationTasks = taskService.createTaskQuery().classificationKeyIn(classificationKey).list();
if (classificationTasks.stream().anyMatch(t -> domain.equals(t.getClassificationSummary().getDomain()))) {
throw new ClassificationInUseException("There are Tasks that belong to this classification or a child classification. Please complete them and try again.");
}
} catch (NotAuthorizedToQueryWorkbasketException e) {
LOGGER.error("ClassificationQuery unexpectedly returned NotauthorizedException. Throwing SystemException ");
throw new SystemException("ClassificationQuery unexpectedly returned NotauthorizedException.");
}
List<String> childKeys = this.classificationMapper.getChildrenOfClassification(classification.getId());
for (String key : childKeys) {
this.deleteClassification(key, domain);
}
this.classificationMapper.deleteClassificationInDomain(classificationKey, domain);
} finally {
taskanaEngine.returnConnection();
LOGGER.debug("exit from deleteClassification()");
}
}
use of pro.taskana.exceptions.SystemException in project taskana by Taskana.
the class TaskanaEngineConfiguration method initTaskanaRoles.
private void initTaskanaRoles(Properties props, String rolesSeparator) {
List<String> validPropertyNames = Arrays.stream(TaskanaRole.values()).map(TaskanaRole::getPropertyName).collect(Collectors.toList());
for (Object obj : props.keySet()) {
String propertyName = ((String) obj);
if (validPropertyNames.contains(propertyName.toLowerCase().trim())) {
String propertyValue = props.getProperty(propertyName);
Set<String> roleMemberSet = new HashSet<>();
StringTokenizer st = new StringTokenizer(propertyValue, rolesSeparator);
while (st.hasMoreTokens()) {
String token = st.nextToken().toLowerCase().trim();
roleMemberSet.add(token);
}
TaskanaRole key = TaskanaRole.fromPropertyName(propertyName);
if (key != null) {
roleMap.put(key, roleMemberSet);
} else {
LOGGER.error("Internal System error when processing role property {}.", propertyName);
throw new SystemException("Internal System error when processing role property " + propertyName);
}
}
}
ensureRoleMapIsFullyInitialized();
roleMap.forEach((k, v) -> LOGGER.debug("Found Taskana RoleConfig {} : {} ", k, LoggerUtils.setToString(v)));
}
use of pro.taskana.exceptions.SystemException in project taskana by Taskana.
the class TaskServiceImpl method getTask.
@Override
public Task getTask(String id) throws TaskNotFoundException, NotAuthorizedException {
LOGGER.debug("entry to getTaskById(id = {})", id);
TaskImpl resultTask = null;
try {
taskanaEngine.openConnection();
resultTask = taskMapper.findById(id);
if (resultTask != null) {
WorkbasketQueryImpl query = (WorkbasketQueryImpl) workbasketService.createWorkbasketQuery();
query.setUsedToAugmentTasks(true);
String workbasketId = resultTask.getWorkbasketSummary().getId();
List<WorkbasketSummary> workbaskets = query.idIn(workbasketId).list();
if (workbaskets.isEmpty()) {
String currentUser = CurrentUserContext.getUserid();
LOGGER.error("The current user {} has no read permission for workbasket {}.", currentUser, workbasketId);
throw new NotAuthorizedException("The current user " + currentUser + " has no read permission for workbasket " + workbasketId);
} else {
resultTask.setWorkbasketSummary(workbaskets.get(0));
}
List<AttachmentImpl> attachmentImpls = attachmentMapper.findAttachmentsByTaskId(resultTask.getId());
if (attachmentImpls == null) {
attachmentImpls = new ArrayList<>();
}
List<ClassificationSummary> classifications;
try {
classifications = findClassificationForTaskImplAndAttachments(resultTask, attachmentImpls);
} catch (NotAuthorizedException e1) {
LOGGER.error("ClassificationQuery unexpectedly returned NotauthorizedException. Throwing SystemException ");
throw new SystemException("ClassificationQuery unexpectedly returned NotauthorizedException.");
}
List<Attachment> attachments = addClassificationSummariesToAttachments(resultTask, attachmentImpls, classifications);
resultTask.setAttachments(attachments);
String classificationId = resultTask.getClassificationSummary().getId();
ClassificationSummary classification = classifications.stream().filter(c -> c.getId().equals(classificationId)).findFirst().orElse(null);
if (classification == null) {
LOGGER.error("Could not find a Classification for task {} ", resultTask);
throw new SystemException("Could not find a Classification for task " + resultTask.getId());
}
resultTask.setClassificationSummary(classification);
return resultTask;
} else {
LOGGER.warn("Method getTaskById() didn't find task with id {}. Throwing TaskNotFoundException", id);
throw new TaskNotFoundException(id, "Task with id " + id + " was not found");
}
} finally {
taskanaEngine.returnConnection();
LOGGER.debug("exit from getTaskById(). Returning result {} ", resultTask);
}
}
use of pro.taskana.exceptions.SystemException in project taskana by Taskana.
the class TaskServiceImpl method addClassificationSummariesToAttachmentSummaries.
private void addClassificationSummariesToAttachmentSummaries(List<AttachmentSummaryImpl> attachmentSummaries, List<TaskSummaryImpl> taskSummaries, List<ClassificationSummary> classifications) {
// prereq: in each attachmentSummary, the classificationSummary.key property is set.
if (attachmentSummaries == null || attachmentSummaries.isEmpty() || taskSummaries == null || taskSummaries.isEmpty()) {
return;
}
// iterate over all attachment summaries an add the appropriate classification summary to each
for (AttachmentSummaryImpl att : attachmentSummaries) {
String classificationId = att.getClassificationSummary().getId();
ClassificationSummary aClassification = classifications.stream().filter(x -> classificationId != null && classificationId.equals(x.getId())).findFirst().orElse(null);
if (aClassification == null) {
LOGGER.error("Could not find a Classification for attachment {}.", att);
throw new SystemException("Could not find a Classification for attachment " + att);
}
att.setClassificationSummary(aClassification);
}
}
Aggregations