00001 <?php 00032 class Kerberos5Auth implements AuthInterface { 00033 00039 private $filename; 00040 00046 private $server; 00047 00053 private $username; 00054 00060 private $password; 00061 00065 private $resource; 00066 00073 public function __construct($auth, $extra_args){ 00074 00075 if(!extension_loaded("kadm5")){ 00076 throw new AuthException("Debe cargar la extensión de php llamada kadm5"); 00077 } 00078 00079 foreach(array('server', 'username', 'principal', 'password') as $param){ 00080 if(isset($extra_args[$param])){ 00081 $this->$param = $extra_args[$param]; 00082 } else { 00083 throw new AuthException("Debe especificar el parametro '$param' en los parámetros"); 00084 } 00085 } 00086 } 00087 00092 public function get_identity(){ 00093 if(!$this->resource){ 00094 new AuthException("La conexion al servidor kerberos5 es invalida"); 00095 } 00096 $identity = array("username" => $this->username, "realm" => $this->username); 00097 return $identity; 00098 } 00099 00105 public function authenticate(){ 00106 $this->resource = kadm5_init_with_password($this->server, $this->realm, $this->principal, $this->password); 00107 if($this->resource===false){ 00108 return false; 00109 } else { 00110 return true; 00111 } 00112 } 00113 00118 public function get_principals(){ 00119 if(!$this->resource){ 00120 new AuthException("La conexion al servidor kerberos5 es invalida"); 00121 } 00122 return kadm5_get_principals($this->resource); 00123 } 00124 00129 public function get_policies(){ 00130 if(!$this->resource){ 00131 new AuthException("La conexion al servidor kerberos5 es invalida"); 00132 } 00133 return kadm5_get_policies($this->resource); 00134 } 00135 00140 public function __destruct(){ 00141 if($this->resource){ 00142 kadm5_destroy($this->resource); 00143 } 00144 } 00145 00151 public function set_params($extra_args){ 00152 foreach(array('server', 'principal', 'username', 'password') as $param){ 00153 if(isset($extra_args[$param])){ 00154 $this->$param = $extra_args[$param]; 00155 } 00156 } 00157 } 00158 00159 }