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


Java UnknownAccountException類代碼示例

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


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

示例1: doGetAuthenticationInfo

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

import org.apache.shiro.authc.UnknownAccountException; //導入依賴的package包/類
/**
 * 授權查詢回調函數, 進行鑒權但緩存中無用戶的授權信息時調用.
 */
@Override
protected AuthorizationInfo doGetAuthorizationInfo(
		PrincipalCollection principalCollection) {
	if (principalCollection == null) {
		throw new AuthorizationException("Principal is not null!");
	}
	Shiro shiro = (Shiro) principalCollection.getPrimaryPrincipal();
	User entity = new User();
	entity.setId(shiro.getId());
	entity = (User) service.iUserService.select(entity);
	if (null == entity) {
		throw new UnknownAccountException("No account found for user ["
				+ shiro.getId() + "]");
	}
	SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
	return info;
}
 
開發者ID:jiangzongyao,項目名稱:kettle_support_kettle8.0,代碼行數:21,代碼來源:Authorizing2Realm.java

示例3: dashboard

import org.apache.shiro.authc.UnknownAccountException; //導入依賴的package包/類
@RequestMapping(value = "/login", method = {
        RequestMethod.POST})
public String dashboard(ModelMap map, Admin admin) {
    String error = null;
    UsernamePasswordToken token = new UsernamePasswordToken(admin.getUsername(), admin.getPassword());
    token.setRememberMe(false);
    try {
        SecurityUtils.getSubject().login(token);
        return "redirect:/video/all";
    } catch (UnknownAccountException uae) {
        error = "用戶名錯誤!";
    } catch (IncorrectCredentialsException ice) {
        error = "密碼錯誤!";
    } catch (LockedAccountException lae) {
        error = "用戶被鎖定!";
    }
    map.addAttribute("error", error);
    return "login.ftl";
}
 
開發者ID:melonlee,項目名稱:LazyAdmin,代碼行數:20,代碼來源:AuthController.java

示例4: doGetAuthenticationInfo

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

import org.apache.shiro.authc.UnknownAccountException; //導入依賴的package包/類
@RequestMapping(value = "/login")
public String showLoginForm(HttpServletRequest req, Model model) {
    if(req.getMethod().equalsIgnoreCase("get")){
        return "login";
    }
    String exceptionClassName = (String)req.getAttribute("shiroLoginFailure");
    String error = null;
    if(UnknownAccountException.class.getName().equals(exceptionClassName)) {
        error = "用戶名/密碼錯誤";
    } else if(IncorrectCredentialsException.class.getName().equals(exceptionClassName)) {
        error = "用戶名/密碼錯誤";
    } else if(exceptionClassName != null) {
        error = "其他錯誤:" + exceptionClassName;
    }
    if(error!=null){
        model.addAttribute("shiroLoginFailure", error);
        return "login";
    }
    return "redirect:/main";

}
 
開發者ID:babymm,項目名稱:mumu,代碼行數:22,代碼來源:LoginController.java

示例6: tryLogin

import org.apache.shiro.authc.UnknownAccountException; //導入依賴的package包/類
public boolean tryLogin(String email, String password, Boolean rememberMe) {
    org.apache.shiro.subject.Subject currentUser = SecurityUtils.getSubject();
    UsernamePasswordToken token = new UsernamePasswordToken(email, password);
    token.setRememberMe(rememberMe);

    try {
        currentUser.login(token);
        System.out.println("User [" + currentUser.getPrincipal().toString() + "] logged in successfully.");
        // save username in the session
        currentUser.getSession().setAttribute("username", email);
        return true;
    } catch (UnknownAccountException uae) {
        System.out.println("There is no user with username of " + token.getPrincipal());
    } catch (IncorrectCredentialsException ice) {
        System.out.println("Password for account " + token.getPrincipal() + " was incorrect!");
    } catch (LockedAccountException lae) {
        System.out.println("The account for username " + token.getPrincipal() + " is locked.  " + "Please contact your administrator to unlock it.");
    }

    return false;
}
 
開發者ID:ETspielberg,項目名稱:bibliometrics,代碼行數:22,代碼來源:BibliometricReportRetrievalServlet.java

示例7: login

import org.apache.shiro.authc.UnknownAccountException; //導入依賴的package包/類
@RequestMapping("/login")
public String login(HttpServletRequest request) throws Exception{
	String exceptionClassName = (String) request.getAttribute("shiroLoginFailure");
	//根據shiro返回的異常類路徑判斷,拋出指定異常信息
	if(exceptionClassName!=null){
		if (UnknownAccountException.class.getName().equals(exceptionClassName)) {
			//最終會拋給異常處理器
			throw new UnknownAccountException("賬號不存在");
		} else if (IncorrectCredentialsException.class.getName().equals(
				exceptionClassName)) {
			throw new IncorrectCredentialsException("用戶名/密碼錯誤");
		}else {
			throw new Exception();//最終在異常處理器生成未知錯誤
		}
	}
	return "login";
}
 
開發者ID:fuyunwang,項目名稱:SSMShiro,代碼行數:18,代碼來源:IndexController.java

示例8: onLoginFailure

import org.apache.shiro.authc.UnknownAccountException; //導入依賴的package包/類
/**
 * 登錄失敗調用事件
 */
@Override
protected boolean onLoginFailure(AuthenticationToken token,
                                    AuthenticationException e, ServletRequest request, ServletResponse response) {
	String className = e.getClass().getName(), message = "";
	if (IncorrectCredentialsException.class.getName().equals(className)
			|| UnknownAccountException.class.getName().equals(className)){
		message = "用戶或密碼錯誤, 請重試.";
	}
	else if (e.getMessage() != null && StringUtils.startsWith(e.getMessage(), "msg:")){
		message = StringUtils.replace(e.getMessage(), "msg:", "");
	}
	else{
		message = "係統出現點問題,請稍後再試!";
		e.printStackTrace(); // 輸出到控製台
	}
       request.setAttribute(getFailureKeyAttribute(), className);
       request.setAttribute(getMessageParam(), message);
       return true;
}
 
開發者ID:egojit8,項目名稱:easyweb,代碼行數:23,代碼來源:FormAuthenticationFilter.java

示例9: signin

import org.apache.shiro.authc.UnknownAccountException; //導入依賴的package包/類
@RequestMapping(value = "/signin", method = {
        RequestMethod.POST})
public String signin(ModelMap map, User user, HttpServletRequest request) {

    String error;
    UsernamePasswordToken token = new UsernamePasswordToken(user.getUsername(), user.getPasswd());
    token.setRememberMe(null != request.getParameter("rememberme") ? true : false);
    try {
        Subject subject = SecurityUtils.getSubject();
        subject.login(token);
        subject.getSession().setAttribute("curUser", userService.findByUsername((String) subject.getPrincipal()));
        return "redirect:/dashboard/console";
    } catch (UnknownAccountException uae) {
        error = "用戶名錯誤!";
    } catch (IncorrectCredentialsException ice) {
        error = "密碼錯誤!";
    } catch (LockedAccountException lae) {
        error = "用戶被鎖定!";
    }
    map.addAttribute("error", error);
    return "signin";
}
 
開發者ID:melonlee,項目名稱:PowerApi,代碼行數:23,代碼來源:AuthController.java

示例10: changepwd

import org.apache.shiro.authc.UnknownAccountException; //導入依賴的package包/類
@RequestMapping(value = "/changepwd", method = {
        RequestMethod.POST})
public String changepwd(ModelMap map, User user, @RequestParam(value = "passwdnew", required = true) String passwdnew) {

    //驗證當前賬號
    UsernamePasswordToken token = new UsernamePasswordToken(user.getUsername(), user.getPasswd());
    token.setRememberMe(false);
    try {
        SecurityUtils.getSubject().login(token);
        //驗證通過更新用戶密碼
        user.setId(getCurrentUser().getId());
        user.setPasswd(passwdnew);
        passwordHelper.encryptPassword(user);
        userService.updateById(user);
        return "redirect:/dashboard/console";
    } catch (UnknownAccountException | IncorrectCredentialsException | LockedAccountException e) {
        map.addAttribute("exception", e.getMessage());
        return "common/error";
    }
}
 
開發者ID:melonlee,項目名稱:PowerApi,代碼行數:21,代碼來源:DashboardController.java

示例11: onLoginFailure

import org.apache.shiro.authc.UnknownAccountException; //導入依賴的package包/類
/**
 * 登錄失敗調用事件
 */
@Override
protected boolean onLoginFailure(AuthenticationToken token, AuthenticationException e, ServletRequest request,
                                 ServletResponse response) {
    String className = e.getClass().getName(), message = "";
    if (IncorrectCredentialsException.class.getName().equals(className)
            || UnknownAccountException.class.getName().equals(className)) {
        message = "用戶或密碼錯誤, 請重試.";
    } else if (e.getMessage() != null && StringUtils.startsWith(e.getMessage(), "msg:")) {
        message = StringUtils.replace(e.getMessage(), "msg:", "");
    } else {
        message = "係統出現點問題,請稍後再試!";
        e.printStackTrace(); // 輸出到控製台
    }
    request.setAttribute(getFailureKeyAttribute(), className);
    request.setAttribute(getMessageParam(), message);
    return true;
}
 
開發者ID:ansafari,項目名稱:melon,代碼行數:21,代碼來源:FormAuthenticationFilter.java

示例12: login

import org.apache.shiro.authc.UnknownAccountException; //導入依賴的package包/類
/**
 * 執行登錄請求
 *
 * @param username
 * @param request
 * @return
 */
private String login(String username, String accessToken, HttpServletRequest request) {
    String ret = getView(Views.LOGIN);

    if (StringUtils.isNotBlank(username)) {
        AuthenticationToken token = createToken(username, accessToken);

        try {
            SecurityUtils.getSubject().login(token);

            ret = Views.REDIRECT_HOME;
        } catch (AuthenticationException e) {
            logger.error(e);
            if (e instanceof UnknownAccountException) {
                throw new MtonsException("用戶不存在");
            } else if (e instanceof LockedAccountException) {
                throw new MtonsException("用戶被禁用");
            } else {
                throw new MtonsException("用戶認證失敗");
            }
        }
        return ret;
    }
    throw new MtonsException("登錄失敗!");
}
 
開發者ID:ThomasYangZi,項目名稱:mblog,代碼行數:32,代碼來源:CallbackController.java

示例13: doGetAuthenticationInfo

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

示例14: doGetAuthenticationInfo

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

示例15: login

import org.apache.shiro.authc.UnknownAccountException; //導入依賴的package包/類
@RequestMapping(value = "/member/login", method = RequestMethod.POST)
  public ResponseEntity login(HttpServletRequest request, Model model){
Map<String, Object> result = new HashMap<>();
      if(SecurityUtils.getSubject().isAuthenticated()){
	String username = (String) SecurityUtils.getSubject().getPrincipal();
	result.put("status", 200);
	result.put("username", username);
          return new ResponseEntity(result, HttpStatus.OK);
      }
String exceptionClassName = (String) request.getAttribute(FormAuthenticationFilterExt.DEFAULT_ERROR_KEY_ATTRIBUTE_NAME);
      String error = null;
RestError restError = new RestError();
restError.setTimestamp(new Date());
      if(DisabledAccountException.class.getName().equals(exceptionClassName)){
	restError.setMessage("該賬號已被鎖定,請聯係客服。");
}else if(UnknownAccountException.class.getName().equals(exceptionClassName)) {
	restError.setMessage("用戶名不存在");
      } else if(IncorrectCredentialsException.class.getName().equals(exceptionClassName)) {
	restError.setMessage("用戶名或密碼錯誤");
      } else if(exceptionClassName != null) {
	restError.setMessage( "登錄失敗:" + exceptionClassName);
      }
restError.setStatus(401);
return new ResponseEntity(restError, HttpStatus.UNAUTHORIZED);
  }
 
開發者ID:xmomen,項目名稱:dms-webapp,代碼行數:26,代碼來源:CommonMemberController.java


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