List of usage examples for org.apache.shiro.authc LockedAccountException LockedAccountException
public LockedAccountException()
From source file:cn.itganhuo.app.service.impl.UserServiceImpl.java
License:Apache License
public User loadByAccount(String account) { User d_user = null;//from www .j a va2 s . com if (StringUtil.hasText(account)) { // 1?????? d_user = userDao.loadByAccount(account); if (d_user == null) { throw new UnknownAccountException(); } if (0 != d_user.getIsLock()) { throw new LockedAccountException(); } } return d_user; }
From source file:cn.mario256.blog.AuthenticationRealm.java
License:Open Source License
/** * ???/*from ww w .ja va 2s. co m*/ * * @param token * * @return ?? */ @Override protected AuthenticationInfo doGetAuthenticationInfo(org.apache.shiro.authc.AuthenticationToken token) { AuthenticationToken authenticationToken = (AuthenticationToken) token; String username = authenticationToken.getUsername(); String password = new String(authenticationToken.getPassword()); String captchaId = authenticationToken.getCaptchaId(); String captcha = authenticationToken.getCaptcha(); String ip = authenticationToken.getHost(); if (!captchaService.isValid(Setting.CaptchaType.adminLogin, captchaId, captcha)) { throw new IncorrectCaptchaException(); } if (username != null && password != null) { Admin admin = adminService.findByUsername(username); if (admin == null) { throw new UnknownAccountException(); } if (!admin.getIsEnabled()) { throw new DisabledAccountException(); } Setting setting = SystemUtils.getSetting(); if (admin.getIsLocked()) { if (ArrayUtils.contains(setting.getAccountLockTypes(), Setting.AccountLockType.admin)) { int loginFailureLockTime = setting.getAccountLockTime(); if (loginFailureLockTime == 0) { throw new LockedAccountException(); } Date lockedDate = admin.getLockedDate(); Date unlockDate = DateUtils.addMinutes(lockedDate, loginFailureLockTime); if (new Date().after(unlockDate)) { admin.setLoginFailureCount(0); admin.setIsLocked(false); admin.setLockedDate(null); adminService.update(admin); } else { throw new LockedAccountException(); } } else { admin.setLoginFailureCount(0); admin.setIsLocked(false); admin.setLockedDate(null); adminService.update(admin); } } if (!DigestUtils.md5Hex(password).equals(admin.getPassword())) { int loginFailureCount = admin.getLoginFailureCount() + 1; if (loginFailureCount >= setting.getAccountLockCount()) { admin.setIsLocked(true); admin.setLockedDate(new Date()); } admin.setLoginFailureCount(loginFailureCount); adminService.update(admin); throw new IncorrectCredentialsException(); } admin.setLoginIp(ip); admin.setLoginDate(new Date()); admin.setLoginFailureCount(0); adminService.update(admin); return new SimpleAuthenticationInfo(new Principal(admin.getId(), username), password, getName()); } throw new UnknownAccountException(); }
From source file:cn.mypandora.shiro.realm.UserRealm.java
License:Apache License
/** * ??subject//from w w w.ja v a 2 s.c o m * * @param token * @return * @throws AuthenticationException */ @Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { UsernamePasswordToken upToken = (UsernamePasswordToken) token; String username = upToken.getUsername().trim(); BaseUser user = baseUserService.findUserByUsername(username); if (user == null) { throw new UnknownAccountException();//?? } if (Boolean.TRUE.equals(user.getLocked())) { throw new LockedAccountException(); //??? } //AuthenticatingRealmCredentialsMatcher???? SimpleAuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo(user.getUsername(), //?? user.getPassword(), //? ByteSource.Util.bytes(user.getCredentialsSalt()), //salt=username+salt getName() //realm name ); return authenticationInfo; }
From source file:com.app.AuthenticationRealm.java
License:Open Source License
/** * ???/*ww w . ja va2 s .c o m*/ * * @param token * * @return ?? */ @Override protected AuthenticationInfo doGetAuthenticationInfo(org.apache.shiro.authc.AuthenticationToken token) { AuthenticationToken authenticationToken = (AuthenticationToken) token; String username = authenticationToken.getUsername(); String password = new String(authenticationToken.getPassword()); String captchaId = authenticationToken.getCaptchaId(); String captcha = authenticationToken.getCaptcha(); String ip = authenticationToken.getHost(); if (!captchaService.isValid(CaptchaType.adminLogin, captchaId, captcha)) { throw new UnsupportedTokenException(); } if (username != null && password != null) { Admin admin = adminService.findByUsername(username); if (admin == null) { throw new UnknownAccountException(); } if (!admin.getIsEnabled()) { throw new DisabledAccountException(); } Setting setting = SettingUtils.get(); if (admin.getIsLocked()) { if (ArrayUtils.contains(setting.getAccountLockTypes(), AccountLockType.admin)) { int loginFailureLockTime = setting.getAccountLockTime(); if (loginFailureLockTime == 0) { throw new LockedAccountException(); } Date lockedDate = admin.getLockedDate(); Date unlockDate = DateUtils.addMinutes(lockedDate, loginFailureLockTime); if (new Date().after(unlockDate)) { admin.setLoginFailureCount(0); admin.setIsLocked(false); admin.setLockedDate(null); adminService.update(admin); } else { throw new LockedAccountException(); } } else { admin.setLoginFailureCount(0); admin.setIsLocked(false); admin.setLockedDate(null); adminService.update(admin); } } if (!DigestUtils.md5Hex(password).equals(admin.getPassword())) { int loginFailureCount = admin.getLoginFailureCount() + 1; if (loginFailureCount >= setting.getAccountLockCount()) { admin.setIsLocked(true); admin.setLockedDate(new Date()); } admin.setLoginFailureCount(loginFailureCount); adminService.update(admin); throw new IncorrectCredentialsException(); } admin.setLoginIp(ip); admin.setLoginDate(new Date()); admin.setLoginFailureCount(0); adminService.update(admin); return new SimpleAuthenticationInfo(new Principal(admin.getId(), username), password, getName()); } throw new UnknownAccountException(); }
From source file:com.appleframework.pay.permission.shiro.realm.OperatorRealm.java
License:Apache License
@Override // ?/*from ww w . j a va 2 s.com*/ protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { String loginName = (String) token.getPrincipal(); if (StringUtils.isEmpty(loginName.trim())) { throw new UnknownAccountException();// ?? } // ???? PmsOperator operator = pmsOperatorService.findOperatorByLoginName(loginName); if (operator == null) { throw new UnknownAccountException();// ?? } if (PublicStatusEnum.UNACTIVE.equals(operator.getStatus())) { throw new LockedAccountException(); // ??? } // AuthenticatingRealmCredentialsMatcher???? SimpleAuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo(operator.getLoginName(), // ?? operator.getLoginPwd(), // ? ByteSource.Util.bytes(operator.getCredentialsSalt()), // salt=username+salt getName() // realm name ); return authenticationInfo; }
From source file:com.cc.framework.security.AuthenticationRealm.java
License:Open Source License
/** * ???//from www.j a va2 s . com * * @param token * * @return ?? */ @Override protected AuthenticationInfo doGetAuthenticationInfo(org.apache.shiro.authc.AuthenticationToken token) { AuthenticationToken authenticationToken = (AuthenticationToken) token; String username = authenticationToken.getUsername(); String password = new String(authenticationToken.getPassword()); String captchaId = authenticationToken.getCaptchaId(); String captcha = authenticationToken.getCaptcha(); String ip = authenticationToken.getHost(); if (!captchaService.isValid(CaptchaType.adminLogin, captchaId, captcha)) { throw new UnsupportedTokenException(); } if (username != null && password != null) { SysAdmin admin = sysAdminService.findByUsername(username); if (admin == null) { throw new UnknownAccountException(); } if (!admin.getIsEnabled()) { throw new DisabledAccountException(); } com.cc.framework.util.Setting setting = SettingUtils.get(); if (admin.getIsLocked()) { if (ArrayUtils.contains(setting.getAccountLockTypes(), AccountLockType.admin)) { int loginFailureLockTime = setting.getAccountLockTime(); if (loginFailureLockTime == 0) { throw new LockedAccountException(); } Date lockedDate = admin.getLockedDate(); Date unlockDate = DateUtils.addMinutes(lockedDate, loginFailureLockTime); if (new Date().after(unlockDate)) { admin.setLoginFailureCount(0); admin.setIsLocked(false); admin.setLockedDate(null); sysAdminService.updateAll(admin); } else { throw new LockedAccountException(); } } else { admin.setLoginFailureCount(0); admin.setIsLocked(false); admin.setLockedDate(null); sysAdminService.updateAll(admin); } } if (!DigestUtils.md5Hex(password).equals(admin.getPassword())) { int loginFailureCount = admin.getLoginFailureCount() + 1; if (loginFailureCount >= setting.getAccountLockCount()) { admin.setIsLocked(true); admin.setLockedDate(new Date()); } admin.setLoginFailureCount(loginFailureCount); sysAdminService.updateAll(admin); throw new IncorrectCredentialsException(); } admin.setLoginIp(ip); admin.setLoginDate(new Date()); admin.setLoginFailureCount(0); sysAdminService.updateAll(admin); return new SimpleAuthenticationInfo(new Principal(admin.getId(), username), password, getName()); } throw new UnknownAccountException(); }
From source file:com.cuisongliu.springboot.shiro.support.realm.ShiroServerRealm.java
License:Open Source License
@Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException { String username = (String) authenticationToken.getPrincipal(); UserInfo user = userCache.selectUserInfoByUsername(springShiroProperties.getAppKey(), username); if (user == null) { //??/* w w w . java 2 s .c o m*/ throw new UnknownAccountException(); } if (Boolean.TRUE.equals(user.getLocked())) { //??? throw new LockedAccountException(); } return passwordHelper.authInfo(user, this); }
From source file:com.hyeb.back.authenticate.AuthenticationRealm.java
License:Open Source License
/** * ???//from w w w . j a v a 2s. c o m * * @param token * * @return ?? */ @Override protected AuthenticationInfo doGetAuthenticationInfo(org.apache.shiro.authc.AuthenticationToken token) { SysUserService sysUserService = (SysUserService) SpringUtils.getBean("sysUserServiceImpl"); AuthenticationToken authenticationToken = (AuthenticationToken) token; String username = authenticationToken.getUsername(); String password = new String(authenticationToken.getPassword()); String captchaId = authenticationToken.getCaptchaId(); String captcha = authenticationToken.getCaptcha(); String ip = authenticationToken.getHost(); if (!captchaService.isValid(CaptchaType.adminLogin, captchaId, captcha)) { throw new UnsupportedTokenException(); } if (username != null && password != null) { SysUser sysUser = sysUserService.findByUsername(username); if (sysUser == null) { throw new UnknownAccountException(); } if (!sysUser.getIsEnabled()) { throw new DisabledAccountException(); } Setting setting = SettingUtils.get(); if (sysUser.getIsLocked()) { if (ArrayUtils.contains(setting.getAccountLockTypes(), AccountLockType.admin)) { int loginFailureLockTime = setting.getAccountLockTime(); if (loginFailureLockTime == 0) { throw new LockedAccountException(); } Date lockedDate = sysUser.getLockedDate(); Date unlockDate = DateUtils.addMinutes(lockedDate, loginFailureLockTime); if (new Date().after(unlockDate)) { sysUser.setLoginFailureCount(0); sysUser.setIsLocked(false); sysUser.setLockedDate(null); sysUserService.update(sysUser); } else { throw new LockedAccountException(); } } else { sysUser.setLoginFailureCount(0); sysUser.setIsLocked(false); sysUser.setLockedDate(null); sysUserService.update(sysUser); } } if (!DigestUtils.md5Hex(password).equals(sysUser.getPassword())) { int loginFailureCount = sysUser.getLoginFailureCount() + 1; if (loginFailureCount >= setting.getAccountLockCount()) { sysUser.setIsLocked(true); sysUser.setLockedDate(new Date()); } sysUser.setLoginFailureCount(loginFailureCount); sysUserService.update(sysUser); throw new IncorrectCredentialsException(); } sysUser.setLoginIp(ip); sysUser.setLoginDate(new Date()); sysUser.setLoginFailureCount(0); sysUserService.update(sysUser); SimpleAuthenticationInfo simpleAuthenticationInfo = new SimpleAuthenticationInfo( new Principal(sysUser.getId(), username), password, getName()); return simpleAuthenticationInfo; } throw new UnknownAccountException(); }
From source file:com.sammyun.AuthenticationRealm.java
License:Open Source License
/** * ???/*ww w .j ava 2s. c om*/ * * @param token * @return ?? */ @Override protected AuthenticationInfo doGetAuthenticationInfo(org.apache.shiro.authc.AuthenticationToken token) { AuthenticationToken authenticationToken = (AuthenticationToken) token; String username = authenticationToken.getUsername(); String password = new String(authenticationToken.getPassword()); String captchaId = authenticationToken.getCaptchaId(); String captcha = authenticationToken.getCaptcha(); String ip = authenticationToken.getHost(); if (!captchaService.isValid(CaptchaType.consoleLogin, captchaId, captcha)) { throw new UnsupportedTokenException(); } if (username != null && password != null) { Admin admin = adminService.findByUsername(username); if (admin == null) { throw new UnknownAccountException(); } if (!admin.getIsEnabled()) { throw new DisabledAccountException(); } Setting setting = SettingUtils.get(); if (admin.getIsLocked()) { if (ArrayUtils.contains(setting.getAccountLockTypes(), AccountLockType.admin)) { int loginFailureLockTime = setting.getAccountLockTime(); if (loginFailureLockTime == 0) { throw new LockedAccountException(); } Date lockedDate = admin.getLockedDate(); Date unlockDate = DateUtils.addMinutes(lockedDate, loginFailureLockTime); if (new Date().after(unlockDate)) { admin.setLoginFailureCount(0); admin.setIsLocked(false); admin.setLockedDate(null); adminService.update(admin); } else { throw new LockedAccountException(); } } else { admin.setLoginFailureCount(0); admin.setIsLocked(false); admin.setLockedDate(null); adminService.update(admin); } } if (!DigestUtils.md5Hex(password).equals(admin.getPassword())) { int loginFailureCount = admin.getLoginFailureCount() + 1; if (loginFailureCount >= setting.getAccountLockCount()) { admin.setIsLocked(true); admin.setLockedDate(new Date()); } admin.setLoginFailureCount(loginFailureCount); adminService.update(admin); throw new IncorrectCredentialsException(); } admin.setLoginIp(ip); admin.setLoginDate(new Date()); admin.setLoginFailureCount(0); adminService.update(admin); return new SimpleAuthenticationInfo(new Principal(admin.getId(), username), password, getName()); } throw new UnknownAccountException(); }
From source file:com.seelecloud.cms.shiro.realm.ManagerRealm.java
License:Apache License
/** * ?//from w w w. j a v a2 s . c o m */ @Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException { System.out.println("doAuthc"); String managerName = (String) token.getPrincipal(); if (managerName != null) { System.out.println("\nmanager name:" + managerName); } Manager manager = managerService.findByName(managerName); if (manager == null) { throw new UnknownAccountException();// ?? } else { System.out.println("\nmanager id:" + manager.getId() + manager.getStatus()); } if (Boolean.FALSE.equals(manager.getStatus())) { throw new LockedAccountException(); // 0??, ??? } // AuthenticatingRealmCredentialsMatcher???? SimpleAuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo(manager.getManagerName(), // ?? manager.getPassword(), // ? // ByteSource.Util.bytes(manager.getCredentialsSalt()),//salt=username+salt getName() // realm name ); return authenticationInfo; }