From 87fccacceac0ebb25796ac01c4cc11639506c82f Mon Sep 17 00:00:00 2001 From: Pavol Mederly Date: Wed, 1 Apr 2020 17:46:55 +0200 Subject: [PATCH 1/7] Make ScriptExprEvalCtx thread-local methods public This is to allow them to be called from custom code. (cherry picked from commit 92368c6bc30e060baf79217095a47b4667f4e82e) --- .../script/ScriptExpressionEvaluationContext.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/model/model-common/src/main/java/com/evolveum/midpoint/model/common/expression/script/ScriptExpressionEvaluationContext.java b/model/model-common/src/main/java/com/evolveum/midpoint/model/common/expression/script/ScriptExpressionEvaluationContext.java index c7a28dd2424..4d883d3bd49 100644 --- a/model/model-common/src/main/java/com/evolveum/midpoint/model/common/expression/script/ScriptExpressionEvaluationContext.java +++ b/model/model-common/src/main/java/com/evolveum/midpoint/model/common/expression/script/ScriptExpressionEvaluationContext.java @@ -160,13 +160,15 @@ public void setResult(OperationResult result) { this.result = result; } - ScriptExpressionEvaluationContext setupThreadLocal() { + @SuppressWarnings("WeakerAccess") // Can be used e.g. from the overlay code + public ScriptExpressionEvaluationContext setupThreadLocal() { ScriptExpressionEvaluationContext oldContext = THREAD_LOCAL_CONTEXT.get(); THREAD_LOCAL_CONTEXT.set(this); return oldContext; } - void cleanupThreadLocal(ScriptExpressionEvaluationContext oldContext) { + @SuppressWarnings("WeakerAccess") // Can be used e.g. from the overlay code + public void cleanupThreadLocal(ScriptExpressionEvaluationContext oldContext) { THREAD_LOCAL_CONTEXT.set(oldContext); } From f7e1f936be2e9ff31956927884a47a08b7b91e61 Mon Sep 17 00:00:00 2001 From: Hiroyuki Wada Date: Thu, 2 Apr 2020 13:01:38 +0900 Subject: [PATCH 2/7] MID-6154 Fix error message to be localized in self registration page (cherry picked from commit cd4deb2eab80a546f497cd445fda5911373bd923) --- .../midpoint/gui/api/util/WebModelServiceUtils.java | 3 +++ .../midpoint/web/page/login/PageSelfRegistration.java | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/api/util/WebModelServiceUtils.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/api/util/WebModelServiceUtils.java index 6f5b378d8ce..da7e98fffc1 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/api/util/WebModelServiceUtils.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/gui/api/util/WebModelServiceUtils.java @@ -523,6 +523,9 @@ public static void save(Collection> deltas, Mo page.getModelService().executeChanges(deltas, options, task, result); } catch (Exception ex) { + if (ex instanceof CommonException) { + subResult.setUserFriendlyMessage(((CommonException) ex).getUserFriendlyMessage()); + } subResult.recordFatalError(ex.getMessage()); LoggingUtils.logUnexpectedException(LOGGER, "Couldn't save object", ex); } finally { diff --git a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/login/PageSelfRegistration.java b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/login/PageSelfRegistration.java index a6406b260c3..42d8c649519 100644 --- a/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/login/PageSelfRegistration.java +++ b/gui/admin-gui/src/main/java/com/evolveum/midpoint/web/page/login/PageSelfRegistration.java @@ -355,8 +355,14 @@ public OperationResult run() { LOGGER.trace("Registration for user {} was successfull.", getUserModel().getObject()); } else { + String message; + if (result.getUserFriendlyMessage() != null) { + message = WebModelServiceUtils.translateMessage(result, this); + } else { + message = result.getMessage(); + } getSession().error( - createStringResource("PageSelfRegistration.registration.error", result.getMessage()) + createStringResource("PageSelfRegistration.registration.error", message) .getString()); // removePassword(target); updateCaptcha(target); From f51a94b536e7211d58362e77b024084e5752934f Mon Sep 17 00:00:00 2001 From: Pavol Mederly Date: Thu, 2 Apr 2020 12:24:28 +0200 Subject: [PATCH 3/7] Fix repo values for RTaskWaitingReason In 3.9 this enum has values of 0, 1, 2. In 4.0 the "1" was removed, shifting value of 2 to 1. Fortunately, since 4.0 we don't use values other than 0 (at least it seems so); but in order to avoid migration issues we now restored the deleted value of 1 as a placeholder. Mapping of enums should be changed to be less fragile. Until that, we CANNOT delete intermediary values from R-enums to avoid this kind of problems. This resolves MID-6117. (cherry picked from commit ce6cc3630faa8a0a9aa180deff2891fd126befcc) --- .../repo/sql/data/common/enums/RTaskWaitingReason.java | 3 +++ .../main/java/com/evolveum/midpoint/repo/sql/util/RUtil.java | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/repo/repo-sql-impl/src/main/java/com/evolveum/midpoint/repo/sql/data/common/enums/RTaskWaitingReason.java b/repo/repo-sql-impl/src/main/java/com/evolveum/midpoint/repo/sql/data/common/enums/RTaskWaitingReason.java index 8207bbcac7f..c745b6bf378 100644 --- a/repo/repo-sql-impl/src/main/java/com/evolveum/midpoint/repo/sql/data/common/enums/RTaskWaitingReason.java +++ b/repo/repo-sql-impl/src/main/java/com/evolveum/midpoint/repo/sql/data/common/enums/RTaskWaitingReason.java @@ -18,6 +18,9 @@ public enum RTaskWaitingReason implements SchemaEnum { OTHER_TASKS(TaskWaitingReasonType.OTHER_TASKS), + // See MID-6117. + PLACEHOLDER(null), + OTHER(TaskWaitingReasonType.OTHER); private TaskWaitingReasonType reason; diff --git a/repo/repo-sql-impl/src/main/java/com/evolveum/midpoint/repo/sql/util/RUtil.java b/repo/repo-sql-impl/src/main/java/com/evolveum/midpoint/repo/sql/util/RUtil.java index 771af5cfbd2..555737c1eb7 100644 --- a/repo/repo-sql-impl/src/main/java/com/evolveum/midpoint/repo/sql/util/RUtil.java +++ b/repo/repo-sql-impl/src/main/java/com/evolveum/midpoint/repo/sql/util/RUtil.java @@ -317,8 +317,9 @@ public static T getRepoEnumValue(Object object, Class } Object[] values = type.getEnumConstants(); for (Object value : values) { + //noinspection unchecked T schemaEnum = (T) value; - if (schemaEnum.getSchemaValue().equals(object)) { + if (object.equals(schemaEnum.getSchemaValue())) { return schemaEnum; } } From 2183ab0ce20161229a4b2f6faee847f3116d0e17 Mon Sep 17 00:00:00 2001 From: Pavol Mederly Date: Fri, 3 Apr 2020 14:47:50 +0200 Subject: [PATCH 4/7] Fix NPEs in ModelEventImpl (cherry picked from commit e255cf880a86379121e6edde3a4c06d331f9478b) --- .../midpoint/notifications/impl/events/ModelEventImpl.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/model/notifications-impl/src/main/java/com/evolveum/midpoint/notifications/impl/events/ModelEventImpl.java b/model/notifications-impl/src/main/java/com/evolveum/midpoint/notifications/impl/events/ModelEventImpl.java index 25f18f37650..7acc5a43ad8 100644 --- a/model/notifications-impl/src/main/java/com/evolveum/midpoint/notifications/impl/events/ModelEventImpl.java +++ b/model/notifications-impl/src/main/java/com/evolveum/midpoint/notifications/impl/events/ModelEventImpl.java @@ -236,7 +236,7 @@ public boolean hasContentToShow(boolean watchAuxiliaryAttributes) { ObjectDelta summarizedDelta; try { summarizedDelta = getSummarizedFocusDeltas(); - if (!summarizedDelta.isModify()) { + if (!ObjectDelta.isModify(summarizedDelta)) { return true; } else if (!getTextFormatter().containsVisibleModifiedItems(summarizedDelta.getModifications(), false, watchAuxiliaryAttributes)) { @@ -255,9 +255,9 @@ public boolean hasContentToShow(boolean watchAuxiliaryAttributes) { public String getContentAsFormattedList(boolean showAuxiliaryAttributes) { try { ObjectDelta summarizedDelta = getSummarizedFocusDeltas(); - if (summarizedDelta.isAdd()) { + if (ObjectDelta.isAdd(summarizedDelta)) { return getTextFormatter().formatObject(summarizedDelta.getObjectToAdd(), false, showAuxiliaryAttributes); - } else if (summarizedDelta.isModify()) { + } else if (ObjectDelta.isModify(summarizedDelta)) { ModelElementContext focusContext = modelContext.getFocusContext(); return getTextFormatter().formatObjectModificationDelta(summarizedDelta, false, showAuxiliaryAttributes, focusContext.getObjectOld(), focusContext.getObjectNew()); From 9a38a1ba4b740cf17b9e94977b8583523c9c9d7b Mon Sep 17 00:00:00 2001 From: Pavol Mederly Date: Fri, 3 Apr 2020 18:50:52 +0200 Subject: [PATCH 5/7] Re-fix NPEs in notifications (cherry picked from commit 8162efdf4d1cc4783a3f600025f4ff4797f772ee) --- .../impl/events/ModelEventImpl.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/model/notifications-impl/src/main/java/com/evolveum/midpoint/notifications/impl/events/ModelEventImpl.java b/model/notifications-impl/src/main/java/com/evolveum/midpoint/notifications/impl/events/ModelEventImpl.java index 7acc5a43ad8..94435537e6a 100644 --- a/model/notifications-impl/src/main/java/com/evolveum/midpoint/notifications/impl/events/ModelEventImpl.java +++ b/model/notifications-impl/src/main/java/com/evolveum/midpoint/notifications/impl/events/ModelEventImpl.java @@ -236,14 +236,16 @@ public boolean hasContentToShow(boolean watchAuxiliaryAttributes) { ObjectDelta summarizedDelta; try { summarizedDelta = getSummarizedFocusDeltas(); - if (!ObjectDelta.isModify(summarizedDelta)) { + if (summarizedDelta == null) { + return false; + } else if (summarizedDelta.isAdd() || summarizedDelta.isDelete()) { return true; - } else if (!getTextFormatter().containsVisibleModifiedItems(summarizedDelta.getModifications(), + } else if (getTextFormatter().containsVisibleModifiedItems(summarizedDelta.getModifications(), false, watchAuxiliaryAttributes)) { + return true; + } else { LOGGER.trace("No relevant attributes in modify delta (watchAux={})", watchAuxiliaryAttributes); return false; - } else { - return true; } } catch (Throwable t) { LoggingUtils.logUnexpectedException(LOGGER, "Unable to check if there's content to show; focus context = {}", t, focusContext.debugDump()); @@ -255,9 +257,11 @@ public boolean hasContentToShow(boolean watchAuxiliaryAttributes) { public String getContentAsFormattedList(boolean showAuxiliaryAttributes) { try { ObjectDelta summarizedDelta = getSummarizedFocusDeltas(); - if (ObjectDelta.isAdd(summarizedDelta)) { + if (summarizedDelta == null) { + return ""; // should not happen + } else if (summarizedDelta.isAdd()) { return getTextFormatter().formatObject(summarizedDelta.getObjectToAdd(), false, showAuxiliaryAttributes); - } else if (ObjectDelta.isModify(summarizedDelta)) { + } else if (summarizedDelta.isModify()) { ModelElementContext focusContext = modelContext.getFocusContext(); return getTextFormatter().formatObjectModificationDelta(summarizedDelta, false, showAuxiliaryAttributes, focusContext.getObjectOld(), focusContext.getObjectNew()); From f282b11c3227ca934d6dfb3131076b83703c7a32 Mon Sep 17 00:00:00 2001 From: mythoss Date: Tue, 7 Apr 2020 17:13:29 +0200 Subject: [PATCH 6/7] Mailtransport connection (#117) Close session after mail was sent Co-authored-by: michael.gruber --- .../notifications/impl/api/transports/MailTransport.java | 1 + 1 file changed, 1 insertion(+) diff --git a/model/notifications-impl/src/main/java/com/evolveum/midpoint/notifications/impl/api/transports/MailTransport.java b/model/notifications-impl/src/main/java/com/evolveum/midpoint/notifications/impl/api/transports/MailTransport.java index 75e0152d81d..9c08e3e1a62 100644 --- a/model/notifications-impl/src/main/java/com/evolveum/midpoint/notifications/impl/api/transports/MailTransport.java +++ b/model/notifications-impl/src/main/java/com/evolveum/midpoint/notifications/impl/api/transports/MailTransport.java @@ -340,6 +340,7 @@ public String getContentType() { long duration = System.currentTimeMillis() - start; task.recordState("Notification mail sent successfully via " + host + ", in " + duration + " ms overall."); task.recordNotificationOperation(NAME, true, duration); + t.close(); return; } catch (MessagingException e) { String msg = "Couldn't send mail message to " + mailMessage.getTo() + " via " + host + ", trying another mail server, if there is any"; From d5b2b881f9e4da9bae2eb83f09ea890aaa956b02 Mon Sep 17 00:00:00 2001 From: Pavol Mederly Date: Thu, 9 Apr 2020 16:41:15 +0200 Subject: [PATCH 7/7] Make closing SMTP session more robust (MID-6190) (cherry picked from commit d7574bfed9a5ac1f4bc049c7893ebce427c445ec) --- .../impl/api/transports/MailTransport.java | 47 ++++++++++--------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/model/notifications-impl/src/main/java/com/evolveum/midpoint/notifications/impl/api/transports/MailTransport.java b/model/notifications-impl/src/main/java/com/evolveum/midpoint/notifications/impl/api/transports/MailTransport.java index 9c08e3e1a62..72d13a6a65a 100644 --- a/model/notifications-impl/src/main/java/com/evolveum/midpoint/notifications/impl/api/transports/MailTransport.java +++ b/model/notifications-impl/src/main/java/com/evolveum/midpoint/notifications/impl/api/transports/MailTransport.java @@ -316,31 +316,34 @@ public String getContentType() { mimeMessage.setContent(multipart); javax.mail.Transport t = session.getTransport("smtp"); - if (StringUtils.isNotEmpty(mailServerConfigurationType.getUsername())) { - ProtectedStringType passwordProtected = mailServerConfigurationType.getPassword(); - String password = null; - if (passwordProtected != null) { - try { - password = protector.decryptString(passwordProtected); - } catch (EncryptionException e) { - String msg = "Couldn't send mail message to " + mailMessage.getTo() + " via " + host + ", because the plaintext password value couldn't be obtained. Trying another mail server, if there is any."; - LoggingUtils.logException(LOGGER, msg, e); - resultForServer.recordFatalError(msg, e); - continue; + try { + if (StringUtils.isNotEmpty(mailServerConfigurationType.getUsername())) { + ProtectedStringType passwordProtected = mailServerConfigurationType.getPassword(); + String password = null; + if (passwordProtected != null) { + try { + password = protector.decryptString(passwordProtected); + } catch (EncryptionException e) { + String msg = "Couldn't send mail message to " + mailMessage.getTo() + " via " + host + ", because the plaintext password value couldn't be obtained. Trying another mail server, if there is any."; + LoggingUtils.logException(LOGGER, msg, e); + resultForServer.recordFatalError(msg, e); + continue; + } } + t.connect(mailServerConfigurationType.getUsername(), password); + } else { + t.connect(); } - t.connect(mailServerConfigurationType.getUsername(), password); - } else { - t.connect(); + t.sendMessage(mimeMessage, mimeMessage.getAllRecipients()); + LOGGER.info("Message sent successfully to " + mailMessage.getTo() + " via server " + host + "."); + resultForServer.recordSuccess(); + result.recordSuccess(); + long duration = System.currentTimeMillis() - start; + task.recordState("Notification mail sent successfully via " + host + ", in " + duration + " ms overall."); + task.recordNotificationOperation(NAME, true, duration); + } finally { + t.close(); } - t.sendMessage(mimeMessage, mimeMessage.getAllRecipients()); - LOGGER.info("Message sent successfully to " + mailMessage.getTo() + " via server " + host + "."); - resultForServer.recordSuccess(); - result.recordSuccess(); - long duration = System.currentTimeMillis() - start; - task.recordState("Notification mail sent successfully via " + host + ", in " + duration + " ms overall."); - task.recordNotificationOperation(NAME, true, duration); - t.close(); return; } catch (MessagingException e) { String msg = "Couldn't send mail message to " + mailMessage.getTo() + " via " + host + ", trying another mail server, if there is any";