This tutorial will show you how to configure Single-Sign-On (SSO) in Apache using Active Directory Federation Service (AD FS) as an identity provider and SimpleSAMLphp as a service provider on CentOS, RHEL Linux.
Single sign-on (SSO) is a property of access control of multiple related, yet independent, software systems. With this property, a user logs in with a single ID and password to gain access to a connected system or systems without using different usernames or passwords, or in some configurations seamlessly sign on at each system.
Apache is the most widely-used web server in the world. It provides many powerful features including dynamically loadable modules, robust media support, and extensive integration with other popular software.
SimpleSAMLphp is an award-winning application written in native PHP that deals with authentication. It authenticates the user against a SAML 2.0 IdP, and grants access to resources depending on attributes received from the identity provider (IdP).
Active Directory Federation Services (AD FS) is a software component developed by Microsoft that can be installed on Windows Server operating systems to provide users with single sign-on access to systems and applications located across organizational boundaries.
The following information will be used throughout this tutorial:
These instructions can also be applied if you are running RHEL, or Oracle Linux on your system.
Prerequisites
To follow this tutorial along, you will need one (physical or virtual) machine installed with CentOS, or RHEL Linux. This guide assume that you already have Active Directory Federation Service (AD FS) in place.
Make sure you have proper DNS entries for your Linux and AD FS FQDN:
![](http://1.bp.blogspot.com/-e74UValacWw/YD4XeVCdT0I/AAAAAAAATMA/75D9kPyhkKcYFPPIMA1-9eOSYqnpSOyvgCLcBGAsYHQ/s16000/dns_entries.png)
Make sure you have proper FQDN entries in /etc/hosts file on your Linux system:
![](http://1.bp.blogspot.com/-yGLDbHVWtMY/YD4YeiyGP4I/AAAAAAAATMI/HhrbXa7S_UosmR52ijXTjv2p34P9Cw_ygCLcBGAsYHQ/s16000/linux_etc_hosts.png)
Make sure your Linux and AD FS machines are reachable to each-other using their FQDN:
![](http://1.bp.blogspot.com/-paBIrHgom2I/YD4Y_Jn3XgI/AAAAAAAATMQ/1AcE7E0yYjADV9TagxUoG4ynpsJamYh9gCLcBGAsYHQ/s16000/ping_windows_linux.png)
Ping your AD FS FQDN from your Linux machine like below:
![](http://1.bp.blogspot.com/-CJ8ybrL1-Tg/YD4ZriHLTuI/AAAAAAAATMY/cdVnApSwoZUFyIQ8BMCbG8_UrDqjtw8WQCLcBGAsYHQ/s16000/ping_linux_windows.png)
When you have all prerequisites in place, you can proceed with below steps.
Install Required Packages
Secure MariaDB
Start MariaDB with below command:
Execute below script, and follow on screen instruction to secure you MariaDB installation:
Configure PHP
Update following parameter with your correct timezone:
Start PHP to make changes effect:
Download SimpleSAMLphp
At the time of writing this article, the latest stable release of SimpleSAMLphp is ( 1.18.8). You can check latest stable release at https://github.com/simplesamlphp/simplesamlphp/releases
You can download stable release on your Linux system from GitHub repository like below:
Create Self-signed SSL Certificate
Type below command to generate a self-signed SSL certificate for your Apache:
Enter the following information accordingly:
Type below command to generate a self-signed SSL certificate for your identity provider:
Enter the following information accordingly:
Combine sp.crt, and sp.pem into sp.pfx format with below command:
Configure SimpleSAMLphp
Type below command to generated a random string to be used as secret salt:
Copy the generated string, save it in a text file, we will use it in a while:
Type below command to generate hashed password for SimpleSAMLphp administrator account:
You will need to log in with administrator account of SimpleSAMLphp to access some of the secure pages from web interface. Copy the generated hashed password, save it in a text file, we will use it in a while:
Edit config.php with any of your preferred text editor:
Locate the following parameters, and replace their values with yours:
Replace timezone value with yours:
Replace secretsalt value with the one your generated earlier:
Replace auth.adminpassword with the one you generated earlier:
Save and close the editor when you are finished.
Configure Apache
Create a simplesamlphp.conf file like below:
Add following parameters in it:
Save and close the editor when you are finished.
Create a directory for your web content like an example below:
Create a VirtualHost configuration file like an example below:
Add following parameters in it, replace highlighted text with yours:
Test Apache configuration with below command:
If everything configured correctly, you will see the output like below:
If you see any configuration error, fix them first, then proceed to next.
Type below command to start Apache:
Synchronize your Linux system clock with your AD FS like below:
You will see output like below:
Open up web browser, type https://sp.techsupportpk.com/simplesaml in the address bar, Click Advanced to ignore browser SSL warning:
![](http://1.bp.blogspot.com/-8zYCM39Ay9E/YD3AVldg4EI/AAAAAAAATHk/fW4ULz8BhVQuwxHc1_AOsxams-khm8SAQCLcBGAsYHQ/s16000/simplesamlphp_apache_adfs.jpg)
You will see SimpleSAMLphp dashboard like below.
Click Login as administrator
![](http://1.bp.blogspot.com/-AUNplhvpTPA/YD3A25QPe1I/AAAAAAAATHs/-hqQFlBGUi4dAZdPiaZFMdvzUVP7TvnfgCLcBGAsYHQ/s16000/simplesamlphp_apache_adfs_1.jpg)
If you remember, this administrator password you generated with pwgen.php command, and configured it in config.php file.
Enter your password, and click Login:
![](http://1.bp.blogspot.com/-4shxTHTibdo/YD3B-Lv2jqI/AAAAAAAATH0/haZ7hvNBt_ALc5RSjM8NL3D-l1RisIzXwCLcBGAsYHQ/s16000/simplesamlphp_apache_adfs_2.jpg)
![](http://1.bp.blogspot.com/-588sac1kSdM/YD3CvbAmRRI/AAAAAAAATH8/mQwa1F-zNvsCYhNEBd3m_nRpbKNfN34YACLcBGAsYHQ/s16000/simplesamlphp_apache_adfs_3.jpg)
Navigate to Federation tab, click XML to SimpleSAMLphp metadata converter sd
![](http://1.bp.blogspot.com/-f4wML8mkM9o/YD3DidrnVvI/AAAAAAAATIE/XBtvd7uaH1oJI0J9Llsi1Tn2BJmY-uYxwCLcBGAsYHQ/s16000/simplesamlphp_apache_adfs_4.jpg)
Click Choose File to upload your AD FS metadata file, click Parse
![](http://1.bp.blogspot.com/-38FcnDfBEBc/YD3ENzuKMGI/AAAAAAAATIM/2vKQ42ttXO42Cjs4dULFm7bYaeCv8wgKQCLcBGAsYHQ/s16000/simplesamlphp_apache_adfs_5.jpg)
The will return two sets of data. The first: saml20-sp-remote can be ignored since we are not using SimpleSAMLphp as an identity provider.
Scroll to saml20-idp-remote and copy the contents of this field to the clipboard.
![](http://1.bp.blogspot.com/-BFR6mUG34Zs/YD3NMxhnNVI/AAAAAAAATIU/eWleqJUgFSwcjV8WwgC8GhJ3l57PsZSggCLcBGAsYHQ/s16000/simplesamlphp_apache_adfs_6.jpg)
Go back to your Linux terminal, edit saml20-idp-remote.php file like below:
Paste copied contents in it:
![](http://1.bp.blogspot.com/-qPuc8pDdfKk/YD3PfrZnMvI/AAAAAAAATIc/qJv3ZYu3IsA1gaVw67kRkheboVGZu__agCLcBGAsYHQ/s16000/simplesamlphp_apache_adfs_7.jpg)
Save and close the editor when you are finished.
Edit authsources.php with any of your preferred text editor:
Add your AD FS as an identity provider in authsource.php like below: Save and close the editor when you are finished.
After modification, authsources.php will look similar to like below:
![](http://1.bp.blogspot.com/-P2wtRyMnkps/YD3VHi1WSCI/AAAAAAAATIk/iHj7d5lINBg3M07grtKodELR8tKJ6yX8QCLcBGAsYHQ/s16000/simplesamlphp_apache_adfs_8.jpg)
Go back to your browser, refresh https://sp.techsupportpk.com/simplesaml page, navigate to Federation tab, and you will see your recently added SP metadata like below:
![](http://1.bp.blogspot.com/-t1jssdfpa4Q/YD3le9RhEVI/AAAAAAAATJ0/8Ub3n0CpClwYlI6xDCyBmjOlh0xBisUWgCLcBGAsYHQ/s16000/SimpleSAMLphp_metadata_adfs.jpg)
You will need this metadata url to configure your AD FS Relying Party Trust in the next step.
At this stage, you need to transfer /var/simplesamlphp/cert/sp.pfx SSL certificate file from your Linux system to your AD FS machine using WinSCP or whatever tool you would like to use.
![](http://1.bp.blogspot.com/-qMAgyJ0IfTc/YD3Ze_mt9lI/AAAAAAAATIs/0K-hkq9ynjg1w5RVIks6qe4ggF6kbcvsACLcBGAsYHQ/s16000/simplesamlphp_apache_adfs_9.jpg)
When you have your sp.pfx file on your AD FS machine, install it like below:
![](http://1.bp.blogspot.com/-77NAahF84Ec/YD3c2Qv9sxI/AAAAAAAATI0/D5YXagBEhXA3X5xMYO-_xESXzDiuF4epgCLcBGAsYHQ/s16000/simplesamlphp_apache_adfs_10.jpg)
Click Local Machine, click Next
![](http://1.bp.blogspot.com/-gDdioiC6ZVU/YD3dOnnsbUI/AAAAAAAATI8/U9Q8D-Osd7cDxDiJiCR5GuuUN4JJzI5bgCLcBGAsYHQ/s16000/simplesamlphp_apache_adfs_11.jpg)
Click Next
![](http://1.bp.blogspot.com/-oRCf7vMlXO0/YD3diNlsp8I/AAAAAAAATJE/NrbLx3cW6G0T-DyKepB8xViHnQgt4-WrQCLcBGAsYHQ/s16000/simplesamlphp_apache_adfs_12.jpg)
We did not set any password, so we will leave it blank, click Next
![](http://1.bp.blogspot.com/-4hAe_f5UZ3g/YD3dsE-PdjI/AAAAAAAATJI/ejHIIm_4iOY_evAxf3lgfoeJGHnHctTFgCLcBGAsYHQ/s16000/simplesamlphp_apache_adfs_13.jpg)
Click Place all certificate in the following store, click Browse
![](http://1.bp.blogspot.com/-oFimnGkXM-s/YD3eNix6ycI/AAAAAAAATJU/0KOQ2TMCpRQKra8tc6Vp3rog49JvvkERQCLcBGAsYHQ/s16000/simplesamlphp_apache_adfs_14.jpg)
Select Trusted Root Certification Authorities, click OK
![](http://1.bp.blogspot.com/-UuXKD_Cho6Q/YD3ehsCSxGI/AAAAAAAATJc/Ks0Fymx7upMgSXDZ5xJ3a8EBgyrwKBUgwCLcBGAsYHQ/s0/simplesamlphp_apache_adfs_15.jpg)
Click Next
![](http://1.bp.blogspot.com/-vul04YXa4NA/YD3ewqiJQCI/AAAAAAAATJg/Rf1rofZQPVgaA6EBDummKqKuI4P2CdIIwCLcBGAsYHQ/s16000/simplesamlphp_apache_adfs_16.jpg)
Click Finish
![](http://1.bp.blogspot.com/-PGuwFZqo6y8/YD3e4xg2KUI/AAAAAAAATJo/Kebpbylp5NgOWnnLgFq3naLAbuwbbcL6QCLcBGAsYHQ/s16000/simplesamlphp_apache_adfs_17.jpg)
Configure AD FS Relying Party Trust
Log in to your AD FS machine, open up AD FS Management console, Right-click Relying Party Trust, Click Add Relying Party TrustKeep default Claims aware, click Start
![](http://1.bp.blogspot.com/-qd4AZgkgXtA/YD3oEvns91I/AAAAAAAATJ8/N1ZxfhmV8g0UsLT-lRnpcU1ozl2y06pywCLcBGAsYHQ/s16000/ad_fs_relying_party_trust_wizard_1.jpg)
Enter your SP metadata url like below, click Next
![](http://1.bp.blogspot.com/-1GfQK5yGfNI/YD3oEqTZNzI/AAAAAAAATKA/V1iCi5U5Sxcwq3ioFbSc61Dc0MkVyBolgCLcBGAsYHQ/s16000/ad_fs_relying_party_trust_wizard_2.jpg)
You can safely ignore this warning, Click OK
![](http://1.bp.blogspot.com/-MTuMan9EcC8/YD3uSBLpDMI/AAAAAAAATKM/Zl-GApQ0b-oOCH0E4QWFTwTICvv_x25ygCLcBGAsYHQ/s16000/ad_fs_relying_party_trust_wizard_3.jpg)
Click Next
![](http://1.bp.blogspot.com/-c2e0aQcBFWM/YD3uqXW6eRI/AAAAAAAATKo/3zl4d3slpeATnWZBXcocHQQ6HWBbwQ3vQCLcBGAsYHQ/s16000/ad_fs_relying_party_trust_wizard_4.jpg)
Click Next
![](http://1.bp.blogspot.com/-rY9-j2EIIHg/YD3uq5A_dsI/AAAAAAAATKs/zPxP2rvZdaY-AZ4qO5h4mqrqrTujzMm0ACLcBGAsYHQ/s16000/ad_fs_relying_party_trust_wizard_5.jpg)
Click Next
![](http://1.bp.blogspot.com/-YnKM62veInM/YD3urov6YAI/AAAAAAAATKw/xQpDiXE4r_oGk5hC2_9YvxO7KjmniGCmQCLcBGAsYHQ/s16000/ad_fs_relying_party_trust_wizard_6.jpg)
Click Close
![](http://1.bp.blogspot.com/-EIog-_MLApY/YD3ur7q29xI/AAAAAAAATK0/QXIXZRNWKhcYnj6Sfox2Rtc6nqq_WIsGACLcBGAsYHQ/s16000/ad_fs_relying_party_trust_wizard_7.jpg)
Right-click on your Relying Party Trust entity, click Edit Claim Issuance Policy
![](http://1.bp.blogspot.com/-XjipAkpwRIQ/YD3usZUxjSI/AAAAAAAATK4/d7pO3fMaPl4L-F9Rxi3pahltQZ4wM3GwACLcBGAsYHQ/s16000/ad_fs_relying_party_trust_wizard_8.jpg)
Click Add Rule
![](http://1.bp.blogspot.com/-8VYZO9icFbo/YD3usVvfqKI/AAAAAAAATK8/7gKYAITdKn4_5xC9bReR6bOLbpJGr4jLACLcBGAsYHQ/s16000/ad_fs_relying_party_trust_wizard_9.jpg)
Select Send LDAP Attributes as Claim, click Next
![](http://1.bp.blogspot.com/-PRwhfjzEwo0/YD3upBi-YSI/AAAAAAAATKc/_essCs4NQlsl9AhKTXxZUTshq2TYwDp_gCLcBGAsYHQ/s16000/ad_fs_relying_party_trust_wizard_10.jpg)
Configure claim rule like below:
![](http://1.bp.blogspot.com/-V6GVBSX0H1E/YD3uoXZ9VuI/AAAAAAAATKU/ndsR7dNBwqUwfVBSRTR5Iyk9d5f5xb6nwCLcBGAsYHQ/s16000/ad_fs_relying_party_trust_wizard_11.jpg)
Click Finish when you are done.
Add another rule, select Transform an Incoming Claim, click Next
![](http://1.bp.blogspot.com/-W24JzBEYPxY/YD3uo4sClpI/AAAAAAAATKY/1M98oB6A3TM4PA0S8cpWTbut6c1uiiVGgCLcBGAsYHQ/s16000/ad_fs_relying_party_trust_wizard_12.jpg)
Configure rule like below:
![](http://1.bp.blogspot.com/-pqEjJOo0uY4/YD3uqE6LyTI/AAAAAAAATKk/BxpDftxChVMMogv7yWHYG5hnzfv9yItQgCLcBGAsYHQ/s16000/ad_fs_relying_party_trust_wizard_13.jpg)
Click Finish when you are done.
Click Apply, OK
![]()
![](http://1.bp.blogspot.com/-CPGan0rsLDo/YD3upuI-f0I/AAAAAAAATKg/cjyR9H4sCvkmEDa8IF7E_3n6_q_6JFTWgCLcBGAsYHQ/s16000/ad_fs_relying_party_trust_wizard_14.jpg)
At this stage, your AD FS Relying Party Trust configuration is ready to serve the purpose.
Verify SimpleSAMLphp AD FS Integration
From a web browser, access your https://sp.techsupportpk.com/simplesaml and navigate to Authentication tab, click Test configured authentication sources
![](http://1.bp.blogspot.com/-4WTLXnkGRfA/YD34BgK-3TI/AAAAAAAATLY/RwRabkBOHG4C0qocKLv2dX2g8P8IltKDACLcBGAsYHQ/s16000/SimpleSAMLphp_ADFS_Authentication_Test.jpg)
Click on a authentication source your added for AD FS.
![](http://1.bp.blogspot.com/-VWffItwuH2Q/YD344Atk9tI/AAAAAAAATLg/kKdo0MCY_KsuB74ZaJjbn1aKY_4LE9WWgCLcBGAsYHQ/s16000/SimpleSAMLphp_test_authentication_sources.jpg)
If everything configured correctly, you will be taken to your AD FS login page:
![](http://1.bp.blogspot.com/-aPmAlp7sMd0/YD36PTPGBfI/AAAAAAAATLo/zQU_PebfN4AK8bSRbxQqa8MEPw3Et8z7wCLcBGAsYHQ/s16000/SimpleSAMLphp_test_authentication_sources_1.jpg)
Enter your valid usernameand password like below to sign-in:
![](http://1.bp.blogspot.com/-QX9lGoL5Kkw/YD37pGlLO0I/AAAAAAAATLw/tUlPh8k69v8IEwS6Mwu7FJGEhxh_nR6rACLcBGAsYHQ/s16000/SimpleSAMLphp_test_authentication_sources_2.jpg)
Once signed in, you’ll be bounced back to SimpleSAMLphp and shown your claims as you can see in screenshot below:
![](http://1.bp.blogspot.com/-9a35GtpFyNs/YD38mdumLGI/AAAAAAAATL4/D9Q-sLVZeBYjOtwWqyR97FT8GzJKZbK3wCLcBGAsYHQ/s16000/SimpleSAMLphp_test_authentication_sources_3.jpg)
If you face any issue, double-check everything your configured and then check the logs for hints as to what could have gone wrong.
Verify Apache SSO
We will create a simple index.php page in /var/www/sp.techsupportpk.com/ to test Apache SSO functionality.
Add following code in it, replace highlighted text with yours:
Create a simple logout.php page like below:
Create a simple logged_out.php page like below:
Open up web browser, enter https://sp.techsupportpk.com in the address bar, you will be taken to your AD FS login page.
![](http://1.bp.blogspot.com/-ThJGLOfs9hE/YD4pfIobB0I/AAAAAAAATMo/Omo-3f1S_NsWsrqKSXypRhUxDaJe-7a6QCLcBGAsYHQ/s16000/SimpleSAMLphp_test_authentication_sources_2.jpg)
Once signed-in with valid credentials, you will be redirected to your simple index.php page as shown in screenshot below:
![](http://1.bp.blogspot.com/-btQNYwjz_ko/YD4qZ18j1hI/AAAAAAAATMw/XFWyYuccuJYpYflqanqwHbvjScp802kiACLcBGAsYHQ/s16000/simple_index_php.png)
Click logout to test your logout functionality.
Conclusion
Now that you have successfully configured SSO in Apache using SimpleSAMLphp and Active Directory Federation Service, you can start testing your applications SSO functionality.