When I get the list of active sessions and try to get the token id, it is null.
-----Original Message----- From: Guillaume Nodet [mailto:[email protected]] Sent: Friday, July 20, 2012 4:09 PM To: [email protected] Subject: Re: [Apache SSHD] Question about authentication Looks good at a first glance. What's the problem ? On Fri, Jul 20, 2012 at 7:26 PM, Wright, Omari <[email protected]>wrote: > I'm still having problems accessing an attribute in the list of > managed sessions. > > public static final AttributeKey<TokenId> TOKEN_ID = new > AttributeKey<TokenId>(); > > public boolean authenticate(String username, String password, > ServerSession session) { > PdaUserManager userManager = (PdaUserManager) > session.getServerFactoryManager().getUserManagerFactory().createUserManager(); > Authentication auth = new > UsernamePasswordAuthentication(username, password); > > try { > String returnVal = > userManager.authenticateSshd(auth); > TokenId tokenId = new > TokenId(returnVal); > session.setAttribute(TOKEN_ID, > tokenId); > } catch (AuthenticationFailedException e) { > return false; > } > > return true; > } > > _____________________________ > > Then in another class I try: > > public static boolean disconnectByTokenId(String tokenId) { > List<AbstractSession> sessions = > server.getActiveSessions(); > for (AbstractSession session : sessions) { > if (session != null > && > SshServer.getTokenId(session).getValue().equalsIgnoreCase(sessionTokenId)) { > session.close(true); > return true; > } > } > > return false; > } > > > -----Original Message----- > From: Guillaume Nodet [mailto:[email protected]] > Sent: Friday, July 13, 2012 9:30 AM > To: [email protected] > Subject: Re: [Apache SSHD] Question about authentication > > Attributes are supposed to be used the following way > > private static final AttributeKey<MyValue> MY_KEY = new > AttributeKey<MyValue>(); > > public static MyValue getMyValue(Session s) { > return s.getAttribute(MY_KEY); > } > > private void setMyValue(Session s, MyValue value) { > s.setAttribute(MY_KEY, value); > } > > > On Fri, Jul 13, 2012 at 3:15 PM, Wright, Omari > <[email protected] > >wrote: > > > Also, does that AttributeKey that I set have to be its own data type? > > > > -----Original Message----- > > From: Guillaume Nodet [mailto:[email protected]] > > Sent: Friday, July 13, 2012 8:49 AM > > To: [email protected] > > Subject: Re: [Apache SSHD] Question about authentication > > > > The UserAuth interface you'll have to implement is given the > > ServerSession as a parameter and you can use get/setAttributes() to > > associate your id with the ssh session. > > When you want to kick users, you can enumerate the sessions using > > sshServer.getActiveSessions() and check what you need there, > > eventually calling close() on the sessions. > > > > On Fri, Jul 13, 2012 at 2:41 PM, Wright, Omari > > <[email protected] > > >wrote: > > > > > I have OpenAM which I plan to use to handle user authentication > > > again an Active Directory server. I plan to make a call during the > > > SSHD authenticate method passing along username/password. The > > > returned value of this call is a token id if it is successful and > > > null otherwise. I then want to associate this value with the > > > session as a type of session id. Is this possible? If so, how can > > > I go about doing > > this? > > > > > > The token id would basically be an added property on the session. > > > The reason I want this functionality is that I then want to be > > > able to kick users based off the token id passed to the disconnect > > > method. The reason for this is a need to have OpenAM manage user > disconnects. > > > > > > > > > > > -- > > ------------------------ > > Guillaume Nodet > > ------------------------ > > Blog: http://gnodet.blogspot.com/ > > ------------------------ > > FuseSource, Integration everywhere > > http://fusesource.com > > > > > > -- > ------------------------ > Guillaume Nodet > ------------------------ > Blog: http://gnodet.blogspot.com/ > ------------------------ > FuseSource, Integration everywhere > http://fusesource.com > -- ------------------------ Guillaume Nodet ------------------------ Blog: http://gnodet.blogspot.com/ ------------------------ FuseSource, Integration everywhere http://fusesource.com
