Example usage for org.apache.shiro.authc.pam UnsupportedTokenException UnsupportedTokenException

List of usage examples for org.apache.shiro.authc.pam UnsupportedTokenException UnsupportedTokenException

Introduction

In this page you can find the example usage for org.apache.shiro.authc.pam UnsupportedTokenException UnsupportedTokenException.

Prototype

public UnsupportedTokenException() 

Source Link

Document

Creates a new UnsupportedTokenException.

Usage

From source file:com.app.AuthenticationRealm.java

License:Open Source License

/**
 * ???/*from  www .j a  v a  2  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.cc.framework.security.AuthenticationRealm.java

License:Open Source License

/**
 * ???// w  w w  .j  av a  2s . 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) {
        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.hyeb.back.authenticate.AuthenticationRealm.java

License:Open Source License

/**
 * ???// w  w w.  j  a v a 2s  .c om
 * 
 * @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

/**
 * ???//from w w  w  . j a  v a  2  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.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:net.osxx.AuthenticationRealm.java

License:Open Source License

/**
 * ???/*from  w ww. j a v  a2s .  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);
        Member member = memberService.findByUsername(username);
        if (admin == null && member == null) {
            throw new UnknownAccountException();
        }
        if (admin != null) {
            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());
        } else {
            if (!member.getIsEnabled()) {
                throw new DisabledAccountException();
            }
            Setting setting = SettingUtils.get();
            if (member.getIsLocked()) {
                if (ArrayUtils.contains(setting.getAccountLockTypes(), AccountLockType.member)) {
                    int loginFailureLockTime = setting.getAccountLockTime();
                    if (loginFailureLockTime == 0) {
                        throw new LockedAccountException();
                    }
                    Date lockedDate = member.getLockedDate();
                    Date unlockDate = DateUtils.addMinutes(lockedDate, loginFailureLockTime);
                    if (new Date().after(unlockDate)) {
                        member.setLoginFailureCount(0);
                        member.setIsLocked(false);
                        member.setLockedDate(null);
                        memberService.update(member);
                    } else {
                        throw new LockedAccountException();
                    }
                } else {
                    member.setLoginFailureCount(0);
                    member.setIsLocked(false);
                    member.setLockedDate(null);
                    memberService.update(member);
                }
            }
            if (!DigestUtils.md5Hex(password).equals(member.getPassword())) {
                int loginFailureCount = member.getLoginFailureCount() + 1;
                if (loginFailureCount >= setting.getAccountLockCount()) {
                    member.setIsLocked(true);
                    member.setLockedDate(new Date());
                }
                member.setLoginFailureCount(loginFailureCount);
                memberService.update(member);
                throw new IncorrectCredentialsException();
            }
            member.setLoginIp(ip);
            member.setLoginDate(new Date());
            member.setLoginFailureCount(0);
            memberService.update(member);

            return new SimpleAuthenticationInfo(new Principal(member.getId(), username), password, getName());
        }

    }
    throw new UnknownAccountException();
}

From source file:net.shopxx.shiro.realm.AuthenticationRealm.java

License:Open Source License

/**
 * ???//from   w w w  .j av a  2s  . 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 (!isDevModel && !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:net.shopxx.shiro.realm.BizAuthenticationRealm.java

License:Apache License

/**
 * ???/*from w ww . ja  v a  2  s  .c  o  m*/
 * 
 * @param token 
 * @return ??
 */
@Override
protected AuthenticationInfo doGetAuthenticationInfo(org.apache.shiro.authc.AuthenticationToken token) {
    BizAuthenticationToken authenticationToken = (BizAuthenticationToken) token;
    String username = authenticationToken.getUsername();
    String password = new String(authenticationToken.getPassword());
    String captchaId = authenticationToken.getCaptchaId();
    String captcha = authenticationToken.getCaptcha();
    String ip = authenticationToken.getHost();
    if (!isDevModel && !captchaService.isValid(CaptchaType.adminLogin, captchaId, captcha)) {
        throw new UnsupportedTokenException();
    }
    if (username != null && password != null) {
        Account admin = accountService.findByUsername(username);
        if (admin == null) {
            throw new UnknownAccountException();
        }
        SecurityUtils.getSubject().getSession().setAttribute("userType", "biz");
        return new SimpleAuthenticationInfo(new Principal(admin.getId(), username), password, getName());
    }
    throw new UnknownAccountException();
}

From source file:pe.gob.sunat.tecnologia3.arquitectura.framework.desktop.seguridad.realm.UsuarioSqliteRealm.java

@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {

    logger.log(Level.INFO, "entrando al metodo doGetAuthenticationInfo.");
    if (!PlatformAuthToken.class.isInstance(token)) {
        logger.log(Level.SEVERE, "token no soportado " + token.getClass().getName(), token);
        throw new UnsupportedTokenException();
    }/*w  w w  .  j  ava  2 s.c o m*/

    String nombreUsuario = ((PlatformAuthToken) token).getPrincipal();
    UsuarioPrincipal usuarioRealm = getUsuarioFromDB(nombreUsuario);

    return new SimpleAuthenticationInfo(usuarioRealm, usuarioRealm.getPassword(), getName());

}