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() 

Source Link

Document

Creates a new ExcessiveAttemptsException.

Usage

From source file:cn.mypandora.shiro.credentials.RetryLimitHashedCredentialsMatcher.java

License:Apache License

@Override
public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
    String username = (String) token.getPrincipal();
    //retry count + 1
    AtomicInteger retryCount = passwordRetryCache.get(username);
    if (retryCount == null) {
        retryCount = new AtomicInteger(0);
        passwordRetryCache.put(username, retryCount);
    }//from  ww  w .  j  a  v  a2s .  c om
    if (retryCount.incrementAndGet() > 5) {
        //if retry count > 5 throw
        throw new ExcessiveAttemptsException();
    }

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

From source file:com.appleframework.pay.permission.shiro.credentials.RetryLimitHashedCredentialsMatcher.java

License:Apache License

@Override
/**/*w ww .  j  a  v a  2s.  c o m*/
 * ???
 */
public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
    String username = (String) token.getPrincipal();
    // retry count + 1
    AtomicInteger retryCount = passwordRetryCache.get(username);
    if (retryCount == null) {
        retryCount = new AtomicInteger(0);
        passwordRetryCache.put(username, retryCount);
    }
    if (retryCount.incrementAndGet() > 5) {
        // if retry count > 5 throw
        throw new ExcessiveAttemptsException();
    }

    boolean matches = super.doCredentialsMatch(token, info);
    if (matches) {
        // clear retry count
        passwordRetryCache.remove(username);

        // ????
        PmsOperator operator = pmsOperatorService.findOperatorByLoginName(username);
        Subject subject = SecurityUtils.getSubject();
        Session session = subject.getSession();
        session.setAttribute("PmsOperator", operator);
    }
    return matches;
}

From source file:org.jcms.system.web.credentials.RetryLimitHashedCredentialsMatcher.java

License:Apache License

@Override
public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
    String userName = token.getPrincipal().toString();
    AtomicInteger retryCount = passwordRetryCache.get(userName);
    if (retryCount == null) {
        retryCount = new AtomicInteger(0);
        passwordRetryCache.put(userName, retryCount);
    }//from w w w.  j  av a2 s .co  m
    if (retryCount.decrementAndGet() > 5) {
        throw new ExcessiveAttemptsException();
    }
    boolean matches = super.doCredentialsMatch(token, info);
    if (matches) {
        passwordRetryCache.remove(userName);
    }
    return matches;
}