Skip to content

Commit 87f9936

Browse files
committed
fix: Mail Notification Failed: SecurityManager Not Available in Async Context (OD-2699)
1 parent e135cc7 commit 87f9936

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

server-core/src/main/java/io/onedev/server/mail/DefaultMailService.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ public void sendMailAsync(Collection<String> toList, Collection<String> ccList,
197197
@Nullable String senderName, @Nullable String references) {
198198
transactionService.runAfterCommit(() -> executorService.execute(() -> {
199199
try {
200+
SecurityUtils.bindAsSystem();
200201
sendMail(toList, ccList, bccList, subject, htmlBody, textBody, replyAddress,
201202
senderName, references);
202203
} catch (Exception e) {

server-core/src/main/java/io/onedev/server/security/SecurityUtils.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -620,9 +620,12 @@ public static void bindAsSystem() {
620620
}
621621

622622
public static Runnable inheritSubject(Runnable task) {
623-
Subject subject = SecurityUtils.getSubject();
623+
Subject subject = ThreadContext.getSubject();
624624
return () -> {
625-
ThreadContext.bind(subject);
625+
if (subject != null)
626+
ThreadContext.bind(subject);
627+
else
628+
ThreadContext.unbindSubject();
626629
task.run();
627630
};
628631
}

0 commit comments

Comments
 (0)