本文整理匯總了Java中org.apache.sshd.server.session.ServerSession.setAttribute方法的典型用法代碼示例。如果您正苦於以下問題:Java ServerSession.setAttribute方法的具體用法?Java ServerSession.setAttribute怎麽用?Java ServerSession.setAttribute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.sshd.server.session.ServerSession
的用法示例。
在下文中一共展示了ServerSession.setAttribute方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: authenticate
import org.apache.sshd.server.session.ServerSession; //導入方法依賴的package包/類
@Override
public boolean authenticate(String username, PublicKey publicKey,
ServerSession session) {
if (username == null || publicKey == null) {
return false;
}
SimpleSession shiroSession = new SimpleSession();
shiroSession.setTimeout(-1L);
Subject subject = new Subject.Builder(securityManager)
.session(shiroSession)
.host(session.getIoSession().getRemoteAddress().toString())
.buildSubject();
try {
subject.login(new PublicKeyToken(username, publicKey));
} catch (AuthenticationException e) {
return false;
}
// Store subject in session.
session.setAttribute(ScmSshServer.SUBJECT_SESSION_ATTRIBUTE_KEY,
subject);
return true;
}
示例2: authenticate
import org.apache.sshd.server.session.ServerSession; //導入方法依賴的package包/類
@Override
public boolean authenticate(String username, String password,
ServerSession session) {
if (username == null || password == null) {
return false;
}
SimpleSession shiroSession = new SimpleSession();
shiroSession.setTimeout(-1L);
Subject subject = new Subject.Builder(securityManager)
.session(shiroSession)
.host(session.getIoSession().getRemoteAddress().toString())
.buildSubject();
try {
subject.login(new UsernamePasswordToken(username, password));
} catch (AuthenticationException e) {
return false;
}
// Store subject in session.
session.setAttribute(ScmSshServer.SUBJECT_SESSION_ATTRIBUTE_KEY,
subject);
return true;
}
示例3: authenticate
import org.apache.sshd.server.session.ServerSession; //導入方法依賴的package包/類
@Override
public boolean authenticate(final String username, final String password, final ServerSession session) {
try {
final Subject subject = new Subject();
final LoginContext loginContext = new LoginContext(getDomain(), subject, new CallbackHandler() {
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
for (final Callback callback : callbacks) {
if (callback instanceof NameCallback) {
((NameCallback) callback).setName(username);
} else if (callback instanceof PasswordCallback) {
((PasswordCallback) callback).setPassword(password.toCharArray());
} else {
throw new UnsupportedCallbackException(callback);
}
}
}
});
loginContext.login();
session.setAttribute(USERNAME_KEY, username);
session.setAttribute(LOGIN_CONTEXT_KEY, loginContext);
return true;
} catch (Exception e) {
LOGGER.debug("can't log using username '" + username + "'", e);
return false;
}
}