Setup SAML server in lab
Setup SAML server in lab
Install a virtual machine software:
- Download and install a virtual machine software like VirtualBox or VMware on your computer.
Download a Linux distribution image:
- Download a Linux distribution image from the official website of the chosen distribution (e.g., Ubuntu, CentOS).
- Save the downloaded image to your computer.
Create a virtual machine:
- Open the virtual machine software and click on the “New” button to create a new virtual machine.
- Follow the wizard to create a new virtual machine, selecting the downloaded Linux distribution image as the operating system.
Install Apache web server:
Open the terminal on the virtual machine and run the following command to install Apache web server:
1
2
3TXT
Copysudo apt-get update
sudo apt-get install apache2
Install SimpleSAMLphp:
- Download the latest version of SimpleSAMLphp from the official website (https://simplesamlphp.org/download).
- Extract the downloaded archive to the Apache web server document root directory (/var/www/html).
- Rename the extracted directory to “simplesamlphp”.
Configure SimpleSAMLphp as a SAML identity provider:
Open the terminal on the virtual machine and navigate to the SimpleSAMLphp configuration directory:
1
2TXT
Copycd /var/www/html/simplesamlphp/configCopy the “config-templates/config.php” file to “config.php”:
1
2TXT
Copycp config-templates/config.php config.phpEdit the “config.php” file and set the following parameters:
1
2
3
4TXT
Copy'baseurlpath' => 'https://localhost/simplesamlphp/',
'auth.adminpassword' => 'CHOOSE-A-STRONG-PASSWORD',
'secretsalt' => 'CHOOSE-A-RANDOM-STRING',Save and close the “config.php” file.
Configure SimpleSAMLphp as a SAML service provider:
Open the terminal on the virtual machine and navigate to the SimpleSAMLphp configuration directory:
1
2TXT
Copycd /var/www/html/simplesamlphp/configCopy the “config-templates/authsources.php” file to “authsources.php”:
1
2TXT
Copycp config-templates/authsources.php authsources.phpEdit the “authsources.php” file and set the following parameters:
1
2
3
4
5
6
7
8
9
10
11
12
13TXT
Copy'default-sp' => array(
'saml:SP',
'entityID' => 'https://localhost/testsp',
'discoURL' => null,
'NameIDFormat' => 'urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified',
'simplesaml.nameidattribute' => 'uid',
'simplesaml.attributes' => false,
'AssertionConsumerService' => 'https://localhost/testsp/saml2-acs.php',
'SingleLogoutService' => 'https://localhost/testsp/saml2-logout.php',
'sign.logout' => true,
'redirect.sign' => true,
),Save and close the “authsources.php” file.
Create a test user account:
Open the terminal on the virtual machine and navigate to the SimpleSAMLphp metadata directory:
1
2TXT
Copycd /var/www/html/simplesamlphp/metadataCopy the “saml20-idp-remote.php” file to “testuser.php”:
1
2TXT
Copycp saml20-idp-remote.php testuser.phpEdit the “testuser.php” file and set the following parameters:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34TXT
Copy$metadata['testuser'] = array(
'entityid' => 'https://localhost/testuser',
'contacts' => array(
array(
'contactType' => 'technical',
'givenName' => 'Test',
'surName' => 'User',
'emailAddress' => 'testuser@example.com',
),
),
'metadata-set' => 'saml20-idp-remote',
'SingleSignOnService' => array(
array(
'Binding' => 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect',
'Location' => 'https://localhost/simplesamlphp/saml2/idp/SSOService.php',
),
),
'SingleLogoutService' => array(
array(
'Binding' => 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect',
'Location' => 'https://localhost/simplesamlphp/saml2/idp/SingleLogoutService.php',
),
),
'NameIDFormat' => 'urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified',
'simplesaml.nameidattribute' => 'uid',
'simplesaml.attributes' => false,
'authproc' => array(
10 => array(
'class' => 'core:AttributeAdd',
'testuser' => array('uid' => array('testuser')),
),
),
);Save and close the “testuser.php” file.
Configure the SAML service provider to trust the SAML identity provider:
Open the terminal on the virtual machine and navigate to the SimpleSAMLphp metadata directory:
1
2TXT
Copycd /var/www/html/simplesamlphp/metadataCreate a new file named “idp-metadata.xml” and add the following metadata for the SAML identity provider:
1
2
3
4
5
6
7
8
9
10TXT
Copy<md:EntityDescriptor xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata" entityID="https://localhost/simplesamlphp/saml2/idp/metadata.php">
<md:IDPSSODescriptor protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol">
<md:NameIDFormat>
urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified
</md:NameIDFormat>
<md:SingleSignOnService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect" Location="https://localhost/simplesamlphp/saml2/idp/SSOService.php"/>
<md:SingleLogoutService Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect" Location="https://localhost/simplesamlphp/saml2/idp/SingleLogoutService.php"/>
</md:IDPSSODescriptor>
</md:EntityDescriptor>Edit the “metadata/saml20-sp-remote.php” file and set the following parameters:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50TXT
Copy$metadata['https://localhost/testsp'] = array(
'AssertionConsumerService' => 'https://localhost/testsp/saml2-acs.php',
'SingleLogoutService' => 'https://localhost/testsp/saml2-logout.php',
'NameIDFormat' => 'urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified',
'simplesaml.nameidattribute' => 'uid',
'simplesaml.attributes' => false,
'metadata-set' => 'saml20-sp-remote',
'entityid' => 'https://localhost/testsp',
'contacts' => array(
array(
'contactType' => 'technical',
'givenName' => 'Test',
'surName' => 'SP',
'emailAddress' => 'testsp@example.com',
),
),
'AssertionConsumerService' => array(
array(
'Binding' => 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST',
'Location' => 'https://localhost/testsp/saml2-acs.php',
),
),
'SingleLogoutService' => array(
array(
'Binding' => 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect',
'Location' => 'https://localhost/testsp/saml2-logout.php',
),
),
'NameIDMappingService' => array(
array(
'Binding' => 'urn:oasis:names:tc:SAML:2.0:bindings:SOAP',
'Location' => 'https://localhost/testsp/saml2-nameidmapping.php',
),
),
'attributes.NameFormat' => 'urn:oasis:names:tc:SAML:2.0:attrname-format:basic',
'attributes' => array(),
'authproc' => array(
3 => array(
'class' => 'saml:NameIDAttribute',
'attribute' => 'uid',
'Format' => 'urn:oasis:names:tc:SAML:2.0:nameid-format:transient',
),
),
'saml20.sign.assertion' => true,
'saml20.sign.response' => true,
'saml20.encrypt' => false,
'saml20.sign.metadata' => true,
'redirect.sign' => true,
);Save and close the “saml20-sp-remote.php” file.
Test the SAML authentication:
- Open a web browser on your host machine and navigate to “https://localhost/testsp“.
- You will be redirected to the SAML identity provider for authentication.
- Enter the test user credentials created earlier and complete the authentication process.
- You will be redirected back to the SAML service provider and should be able to access the protected resource.
- Verify that the SAML response is valid and that the user is authenticated.