當前位置: 首頁>>代碼示例>>Java>>正文


Java ServerSession.setAttribute方法代碼示例

本文整理匯總了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;
}
 
開發者ID:litesolutions,項目名稱:scm-ssh-plugin,代碼行數:23,代碼來源:ScmPublickeyAuthenticator.java

示例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;
}
 
開發者ID:litesolutions,項目名稱:scm-ssh-plugin,代碼行數:23,代碼來源:ScmPasswordAuthenticator.java

示例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;
    }
}
 
開發者ID:apache,項目名稱:tomee,代碼行數:28,代碼來源:OpenEJBJaasPasswordAuthenticator.java


注:本文中的org.apache.sshd.server.session.ServerSession.setAttribute方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。