Wiki » Historique » Version 1
Gaston TJEBBES, 01/06/2010 16:04
| 1 | 1 | Gaston TJEBBES | h1. Cassification d'une application sur Scribe |
|---|---|---|---|
| 2 | 1 | Gaston TJEBBES | |
| 3 | 1 | Gaston TJEBBES | Scribe est fourni avec un serveur d'authentification SSO compatible CAS. Cette page a pour objectif de guider les utilisateurs (administrateurs) de Scribe à utiliser le mode SSO dans leurs applications web php. Les indications fournies permettent de garantir la compatibilité avec les version 0.5 et 1.0.1 de la librairie php-cas sur laquelle se base le paquet php5-cas. |
| 4 | 1 | Gaston TJEBBES | |
| 5 | 1 | Gaston TJEBBES | h2. Cas n°1 : authentification simple |
| 6 | 1 | Gaston TJEBBES | |
| 7 | 1 | Gaston TJEBBES | Ici, seule l'authentification de l'utilisateur est nécessaire (l'application ne requière aucune autre information). La cassification de l'accès à une page reste très simple (fonctionnement du Cas classique). On utilisera la configuration centralisée située dans /usr/share/php/configCAS/cas.inc.php. |
| 8 | 1 | Gaston TJEBBES | |
| 9 | 1 | Gaston TJEBBES | h3. Initialisation du client |
| 10 | 1 | Gaston TJEBBES | |
| 11 | 1 | Gaston TJEBBES | <pre> |
| 12 | 1 | Gaston TJEBBES | <?php |
| 13 | 1 | Gaston TJEBBES | require_once('CAS/CAS.php'); |
| 14 | 1 | Gaston TJEBBES | require_once('configCAS/cas.inc.php'); |
| 15 | 1 | Gaston TJEBBES | phpCAS::client(__CAS_VERSION, __CAS_SERVER, __CAS_PORT, __CAS_URL, false); |
| 16 | 1 | Gaston TJEBBES | </pre> |
| 17 | 1 | Gaston TJEBBES | Les variables __CAS... sont configurées dans le fichier 'cas.inc.php'. La variable à false signifie qu'une session php a déjà été démarrée avant l'appel au client. |
| 18 | 1 | Gaston TJEBBES | |
| 19 | 1 | Gaston TJEBBES | h3. Désactivation du contrôle de certificats |
| 20 | 1 | Gaston TJEBBES | |
| 21 | 1 | Gaston TJEBBES | En attendant une méthode stable de gestion des certificats, nous utiliserons la méthode setNoCasServerValidation : |
| 22 | 1 | Gaston TJEBBES | <pre> |
| 23 | 1 | Gaston TJEBBES | if (method_exists(phpCAS, 'setNoCasServerValidation')){ |
| 24 | 1 | Gaston TJEBBES | phpCAS::setNoCasServerValidation(); |
| 25 | 1 | Gaston TJEBBES | } |
| 26 | 1 | Gaston TJEBBES | </pre> |
| 27 | 1 | Gaston TJEBBES | |
| 28 | 1 | Gaston TJEBBES | L'utilisation de la fonction method_exists permet d'assuere la compatibilité avec les différentes version du client phpCas (paquet php5-cas) |
| 29 | 1 | Gaston TJEBBES | |
| 30 | 1 | Gaston TJEBBES | h3. Authentification |
| 31 | 1 | Gaston TJEBBES | |
| 32 | 1 | Gaston TJEBBES | <pre> |
| 33 | 1 | Gaston TJEBBES | phpCAS::forceAuthentication(); |
| 34 | 1 | Gaston TJEBBES | </pre> |
| 35 | 1 | Gaston TJEBBES | La redirection vers le serveur CAS est effectuée si nécessaire, par la suite le code est éxécuté dans un contexte authentifié. |
| 36 | 1 | Gaston TJEBBES | |
| 37 | 1 | Gaston TJEBBES | h3. Déconnexion |
| 38 | 1 | Gaston TJEBBES | |
| 39 | 1 | Gaston TJEBBES | <pre> |
| 40 | 1 | Gaston TJEBBES | if (isset($_REQUEST['logout'])) { |
| 41 | 1 | Gaston TJEBBES | if (method_exists(phpCAS, 'logoutWithUrl')){ |
| 42 | 1 | Gaston TJEBBES | phpCAS::logoutWithUrl($_SERVER["SCRIPT_URI"]); |
| 43 | 1 | Gaston TJEBBES | }else{ |
| 44 | 1 | Gaston TJEBBES | phpCAS::logout($_SERVER["SCRIPT_URI"]); |
| 45 | 1 | Gaston TJEBBES | } |
| 46 | 1 | Gaston TJEBBES | } |
| 47 | 1 | Gaston TJEBBES | </pre> |
| 48 | 1 | Gaston TJEBBES | |
| 49 | 1 | Gaston TJEBBES | La variable de redirection ici : $_SERVER["SCRIPT_URI"] peut être remplacée par la page de logout prévue au départ dans l'application. |
| 50 | 1 | Gaston TJEBBES | |
| 51 | 1 | Gaston TJEBBES | h3. Déconnexion centralisée |
| 52 | 1 | Gaston TJEBBES | |
| 53 | 1 | Gaston TJEBBES | <pre> |
| 54 | 1 | Gaston TJEBBES | if (__CAS_LOGOUT){ |
| 55 | 1 | Gaston TJEBBES | if (method_exists(phpCAS, 'logoutRequests')){ |
| 56 | 1 | Gaston TJEBBES | phpCAS::logoutRequests(); |
| 57 | 1 | Gaston TJEBBES | } |
| 58 | 1 | Gaston TJEBBES | } |
| 59 | 1 | Gaston TJEBBES | </pre> |
| 60 | 1 | Gaston TJEBBES | La variable __CAS_LOGOUT est configuré dans le fichier configCAS/cas.inc.php. |
| 61 | 1 | Gaston TJEBBES | A noter : cette fonction fournit par le client CAS d'origine a un fonctionnement très limité, elle ne fonctionne pas lorsque le nom de la session est forcé par l'application cassifié (appel à session_name(nomdelasession)). |
| 62 | 1 | Gaston TJEBBES | Dans ce cas, préféré l'utilisation de la librairie eolePhpCAS. |
| 63 | 1 | Gaston TJEBBES | |
| 64 | 1 | Gaston TJEBBES | h3. Forcer l'url de votre application auprès du serveur CAS |
| 65 | 1 | Gaston TJEBBES | |
| 66 | 1 | Gaston TJEBBES | Dans certains cas, par exemple : |
| 67 | 1 | Gaston TJEBBES | Accès au travers d'un reverseproxy d'une application http par le protocole https et port 80 fermé sur le reverseproxy. |
| 68 | 1 | Gaston TJEBBES | |
| 69 | 1 | Gaston TJEBBES | Il peut être utile de forcer l'url de l'application. |
| 70 | 1 | Gaston TJEBBES | <pre> |
| 71 | 1 | Gaston TJEBBES | phpCAS::setFixedServiceURL("https://adressedemonapplication"); |
| 72 | 1 | Gaston TJEBBES | </pre> |
| 73 | 1 | Gaston TJEBBES | Il est possible de construire l'url depuis les variables php ($_SERVER par exemple). |
| 74 | 1 | Gaston TJEBBES | |
| 75 | 1 | Gaston TJEBBES | |
| 76 | 1 | Gaston TJEBBES | h3. Récupération du login de l'utilisateur |
| 77 | 1 | Gaston TJEBBES | |
| 78 | 1 | Gaston TJEBBES | <pre> |
| 79 | 1 | Gaston TJEBBES | phpCAS::getUser(); |
| 80 | 1 | Gaston TJEBBES | </pre> |
| 81 | 1 | Gaston TJEBBES | |
| 82 | 1 | Gaston TJEBBES | h3. Le tout dans des fonctions |
| 83 | 1 | Gaston TJEBBES | |
| 84 | 1 | Gaston TJEBBES | <pre> |
| 85 | 1 | Gaston TJEBBES | <?php |
| 86 | 1 | Gaston TJEBBES | function cas_auth(){ |
| 87 | 1 | Gaston TJEBBES | require_once('CAS/CAS.php'); |
| 88 | 1 | Gaston TJEBBES | require_once('configCAS/cas.inc.php'); |
| 89 | 1 | Gaston TJEBBES | phpCAS::client(__CAS_VERSION, __CAS_SERVER, __CAS_PORT, __CAS_URL, false); |
| 90 | 1 | Gaston TJEBBES | if (method_exists(phpCAS, 'setNoCasServerValidation')){ |
| 91 | 1 | Gaston TJEBBES | phpCAS::setNoCasServerValidation(); |
| 92 | 1 | Gaston TJEBBES | } |
| 93 | 1 | Gaston TJEBBES | if (__CAS_LOGOUT){ |
| 94 | 1 | Gaston TJEBBES | if (method_exists(phpCAS, 'logoutRequests')){ |
| 95 | 1 | Gaston TJEBBES | phpCAS::logoutRequests(); |
| 96 | 1 | Gaston TJEBBES | } |
| 97 | 1 | Gaston TJEBBES | } |
| 98 | 1 | Gaston TJEBBES | phpCAS::forceAuthentication(); |
| 99 | 1 | Gaston TJEBBES | } |
| 100 | 1 | Gaston TJEBBES | function cas_logout( |
| 101 | 1 | Gaston TJEBBES | require_once('CAS/CAS.php'); |
| 102 | 1 | Gaston TJEBBES | require_once('configCAS/cas.inc.php'); |
| 103 | 1 | Gaston TJEBBES | phpCAS::client(__CAS_VERSION, __CAS_SERVER, __CAS_PORT, __CAS_URL, false); |
| 104 | 1 | Gaston TJEBBES | if (method_exists(phpCAS, 'setNoCasServerValidation')){ |
| 105 | 1 | Gaston TJEBBES | phpCAS::setNoCasServerValidation(); |
| 106 | 1 | Gaston TJEBBES | } |
| 107 | 1 | Gaston TJEBBES | if (method_exists(phpCAS, 'logoutWithUrl')){ |
| 108 | 1 | Gaston TJEBBES | phpCAS::logoutWithUrl($_SERVER["SCRIPT_URI"]); |
| 109 | 1 | Gaston TJEBBES | }else{ |
| 110 | 1 | Gaston TJEBBES | phpCAS::logout($_SERVER["SCRIPT_URI"]); |
| 111 | 1 | Gaston TJEBBES | } |
| 112 | 1 | Gaston TJEBBES | } |
| 113 | 1 | Gaston TJEBBES | ?> |
| 114 | 1 | Gaston TJEBBES | </pre> |