Adding apache basic auth for a path in content hierarchy(one subdomain) | Community
Skip to main content
Level 4
February 24, 2022
Solved

Adding apache basic auth for a path in content hierarchy(one subdomain)

  • February 24, 2022
  • 3 replies
  • 3805 views

 

 

Hi All,

how could we add basic authentication in apache for a particular subdomain- there by requiring requests to a content path allowed with authentication credentials?

 

thanks in advance for your help or direction.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Raja-Karuppsamy

You can create the .htaccess file in your local. Add the username into the file and the file looks like :

username:password (password in encrypted format).

 

Regards,

Raja

3 replies

Bhuwan_B
Community Advisor
Community Advisor
February 24, 2022
Peter_Puzanovs
Community Advisor
Community Advisor
February 24, 2022

Hey Kent,

 

If you are looking for a particular subdomain you can set auth requirement in the specific vhost as well.

 

Regards,

Peter

Raja-Karuppsamy
Community Advisor
Community Advisor
February 25, 2022

@asn11 Please follow the below steps to handle the authentication in domain level:

1.Create a file dispatcher.htaccess in dispatcher.
2.Create the users to access the password protected domain:
htpasswd -c /etc/httpd/conf.d/dispatcher.htaccess <user>

Enter the password (twice)
3.Add the following configurations to your virtual host to handle the authentication:

<Location />
## unsets authorization header when sending request to AEM
RequestHeader unset Authorization
Deny from all
#Allow from (Set IP to allow access without password)
AuthUserFile /etc/httpd/conf.d/dispatcher.htaccess
AuthName "Authentication Required"
AuthType Basic
Satisfy Any
require valid-user
</Location>


4.Check the syntax -> httpd -t

5.Restart the dispatcher.

6. Access the domain whether you are getting the authentication pop-up.

 

OR

 

You can configure the below configuration in your dispatcher.conf file to handle particular content path:

# unsets authorization header when sending request to AEM
RequestHeader unset Authorization
SetEnvIf Request_URI ^/content/xyz* auth=1
AuthType Basic
AuthUserFile /etc/httpd/conf.d/dispatcher.htaccess
# first, allow everybody
Order Allow,Deny
Satisfy any
Allow from all
Require valid-user
# then, deny only if required
Deny from env=auth

 

Regards,

Raja

asn11Author
Level 4
February 25, 2022

@raja-karuppsamy thanks for the answer. a followup question, how can I create user interactively as you mentioned with htpasswd command in case of aem as cloud where we cant access dispatcher server and configuration is done via code deployment?

Raja-Karuppsamy
Community Advisor
Raja-KaruppsamyCommunity AdvisorAccepted solution
Community Advisor
February 25, 2022

You can create the .htaccess file in your local. Add the username into the file and the file looks like :

username:password (password in encrypted format).

 

Regards,

Raja