Added by Sebastian Gonzalez Oyuela, last edited by Goran Nastov on Nov 23, 2009  (view change)

Labels:

Enter labels to add to this page:
Wait Image 
Looking for a label? Just start typing.

Introduction

This guide will explain how to make your PHP Application become a JOSSO Partner Application.

The guide will be based on the provided JOSSO sample application.

Prerequisites

  • JOSSO Gateway configured and running (in any platform).
  • JOSSO Agent configured in the selected platform. Take a look at Setup JOSSO Agent - PHP
  • A Java Web Application, you can use the sample application distributed with JOSSO for testing purposes.
JOSSO Distribution

PHP Agent is found in josso-1.8.0.zip distribution only. You can download it here

Unpack JOSSO Distribution

The PHP Agent and a sample PHP application already jossified are distributed with JOSSO. Unzip the file josso-php-agent-1.8.0.zip located in the josso-1.8.0/dist/agents/src folder of JOSSO distribution. You will find the following structure:

Make your PHP web application become a JOSSO Single Sign-On partner application

Install JOSSO PHP pages in your application, copy the files located in josso-php-agent-1.8.0/josso-php-partnerapp/ to your application root directory:

  • josso-login.php
  • josso-logout.php
  • josso-security-check.php

We'll use JOSSO PHP sample partner application located in /var/www/php/php-partnerapp.

For Unix systems you can use :

$ cd ./josso-php-agent-1.8.0/
$ cp -r josso-php-partnerapp /var/www/php/php-partnerapp

For Win32 systems you can use :

cd josso-php-agent-1.8.0
xcopy josso-php-partnerapp C:\Apache\php\php-partnerapp\

Make sure to include the josso.php page in your application pages. If you used the prepend_file option the file will be automatically included by the PHP runtime.

JOSSO Pages folder name

Make sure the folder name you use matches the josso_agentBasecode variable defined in josso-inc.cfg file!

The sample application is also distributed with JOSSO and can be found at josso-1.8.0/dist/samples/apps/josso-partner-php-1.8.0-.zip

Sample page

index.php
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
	<title>Sample Partner Application - JOSSO</title>
	<meta name="description" content="Java Open Single Signon">
</head>

<body>
    <h1>This is a very simple PHP JOSSO partner application</h1>
<?php

// jossoagent is automatically instantiated by josso.php,
// declared in auto_prepend_file property of php.ini.
// If you do not use auto_prepend feature, include josso.php in all your pages

// Get current SSO User and SSO Session information,
$user = $josso_agent->getUserInSession();
$sessionId = $josso_agent->getSessionId();

// Check if user is authenticated
if (isset($user)) {

    // Display USER INFORMATION

    // Username associated to authenticated user
    echo 'Username : ' . $user->getName() . '<br><br>';

    // Get a specific user property
    echo 'user.name=' . $user->getProperty('user.name') . '<br><br>';

    // Get all user properties
    $properties = $user->getProperties();
    if (is_array($properties)) {
        foreach ($properties as $property) {
            echo $property['name'] . '=' . $property['value'] . '<br>';
        }
    }

	// Get all user roles
	$roles = $josso_agent->findRolesBySSOSessionId($sessionId);
	echo '<h2>Roles</h2>';
	foreach ($roles as $role) {
		echo $role->getName() . '<br>';
	}

	// Check if user belongs to a specific role
	if ($josso_agent->isUserInRole('role1')) {
		echo '<h3>user is in role1</h3>';
	}

	echo 'Click <a href="'.jossoCreateLogoutUrl().'">here</a> to logout ...<br>';

	echo '<p>SSO Session ID : ' . $sessionId . '</p>';


} else {

    // User is unknown..
    echo '<h2>you are an annonymous user ...</h2>';

	echo 'Click <a href="'.jossoCreateLoginUrl().'">here</a> to login ...';

}
?>

</body>
</html>
JOSSO 1.8.2 and later
From JOSSO 1.8.2 use $property['!name'] and $property['!value'] to access user properties.

Using JOSSO PHP Functions

Take a look at functions declared in josso.php file. You can use them to access user information, trigger the authentication process, obtain user roles, etc.

For more information

Check the sample partner application in the JOSSO distribution located in the src/webapp/samples/partnerappdirectory. Browse it online from our SVN repository here.