Richard Bruno
navigation
Home
admin









Apache 2 - Cassifier un repertoire - PHPCAS
October 18th, 2016

Méthode 1


Récupérer la distrib ici http://www.ja-sig.org/wiki/display/CASC/phpCAS
copier CAS.php et le répertoire CAS dans /usr/share/php
that's all folks !

Méthode 2



- apt-get install php-pear
- pear install http://www.ja-sig.org/downloads/cas-clients/php/1.0.1/CAS-1.0.1.tgz
- apt-get install php5-curl
- pear install http://www.ja-sig.org/downloads/cas-clients/php/1.0.1/CAS-1.0.1.tgz


- Dans le répertoire /usr/share/php/ sont copiés :
-> un répertoire CAS
-> un fichier CAS.php
- test :


<?php

//
// phpCAS simple client with HTML output customization
//

// import phpCAS lib
include_once('CAS.php');

// initialize phpCAS
phpCAS::client(CAS_VERSION_2_0,'cas.domaine.fr',443,'/cas');

// no SSL validation for the CAS server
phpCAS::setNoCasServerValidation();

// customize HTML output
phpCAS::setHTMLHeader('
<html>
<head>
<title>__TITLE__</title>
</head>
<body>
<h1>__TITLE__</h1>
');
phpCAS::setHTMLFooter('
<address>
phpCAS __PHPCAS_VERSION__,
CAS __CAS_VERSION__ (__SERVER_BASE_URL__)
</address>
</body>
</html>
');


// force CAS authentication
phpCAS::forceAuthentication();

// at this step, the user has been authenticated by the CAS server
// and the user's login name can be read with phpCAS::getUser().

// for this test, simply print that the authentication was successfull
?>
<html>
<head>
<title>phpCAS simple client with HTML output customization</title>
</head>
<body>
<h1>Successfull Authentication!</h1>
<p>the user's login is <?php echo phpCAS::getUser(); ?>.</p>
<p>phpCAS version is <?php echo phpCAS::getVersion(); ?>.</p>
</body>
</html>



Mise à jour


Erreur :

iq:/usr/local# pear install http://downloads.jasig.org/cas-clients/php/1.1.2/CAS-1.1.2.tgz
Skipping package "__uri/CAS", already installed as version 1.0.1
No valid packages found
install failed


Solution :

iq:/usr/local# pear uninstall "__uri/CAS"
uninstall ok: channel://__uri/CAS-1.0.1




Ajouter une vérification d'attributs du LDAP



cf http://iq.domaine.fr/phpcas_protected/

on rajoute dans le code (en plus du code du phpCAS) :


<?
// bruno
include('fonctions_ldap.php');

if (!verif_attribut_ldap("title=IGE"">
{
print "<h1>Désolé, vous n'êtes pas autorisé à vous connecter sur cette page.</h1>";
exit();
}

?>



avec fonctions_ldap.php :


<?
function verif_attribut_ldap($attribut)
{

include('/etc/apache2/auth/connexion_ldap_iq.php');

$retour = FALSE;

$ds=ldap_connect($server);
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
if ($ds)
{
// on s'authentifie
$r=ldap_bind($ds,$rootdn,$rootpw);
$dn = "ou=people,dc=domaine,dc=fr";
$uid = phpCAS::getUser();
$filtre="(&(uid=$uid)($attribut">";
$restriction = array( "sn", "givenName", "uid", "mail", "title");
$sr=ldap_search($ds, $dn, $filtre, $restriction);
$info = ldap_get_entries($ds, $sr);
if ($info["count"] == 1)
{
$retour = TRUE;
}
}

return $retour;
}
?>





Dernières modifs
Selinux (October 24th, 2020)
Apache 2 - Cassifier un repertoire - PHPCAS (October 18th, 2016)
Apache 2 - Authentification LDAP (October 18th, 2016)
Cas (October 18th, 2016)
Eduroam (October 18th, 2016)
Hashage (October 18th, 2016)
Keepass (October 18th, 2016)

Contact
Pour m'envoyer un mail,
Pour me laisser un commentaire :
richard.brunooo
chez
gmail.com


powered by kure, modified by Bruno