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(String message, Throwable cause) 

Source Link

Document

Constructs a new LockedAccountException.

Usage

From source file:com.digitalplay.network.ireader.shiro.ShiroDbRealm.java

License:Apache License

/**
 * ?,.//from  www  .  j  a v  a 2s  . c  o  m
 */
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken)
        throws AuthenticationException {
    UsernamePasswordToken upToken = (UsernamePasswordToken) authcToken;
    String username = upToken.getUsername().trim();
    String password = "";
    if (upToken.getPassword() != null) {
        password = new String(upToken.getPassword());
    }

    User user = null;
    try {
        user = userService.login(username, password);
    } catch (UserNotExistsException e) {
        throw new UnknownAccountException(e.getMessage(), e);
    } catch (UserPasswordNotMatchException e) {
        throw new AuthenticationException(e.getMessage(), e);
    } catch (UserPasswordRetryLimitExceedException e) {
        throw new ExcessiveAttemptsException(e.getMessage(), e);
    } catch (UserBlockedException e) {
        throw new LockedAccountException(e.getMessage(), e);
    } catch (Exception e) {
        throw new AuthenticationException(new UserException("user.unknown.error", null));
    }

    SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(user.getUsername(), password.toCharArray(),
            getName());
    return info;
}

From source file:com.huntering.security.UserRealm.java

License:Apache License

@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
    UsernamePasswordToken upToken = (UsernamePasswordToken) token;
    String username = upToken.getUsername().trim();
    String password = "";
    if (upToken.getPassword() != null) {
        password = new String(upToken.getPassword());
    }/*from   w w w .  j  a  va2 s .co m*/

    Account account = null;
    try {
        account = accountService.login(username, password);
    } catch (UserNotExistsException e) {
        throw new UnknownAccountException(e.getMessage(), e);
    } catch (UserPasswordNotMatchException e) {
        throw new AuthenticationException(e.getMessage(), e);
    } catch (UserPasswordRetryLimitExceedException e) {
        throw new ExcessiveAttemptsException(e.getMessage(), e);
    } catch (UserBlockedException e) {
        throw new LockedAccountException(e.getMessage(), e);
    } catch (Exception e) {
        log.error("login error", e);
        throw new AuthenticationException(new UserException("user.unknown.error", null));
    }

    String name = username;
    for (Email email : account.getEmails()) {
        if (Boolean.TRUE.equals(email.getMain())) {
            name = email.getEmail();
            break;
        }
    }
    SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(name, password.toCharArray(), getName());
    return info;
}

From source file:com.playersun.jbf.common.shiro.realm.UserRealm.java

License:Apache License

/**
 * ?/*w  w w. j ava2s. c o  m*/
 */
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
    UsernamePasswordToken upToken = (UsernamePasswordToken) token;

    String username = upToken.getUsername().trim();
    String password = "";
    if (upToken.getPassword() != null) {
        password = new String(upToken.getPassword());
    }

    User user = null;
    try {
        user = userService.login(username, password);
    } catch (UserNotExistsException e) {
        throw new UnknownAccountException(e.getMessage(), e);
    } catch (UserPasswordNotMatchException e) {
        throw new AuthenticationException(e.getMessage(), e);
    } catch (UserPasswordRetryLimitExceedException e) {
        throw new ExcessiveAttemptsException(e.getMessage(), e);
    } catch (UserBlockedException e) {
        throw new LockedAccountException(e.getMessage(), e);
    } catch (Exception e) {
        LogUtils.logError("login error", e);
        throw new AuthenticationException(new UserException("user.unknown.error", null));
    }

    SimpleAuthenticationInfo info = new SimpleAuthenticationInfo(user.getUsername(), password.toCharArray(),
            getName());
    return info;
}

From source file:com.teemo.core.security.ShiroSecurityRealm.java

License:GNU General Public License

/**
 * /*  w  w w . jav  a2  s  . c  o  m*/
 * @param authcToken token
 * @return SimpleAuthenticationInfo
 * @throws AuthenticationException
 */
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken)
        throws AuthenticationException {
    UsernamePasswordToken token = (UsernamePasswordToken) authcToken;
    String username = token.getUsername();
    String password = "";
    if (token.getPassword() != null) {
        password = new String(token.getPassword());
    }
    User user;
    try {
        user = userService.login(username, password);
    } catch (UserNotExistsException e) {
        throw new UnknownAccountException(e.getMessage(), e);
    } catch (UserPasswordIncorrectnessException e) {
        throw new IncorrectCredentialsException(e.getMessage(), e);
    } catch (UserBlockedException e) {
        throw new LockedAccountException(e.getMessage(), e);
    }
    setSession(Constants.CURRENT_USER, user);
    return new SimpleAuthenticationInfo(user.getId(), user.getPassword(), this.getName());
}

From source file:org.apache.camel.component.shiro.security.ShiroSecurityProcessor.java

License:Apache License

private void authenticateUser(Subject currentUser, ShiroSecurityToken securityToken) {
    boolean authenticated = currentUser.isAuthenticated();
    boolean sameUser = securityToken.getUsername().equals(currentUser.getPrincipal());
    LOG.trace("Authenticated: {}, same Username: {}", authenticated, sameUser);

    if (!authenticated || !sameUser) {
        UsernamePasswordToken token = new UsernamePasswordToken(securityToken.getUsername(),
                securityToken.getPassword());
        if (policy.isAlwaysReauthenticate()) {
            token.setRememberMe(false);/*from  w w w  .ja  v  a2s  .c  o m*/
        } else {
            token.setRememberMe(true);
        }

        try {
            currentUser.login(token);
            LOG.debug("Current user {} successfully authenticated", currentUser.getPrincipal());
        } catch (UnknownAccountException uae) {
            throw new UnknownAccountException(
                    "Authentication Failed. There is no user with username of " + token.getPrincipal(),
                    uae.getCause());
        } catch (IncorrectCredentialsException ice) {
            throw new IncorrectCredentialsException(
                    "Authentication Failed. Password for account " + token.getPrincipal() + " was incorrect!",
                    ice.getCause());
        } catch (LockedAccountException lae) {
            throw new LockedAccountException("Authentication Failed. The account for username "
                    + token.getPrincipal() + " is locked." + "Please contact your administrator to unlock it.",
                    lae.getCause());
        } catch (AuthenticationException ae) {
            throw new AuthenticationException("Authentication Failed.", ae.getCause());
        }
    }
}