Ejemplo n.º 1
0
  protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token)
      throws AuthenticationException {
    UsernamePasswordToken upToken = (UsernamePasswordToken) token;
    SimpleAccount account = (SimpleAccount) getAuthorizationCache().get(upToken.getUsername());

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

    return account;
  }
  @Override
  protected AuthenticationInfo queryForAuthenticationInfo(
      AuthenticationToken token, LdapContextFactory ldapContextFactory) throws NamingException {
    UsernamePasswordToken upToken = (UsernamePasswordToken) token;
    String username = upToken.getUsername();
    String pass = String.valueOf(upToken.getPassword());

    try {
      this.ldapManager.authenticateUser(username, pass);
      return this.buildAuthenticationInfo(username, null);
    } catch (org.sonatype.security.authentication.AuthenticationException e) {
      if (this.logger.isDebugEnabled()) {
        this.logger.debug("User: "******" could not be authenticated ", e);
      }
      throw new org.jsecurity.authc.AuthenticationException(e.getMessage());
    }
  }