Example usage for org.apache.shiro.authc LockedAccountException LockedAccountException

List of usage examples for org.apache.shiro.authc LockedAccountException LockedAccountException

Introduction

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

Prototype

public LockedAccountException(Throwable cause) 

Source Link

Document

Constructs a new LockedAccountException.

Usage

From source file:cn.guoyukun.spring.shiro.realm.AbstractUserPasswordRealm.java

License:Apache License

/**
 * ??// w w w  .  jav a 2 s.  c  o  m
 */
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
    UsernamePasswordToken upt = (UsernamePasswordToken) token;
    // 
    String identify = upt.getUsername().trim();
    try {
        // ?
        SystemAccount account = getAccountByLoginIdentify(identify);
        // ?
        if (account == null) {
            throw new UnknownAccountException("[" + identify + "]??");
        }
        if (account.isLocked()) {
            throw new LockedAccountException("[" + identify + "]????");
        }
        //         LOG.debug("[{}]???:[{}]",identify,account.getCredentials());
        SimpleAuthenticationInfo sai = new SimpleAuthenticationInfo(account.getIdentify(),
                account.getCredentials(), this.getName());
        if (!getCredentialsMatcher().doCredentialsMatch(token, sai)) {
            throw new IncorrectCredentialsException("?");
        }
        LOG.debug("[{}]?", identify);
        return sai;
    } catch (AuthenticationException ae) {
        throw ae;
    } catch (Exception e) {
        throw new AuthenticationException("?[" + identify + "]?", e);
    }
}

From source file:com.caricah.iotracah.bootstrap.security.realm.IOTAbstractRealm.java

License:Apache License

/**
 * Retrieves authentication data from an implementation-specific datasource (RDBMS, LDAP, etc) for the given
 * authentication token.//from w ww . j a v a2 s . co m
 * <p>
 * For most datasources, this means just 'pulling' authentication data for an associated subject/user and nothing
 * more and letting Shiro do the rest.  But in some systems, this method could actually perform EIS specific
 * log-in logic in addition to just retrieving data - it is up to the Realm implementation.
 * <p>
 * A {@code null} return value means that no account could be associated with the specified token.
 *
 * @param token the authentication token containing the user's principal and credentials.
 * @return an {@link AuthenticationInfo} object containing account data resulting from the
 * authentication ONLY if the lookup is successful (i.e. account exists and is valid, etc.)
 * @throws AuthenticationException if there is an error acquiring data or performing
 *                                 realm-specific authentication logic for the specified <tt>token</tt>
 */
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {

    IdConstruct idConstruct = ((IdPassToken) token).getIdConstruct();
    IOTAccount account = getIOTAccount(idConstruct.getPartition(), idConstruct.getUsername());

    if (account != null) {

        if (account.getIsLocked()) {
            throw new LockedAccountException("Account [" + account + "] is locked.");
        }
        if (account.getIsCredentialExpired()) {
            String msg = "The credentials for account [" + account + "] are expired";
            throw new ExpiredCredentialsException(msg);
        }

    }

    return account;

}

From source file:com.migo.shiro.UserRealm.java

License:Apache License

@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken)
        throws AuthenticationException {
    String username = (String) authenticationToken.getPrincipal();
    String password = new String((char[]) authenticationToken.getCredentials());

    //?//from   w ww .  j av a  2  s. c om
    SysUserEntity user = sysUserService.queryByUserName(username);

    //??
    if (user == null) {
        throw new UnknownAccountException("???");
    }

    //?
    if (!password.equals(user.getPassword())) {
        throw new IncorrectCredentialsException("???");
    }

    //??
    if (user.getStatus() == 0) {
        throw new LockedAccountException("??,??");
    }

    return new SimpleAuthenticationInfo(user, password, getName());
}

From source file:com.miki.webapp.shiro.EntityRealm.java

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

    final UsernamePasswordToken token = (UsernamePasswordToken) authcToken;

    SimpleAuthenticationInfo simpleAuthenticationInfo = new SimpleAuthenticationInfo();

    user = userDAO.getOneBy("login", token.getUsername());

    if (user != null) {

        //Control de l'activation du compte
        if (!user.isActif()) {
            throw new LockedAccountException(
                    "Dsol votre compte est inactif, veuillez contacter l'administrateur Svp");
        }// w ww  .j  a  v  a  2  s.c o  m

        //Connexion
        simpleAuthenticationInfo = new SimpleAuthenticationInfo(user.getLogin(), user.getMotDePasse(),
                getName());
        return simpleAuthenticationInfo;
    } else {
        throw new UnknownAccountException(
                "L'utilisateur ne se trouve pas dans le systme, veuillez ressayer Svp !");
    }
}

From source file:com.quyiyuan.realms.SecondRealm.java

License:Open Source License

@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
    log.info("doGetAuthenticationInfo:" + token);

    log.info("[SecondRealm]");
    //1?AuthenticationToken?UsernamePasswordToekn
    UsernamePasswordToken usernamePasswordToken = (UsernamePasswordToken) token;

    //2?UsernamePasswordToken ?username
    String username = usernamePasswordToken.getUsername();

    //3????username
    log.info("??username:" + username + "?");

    //4??UnknowAccountException 
    if ("unknown".equals(username)) {
        throw new UnknownAccountException("?!");
    }//from   w  w w . ja  v a  2  s . c  om
    //5?????AuthenticationException
    if ("monster".equals(username)) {
        throw new LockedAccountException("?");
    }
    //6???AuthenticationInfo
    //1)?principal???username??
    Object principal = username;
    //2)?credentials: ?
    Object credentials = null;//"fc1709d0a95a6be30bc5926fdb7f22f4";
    if ("admin".equals(username)) {
        credentials = "ce2f6417c7e1d32c1d81a797ee0b499f87c5de06";
    } else if ("user".equals(username)) {
        credentials = "073d4c3ae812935f23cb3f2a71943f49e082a718";
    }
    //3)?realmName ?realmnamegetName??
    String realmName = getName();
    //4)??
    ByteSource credentialsSalt = ByteSource.Util.bytes(username);
    //        SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(principal,credentials,realmName);
    SimpleAuthenticationInfo info = null;
    info = new SimpleAuthenticationInfo(principal, credentials, credentialsSalt, realmName);
    return info;
}

From source file:com.safziy.fm.admin.sercurity.ShiroDbRealm.java

License:Apache License

/**
 * ?, ./*from   w ww. j a  v a2s.com*/
 */
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken)
        throws AuthenticationException {

    UsernamePasswordToken token = (UsernamePasswordToken) authcToken;
    User user;
    try {
        user = userService.findByLoginName(token.getUsername());

        if (user != null) {
            if (!user.getIsAccountEnabled()) {
                throw new LockedAccountException("???,??");
            }
            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;
        }
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;

}

From source file:com.tianxiaxinyong.web.security.shrio.ShiroAuthorizingRealm.java

License:Apache License

/**
 * ?????????//from   ww  w .  j  a  v  a2s  .c o m
 */
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
    UsernamePasswordToken upToken = (UsernamePasswordToken) token;
    String username = upToken.getUsername();
    if (username == null) {
        log.warn("???");
        throw new AccountException("???");
    }
    Member member = null;
    try {
        member = memberService.findMemberByMemberName(username);
    } catch (Exception ex) {
        log.error("?ex={}", ex);
    }
    if (member == null) {
        log.warn("?");
        throw new UnknownAccountException("?!");
    }
    if (2 == member.getUserStatus()) {
        log.warn("?");
        throw new UnknownAccountException("?!");
    }
    if (3 == member.getUserStatus()) {
        log.warn("??");
        throw new LockedAccountException("?!");
    }
    //?
    Date lockedDate = member.getLocktime();
    //?
    Date nowDate = Calendar.getInstance().getTime();
    // 
    int loginFailureLockTime = WebConstance.LOCKTIMES;
    if (3 == member.getUserStatus() && isUnLock(lockedDate, nowDate, loginFailureLockTime)) {
        //?
        member.setUserStatus(1);
        member.setLoginFailtimes(0);
        try {
            memberService.updateMember(member);
        } catch (ServiceException e) {
            log.error("?e={}", e);
        } catch (DataException e) {
            log.error("?e={}", e);
        }
    }

    log.info("?" + username + "?");
    ShiroPrincipal subject = new ShiroPrincipal(member);
    //List<String> authorities = Member.dao.getAuthoritiesName(user.getStr("id"));
    //List<String> rolelist = Member.dao.getRolesName(user.getStr("id"));
    //subject.setAuthorities(authorities);
    //subject.setRoles(rolelist);
    subject.setAuthorized(true);
    return new SimpleAuthenticationInfo(subject, member.getPassword(), getName());
}

From source file:com.yea.shiro.realm.AbstractRealm.java

License:Apache License

protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
    UsernamePasswordToken upToken = (UsernamePasswordToken) token;
    String username = upToken.getUsername();
    if (username == null) {
        throw new AccountException("???????");
    }// w w w . j a v  a 2  s. c  o m

    Map<String, Object> mapUser = getUser(username);
    String password = null;
    String salt = null;
    switch (saltStyle) {
    case NO_SALT:
        password = ((String) mapUser.get(ShiroConstants.ShiroColumn.LOGIN_PASSWORD.value())).trim();
        break;
    case COLUMN:
        password = ((String) mapUser.get(ShiroConstants.ShiroColumn.LOGIN_PASSWORD.value())).trim();
        salt = ((String) mapUser.get(ShiroConstants.ShiroColumn.LOGIN_SALT.value())).trim();
    }
    if (password == null) {
        throw new UnknownAccountException("??[" + username + "]??");
    }
    if (ShiroConstants.LockTag.LOCK.value()
            .equals(mapUser.get(ShiroConstants.ShiroColumn.LOGIN_LOCK_TAG.value()))) {
        throw new LockedAccountException("?[" + username + "]??");
    }
    UserPrincipal user = new UserPrincipal();
    user.setLoginName(username);
    user.setPartyId((Long) mapUser.get(ShiroConstants.ShiroColumn.LOGIN_ID.value()));
    user.setPersonName((String) mapUser.get(ShiroConstants.ShiroColumn.LOGIN_PERSON_NAME.value()));
    user.setIsLock((String) mapUser.get(ShiroConstants.ShiroColumn.LOGIN_LOCK_TAG.value()));

    SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(user, password.toCharArray(), getName());
    if (salt != null) {
        info.setCredentialsSalt(ByteSource.Util.bytes(salt));
    }

    return info;
}

From source file:com.yiguang.payment.rbac.controller.ShiroDbRealm.java

License:Apache License

/**
 * ??//w  ww. ja va 2s.c  o m
 */
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken)
        throws AuthenticationException {
    UsernamePasswordToken token = (UsernamePasswordToken) authcToken;
    String userName = token.getUsername();
    String pwd = null;
    if (!StringUtil.isNullOrEmpty(userName)) {
        User user = userService.queryUserByName(userName);
        if (user != null) {
            if (CommonConstant.CommonStatus.CLOSE == user.getStatus()) {
                throw new LockedAccountException("?????");
            }

            String loginPwd = user.getPassword();

            pwd = String.valueOf(token.getPassword());
            String md5Password = securityKeystoreService.getEncryptKeyByJSRSAKey(pwd, user.getId());
            if (!md5Password.equals(loginPwd)) {
                throw new IncorrectCredentialsException("????");
            }
            token.setPassword(md5Password.toCharArray());
            SimpleAuthenticationInfo simpleAuthenticationInfo = new SimpleAuthenticationInfo(user, loginPwd,
                    getName());
            return simpleAuthenticationInfo;
        } else {
            throw new UnknownAccountException("???!");
        }
    } else {
        throw new AuthenticationException("????");
    }
}

From source file:graphene.security.tomcat.preaa.PreAASecurityRealm.java

License:Apache License

@Override
protected AuthenticationInfo doGetAuthenticationInfo(final AuthenticationToken authToken)
        throws AuthenticationException {

    logger.debug("doGetAuthenticationInfo " + authToken.getPrincipal());
    // return null;
    final UsernamePasswordToken upToken = (UsernamePasswordToken) authToken;
    G_User g_User = null;//  w  w  w  . ja v a 2s. c o m
    SimpleAccount account = null;
    try {
        g_User = userDataAccess.getByUsername(upToken.getUsername());
        final Set<String> roleNames = CollectionUtils.asSet((String[]) null);
        account = new SimpleAccount(g_User.getUsername(), "password", getName(), roleNames, null);
    } catch (final AvroRemoteException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    if (account != null) {

        if (account.isLocked()) {
            throw new LockedAccountException("Account [" + account + "] is locked.");
        }
        if (account.isCredentialsExpired()) {
            final String msg = "The credentials for account [" + account + "] are expired";
            throw new ExpiredCredentialsException(msg);
        }

    } else {
        logger.error("user was null");
    }

    return account;
}