コード例 #1
0
  @Override
  public boolean login() throws LoginException {
    Callback[] callbacks = new Callback[2];

    callbacks[0] = new NameCallback("Username: "******"Password: "******" not available to obtain information from user");
    }
    user = ((NameCallback) callbacks[0]).getName();
    char[] tmpPassword = ((PasswordCallback) callbacks[1]).getPassword();
    if (tmpPassword == null) {
      tmpPassword = new char[0];
    }
    if (user == null) {
      if (configuration.getDefaultUser() == null) {
        throw new FailedLoginException("Both username and defaultUser are null");
      } else {
        user = configuration.getDefaultUser();
      }
    } else {
      String password =
          configuration.getUser(user) == null ? null : configuration.getUser(user).getPassword();

      if (password == null) {
        throw new FailedLoginException("User does not exist");
      }
      if (!password.equals(new String(tmpPassword))) {
        throw new FailedLoginException("Password does not match");
      }
    }
    loginSucceeded = true;

    logger.debug("login " + user);

    return loginSucceeded;
  }
コード例 #2
0
  @Override
  public boolean commit() throws LoginException {
    boolean result = loginSucceeded;
    if (result) {
      principals.add(new UserPrincipal(user));

      List<String> roles = configuration.getRole(user);

      if (roles != null) {
        for (String role : roles) {
          principals.add(new RolePrincipal(role));
        }
      }

      subject.getPrincipals().addAll(principals);
    }

    // will whack loginSucceeded
    clear();

    logger.debug("commit, result: " + result);

    return result;
  }