本文整理了Java中org.apache.shiro.authc.UnknownAccountException
类的一些代码示例,展示了UnknownAccountException
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。UnknownAccountException
类的具体详情如下:
包路径:org.apache.shiro.authc.UnknownAccountException
类名称:UnknownAccountException
[英]Thrown when attempting to authenticate with a principal that doesn't exist in the system (e.g. by specifying a username that doesn't relate to a user account).
Whether or not an application wishes to alert a user logging in to the system of this fact is at the discretion of those responsible for designing the view and what happens when this exception occurs.
[中]尝试使用系统中不存在的主体进行身份验证时抛出(例如,通过指定与用户帐户无关的用户名)。
应用程序是否希望提醒登录到系统的用户这一事实,由负责设计视图的人员自行决定,以及发生此异常时会发生什么情况。
代码示例来源:origin: apache/shiro
"all configured realm(s) to acquire valid account data for a submitted token during the " +
"log-in process.";
throw new UnknownAccountException(msg);
代码示例来源:origin: org.apache.camel/camel-shiro
private void authenticateUser(Subject currentUser, ShiroSecurityToken securityToken) {
boolean authenticated = currentUser.isAuthenticated();
boolean sameUser = securityToken.getUsername().equals(currentUser.getPrincipal());
LOG.trace("Authenticated: {}, same Username: {}", authenticated, sameUser);
if (!authenticated || !sameUser) {
UsernamePasswordToken token = new UsernamePasswordToken(securityToken.getUsername(), securityToken.getPassword());
if (policy.isAlwaysReauthenticate()) {
token.setRememberMe(false);
} else {
token.setRememberMe(true);
}
try {
currentUser.login(token);
LOG.debug("Current user {} successfully authenticated", currentUser.getPrincipal());
} catch (UnknownAccountException uae) {
throw new UnknownAccountException("Authentication Failed. There is no user with username of " + token.getPrincipal(), uae.getCause());
} catch (IncorrectCredentialsException ice) {
throw new IncorrectCredentialsException("Authentication Failed. Password for account " + token.getPrincipal() + " was incorrect!", ice.getCause());
} catch (LockedAccountException lae) {
throw new LockedAccountException("Authentication Failed. The account for username " + token.getPrincipal() + " is locked."
+ "Please contact your administrator to unlock it.", lae.getCause());
} catch (AuthenticationException ae) {
throw new AuthenticationException("Authentication Failed.", ae.getCause());
}
}
}
代码示例来源:origin: ueboot/ueboot
@ExceptionHandler(UnknownAccountException.class)
@ResponseStatus(HttpStatus.UNAUTHORIZED)
@ResponseBody
public Response<Void> handleException(UnknownAccountException e) {
shiroEventListener.afterLogin(currentUserName.get(),false,e.getMessage());
ShiroExceptionHandler.remove();
log.error("进行登录验证..验证未通过,未知账户 {}",e.getMessage());
return new Response<>(HttpStatus.UNAUTHORIZED.value() + "", "验证未通过,未知账户", null);
}
@ExceptionHandler(IncorrectCredentialsException.class)
代码示例来源:origin: ueboot/ueboot
log.info("验证用户和密码结束...");
}catch(UnknownAccountException e){
log.error(e.getMessage(),e);
throw new AuthenticationException("用户不存在");
}catch(IncorrectCredentialsException e){
代码示例来源:origin: linlinjava/litemall
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
UsernamePasswordToken upToken = (UsernamePasswordToken) token;
String username = upToken.getUsername();
String password=new String(upToken.getPassword());
if (StringUtils.isEmpty(username)) {
throw new AccountException("用户名不能为空");
}
if (StringUtils.isEmpty(password)) {
throw new AccountException("密码不能为空");
}
List<LitemallAdmin> adminList = adminService.findAdmin(username);
Assert.state(adminList.size() < 2, "同一个用户名存在两个账户");
if (adminList.size() == 0) {
throw new UnknownAccountException("找不到用户("+username+")的帐号信息");
}
LitemallAdmin admin = adminList.get(0);
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
if (!encoder.matches(password, admin.getPassword())) {
throw new UnknownAccountException("找不到用户("+username+")的帐号信息");
}
return new SimpleAuthenticationInfo(admin,password,getName());
}
代码示例来源:origin: com.manydesigns/portofino-base
String errMsg = ElementsThreadLocals.getText("login.failed.for.user._", userName);
SessionMessages.addErrorMessage(errMsg);
logger.warn("Login failed for '" + userName + "': " + e.getMessage());
} catch (AuthenticationException e) {
String errMsg = ElementsThreadLocals.getText("login.failed.for.user._", userName);
代码示例来源:origin: apache/shiro
/**
* Performs the authentication attempt by interacting with the single configured realm, which is significantly
* simpler than performing multi-realm logic.
*
* @param realm the realm to consult for AuthenticationInfo.
* @param token the submitted AuthenticationToken representing the subject's (user's) log-in principals and credentials.
* @return the AuthenticationInfo associated with the user account corresponding to the specified {@code token}
*/
protected AuthenticationInfo doSingleRealmAuthentication(Realm realm, AuthenticationToken token) {
if (!realm.supports(token)) {
String msg = "Realm [" + realm + "] does not support authentication token [" +
token + "]. Please ensure that the appropriate Realm implementation is " +
"configured correctly or that the realm accepts AuthenticationTokens of this type.";
throw new UnsupportedTokenException(msg);
}
AuthenticationInfo info = realm.getAuthenticationInfo(token);
if (info == null) {
String msg = "Realm [" + realm + "] was unable to find account data for the " +
"submitted AuthenticationToken [" + token + "].";
throw new UnknownAccountException(msg);
}
return info;
}
代码示例来源:origin: org.jasig.cas/cas-server-support-generic
@Override
protected final HandlerResult authenticateUsernamePasswordInternal(final UsernamePasswordCredential transformedCredential)
throws GeneralSecurityException, PreventedException {
try {
final RememberMeUsernamePasswordCredential credential =
(RememberMeUsernamePasswordCredential) transformedCredential;
final UsernamePasswordToken token = new UsernamePasswordToken(credential.getUsername(),
this.getPasswordEncoder().encode(credential.getPassword()));
token.setRememberMe(credential.isRememberMe());
final Subject currentUser = getCurrentExecutingSubject();
currentUser.login(token);
checkSubjectRolesAndPermissions(currentUser);
return createAuthenticatedSubjectResult(credential, currentUser);
} catch (final UnknownAccountException uae) {
throw new AccountNotFoundException(uae.getMessage());
} catch (final IncorrectCredentialsException ice) {
throw new FailedLoginException(ice.getMessage());
} catch (final LockedAccountException lae) {
throw new AccountLockedException(lae.getMessage());
} catch (final ExcessiveAttemptsException eae) {
throw new AccountLockedException(eae.getMessage());
} catch (final ExpiredCredentialsException eae) {
throw new CredentialExpiredException(eae.getMessage());
} catch (final DisabledAccountException eae) {
throw new AccountDisabledException(eae.getMessage());
} catch (final AuthenticationException ae){
throw new FailedLoginException(ae.getMessage());
}
}
代码示例来源:origin: wuyouzhuguli/FEBS-Shiro
/**
* 用户认证
*
* @param token AuthenticationToken 身份认证 token
* @return AuthenticationInfo 身份认证信息
* @throws AuthenticationException 认证相关异常
*/
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
// 获取用户输入的用户名和密码
String userName = (String) token.getPrincipal();
String password = new String((char[]) token.getCredentials());
// 通过用户名到数据库查询用户信息
User user = this.userService.findByName(userName);
if (user == null)
throw new UnknownAccountException("用户名或密码错误!");
if (!password.equals(user.getPassword()))
throw new IncorrectCredentialsException("用户名或密码错误!");
if (User.STATUS_LOCK.equals(user.getStatus()))
throw new LockedAccountException("账号已被锁定,请联系管理员!");
return new SimpleAuthenticationInfo(user, password, getName());
}
代码示例来源:origin: shuzheng/zheng
/**
* 认证:登录时调用
* @param authenticationToken
* @return
* @throws AuthenticationException
*/
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
String username = (String) authenticationToken.getPrincipal();
String password = new String((char[]) authenticationToken.getCredentials());
// client无密认证
String upmsType = PropertiesFileUtil.getInstance("zheng-upms-client").get("zheng.upms.type");
if ("client".equals(upmsType)) {
return new SimpleAuthenticationInfo(username, password, getName());
}
// 查询用户信息
UpmsUser upmsUser = upmsApiService.selectUpmsUserByUsername(username);
if (null == upmsUser) {
throw new UnknownAccountException();
}
if (!upmsUser.getPassword().equals(MD5Util.md5(password + upmsUser.getSalt()))) {
throw new IncorrectCredentialsException();
}
if (upmsUser.getLocked() == 1) {
throw new LockedAccountException();
}
return new SimpleAuthenticationInfo(username, password, getName());
}
代码示例来源:origin: apache/shiro
throw new UnknownAccountException("No account found for user [" + username + "]");
代码示例来源:origin: org.apache.shiro/shiro-core
"all configured realm(s) to acquire valid account data for a submitted token during the " +
"log-in process.";
throw new UnknownAccountException(msg);
代码示例来源:origin: tomoya92/pybbs
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
String username = (String) token.getPrincipal();
log.info("用户:{} 正在登录...", username);
AdminUser adminUser = adminUserService.selectByUsername(username);
// 如果用户不存在,则抛出未知用户的异常
if (adminUser == null) throw new UnknownAccountException();
return new SimpleAuthenticationInfo(username, adminUser.getPassword(), getName());
}
代码示例来源:origin: org.apache.shiro/shiro-core
/**
* Performs the authentication attempt by interacting with the single configured realm, which is significantly
* simpler than performing multi-realm logic.
*
* @param realm the realm to consult for AuthenticationInfo.
* @param token the submitted AuthenticationToken representing the subject's (user's) log-in principals and credentials.
* @return the AuthenticationInfo associated with the user account corresponding to the specified {@code token}
*/
protected AuthenticationInfo doSingleRealmAuthentication(Realm realm, AuthenticationToken token) {
if (!realm.supports(token)) {
String msg = "Realm [" + realm + "] does not support authentication token [" +
token + "]. Please ensure that the appropriate Realm implementation is " +
"configured correctly or that the realm accepts AuthenticationTokens of this type.";
throw new UnsupportedTokenException(msg);
}
AuthenticationInfo info = realm.getAuthenticationInfo(token);
if (info == null) {
String msg = "Realm [" + realm + "] was unable to find account data for the " +
"submitted AuthenticationToken [" + token + "].";
throw new UnknownAccountException(msg);
}
return info;
}
代码示例来源:origin: bill1012/AdminEAP
/**
* 用户认证
*
* @param authcToken 含登录名密码的信息
* @return 认证信息
*/
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken) {
if (authcToken == null)
throw new AuthenticationException("parameter token is null");
UsernamePasswordToken token = (UsernamePasswordToken) authcToken;
// 校验用户名密码
String password=String.copyValueOf(token.getPassword());
User user= userService.getUserByLoginName(token.getUsername());
if (user!=null) {
if(!password.equals(user.getPassword())&& isNeedPassword()){
throw new IncorrectCredentialsException();
}
//这样前端页面可取到数据
SecurityUtils.getSubject().getSession().setAttribute("user",user);
SecurityUtils.getSubject().getSession().setAttribute("userId",user.getId());
// 注意此处的返回值没有使用加盐方式,如需要加盐,可以在密码参数上加
return new SimpleAuthenticationInfo(user.getId(), token.getPassword(), token.getUsername());
}
throw new UnknownAccountException();
}
代码示例来源:origin: org.apache.shiro/shiro-core
throw new UnknownAccountException("No account found for user [" + username + "]");
代码示例来源:origin: stackoverflow.com
throw new UnknownAccountException("User doesn't exist in local database");
代码示例来源:origin: com.gitee.qdbp/qdbp-base-ctl
"all configured realm(s) to acquire valid account data for a submitted token during the " +
"log-in process.";
throw new UnknownAccountException(msg);
代码示例来源:origin: com.gitee.zhaohuihua/bdp-general-web
"all configured realm(s) to acquire valid account data for a submitted token during the " +
"log-in process.";
throw new UnknownAccountException(msg);
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.shiro
"all configured realm(s) to acquire valid account data for a submitted token during the " +
"log-in process.";
throw new UnknownAccountException(msg);
内容来源于网络,如有侵权,请联系作者删除!