org.apache.jmeter.protocol.http.control

## Class AuthManager

- java.lang.Object
- - org.apache.jmeter.testelement.AbstractTestElement
  - - org.apache.jmeter.config.ConfigTestElement
    - - org.apache.jmeter.protocol.http.control.AuthManager

- All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, ConfigElement, Searchable, TestElement, TestIterationListener, TestStateListener

      public class AuthManager
      extends ConfigTestElement
      implements TestStateListener, TestIterationListener, java.io.Serializable

  This class provides a way to provide Authorization in jmeter requests. The format of the authorization file is: URL user pass where URL is an HTTP URL, user a username to use and pass the appropriate password.
  See Also:
    Serialized Form

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `AuthManager.Mechanism`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `COL_DOMAIN`
    `static int` | `COL_MECHANISM`
    `static int` | `COL_PASSWORD`
    `static int` | `COL_REALM`
    `static int` | `COL_URL`
    `static int` | `COL_USERNAME`
    `static boolean` | `STRIP_PORT` Decides whether port should be omitted from SPN for kerberos spnego authentication
    `static boolean` | `USE_CANONICAL_HOST_NAME` Decides whether port should be omitted from SPN for kerberos spnego authentication

    - ### Fields inherited from class org.apache.jmeter.config.ConfigTestElement

      `PASSWORD, USERNAME`

    - ### Fields inherited from interface org.apache.jmeter.testelement.TestElement

      `COMMENTS, ENABLED, GUI_CLASS, NAME, TEST_CLASS`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `AuthManager()` Default Constructor.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `addAuth()`
    `void` | `addAuth(Authorization newAuthorization)` Add newAuthorization if it does not already exist
    `void` | `addConfigElement(ConfigElement config)` Add a configuration element to this one.
    `void` | `addFile(java.lang.String authFile)` Add authentication data from a file.
    `void` | `clear()` Clear the TestElement of all data.
    `boolean` | `expectsModification()` If your config element expects to be modified in the process of a test run, and you want those modifications to carry over from sample to sample (as in a cookie manager - you want to save all cookies that get set throughout the test), then return true for this method.
    `Authorization` | `get(int i)` Return the record at index i
    `int` | `getAuthCount()` Return the number of records.
    `Authorization` | `getAuthForURL(java.net.URL url)`
    `java.lang.String` | `getAuthHeaderForURL(java.net.URL url)`
    `Authorization` | `getAuthObjectAt(int row)`
    `CollectionProperty` | `getAuthObjects()`
    `boolean` | `getClearEachIteration()`
    `java.lang.Class<?>` | `getColumnClass(int column)`
    `int` | `getColumnCount()`
    `java.lang.String` | `getColumnName(int column)`
    `javax.security.auth.Subject` | `getSubjectForUrl(java.net.URL url)` Get a `Subject` for a given URL, if available
    `boolean` | `hasAuthForURL(java.net.URL url)` Tests whether an authorization record is available for a given URL
    `boolean` | `isEditable()`
    `void` | `remove(int index)` Remove an authentication record.
    `void` | `save(java.lang.String authFile)` Save the authentication data to a file.
    `void` | `set(int index, java.lang.String url, java.lang.String user, java.lang.String pass, java.lang.String domain, java.lang.String realm, AuthManager.Mechanism mechanism)` Update an authentication record.
    `void` | `setClearEachIteration(boolean clear)`
    `void` | `setupCredentials(Authorization auth, java.net.URL url, org.apache.http.client.protocol.HttpClientContext localContext, org.apache.http.client.CredentialsProvider credentialsProvider, java.lang.String localhost)` Configure credentials and auth scheme on client if an authorization is
    `void` | `testEnded()` Called once for all threads after the end of a test.
    `void` | `testEnded(java.lang.String host)` Called once for all threads after the end of a test.
    `void` | `testIterationStart(LoopIterationEvent event)` Each time through a Thread Group's test script, an iteration event is fired for each thread.
    `void` | `testStarted()` Called just before the start of the test from the main engine thread.
    `void` | `testStarted(java.lang.String host)` Called just before the start of the test from the main engine thread.

    - ### Methods inherited from class org.apache.jmeter.config.ConfigTestElement

      `addTestElement`

    - ### Methods inherited from class org.apache.jmeter.testelement.AbstractTestElement

      `addPropertiesValues, addProperty, addProperty, canRemove, clearTemporary, clearTestElementChildren, clone, emptyTemporary, equals, getComment, getName, getProperty, getPropertyAsBoolean, getPropertyAsBoolean, getPropertyAsDouble, getPropertyAsFloat, getPropertyAsInt, getPropertyAsInt, getPropertyAsLong, getPropertyAsLong, getPropertyAsString, getPropertyAsString, getSearchableTokens, getThreadContext, getThreadName, hashCode, isEnabled, isRunningVersion, isTemporary, logProperties, mergeIn, propertyIterator, recoverRunningVersion, removeProperty, setComment, setEnabled, setName, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setRunningVersion, setTemporary, setThreadContext, setThreadName, traverse, traverseCollection, traverseMap, traverseProperty`

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

      `finalize, getClass, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface org.apache.jmeter.config.ConfigElement

      `clone`

    - ### Methods inherited from interface org.apache.jmeter.testelement.TestElement

      `removed`

- - ### Field Detail

    - #### COL_URL

          public static final int COL_URL

      See Also:
        Constant Field Values

    - #### COL_USERNAME

          public static final int COL_USERNAME

      See Also:
        Constant Field Values

    - #### COL_PASSWORD

          public static final int COL_PASSWORD

      See Also:
        Constant Field Values

    - #### COL_DOMAIN

          public static final int COL_DOMAIN

      See Also:
        Constant Field Values

    - #### COL_REALM

          public static final int COL_REALM

      See Also:
        Constant Field Values

    - #### COL_MECHANISM

          public static final int COL_MECHANISM

      See Also:
        Constant Field Values

    - #### STRIP_PORT

          public static final boolean STRIP_PORT

      Decides whether port should be omitted from SPN for kerberos spnego authentication

    - #### USE_CANONICAL_HOST_NAME

          public static final boolean USE_CANONICAL_HOST_NAME

      Decides whether port should be omitted from SPN for kerberos spnego authentication

  - ### Constructor Detail

    - #### AuthManager

          public AuthManager()

      Default Constructor.

  - ### Method Detail

    - #### clear

          public void clear()

      Clear the TestElement of all data.
      Specified by:
        `clear` in interface `TestElement`
      Overrides:
        `clear` in class `AbstractTestElement`

    - #### set

          public void set(int index,
                          java.lang.String url,
                          java.lang.String user,
                          java.lang.String pass,
                          java.lang.String domain,
                          java.lang.String realm,
                          AuthManager.Mechanism mechanism)

      Update an authentication record.
      Parameters:
        `index` - index at which position the record should be set
        `url` - url for which the authentication record should be used
        `user` - name of the user
        `pass` - password of the user
        `domain` - domain of the user
        `realm` - realm of the site
        `mechanism` - authentication `AuthManager.Mechanism` to use

    - #### getAuthObjects

          public CollectionProperty getAuthObjects()

    - #### getColumnCount

          public int getColumnCount()

    - #### getColumnName

          public java.lang.String getColumnName(int column)

    - #### getColumnClass

          public java.lang.Class<?> getColumnClass(int column)

    - #### getAuthObjectAt

          public Authorization getAuthObjectAt(int row)

    - #### isEditable

          public boolean isEditable()

    - #### get

          public Authorization get(int i)

      Return the record at index i
      Parameters:
        `i` - index of the record to get
      Returns:
        authorization record at index `i`

    - #### getAuthHeaderForURL

          public java.lang.String getAuthHeaderForURL(java.net.URL url)

    - #### getAuthForURL

          public Authorization getAuthForURL(java.net.URL url)

    - #### hasAuthForURL

          public boolean hasAuthForURL(java.net.URL url)

      Tests whether an authorization record is available for a given URL
      Parameters:
        `url` - `URL` for which an authorization record should be available
      Returns:
        `true` if an authorization is setup for url, `false` otherwise

    - #### getSubjectForUrl

          public javax.security.auth.Subject getSubjectForUrl(java.net.URL url)

      Get a `Subject` for a given URL, if available
      Parameters:
        `url` - `URL` for which the subject was asked
      Returns:
        Subject if Auth Scheme uses Subject and an authorization is setup for `url`, `null` otherwise

    - #### addConfigElement

          public void addConfigElement(ConfigElement config)

      Add a configuration element to this one. This allows config elements to combine and give a "layered" effect. For example, HTTPConfigElements have properties for domain, path, method, and parameters. If element A has everything filled in, but null for domain, and element B is added, which has only domain filled in, then after adding B to A, A will have the domain from B. If A already had a domain, then the correct behavior is for A to ignore the addition of element B.
      Specified by:
        `addConfigElement` in interface `ConfigElement`
      Overrides:
        `addConfigElement` in class `ConfigTestElement`
      Parameters:
        `config` - the element to be added to this ConfigElement

    - #### addAuth

          public void addAuth(Authorization newAuthorization)

      Add newAuthorization if it does not already exist
      Parameters:
        `newAuthorization` - authorization to be added

    - #### addAuth

          public void addAuth()

    - #### expectsModification

          public boolean expectsModification()

      If your config element expects to be modified in the process of a test run, and you want those modifications to carry over from sample to sample (as in a cookie manager - you want to save all cookies that get set throughout the test), then return true for this method. Your config element will not be cloned for each sample. If your config elements are more static in nature, return false. If in doubt, return false.
      Specified by:
        `expectsModification` in interface `ConfigElement`
      Overrides:
        `expectsModification` in class `ConfigTestElement`
      Returns:
        true if the element expects to be modified over the course of a test run

    - #### save

          public void save(java.lang.String authFile)
                    throws java.io.IOException

      Save the authentication data to a file.
      Parameters:
        `authFile` - path of the file to save the authentication data to
      Throws:
        `java.io.IOException` - when writing to the file fails

    - #### addFile

          public void addFile(java.lang.String authFile)
                       throws java.io.IOException

      Add authentication data from a file.
      Parameters:
        `authFile` - path to the file to read the authentication data from
      Throws:
        `java.io.IOException` - when reading the data fails

    - #### remove

          public void remove(int index)

      Remove an authentication record.
      Parameters:
        `index` - index of the authentication record to remove

    - #### getClearEachIteration

          public boolean getClearEachIteration()

      Returns:
        true if kerberos auth must be cleared on each mail loop iteration

    - #### setClearEachIteration

          public void setClearEachIteration(boolean clear)

    - #### getAuthCount

          public int getAuthCount()

      Return the number of records.
      Returns:
        the number of records

    - #### setupCredentials

          public void setupCredentials(Authorization auth,
                                       java.net.URL url,
                                       org.apache.http.client.protocol.HttpClientContext localContext,
                                       org.apache.http.client.CredentialsProvider credentialsProvider,
                                       java.lang.String localhost)

      Configure credentials and auth scheme on client if an authorization is
      Parameters:
        `auth` - information about the authorization to use
        `url` - the URL for which the authorization info should be used
        `localContext` - http client context which should be set up
        `credentialsProvider` - provider which should be set up
        `localhost` - name of the workstation to be used for `NTCredentials`

    - #### testStarted

          public void testStarted()

      Called just before the start of the test from the main engine thread. This is before the test elements are cloned. Note that not all the test variables will have been set up at this point.

      N.B. testStarted() and testEnded() are called from different threads.

      Specified by:
        `testStarted` in interface `TestStateListener`
      See Also:
        `StandardJMeterEngine.run()`

    - #### testEnded

          public void testEnded()

      Called once for all threads after the end of a test. This will use the same element instances as at the start of the test.

      N.B. testStarted() and testEnded() are called from different threads.

      Specified by:
        `testEnded` in interface `TestStateListener`
      See Also:
        `StandardJMeterEngine.stopTest()`

    - #### testStarted

          public void testStarted(java.lang.String host)

      Called just before the start of the test from the main engine thread. This is before the test elements are cloned. Note that not all the test variables will have been set up at this point.

      N.B. testStarted() and testEnded() are called from different threads.

      Specified by:
        `testStarted` in interface `TestStateListener`
      Parameters:
        `host` - name of host
      See Also:
        `StandardJMeterEngine.run()`

    - #### testEnded

          public void testEnded(java.lang.String host)

      Called once for all threads after the end of a test. This will use the same element instances as at the start of the test.

      N.B. testStarted() and testEnded() are called from different threads.

      Specified by:
        `testEnded` in interface `TestStateListener`
      Parameters:
        `host` - name of host
      See Also:
        `StandardJMeterEngine.stopTest()`

    - #### testIterationStart

          public void testIterationStart(LoopIterationEvent event)

      Each time through a Thread Group's test script, an iteration event is fired for each thread. This will be after the test elements have been cloned, so in general the instance will not be the same as the ones the start/end methods call.
      Specified by:
        `testIterationStart` in interface `TestIterationListener`
      Parameters:
        `event` - the iteration event

Copyright © 1998-2018 Apache Software Foundation. All Rights Reserved.