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


Java SimpleAuthenticationInfo類代碼示例

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


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

示例1: doGetAuthenticationInfo

import org.apache.shiro.authc.SimpleAuthenticationInfo; //導入依賴的package包/類
/**
 * 認證回調函數,登錄時調用.
 */
@Override
protected AuthenticationInfo doGetAuthenticationInfo(
		AuthenticationToken authcToken) throws AuthenticationException {
	UsernamePassword2Token token = (UsernamePassword2Token) authcToken;
	String username = token.getUsername();
	if (username == null || null == username) {
		throw new AccountException(
				"Null usernames are not allowed by this realm.");
	}
	User entity = new User();
	entity.setEmail(username);
	entity.setStatus(Constant.STATUS_ENABLED);
	entity = (User) service.iUserService.select(entity);
	if (null == entity) {
		throw new UnknownAccountException("No account found for user ["
				+ username + "]");
	}
	byte[] key = Encode.decodeHex(entity.getRandom());
	return new SimpleAuthenticationInfo(new Shiro(entity.getId(),
			entity.getEmail(), entity.getName()), entity.getPassword(),
			ByteSource.Util.bytes(key), getName());
}
 
開發者ID:jiangzongyao,項目名稱:kettle_support_kettle8.0,代碼行數:26,代碼來源:Authorizing2Realm.java

示例2: doGetAuthenticationInfo

import org.apache.shiro.authc.SimpleAuthenticationInfo; //導入依賴的package包/類
@Override
	protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
		//UsernamePasswordToken對象用來存放提交的登錄信息
        UsernamePasswordToken token=(UsernamePasswordToken) authenticationToken;

        log.info("驗證當前Subject時獲取到token為:" + ReflectionToStringBuilder.toString(token, ToStringStyle.MULTI_LINE_STYLE)); 
//        return new SimpleAuthenticationInfo("hsjhsj","8e24137dee97c9bbddb9a0cd6e043be4" , getName());
        return new SimpleAuthenticationInfo("hsjhsj","" , getName());
        //查出是否有此用戶
//        TbUser user=null;
//        if(user!=null){
            // 若存在,將此用戶存放到登錄認證info中,無需自己做密碼對比,Shiro會為我們進行密碼對比校驗
//            return new SimpleAuthenticationInfo(user.getUsername(), , getName());
//        }
//        return null;
	}
 
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:17,代碼來源:ShiroRealm.java

示例3: doGetAuthenticationInfo

import org.apache.shiro.authc.SimpleAuthenticationInfo; //導入依賴的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

示例4: doGetAuthenticationInfo

import org.apache.shiro.authc.SimpleAuthenticationInfo; //導入依賴的package包/類
/**
 * 用戶認證-驗證用戶是否登錄、用戶名密碼是否匹配
 */
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
	logger.info(">>> 【用戶認證】token = {}", token);
	String userName = (String)token.getPrincipal();
	AdminUser user = getPrincipalService().getPrincipalObject(userName);
       if(user == null) {
           throw new UnknownAccountException("Unknown account: " + userName);//沒找到帳號
       }
       if(AdminUserStatusEnum.ADMIN_USER_STATUS_DISABLED.getStatusCode().equals(user.getStatus())) {
           throw new LockedAccountException("Account[" + userName + "] has been locked!"); //帳號鎖定
       }
       //交給AuthenticatingRealm使用CredentialsMatcher進行密碼匹配
       SimpleAuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo(
               user.getUserName(), //用戶名
               user.getPassword(), //密碼
               ByteSource.Util.bytes(user.getPasswordSalt()),//salt
               getName()  //realm name
       );
       return authenticationInfo;
}
 
開發者ID:penggle,項目名稱:xproject,代碼行數:23,代碼來源:AdminUserRealm.java

示例5: doGetAuthenticationInfo

import org.apache.shiro.authc.SimpleAuthenticationInfo; //導入依賴的package包/類
/**
 * 先執行登錄驗證
 * @param token
 * @return
 * @throws AuthenticationException
 */
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {

    //獲取用戶名密碼
    String username = token.getPrincipal().toString();
    TbUser tbUser = userService.getUserByUsername(username);
    if (tbUser != null){
        //得到用戶賬號和密碼存放到authenticationInfo中用於Controller層的權限判斷 第三個參數隨意不能為null
        AuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo(tbUser.getUsername(),tbUser.getPassword(),
                tbUser.getUsername()) ;
        return authenticationInfo ;
    }else{
        return null ;
    }
}
 
開發者ID:Exrick,項目名稱:xmall,代碼行數:22,代碼來源:MyRealm.java

示例6: doGetAuthenticationInfo

import org.apache.shiro.authc.SimpleAuthenticationInfo; //導入依賴的package包/類
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken)
		throws AuthenticationException {
	UsernamePasswordToken token = (UsernamePasswordToken) authcToken;
	Map<String, Object> params = new HashMap<String, Object>();
	params.put("enable", 1);
	params.put("account", token.getUsername());
	Parameter parameter = new Parameter("sysUserService", "queryList").setMap(params);
	logger.info("{} execute sysUserService.queryList start...", parameter.getNo());
	List<?> list = provider.execute(parameter).getList();
	logger.info("{} execute sysUserService.queryList end.", parameter.getNo());
	if (list.size() == 1) {
		SysUser user = (SysUser) list.get(0);
		StringBuilder sb = new StringBuilder(100);
		for (int i = 0; i < token.getPassword().length; i++) {
			sb.append(token.getPassword()[i]);
		}
		if (user.getPassword().equals(sb.toString())) {
			WebUtil.saveCurrentUser(user.getId());
			saveSession(user.getAccount(), token.getHost());
			AuthenticationInfo authcInfo = new SimpleAuthenticationInfo(user.getAccount(), user.getPassword(),
					user.getUserName());
			return authcInfo;
		}
		logger.warn("USER [{}] PASSWORD IS WRONG: {}", token.getUsername(), sb.toString());
		return null;
	} else {
		logger.warn("No user: {}", token.getUsername());
		return null;
	}
}
 
開發者ID:youngMen1,項目名稱:JAVA-,代碼行數:31,代碼來源:Realm.java

示例7: doGetAuthenticationInfo

import org.apache.shiro.authc.SimpleAuthenticationInfo; //導入依賴的package包/類
@Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
        // token是用戶輸入的用戶名和密碼
        // 第一步從token中取出用戶名
        String userCode = (String) token.getPrincipal();

        // 如果查詢不到返回null
        //數據庫中用戶賬號是zhangsansan
//        if(!userCode.equals("zhangsansan")){//
//            return null;
//        }

        // 模擬從數據庫查詢到密碼
        String password = "111111";

        //將activeUser設置simpleAuthenticationInfo
        SimpleAuthenticationInfo simpleAuthenticationInfo = new SimpleAuthenticationInfo(
                userCode, password, this.getName());

        return simpleAuthenticationInfo;
    }
 
開發者ID:lgpzjp,項目名稱:rure,代碼行數:22,代碼來源:CustomRealm.java

示例8: doGetAuthenticationInfo

import org.apache.shiro.authc.SimpleAuthenticationInfo; //導入依賴的package包/類
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
	String username = (String) token.getPrincipal();// 根據剛剛傳過來的token獲取用戶名
	Blogger blogger = bloggerService.findByUsername(username);// 隻是根據用戶名查詢出,不涉及密碼
	if (blogger != null) {
		System.out.println("驗證信息:" + blogger);
		// 把獲取到的用戶存到session中
		SecurityUtils.getSubject().getSession().setAttribute("blogger", blogger);
		// 把從數據庫中查詢出來的博主信息放到AuthenticationInfo中,即把正確的用戶名,密碼,交給shiro,再和前台輸入的校驗。
		AuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo(blogger.getUsername(),
				blogger.getPassword(), "MyRealm");
		return authenticationInfo;
	} else {
		return null;
	}

}
 
開發者ID:shinyjunjun,項目名稱:myblog,代碼行數:18,代碼來源:MyRealm.java

示例9: doGetAuthenticationInfo

import org.apache.shiro.authc.SimpleAuthenticationInfo; //導入依賴的package包/類
/**
	 * 認證回調函數,登錄時調用.
	 */
	@Override
	protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken) throws AuthenticationException {
		UsernamePasswordToken token = (UsernamePasswordToken) authcToken;
//		User user = accountManager.findUserByLoginName(token.getUsername());
		
		//根據loginToken 看能不查到當前token token有效期就1分鍾
		
		String tokenPassword=new String(token.getPassword());

		User user = accountManager.findUserByLoginNameOrEmail(token.getUsername());

		//user.getStandardLock()==1 
		if (user != null &&  user.getStatus().intValue()!=0 && !user.getLoginName().endsWith("@chacuo.net")) {
			 return new SimpleAuthenticationInfo(user.getLoginName(), user.getShaPassword() , getName());
		} else {
			return null;
		}
	}
 
開發者ID:wkeyuan,項目名稱:DWSurvey,代碼行數:22,代碼來源:ShiroDbRealm.java

示例10: doGetAuthenticationInfo

import org.apache.shiro.authc.SimpleAuthenticationInfo; //導入依賴的package包/類
/**
 * 登錄認證,在權限認證前執行
 *
 * @param token
 * @return AuthenticationInfo
 * @throws AuthenticationException
 */
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
  String username = token.getPrincipal().toString();
  UUser user = userMService.findUserByUserName(username);
  if (null == user) {
    return null;
  } else {
    /**
     * info中principal選擇方案:1.username, 2.User, 3.UserWithRoleAndPermission
     * 各有優劣,這裏選擇使用username
     *
     * EAO isssue: 新建對象WholeUser,有屬性roles,permissions,登錄時產生此對象作為principals,則authorization時無需再和sql交互
     * 1.優勢: 減少sql交互,
     * 2.劣勢:緩存大,對變更的用戶信息反饋不及時
     * 適用: 變化不大信息量少,但權限校驗頻繁的用戶類型.
     *
     * SimpleAuthorizationInfo: param: principal檢查源碼最後被強轉為Collection不知何意??
     */
    SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(user.getUsername(), user.getPassword(), "UserRealm");
    return info;
  }
}
 
開發者ID:MiniPa,項目名稱:cjs_ssms,代碼行數:30,代碼來源:UUserRealm.java

示例11: doGetAuthenticationInfo

import org.apache.shiro.authc.SimpleAuthenticationInfo; //導入依賴的package包/類
/**
 * 登錄認證,在權限認證前執行
 *
 * @param token
 * @return AuthenticationInfo
 * @throws AuthenticationException
 */
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
  String userName = token.getPrincipal().toString();
  UUser user = userFService.findUserByUsername(userName);
  if (null == user) {
    return null;
  } else {
    /**
     * info中principal選擇方案:1.username, 2.User, 3.UserWithRoleAndPermission
     * 各有優劣,這裏選擇使用username
     *
     * EAO isssue: 新建對象WholeUser,有屬性roles,permissions,登錄時產生此對象作為principals,則authorization時無需再和sql交互
     * 1.優勢: 減少sql交互,
     * 2.劣勢:緩存大,對變更的用戶信息反饋不及時
     * 適用: 變化不大信息量少,但權限校驗頻繁的用戶類型.
     *
     * SimpleAuthorizationInfo: param: principal檢查源碼最後被強轉為Collection不知何意??
     */
    SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(user.getUsername(), user.getPassword(), "UserRealm");
    return info;
  }
}
 
開發者ID:MiniPa,項目名稱:cjs_ssms,代碼行數:30,代碼來源:UserRealm.java

示例12: doGetAuthenticationInfo

import org.apache.shiro.authc.SimpleAuthenticationInfo; //導入依賴的package包/類
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
    String username = "liu";
    //隨機數
    String salt2 = "0072273a5d87322163795118fdd7c45e";
    //加密後的密碼
    String password = "be320beca57748ab9632c4121ccac0db";

    SimpleAuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo(username, password, getName());
    authenticationInfo.setCredentialsSalt(ByteSource.Util.bytes(username + salt2));
    return authenticationInfo;
}
 
開發者ID:l81893521,項目名稱:shiro-demo,代碼行數:12,代碼來源:MyRealm2.java

示例13: doGetAuthenticationInfo

import org.apache.shiro.authc.SimpleAuthenticationInfo; //導入依賴的package包/類
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
      UsernamePasswordToken upToken = (UsernamePasswordToken) token;

     /* if (Strings.isBlank(upToken.getCaptcha()))
          throw new AuthenticationException("驗證碼不能為空");
      String _captcha = Strings.sBlank(SecurityUtils.getSubject().getSession(true).getAttribute(Toolkit.captcha_attr));
      if (!upToken.getCaptcha().equalsIgnoreCase(_captcha))
          throw new AuthenticationException("驗證碼錯誤");*/

      User user = dao().fetch(User.class, Cnd.where("name", "=", upToken.getUsername()));
      if (user == null)
          return null;
      if (user.isLocked()) 
          throw new LockedAccountException("Account [" + upToken.getUsername() + "] is locked.");
      ByteSource salt = ByteSource.Util.bytes(user.getSalt());
SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(user, user.getPassword(), getName());
info.setCredentialsSalt(salt);
return info;
  }
 
開發者ID:strictnerd,項目名稱:windows-file-change,代碼行數:20,代碼來源:NutDaoRealm.java

示例14: doGetAuthenticationInfo

import org.apache.shiro.authc.SimpleAuthenticationInfo; //導入依賴的package包/類
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
	String phoneNumber = (String)token.getPrincipal();
       if(StringUtils.trimToNull(phoneNumber) == null){
           throw new IncorrectCredentialsException();//賬號或密碼錯誤
       }
	CdMember query = new CdMember();
	query.setPhoneNumber(phoneNumber);
       CdMember member = memberService.findMember(query);
       if(member == null) {
           throw new UnknownAccountException();//沒找到帳號
       }
       SimpleAuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo(
               phoneNumber, //用戶名
               member.getPassword(), //密碼
               ByteSource.Util.bytes(AppConstants.PC_PASSWORD_SALT),//salt=phoneNumber
               getName()  //realm name
       );
       return authenticationInfo;
}
 
開發者ID:xmomen,項目名稱:dms-webapp,代碼行數:21,代碼來源:MemberRealm.java

示例15: doGetAuthenticationInfo

import org.apache.shiro.authc.SimpleAuthenticationInfo; //導入依賴的package包/類
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {

    String username = (String)token.getPrincipal();

    SysUsers user = userService.findByUsername(username);

    if(user == null) {
        throw new UnknownAccountException();//沒找到帳號
    }

    if(Boolean.TRUE.equals(user.getLocked())) {
        throw new LockedAccountException(); //帳號鎖定
    }

    //交給AuthenticatingRealm使用CredentialsMatcher進行密碼匹配,如果覺得人家的不好可以自定義實現
    SimpleAuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo(
            username, //用戶名
            user.getPassword(), //密碼
            ByteSource.Util.bytes(user.getSalt()),//salt=salt
            getName()  //realm name
    );
    return authenticationInfo;
}
 
開發者ID:xmomen,項目名稱:dms-webapp,代碼行數:25,代碼來源:UserRealm.java


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