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

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

Introduction

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

Prototype

public ExcessiveAttemptsException(Throwable cause) 

Source Link

Document

Constructs a new ExcessiveAttemptsException.

Usage

From source file:com.frigga.shiro.RetryLimitCredentialsMatcher.java

License:Open Source License

@Override
public boolean doCredentialsMatch(AuthenticationToken authcToken, AuthenticationInfo info) {
    String username = (String) authcToken.getPrincipal();
    //retry count + 1
    AtomicInteger retryCount = passwordRetryCache.get(username);
    if (retryCount == null) {
        retryCount = new AtomicInteger(0);
        passwordRetryCache.put(username, retryCount);
    }//from w  w w  .  ja va  2 s. c  o  m
    if (retryCount.incrementAndGet() > 5) {
        //if retry count > 5 throw
        logger.warn("username: " + username + " tried to login more than 5 times in period");
        throw new ExcessiveAttemptsException(
                "??: " + username + " ?5????");
    }

    boolean matches = super.doCredentialsMatch(authcToken, info);
    if (matches) {
        //clear retry data
        passwordRetryCache.remove(username);
    }
    return matches;
}

From source file:com.yea.shiro.credential.RetryLimitHashedCredentialsMatcher.java

License:Apache License

@Override
public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
    String username = (String) token.getPrincipal();
    if (shiroCache.containsKey(username) && shiroCache.get(username) != null) {
        AtomicInteger retryCount = shiroCache.get(username);
        if (retryCount.get() > ShiroConstants.LOGIN_RETRY_LIMIT) {
            throw new ExcessiveAttemptsException("??");
        }/*from   w  w w. j  av a2  s .c  om*/
    }

    boolean matches = super.doCredentialsMatch(token, info);
    if (matches) {
        shiroCache.remove(username);
    } else {
        AtomicInteger retryCount = shiroCache.get(username);
        if (retryCount == null) {
            shiroCache.put(username, new AtomicInteger(1));
        } else {
            retryCount.incrementAndGet();
        }
    }

    return matches;
}

From source file:org.lazulite.boot.autoconfigure.osaam.shiro.matcher.RetryLimitHashedCredentialsMatcher.java

License:Apache License

@Override
public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info)
        throws ExcessiveAttemptsException {
    String username = (String) token.getPrincipal();
    AtomicInteger retryCount = passwordRetryCache.get(username);

    if (retryCount == null) {
        retryCount = new AtomicInteger(0);
        passwordRetryCache.put(username, retryCount);
    }/*from w  ww. j a  v a2  s. c  o m*/
    if (retryCount.incrementAndGet() > retryMax) {
        throw new ExcessiveAttemptsException("" + retryMax + "?10??");
    }

    boolean matches = super.doCredentialsMatch(token, info);
    if (matches) {
        passwordRetryCache.remove(username);
    } else {
        throw new IncorrectCredentialsException(
                "?" + retryCount.get() + "" + retryMax + "");
    }
    return true;
}

From source file:top.sj.shiro.RetryLimitCredentialsMatcher.java

License:Open Source License

@Override
public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
    String username = (String) token.getPrincipal();
    AtomicInteger retryCount = passwordRetryCache.get(username);
    if (null == retryCount) {
        retryCount = new AtomicInteger(0);
        passwordRetryCache.put(username, retryCount);
    }/*from w  w w .j a v a  2s .  c  o  m*/
    if (retryCount.incrementAndGet() > 5) {
        LOGGER.warn("username: " + username + " tried to login more than 5 times in period");
        throw new ExcessiveAttemptsException(
                "username: " + username + " tried to login more than 5 times in period");
    }
    boolean matches = super.doCredentialsMatch(token, info);
    if (matches) {
        passwordRetryCache.remove(username);
    }
    return matches;
}

From source file:uk.co.q3c.v7.base.shiro.DefaultLoginAttemptLog.java

License:Apache License

@Override
public void recordFailedAttempt(UsernamePasswordToken upToken) {
    Integer record = unsuccessful.get(upToken.getUsername());
    int count = 0;
    if (record == null) {
        count = 0;//from  www.j  ava  2s  .  c  o  m
    } else {
        count = record;
    }
    count++;
    if (count >= maxAttempts) {
        throw new ExcessiveAttemptsException("Login failed after maximum attempts");
    }
    unsuccessful.put(upToken.getUsername(), new Integer(count));
}

From source file:uk.q3c.krail.core.shiro.DefaultLoginAttemptLog.java

License:Apache License

/**
 * records a failed login attempt and throws a ExcessiveAttemptsException if the number of attempts exceeds
 * {@link #maxAttempts}/*ww w  .ja v  a2 s . co m*/
 *
 * @see uk.q3c.krail.core.shiro.LoginAttemptLog#recordFailedAttempt(org.apache.shiro.authc.UsernamePasswordToken)
 */
@Override
public synchronized void recordFailedAttempt(UsernamePasswordToken upToken) {
    createLog(upToken, LogOutcome.FAIL);

    Integer failedAttempts = unsuccessfulAttempts.get(upToken.getUsername());
    if (failedAttempts == null) {
        failedAttempts = 0;
    }
    unsuccessfulAttempts.put(upToken.getUsername(), Integer.valueOf(failedAttempts + 1));
    int attemptsLeft = attemptsRemaining(upToken.getUsername());
    if (attemptsLeft == 0) {
        throw new ExcessiveAttemptsException("Login failed after maximum attempts");
    }
}