Skip to content

Commit

Permalink
Bot.java: onMessage(): if we have a UsernameNotFoundException blockin…
Browse files Browse the repository at this point in the history
…g command execution, outline this to private message sender [JENKINS-72590]

Signed-off-by: Jim Klimov <[email protected]>
  • Loading branch information
jimklimov committed Jan 23, 2024
1 parent ce1bbe9 commit 438d0ca
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/main/java/hudson/plugins/im/bot/Bot.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import jenkins.model.Jenkins;
import jenkins.security.NotReallyRoleSensitiveCallable;
import org.acegisecurity.userdetails.UsernameNotFoundException;

/**
* Instant messaging bot.
Expand Down Expand Up @@ -162,15 +163,20 @@ public void onMessage(final IMMessage msg) {
final BotCommand command = this.cmdsAndAliases.get(cmd);
if (command != null) {
if (isAuthenticationNeeded()) {
ACL.impersonate(this.authentication.getAuthentication(), new NotReallyRoleSensitiveCallable<Void, IMException>() {
private static final long serialVersionUID = 1L;

@Override
public Void call() throws IMException {
command.executeCommand(Bot.this, chat, msg, s, args);
return null;
}
});
try {
ACL.impersonate(this.authentication.getAuthentication(), new NotReallyRoleSensitiveCallable<Void, IMException>() {
private static final long serialVersionUID = 1L;

@Override
public Void call() throws IMException {
command.executeCommand(Bot.this, chat, msg, s, args);
return null;
}
});
} catch (UsernameNotFoundException ue) {
this.chat.sendMessage(s.getNickname() + " This bot is not authorized to execute commands at this time, sorry!");
throw ue;
}

Check warning on line 179 in src/main/java/hudson/plugins/im/bot/Bot.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 176-179 are not covered by tests
} else {
command.executeCommand(Bot.this, chat, msg, s, args);
}
Expand Down

0 comments on commit 438d0ca

Please sign in to comment.