コード例 #1
0
  /**
   * Get the username and password. This method does not return any value. Instead, it sets global
   * name and password variables.
   *
   * <p>Also note that this method will set the username and password values in the shared state in
   * case subsequent LoginModules want to use them via use/tryFirstPass.
   *
   * @param getPasswdFromSharedState boolean that tells this method whether to retrieve the password
   *     from the sharedState.
   * @exception LoginException if the username/password cannot be acquired.
   */
  private void getUsernamePassword(boolean getPasswdFromSharedState) throws LoginException {

    if (getPasswdFromSharedState) {
      // use the password saved by the first module in the stack
      username = (String) sharedState.get(USERNAME_KEY);
      password = (char[]) sharedState.get(PASSWORD_KEY);
      return;
    }

    // prompt for a username and password
    if (callbackHandler == null)
      throw new LoginException(
          "No CallbackHandler available " + "to acquire authentication information from the user");

    Callback[] callbacks = new Callback[2];
    callbacks[0] = new NameCallback(rb.getString("username: "******"password: "******"Error: "
              + uce.getCallback().toString()
              + " not available to acquire authentication information"
              + " from the user");
    }
  }
コード例 #2
0
  /**
   * Authenticate the user (first phase).
   *
   * <p>The implementation of this method attempts to retrieve the user's Unix {@code Subject}
   * information by making a native Unix system call.
   *
   * @exception FailedLoginException if attempts to retrieve the underlying system information fail.
   * @return true in all cases (this {@code LoginModule} should not be ignored).
   */
  public boolean login() throws LoginException {

    long[] unixGroups = null;

    try {
      ss = new UnixSystem();
    } catch (UnsatisfiedLinkError ule) {
      succeeded = false;
      throw new FailedLoginException(
          "Failed in attempt to import "
              + "the underlying system identity information"
              + " on "
              + System.getProperty("os.name"));
    }
    userPrincipal = new UnixPrincipal(ss.getUsername());
    UIDPrincipal = new UnixNumericUserPrincipal(ss.getUid());
    GIDPrincipal = new UnixNumericGroupPrincipal(ss.getGid(), true);
    if (ss.getGroups() != null && ss.getGroups().length > 0) {
      unixGroups = ss.getGroups();
      for (int i = 0; i < unixGroups.length; i++) {
        UnixNumericGroupPrincipal ngp = new UnixNumericGroupPrincipal(unixGroups[i], false);
        if (!ngp.getName().equals(GIDPrincipal.getName())) supplementaryGroups.add(ngp);
      }
    }
    if (debug) {
      System.out.println("\t\t[UnixLoginModule]: " + "succeeded importing info: ");
      System.out.println("\t\t\tuid = " + ss.getUid());
      System.out.println("\t\t\tgid = " + ss.getGid());
      unixGroups = ss.getGroups();
      for (int i = 0; i < unixGroups.length; i++) {
        System.out.println("\t\t\tsupp gid = " + unixGroups[i]);
      }
    }
    succeeded = true;
    return true;
  }