-
Notifications
You must be signed in to change notification settings - Fork 392
Description
Description
Hi Thomas,
I have a question regarding the AttributeRepository context that we can pass while connecting the ssh session.
It is a bit confusing from the Java doc to which session it is attached to.
I opened a previous ticket where #439 where I needed to override at runtime the different algorithms that we could potentially used to customize them.
Thanks to you I managed to do it thanks to listeners SessionListener#sessionCreated(Session session), but after some code changes I saw this AttributeRepository and tried to something more generic to pass my attribute directly from there instead of tryin to match the host and port of the ClientSession.
Here I have one listener / sshdConfiguration that I apply if host and port matches...
private MyConfig sshdConfiguration;
@Override
public void sessionCreated(Session session) {
InetSocketAddress remoteAddress = (InetSocketAddress)session.getIoSession().getRemoteAddress();
LOG.info("User name {}", session.getUsername());
if (remoteAddress.getHostName().equals(sshdConfiguration.getHost())
&& remoteAddress.getPort() == sshdConfiguration.getPort()) {
// The do something
}
}
So instead I tried only one listener where I get from the session itself the context...
@Override
public void sessionCreated(Session session) {
LOG.info("User name {}", session.getUsername());
// Not working
SshdConfiguration attribute = session.getAttribute(SshdConfiguration.SSHD_CONFIGURATION_ATTRIBUTE_KEY);
// Working
attribute =
((AttributeRepository)session.getIoSession().getAttribute(AttributeRepository.class)).getAttribute(
SshdConfiguration.SSHD_CONFIGURATION_ATTRIBUTE_KEY);
}
I had hard time to find where this AttributeRepository context was added (Nio2Connector.ConnectionCompletionHandler#onCompleted), to be able to retrieve it:
Nio2Session session = createSession(propertyResolver, handler, socket);
if (context != null) {
session.setAttribute(AttributeRepository.class, context);
}
My question is, am I doing good doing this way.
Also Why not attached attributes directly to the org.apache.sshd.common.session.Session object created directly ?
Many Thanks.
Motivation
it would really simplify to pass contextual information when creating a new session. In our application we cannot set default algorithms for all our clients and need to be really flexible regarding the algorithms used.
Alternatives considered
No response
Additional context
No response