This is an automated email from the ASF dual-hosted git repository.
jbonofre pushed a commit to branch karaf-4.4.x
in repository https://gitbox.apache.org/repos/asf/karaf.git
The following commit(s) were added to refs/heads/karaf-4.4.x by this push:
new 0fec7d67e4 [KARAF-7805] Add JAAS Subject to SSH shell session
0fec7d67e4 is described below
commit 0fec7d67e4242fdae5340e9ac941dee3a1b185ce
Author: Matt Pavlovich <[email protected]>
AuthorDate: Thu May 8 10:03:00 2025 -0500
[KARAF-7805] Add JAAS Subject to SSH shell session
(cherry picked from commit 0d836aac632488c769567ddd347cb7ddf0429b12)
---
.../main/java/org/apache/karaf/shell/ssh/ShellCommand.java | 11 ++++++-----
.../java/org/apache/karaf/shell/ssh/ShellFactoryImpl.java | 1 +
2 files changed, 7 insertions(+), 5 deletions(-)
diff --git
a/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/ShellCommand.java
b/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/ShellCommand.java
index 3eefbddce5..1affedb054 100644
--- a/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/ShellCommand.java
+++ b/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/ShellCommand.java
@@ -62,7 +62,7 @@ public class ShellCommand implements Command {
private OutputStream out;
private OutputStream err;
private ExitCallback callback;
- private ServerSession session;
+ private ServerSession serverSession;
private SessionFactory sessionFactory;
private Environment env;
@@ -89,7 +89,7 @@ public class ShellCommand implements Command {
@Override
public void start(ChannelSession channelSession, Environment environment)
throws IOException {
- this.session = channelSession.getServerSession();
+ this.serverSession = channelSession.getServerSession();
this.env = environment;
new Thread(this::run).start();
}
@@ -102,9 +102,10 @@ public class ShellCommand implements Command {
session.put(e.getKey(), e.getValue());
}
try {
- Subject subject = this.session != null ?
this.session.getAttribute(KarafJaasAuthenticator.SUBJECT_ATTRIBUTE_KEY) : null;
+ Subject subject = this.serverSession != null ?
this.serverSession.getAttribute(KarafJaasAuthenticator.SUBJECT_ATTRIBUTE_KEY) :
null;
Object result;
if (subject != null) {
+ session.put(Subject.class.getName(), subject);
try {
result = JaasHelper.doAs(subject,
(PrivilegedExceptionAction<Object>) () -> {
String scriptFileName =
System.getProperty(EXEC_INIT_SCRIPT);
@@ -145,8 +146,8 @@ public class ShellCommand implements Command {
} finally {
callback.onExit(exitStatus);
StreamUtils.close(in, out, err);
- if (session != null) {
- session.close(false);
+ if (serverSession != null) {
+ serverSession.close(false);
}
}
}
diff --git
a/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/ShellFactoryImpl.java
b/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/ShellFactoryImpl.java
index dcfec7c178..54487b7144 100644
--- a/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/ShellFactoryImpl.java
+++ b/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/ShellFactoryImpl.java
@@ -108,6 +108,7 @@ public class ShellFactoryImpl implements ShellFactory {
for (Map.Entry<String, String> e :
environment.getEnv().entrySet()) {
shell.put(e.getKey(), e.getValue());
}
+ shell.put(Subject.class.getName(), subject);
JaasHelper.runAs(subject, () ->
new Thread(shell, "Karaf ssh console user " +
ShellUtil.getCurrentUserName()).start());
} catch (Exception e) {