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


Java AuthenticationToken.getCredentials方法代碼示例

本文整理匯總了Java中org.apache.shiro.authc.AuthenticationToken.getCredentials方法的典型用法代碼示例。如果您正苦於以下問題:Java AuthenticationToken.getCredentials方法的具體用法?Java AuthenticationToken.getCredentials怎麽用?Java AuthenticationToken.getCredentials使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.shiro.authc.AuthenticationToken的用法示例。


在下文中一共展示了AuthenticationToken.getCredentials方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: queryForAuthenticationInfo

import org.apache.shiro.authc.AuthenticationToken; //導入方法依賴的package包/類
/**
 * This implementation opens an LDAP connection using the token's
 * {@link #getLdapPrincipal(org.apache.shiro.authc.AuthenticationToken) discovered principal} and provided
 * {@link AuthenticationToken#getCredentials() credentials}.  If the connection opens successfully, the
 * authentication attempt is immediately considered successful and a new
 * {@link AuthenticationInfo} instance is
 * {@link #createAuthenticationInfo(org.apache.shiro.authc.AuthenticationToken, Object, Object, javax.naming.ldap.LdapContext) created}
 * and returned.  If the connection cannot be opened, either because LDAP authentication failed or some other
 * JNDI problem, an {@link NamingException} will be thrown.
 *
 * @param token              the submitted authentication token that triggered the authentication attempt.
 * @param ldapContextFactory factory used to retrieve LDAP connections.
 * @return an {@link AuthenticationInfo} instance representing the authenticated user's information.
 * @throws NamingException if any LDAP errors occur.
 */
protected AuthenticationInfo queryForAuthenticationInfo(AuthenticationToken token,
                                                        LdapContextFactory ldapContextFactory)
        throws NamingException {

    Object principal = token.getPrincipal();
    Object credentials = token.getCredentials();

    log.debug("Authenticating user '{}' through LDAP", principal);

    principal = getLdapPrincipal(token);

    LdapContext ctx = null;
    try {
        ctx = ldapContextFactory.getLdapContext(principal, credentials);
        //context was opened successfully, which means their credentials were valid.  Return the AuthenticationInfo:
        return createAuthenticationInfo(token, principal, credentials, ctx);
    } finally {
        LdapUtils.closeContext(ctx);
    }
}
 
開發者ID:xuegongzi,項目名稱:rabbitframework,代碼行數:36,代碼來源:DefaultLdapRealm.java

示例2: doGetAuthenticationInfo

import org.apache.shiro.authc.AuthenticationToken; //導入方法依賴的package包/類
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken auth) throws AuthenticationException {
    String token = (String) auth.getCredentials();
    Cache<String, String> authCache = CacheController.getAuthCache();
    if (! authCache.containsKey(token)) {
        // get user info from database
        int uid = JWTUtil.getUid(token);
        UserEntity userEntity = userService.getUserByUid(uid);
        authCache.put(token, String.valueOf(userEntity.getPassword()));
    }

    String secret = authCache.get(token);
    if (!JWTUtil.decode(token, secret)) {
        throw new AuthenticationException("Token invalid");
    }

    return new SimpleAuthenticationInfo(token, token, "jwt_realm");
}
 
開發者ID:Eagle-OJ,項目名稱:eagle-oj-api,代碼行數:19,代碼來源:Realm.java

示例3: doGetAuthenticationInfo

import org.apache.shiro.authc.AuthenticationToken; //導入方法依賴的package包/類
/**
 * 認證(登錄時調用)
 */
@Override
protected AuthenticationInfo doGetAuthenticationInfo(
		AuthenticationToken token) throws AuthenticationException {
	String username = (String) token.getPrincipal();
       String password = new String((char[]) token.getCredentials());
       
       //查詢用戶信息
       SysUserEntity user = sysUserDao.queryByUserName(username);
       
       //賬號不存在
       if(user == null) {
           throw new UnknownAccountException("賬號或密碼不正確");
       }
       
       //密碼錯誤
       if(!password.equals(user.getPassword())) {
           throw new IncorrectCredentialsException("賬號或密碼不正確");
       }
       
       //賬號鎖定
       if(user.getStatus() == 0){
       	throw new LockedAccountException("賬號已被鎖定,請聯係管理員");
       }
       
       SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(user, password, getName());
       return info;
}
 
開發者ID:gyp220203,項目名稱:renren-msg,代碼行數:31,代碼來源:UserRealm.java

示例4: doGetAuthenticationInfo

import org.apache.shiro.authc.AuthenticationToken; //導入方法依賴的package包/類
/**
 * 認證(登錄時調用)
 */
@Override
protected AuthenticationInfo doGetAuthenticationInfo(
		AuthenticationToken token) throws AuthenticationException {
	String username = (String) token.getPrincipal();
       String password = new String((char[]) token.getCredentials());
       
       //查詢用戶信息
       SysUserEntity user = sysUserService.queryByUserName(username);
       
       //賬號不存在
       if(user == null) {
           throw new UnknownAccountException("賬號或密碼不正確");
       }
       
       //密碼錯誤
       if(!password.equals(user.getPassword())) {
           throw new IncorrectCredentialsException("賬號或密碼不正確");
       }
       
       //賬號鎖定
       if(user.getStatus() == 0){
       	throw new LockedAccountException("賬號已被鎖定,請聯係管理員");
       }
       
       SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(user, password, getName());
       return info;
}
 
開發者ID:lorcx,項目名稱:renren-security,代碼行數:31,代碼來源:UserRealm.java

示例5: getAuthenticationInfo

import org.apache.shiro.authc.AuthenticationToken; //導入方法依賴的package包/類
public AuthenticationInfo getAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
	String username = (String) token.getPrincipal();
	String password = new String((char[])token.getCredentials());
	if(!"zhang".equals(username)){
		//用戶名錯誤
		throw new UnknownAccountException();
	}
	if(!"123".equals(password)){
		//密碼錯誤
		throw new IncorrectCredentialsException();
	}
	//認證成功 返回一個Authentication的實現
	return new SimpleAuthenticationInfo(username + "@163.com", password, getName());
}
 
開發者ID:l81893521,項目名稱:shiro-demo,代碼行數:15,代碼來源:MyRealm3.java

示例6: getAuthenticationInfo

import org.apache.shiro.authc.AuthenticationToken; //導入方法依賴的package包/類
public AuthenticationInfo getAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
	String username = (String) token.getPrincipal();
	String password = new String((char[])token.getCredentials());
	if(!"zhang".equals(username)){
		//用戶名錯誤
		throw new UnknownAccountException();
	}
	if(!"123".equals(password)){
		//密碼錯誤
		throw new IncorrectCredentialsException();
	}
	//認證成功 返回一個Authentication的實現
	return new SimpleAuthenticationInfo(username, password, getName());
}
 
開發者ID:l81893521,項目名稱:shiro-demo,代碼行數:15,代碼來源:MyRealm1.java

示例7: getAuthenticationInfo

import org.apache.shiro.authc.AuthenticationToken; //導入方法依賴的package包/類
public AuthenticationInfo getAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
	String username = (String) token.getPrincipal();
	String password = new String((char[])token.getCredentials());
	if(!"wang".equals(username)){
		//用戶名錯誤
		throw new UnknownAccountException();
	}
	if(!"123".equals(password)){
		//密碼錯誤
		throw new IncorrectCredentialsException();
	}
	//認證成功 返回一個Authentication的實現
	return new SimpleAuthenticationInfo(username, password, getName());
}
 
開發者ID:l81893521,項目名稱:shiro-demo,代碼行數:15,代碼來源:MyRealm2.java

示例8: doGetAuthenticationInfo

import org.apache.shiro.authc.AuthenticationToken; //導入方法依賴的package包/類
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
    AccountProfile profile = getAccount(userService, token);

    if(profile.getStatus() == Const.STATUS_CLOSED){
        throw new LockedAccountException(profile.getName());
    }

    AccountAuthenticationInfo info = new AccountAuthenticationInfo(token.getPrincipal(), token.getCredentials(), getName());
    info.setProfile(profile);

    return info;
}
 
開發者ID:ThomasYangZi,項目名稱:mblog,代碼行數:14,代碼來源:AccountRealm.java

示例9: doCredentialsMatch

import org.apache.shiro.authc.AuthenticationToken; //導入方法依賴的package包/類
@Override
public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
    checkArgument(token instanceof UsernamePasswordToken,
            "this matcher is only support username password token");

    String dbPassword = info.getCredentials().toString();

    String cltPassword = new String((char[]) token.getCredentials());
    return Objects.equals(dbPassword, cltPassword);
}
 
開發者ID:srarcbrsent,項目名稱:tc,代碼行數:11,代碼來源:TcCredentialsMatcher.java

示例10: doGetAuthenticationInfo

import org.apache.shiro.authc.AuthenticationToken; //導入方法依賴的package包/類
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
	String userno = (String) authenticationToken.getPrincipal();
	String password = new String((char[]) authenticationToken.getCredentials());
	Result<RcUser> result = biz.login(userno, password);
	if (result.isStatus()) {
		Session session = SecurityUtils.getSubject().getSession();
		session.setAttribute(Constants.Token.RONCOO, userno);
		RcUser user = result.getResultData();
		return new SimpleAuthenticationInfo(user.getUserNo(), user.getPassword(), getName());
	}
	return null;
}
 
開發者ID:roncoo,項目名稱:roncoo-adminlte-springmvc,代碼行數:14,代碼來源:UserRealm.java

示例11: doGetAuthenticationInfo

import org.apache.shiro.authc.AuthenticationToken; //導入方法依賴的package包/類
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
	String username = (String)token.getPrincipal();  				//得到用戶名 
    String password = new String((char[])token.getCredentials()); 	//得到密碼
    if(null != username && null != password){
    	return new SimpleAuthenticationInfo(username, password, getName());
    }else{
    	return null;
    }
}
 
開發者ID:tank2140896,項目名稱:JavaWeb,代碼行數:10,代碼來源:ShiroRealm.java

示例12: doGetAuthenticationInfo

import org.apache.shiro.authc.AuthenticationToken; //導入方法依賴的package包/類
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
	String username = (String) token.getPrincipal();
	String password = new String((char[]) token.getCredentials());
	return new SimpleAuthenticationInfo(username, password, "roncooRealm");
}
 
開發者ID:roncoo,項目名稱:roncoo-adminlte-springmvc,代碼行數:7,代碼來源:RoncooRealm.java

示例13: getSubmittedPassword

import org.apache.shiro.authc.AuthenticationToken; //導入方法依賴的package包/類
protected Object getSubmittedPassword(AuthenticationToken token) {
    return token != null ? token.getCredentials() : null;
}
 
開發者ID:xuegongzi,項目名稱:rabbitframework,代碼行數:4,代碼來源:PasswordMatcher.java

示例14: createAuthenticationInfo

import org.apache.shiro.authc.AuthenticationToken; //導入方法依賴的package包/類
/**
 * Returns the {@link AuthenticationInfo} resulting from a Subject's successful LDAP authentication attempt.
 * <p/>
 * This implementation ignores the {@code ldapPrincipal}, {@code ldapCredentials}, and the opened
 * {@code ldapContext} arguments and merely returns an {@code AuthenticationInfo} instance mirroring the
 * submitted token's principal and credentials.  This is acceptable because this method is only ever invoked after
 * a successful authentication attempt, which means the provided principal and credentials were correct, and can
 * be used directly to populate the (now verified) {@code AuthenticationInfo}.
 * <p/>
 * Subclasses however are free to override this method for more advanced construction logic.
 *
 * @param token           the submitted {@code AuthenticationToken} that resulted in a successful authentication
 * @param ldapPrincipal   the LDAP principal used when creating the LDAP connection.  Unlike the token's
 *                        {@link AuthenticationToken#getPrincipal() principal}, this value is usually a constructed
 *                        User DN and not a simple username or uid.  The exact value is depending on the
 *                        configured
 *                        <a href="http://download-llnw.oracle.com/javase/tutorial/jndi/ldap/auth_mechs.html">
 *                        LDAP authentication mechanism</a> in use.
 * @param ldapCredentials the LDAP credentials used when creating the LDAP connection.
 * @param ldapContext     the LdapContext created that resulted in a successful authentication.  It can be used
 *                        further by subclasses for more complex operations.  It does not need to be closed -
 *                        it will be closed automatically after this method returns.
 * @return the {@link AuthenticationInfo} resulting from a Subject's successful LDAP authentication attempt.
 * @throws NamingException if there was any problem using the {@code LdapContext}
 */
@SuppressWarnings({"UnusedDeclaration"})
protected AuthenticationInfo createAuthenticationInfo(AuthenticationToken token, Object ldapPrincipal,
                                                      Object ldapCredentials, LdapContext ldapContext)
        throws NamingException {
    return new SimpleAuthenticationInfo(token.getPrincipal(), token.getCredentials(), getName());
}
 
開發者ID:xuegongzi,項目名稱:rabbitframework,代碼行數:32,代碼來源:DefaultLdapRealm.java

示例15: getCredentials

import org.apache.shiro.authc.AuthenticationToken; //導入方法依賴的package包/類
/**
 * Returns the {@code token}'s credentials.
 * <p/>
 * <p>This default implementation merely returns
 * {@link AuthenticationToken#getCredentials() authenticationToken.getCredentials()} and exists as a template hook
 * if subclasses wish to obtain the credentials in a different way or convert them to a different format before
 * returning.
 *
 * @param token the {@code AuthenticationToken} submitted during the authentication attempt.
 * @return the {@code token}'s associated credentials.
 */
protected Object getCredentials(AuthenticationToken token) {
    return token.getCredentials();
}
 
開發者ID:xuegongzi,項目名稱:rabbitframework,代碼行數:15,代碼來源:SimpleCredentialsMatcher.java


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