本文整理匯總了Java中org.apache.shiro.authc.LockedAccountException類的典型用法代碼示例。如果您正苦於以下問題:Java LockedAccountException類的具體用法?Java LockedAccountException怎麽用?Java LockedAccountException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
LockedAccountException類屬於org.apache.shiro.authc包,在下文中一共展示了LockedAccountException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: login
import org.apache.shiro.authc.LockedAccountException; //導入依賴的package包/類
/**
* 用戶登錄
* @param request
* @param user
* @param model
* @return
*/
@RequestMapping(value = "/login",method = RequestMethod.POST)
public String login(HttpServletRequest request, AdminUser user, Model model) {
if (StringUtils.isEmpty(user.getUsername())||StringUtils.isEmpty(user.getPassword())){
request.setAttribute("msg","用戶名或者密碼不能為空!");
return "login";
}
Subject subject = SecurityUtils.getSubject();
UsernamePasswordToken token=new UsernamePasswordToken(user.getUsername(),user.getPassword());
try {
subject.login(token);
return "redirect:/initPage";
}catch (LockedAccountException lae) {
token.clear();
request.setAttribute("msg", "用戶已經被鎖定不能登錄,請與管理員聯係!");
return "login";
} catch (AuthenticationException e) {
token.clear();
request.setAttribute("msg", "用戶或密碼不正確!");
return "login";
}
}
示例2: dashboard
import org.apache.shiro.authc.LockedAccountException; //導入依賴的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";
}
示例3: doGetAuthenticationInfo
import org.apache.shiro.authc.LockedAccountException; //導入依賴的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;
}
示例4: tryLogin
import org.apache.shiro.authc.LockedAccountException; //導入依賴的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;
}
示例5: login
import org.apache.shiro.authc.LockedAccountException; //導入依賴的package包/類
@PostMapping("/login")
public String login(HttpServletRequest request, User user, Model model){
if (StringUtils.isEmpty(user.getLoginId()) || StringUtils.isEmpty(user.getPassword())) {
request.setAttribute("msg", "用戶名或密碼不能為空!");
return "login";
}
Subject subject = SecurityUtils.getSubject();
UsernamePasswordToken token=new UsernamePasswordToken(user.getLoginId(),user.getPassword());
try {
subject.login(token);
return "manage";
}catch (LockedAccountException lae) {
token.clear();
request.setAttribute("msg", "用戶已經被鎖定不能登錄,請與管理員聯係!");
return "login";
} catch (AuthenticationException e) {
token.clear();
request.setAttribute("msg", "用戶或密碼不正確!");
return "login";
}
}
示例6: signin
import org.apache.shiro.authc.LockedAccountException; //導入依賴的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";
}
示例7: changepwd
import org.apache.shiro.authc.LockedAccountException; //導入依賴的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";
}
}
示例8: login
import org.apache.shiro.authc.LockedAccountException; //導入依賴的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("登錄失敗!");
}
示例9: doGetAuthenticationInfo
import org.apache.shiro.authc.LockedAccountException; //導入依賴的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;
}
示例10: doGetAuthenticationInfo
import org.apache.shiro.authc.LockedAccountException; //導入依賴的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;
}
示例11: createRouteBuilder
import org.apache.shiro.authc.LockedAccountException; //導入依賴的package包/類
protected RouteBuilder createRouteBuilder() throws Exception {
final ShiroSecurityPolicy securityPolicy = new ShiroSecurityPolicy("./src/test/resources/securityconfig.ini", passPhrase, false);
return new RouteBuilder() {
@SuppressWarnings("unchecked")
public void configure() {
onException(UnknownAccountException.class, IncorrectCredentialsException.class,
LockedAccountException.class, AuthenticationException.class).
to("mock:authenticationException");
from("direct:secureEndpoint").
policy(securityPolicy).
to("log:incoming payload").
to("mock:success");
}
};
}
示例12: createRouteBuilder
import org.apache.shiro.authc.LockedAccountException; //導入依賴的package包/類
protected RouteBuilder createRouteBuilder() throws Exception {
final ShiroSecurityPolicy securityPolicy = new ShiroSecurityPolicy("src/test/resources/securityconfig.ini", passPhrase);
securityPolicy.setBase64(true);
return new RouteBuilder() {
@SuppressWarnings("unchecked")
public void configure() {
onException(UnknownAccountException.class, IncorrectCredentialsException.class,
LockedAccountException.class, AuthenticationException.class).
to("mock:authenticationException");
from("direct:secureEndpoint").
policy(securityPolicy).
to("log:incoming payload").
to("mock:success");
}
};
}
示例13: createRouteBuilder
import org.apache.shiro.authc.LockedAccountException; //導入依賴的package包/類
protected RouteBuilder createRouteBuilder() throws Exception {
final ShiroSecurityPolicy securityPolicy = new ShiroSecurityPolicy("src/test/resources/securityconfig.ini", passPhrase);
return new RouteBuilder() {
@SuppressWarnings("unchecked")
public void configure() {
onException(UnknownAccountException.class, IncorrectCredentialsException.class,
LockedAccountException.class, AuthenticationException.class).
to("mock:authenticationException");
from("direct:secureEndpoint").
policy(securityPolicy).
to("log:incoming payload").
to("mock:success");
}
};
}
示例14: setFailureAttribute
import org.apache.shiro.authc.LockedAccountException; //導入依賴的package包/類
protected void setFailureAttribute(ServletRequest request,
AuthenticationException ae) {
String errorMessage = null;
if (ae instanceof IncorrectCredentialsException) {
errorMessage = "密碼錯誤,輸入錯誤超過當日限製,將鎖定賬戶";
// 登錄失敗日誌記錄
logLoginStatus(request, LoginType.登錄失敗);
} else if (ae instanceof ValidateCodeException) {
errorMessage = "驗證碼錯誤";
} else if (ae instanceof UnValidationAccountException) {
errorMessage = "賬號未被驗證";
} else if (ae instanceof LockedAccountException) {
errorMessage = "密碼輸入錯誤超過當日限製,請明天再試";
} else if (ae instanceof DisabledAccountException) {
errorMessage = "賬號被管理員鎖定";
} else if (ae instanceof UnknownAccountException) {
errorMessage = "賬號不存在";
} else {
errorMessage = "未知錯誤";
log.fatal("登錄錯誤-未知錯誤,請管理員檢查", ae);
}
request.setAttribute(getFailureKeyAttribute(), errorMessage);
}
示例15: doGetAuthenticationInfo
import org.apache.shiro.authc.LockedAccountException; //導入依賴的package包/類
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
String username = (String) token.getPrincipal();
User user = userService.findByName(username);
if (user == null) {
throw new UnknownAccountException();// 沒找到帳號
}
if (Boolean.TRUE.equals(user.getLocked())) {
throw new LockedAccountException(); // 帳號鎖定
}
// 交給AuthenticatingRealm使用CredentialsMatcher進行密碼匹配,如果覺得不好可以自定義實現
SimpleAuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo(user, user.getPassword(), // 密碼
ByteSource.Util.bytes(user.getSalt()),// salt
getName() // realm name
);
return authenticationInfo;
}