edu.ucsb.nceas.metacat.authentication

## Class AuthFile

- java.lang.Object
- - edu.ucsb.nceas.metacat.authentication.AuthFile

- All Implemented Interfaces:
    AuthInterface

      public class AuthFile
      extends java.lang.Object
      implements AuthInterface

  This an authentication class base on a username/password file. It is an alternative authentication mechanism of the ldap authentication. The password file looks like: ******* foo@foo.com Smith John NCEAS nceas-dev developers at NCEAS http://commons.apache.org/proper/commons-configuration/userguide/howto_xml.html
  Author:
    tao

- - ### Field Summary

    - ### Fields inherited from interface edu.ucsb.nceas.metacat.AuthInterface

      `GROUPDESINDEX, GROUPNAMEINDEX, USERCNINDEX, USERDNINDEX, USEREMAILINDEX, USERINFOCNINDEX, USERINFOEMAILINDEX, USERINFOORGANIDEX, USERORGINDEX, USERORGUNITINDEX`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `AuthFile()` Constructor
    `AuthFile(java.lang.String passwordFile)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addGroup(java.lang.String groupName, java.lang.String description)` Add a group into the file
    `void` | `addUser(java.lang.String dn, java.lang.String[] groups, java.lang.String plainPass, java.lang.String hashedPass, java.lang.String email, java.lang.String surName, java.lang.String givenName, java.lang.String organization)` Add a user to the file
    `void` | `addUserToGroup(java.lang.String userName, java.lang.String group)` Add a user to a group
    `boolean` | `authenticate(java.lang.String user, java.lang.String password)` Determine if a user/password are valid according to the authentication service.
    `java.util.HashMap<java.lang.String,java.util.Vector<java.lang.String>>` | `getAttributes(java.lang.String foruser)` Get attributes describing a user or group
    `java.util.HashMap<java.lang.String,java.util.Vector<java.lang.String>>` | `getAttributes(java.lang.String user, java.lang.String password, java.lang.String foruser)` Get attributes describing a user or group
    `java.lang.String[][]` | `getGroups(java.lang.String user, java.lang.String password)` Get all groups from the authentication service
    `java.lang.String[][]` | `getGroups(java.lang.String user, java.lang.String password, java.lang.String foruser)` Get the groups for a particular user from the authentication service
    `java.lang.String` | `getPrincipals(java.lang.String user, java.lang.String password)` Get all groups and users from authentication service.
    `java.lang.String[]` | `getUserInfo(java.lang.String user, java.lang.String password)` Get information for a user - name, organization and email address.
    `java.lang.String[][]` | `getUsers(java.lang.String user, java.lang.String password)` Get all users from the authentication service
    `java.lang.String[]` | `getUsers(java.lang.String user, java.lang.String password, java.lang.String group)` Get the users for a particular group from the authentication service
    `static void` | `main(java.lang.String[] argus)` A method is used to help administrator to manage users and groups
    `void` | `modifyPassWithHash(java.lang.String userName, java.lang.String newHashPassword)` Change the password of the user to the new one which is hashed
    `void` | `modifyPassWithPlain(java.lang.String userName, java.lang.String newPlainPassword)` Change the password of the user to the new one which is plain.
    `void` | `removeUserFromGroup(java.lang.String userName, java.lang.String group)` Remove a user from a group.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### AuthFile

          public AuthFile()
                   throws AuthenticationException

      Constructor
      Throws:
        `AuthenticationException`

    - #### AuthFile

          public AuthFile(java.lang.String passwordFile)
                   throws AuthenticationException

      Parameters:
        `passwordFile` -
      Throws:
        `AuthenticationException`

  - ### Method Detail

    - #### authenticate

          public boolean authenticate(java.lang.String user,
                                      java.lang.String password)
                               throws AuthenticationException

      Description copied from interface: `AuthInterface`
      Determine if a user/password are valid according to the authentication service.
      Specified by:
        `authenticate` in interface `AuthInterface`
      Parameters:
        `user` - the name of the principal to authenticate
        `password` - the password to use for authentication
      Throws:
        `AuthenticationException`

    - #### getUsers

          public java.lang.String[][] getUsers(java.lang.String user,
                                               java.lang.String password)
                                        throws java.net.ConnectException

      Description copied from interface: `AuthInterface`
      Get all users from the authentication service
      Specified by:
        `getUsers` in interface `AuthInterface`
      Throws:
        `java.net.ConnectException`

    - #### getUserInfo

          public java.lang.String[] getUserInfo(java.lang.String user,
                                                java.lang.String password)
                                         throws java.net.ConnectException

      Description copied from interface: `AuthInterface`
      Get information for a user - name, organization and email address.
      Specified by:
        `getUserInfo` in interface `AuthInterface`
      Throws:
        `java.net.ConnectException`

    - #### getUsers

          public java.lang.String[] getUsers(java.lang.String user,
                                             java.lang.String password,
                                             java.lang.String group)
                                      throws java.net.ConnectException

      Description copied from interface: `AuthInterface`
      Get the users for a particular group from the authentication service
      Specified by:
        `getUsers` in interface `AuthInterface`
      Throws:
        `java.net.ConnectException`

    - #### getGroups

          public java.lang.String[][] getGroups(java.lang.String user,
                                                java.lang.String password)
                                         throws java.net.ConnectException

      Description copied from interface: `AuthInterface`
      Get all groups from the authentication service
      Specified by:
        `getGroups` in interface `AuthInterface`
      Throws:
        `java.net.ConnectException`

    - #### getGroups

          public java.lang.String[][] getGroups(java.lang.String user,
                                                java.lang.String password,
                                                java.lang.String foruser)
                                         throws java.net.ConnectException

      Description copied from interface: `AuthInterface`
      Get the groups for a particular user from the authentication service
      Specified by:
        `getGroups` in interface `AuthInterface`
      Throws:
        `java.net.ConnectException`

    - #### getAttributes

          public java.util.HashMap<java.lang.String,java.util.Vector<java.lang.String>> getAttributes(java.lang.String foruser)
                                                                                               throws java.net.ConnectException

      Description copied from interface: `AuthInterface`
      Get attributes describing a user or group
      Specified by:
        `getAttributes` in interface `AuthInterface`
      Throws:
        `java.net.ConnectException`

    - #### getAttributes

          public java.util.HashMap<java.lang.String,java.util.Vector<java.lang.String>> getAttributes(java.lang.String user,
                                                                                                      java.lang.String password,
                                                                                                      java.lang.String foruser)
                                                                                               throws java.net.ConnectException

      Description copied from interface: `AuthInterface`
      Get attributes describing a user or group
      Specified by:
        `getAttributes` in interface `AuthInterface`
      Parameters:
        `user` - the user for which the attribute list is requested
        `password` - the password for authenticating against the service
      Throws:
        `java.net.ConnectException`

    - #### getPrincipals

          public java.lang.String getPrincipals(java.lang.String user,
                                                java.lang.String password)
                                         throws java.net.ConnectException

      Description copied from interface: `AuthInterface`
      Get all groups and users from authentication service. The output is formatted in XML.
      Specified by:
        `getPrincipals` in interface `AuthInterface`
      Parameters:
        `user` - the user which requests the information
        `password` - the user's password
      Throws:
        `java.net.ConnectException`

    - #### addUser

          public void addUser(java.lang.String dn,
                              java.lang.String[] groups,
                              java.lang.String plainPass,
                              java.lang.String hashedPass,
                              java.lang.String email,
                              java.lang.String surName,
                              java.lang.String givenName,
                              java.lang.String organization)
                       throws AuthenticationException

      Add a user to the file
      Parameters:
        `userName` - the name of the user
        `groups` - the groups the user belong to. The group should exist in the file
        `password` - the password of the user
      Throws:
        `AuthenticationException`

    - #### addGroup

          public void addGroup(java.lang.String groupName,
                               java.lang.String description)
                        throws AuthenticationException

      Add a group into the file
      Parameters:
        `groupName` - the name of group
      Throws:
        `AuthenticationException`

    - #### modifyPassWithHash

          public void modifyPassWithHash(java.lang.String userName,
                                         java.lang.String newHashPassword)
                                  throws AuthenticationException

      Change the password of the user to the new one which is hashed
      Parameters:
        `usrName` - the specified user.
        `newPassword` - the new password which will be set
      Throws:
        `AuthenticationException`

    - #### modifyPassWithPlain

          public void modifyPassWithPlain(java.lang.String userName,
                                          java.lang.String newPlainPassword)
                                   throws AuthenticationException

      Change the password of the user to the new one which is plain. However, only the hashed version will be serialized.
      Parameters:
        `usrName` - the specified user.
        `newPassword` - the new password which will be set
      Throws:
        `AuthenticationException`

    - #### addUserToGroup

          public void addUserToGroup(java.lang.String userName,
                                     java.lang.String group)
                              throws AuthenticationException

      Add a user to a group
      Parameters:
        `userName` - the name of the user. the user should already exist
        `group` - the name of the group. the group should already exist
      Throws:
        `AuthenticationException`

    - #### removeUserFromGroup

          public void removeUserFromGroup(java.lang.String userName,
                                          java.lang.String group)
                                   throws AuthenticationException

      Remove a user from a group.
      Parameters:
        `userName` - the name of the user. the user should already exist.
        `group` - the name of the group
      Throws:
        `AuthenticationException`

    - #### main

          public static void main(java.lang.String[] argus)
                           throws java.lang.Exception

      A method is used to help administrator to manage users and groups
      Parameters:
        `argus` -
      Throws:
        `java.lang.Exception`

Copyright © 2020 Regents of the University of California. All Rights Reserved.