Bobcares

Apache JMeter Basic Authentication | Set Up Guide

by | Aug 30, 2023

Learn more about Apache JMeter Basic Authentication from our experts. Our Apache Support team is here to help you with your questions and concerns.

Apache JMeter Basic Authentication | Set Up Guide

In the world of performance testing, JMeter is a powerful tool. It helps evaluate the functional behavior of web services.

However, testers tend to run into situations where the web services being tested are protected by HTTP Basic Authentication.

Apache JMeter Basic AuthenticationIf you are in a similar spot, our experts have your back.

Before we dive into the implementation details, let’s take a closer look at Basic Authentication. It is a simple access-control method that helps us secure a web resource. It includes an HTTP header sent by the client.

This header contains the credentials as a Base64 string. It contains the username and password delimited by a single colon.

Furthermore, Basic Authentication is used when logins are requested in the browser’s window.

Hence, if we start a JMeter test on a secured web response, we will get HTTP 401 as the response.

Additionally, we will get a “WWW-Authenticate” response header that lets us know the authentication type required by the server.

How to implement Basic Authentication in JMeter

Method 1: Authorization Header Injection

The simplest way to offer credentials is by embedding them directly into the request header.
JMeter does this via the HTTP Header Manager component as seen below:

  1. First, we have to place the HTTP Header Manager under the desired HTTP Request component.
  2. Then, head to the manager’s configuration tab and add an entry with our authentication details. Additionally, name it “Authorization.”
  3. Next, we have to encode our credentials with online tools. We have to add the prefix “Basic” before the encoded string.
  4. When executed smoothly, our server will respond with a cheerful HTTP 200, signifying success.

Method 2: JSR223 PreProcessor Magic

Alternatively, we can use the JSR223 PreProcessor to encode the credentials. Here are the steps:

  1. First, we have to add a JSR223 PreProcessor before our HTTP Header Manager.
    We can run a script at runtime with this component.

  2. Then, we have to define our username and password variables in User Defined Variables.
  3. Finally, we have to set the Authorization header to use the encoded credentials in the HTTP Header Manager. This makes it easy to change credentials in our user-defined variables.

Method 3: Using HTTP Authorization Manager

JMeter also lets HTTP Authorization Manager handle credentials.

This component lets us offer credentials for different domains and authentication protocols.

  1. First, we have to embed the HTTP Authorization Manager within the Thread Group and before to the HTTP Request component.
  2. Then, we have to add our username and password in its configuration tab.
  3. Furthermore, variables from the User Defined Variables component can be used here too.
  4. Then, we have to make sure we choose BASIC as the mechanism.

At the end of the day, we can choose one of the above options to help JMeter deal with Basic Authentication.

[Need assistance with a different issue? Our team is available 24/7.]

Conclusion

Today, our Support Techs demonstrated how to set up Basic Authentication in Apache JMeter.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.