List of usage examples for org.apache.shiro.authc DisabledAccountException DisabledAccountException
public DisabledAccountException()
From source file:cn.com.axiom.system.security.ShiroDbRealm.java
License:Apache License
/** * ?,./*from w ww . j a v a2s . c o m*/ */ @Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken) throws AuthenticationException { UsernamePasswordToken token = (UsernamePasswordToken) authcToken; User user = userService.findUserByUserName(token.getUsername()); if (user != null) { if (user.getStatus() != 1) { throw new DisabledAccountException(); } // sysLogService.log("","",user.getUserName(), SysLog.INFO, // token.getHost(),SysLog.USER); SimpleByteSource salt = (SimpleByteSource) ByteSource.Util.bytes(user.getUserName()); String passwordMd5 = new Md5Hash(user.getPassword().getBytes(), salt).toString(); return new SimpleAuthenticationInfo(new ShiroUser(user.getId(), user.getUserName(), user.getRealName()), passwordMd5, ByteSource.Util.bytes(user.getUserName()), getName()); } else { return null; } }
From source file:cn.com.qiqi.order.web.system.security.ShiroDbRealm.java
License:Apache License
/** * ?,./*from w w w . j a v a 2 s . c om*/ */ @Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken) throws AuthenticationException { UsernamePasswordToken token = (UsernamePasswordToken) authcToken; User user = userService.findUserByUserName(token.getUsername()); if (user != null) { if (user.getStatus() != 1) { Subject subject = SecurityUtils.getSubject(); subject.getSession().setAttribute(Constants.CURRENT_USER_NAME, user.getUserName()); throw new DisabledAccountException(); } String md5 = Encodes.encodeHex( Digests.md5(String.valueOf(token.getPassword()).getBytes(), user.getUserName().getBytes(), 1)); if (!user.getPassword().equals(md5)) { throw new IncorrectCredentialsException(); } sysLogService.log("", "", user.getUserName(), SysLog.INFO, token.getHost(), SysLog.USER); Subject subject = SecurityUtils.getSubject(); subject.getSession().setAttribute(Constants.CURRENT_USER_NAME, user.getUserName()); return new SimpleAuthenticationInfo(new ShiroUser(user.getId(), user.getUserName(), user.getRealName()), user.getPassword(), ByteSource.Util.bytes(user.getUserName()), getName()); } else { throw new UnknownAccountException(); } }
From source file:cn.com.xl.core.shiro.DefaultShiroFactory.java
License:Apache License
public User user(String account) { User user = Blade.create(User.class).findFirstBy("account = #{account}", CMap.init().set("account", account)); // ??// w w w. ja va 2s. c om if (null == user) { throw new UnknownAccountException(); } // ? if (user.getStatus() == 3 || user.getStatus() == 4) { throw new DisabledAccountException(); } // ? if (user.getStatus() == 2 || user.getStatus() == 5) { throw new DisabledAccountException(); } return user; }
From source file:cn.ligoo.part.service.shiro.CustomAuthorizingRealm.java
License:Apache License
/** * ?,.// www .j a va 2 s. co m */ @Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken) throws AuthenticationException { logger.debug("...CustomAuthorizingRealm.doGetAuthenticationInfo()"); CustomToken token = (CustomToken) authcToken; String username = token.getUsername(); if (username == null) { throw new AccountException(); } UserInfo user = userInfoService.findByEmail(username); if (user == null) { throw new UnknownAccountException(); } if (user.getIs_del() == Constants.BYTE_1) { throw new DisabledAccountException(); } return new SimpleAuthenticationInfo(new ShiroUser(user.getId(), user.getEmail()), user.getPassword(), getName()); }
From source file:cn.mario256.blog.AuthenticationRealm.java
License:Open Source License
/** * ???//from www .j av a2 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(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.wm.sum.security.shiro.service.ShiroDbRealm.java
License:Apache License
/** * ?,.//w w w . jav a 2s. c o m */ @Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken) throws AuthenticationException { CaptchaUsernamePasswordToken token = (CaptchaUsernamePasswordToken) authcToken; User user = accountService.findUserByLoginName(token.getUsername()); if (user != null) { if (StringUtils.isNotBlank(user.getStatus())) { if ("disabled".equals(user.getStatus())) { throw new DisabledAccountException(); } } byte[] salt = Encodes.decodeHex(user.getSalt()); return new SimpleAuthenticationInfo(new ShiroUser(user.getId(), user.getLoginName(), user.getName()), user.getPassword(), ByteSource.Util.bytes(salt), getName()); } else { return null; } }
From source file:com.androidwhy.examples.showcase.service.ShiroDbRealm.java
License:Apache License
/** * ?,.// www .j a v a 2 s .c o m */ @Override protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken) throws AuthenticationException { UsernamePasswordToken token = (UsernamePasswordToken) authcToken; User user = accountService.findUserByLoginName(token.getUsername()); if (user != null) { if (user.getStatus().equals("disabled")) { throw new DisabledAccountException(); } byte[] salt = Encodes.decodeHex(user.getSalt()); return new SimpleAuthenticationInfo(new ShiroUser(user.getLoginName(), user.getName()), user.getPassword(), ByteSource.Util.bytes(salt), getName()); } else { return null; } }
From source file:com.app.AuthenticationRealm.java
License:Open Source License
/** * ???/* w w w . j a v a 2 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) { 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.biu.core.shiro.DefaultShiroFactory.java
License:Apache License
public User user(String account) { User record = new User(); record.setAccount(account);// w w w .j ava 2 s. c o m User user = userMapper.selectOne(record); // User user = Blade.create(User.class).findFirstBy("account = #{account}", CMap.init().set("account", account)); // ?? if (null == user) { throw new UnknownAccountException(); } // ? if (user.getStatus() == 3 || user.getStatus() == 4) { throw new DisabledAccountException(); } // ? if (user.getStatus() == 2 || user.getStatus() == 5) { throw new DisabledAccountException(); } return user; }
From source file:com.cc.framework.security.AuthenticationRealm.java
License:Open Source License
/** * ???/* ww w . j a v a 2 s .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.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(); }