[Jaws-commits] r12496 - in trunk/jaws/html/include/Jaws: . Auth

afz at jaws-project.com afz at jaws-project.com
Fri Jan 27 16:48:04 UTC 2012


Author: afz
Date: 2012-01-27 16:48:03 +0000 (Fri, 27 Jan 2012)
New Revision: 12496

Added:
   trunk/jaws/html/include/Jaws/Auth/LDAP.php
   trunk/jaws/html/include/Jaws/Auth/POP3.php
Removed:
   trunk/jaws/html/include/Jaws/Auth/LDAPAuthentication.php
   trunk/jaws/html/include/Jaws/Auth/POP3Authentication.php
Modified:
   trunk/jaws/html/include/Jaws/Auth/Default.php
   trunk/jaws/html/include/Jaws/Auth/IMAP.php
   trunk/jaws/html/include/Jaws/Session.php
Log:
compatible IMAP, POP3 and LDAP authentication methods with new changes

Modified: trunk/jaws/html/include/Jaws/Auth/Default.php
===================================================================
--- trunk/jaws/html/include/Jaws/Auth/Default.php	2012-01-27 16:44:37 UTC (rev 12495)
+++ trunk/jaws/html/include/Jaws/Auth/Default.php	2012-01-27 16:48:03 UTC (rev 12496)
@@ -43,7 +43,9 @@
         $result = $this->_Model->Valid($user, $password, false);
         if (!Jaws_Error::IsError($result)) {
             $this->_AuthID = $result['id'];
+            return $this->_AuthID;
         }
+
         return $result;
     }
 

Modified: trunk/jaws/html/include/Jaws/Auth/IMAP.php
===================================================================
--- trunk/jaws/html/include/Jaws/Auth/IMAP.php	2012-01-27 16:44:37 UTC (rev 12495)
+++ trunk/jaws/html/include/Jaws/Auth/IMAP.php	2012-01-27 16:48:03 UTC (rev 12496)
@@ -11,22 +11,16 @@
 class Jaws_Auth_IMAP
 {
     /**
-     * MBox resource
-     * @access private
-     */
-    var $_MBox;
-
-    /**
      * Authentication ID
      * @access private
      */
-    var $_AuthID = 0;
+    var $_AuthID = '';
 
     /**
-     * Authentication ID
+     * username
      * @access private
      */
-    var $_User = 0;
+    var $_User = '';
 
     /**
      * IMAP server
@@ -65,18 +59,22 @@
      */
     function Auth($user, $password)
     {
-        $this->_User   = $user;
-        $this->_AuthID = 0;
-        $this->_MBox = @imap_open('{'.$this->_Server.':'.$this->_Port.($this->_SSL?'/imap/ssl':'').'}INBOX',
-                                  $user,
-                                  $password);
-        if ($this->_MBox) {
-            $result = array();
-            $result['id'] = $this->_AuthID;
-            $result['concurrent_logins'] = 0;
-            return $result;
+        if (!function_exists('imap_open')) {
+            return Jaws_Error::raiseError('Undefined function imap_open()',
+                                          'Jaws_Auth_IMAP',
+                                          JAWS_ERROR_ERROR);
         }
 
+        $mbox = @imap_open('{'.$this->_Server.':'.$this->_Port.($this->_SSL?'/imap/ssl':'').'}INBOX',
+                           $user,
+                           $password);
+        if ($mbox) {
+            @imap_close($mbox);
+            $this->_User   = $user;
+            $this->_AuthID = strtolower('imap:'.$user);
+            return $this->_AuthID; 
+        }
+
         return Jaws_Error::raiseError(_t('GLOBAL_ERROR_LOGIN_WRONG'),
                                       'Jaws_Auth_IMAP',
                                       JAWS_ERROR_ERROR);

Copied: trunk/jaws/html/include/Jaws/Auth/LDAP.php (from rev 12473, trunk/jaws/html/include/Jaws/Auth/LDAPAuthentication.php)
===================================================================
--- trunk/jaws/html/include/Jaws/Auth/LDAP.php	                        (rev 0)
+++ trunk/jaws/html/include/Jaws/Auth/LDAP.php	2012-01-27 16:48:03 UTC (rev 12496)
@@ -0,0 +1,117 @@
+<?php
+/**
+ * LDAP authentication class
+ *
+ * @category   Auth
+ * @package    Core
+ * @author     Ali Fazelzadeh <afz at php.net>
+ * @author     Pablo Fischer <pablo at pablo.com.mx>
+ * @copyright  2005-2012 Jaws Development Group
+ * @license    http://www.gnu.org/copyleft/lesser.html
+ */
+class Jaws_Auth_LDAP
+{
+    /**
+     * LDAP connection
+     * @access private
+     */
+    var $_LdapConnection;
+
+    /**
+     * Authentication ID
+     * @access private
+     */
+    var $_AuthID = '';
+
+    /**
+     * username
+     * @access private
+     */
+    var $_User = '';
+
+    /**
+     * LDAP server
+     * @access private
+     */
+    var $_Server = 'localhost';
+
+    /**
+     * LDAP port
+     * @access private
+     */
+    var $_Port = '389';
+
+    /**
+     * LDAP domain name string
+     * @access private
+     */
+    var $_DN = 'dc=foobar,dc=org';
+
+    /**
+     * Constructor
+     *
+     * @access public
+     */
+    function Jaws_Auth_LDAP()
+    {
+        $this->_Server = 'localhost';
+        $this->_Port   = '389';
+        $this->_DN     = 'dc=foobar,dc=org';
+    }
+
+    /**
+     * Authenticate user/password
+     *
+     * @access public
+     */
+    function Auth($user, $password)
+    {
+        if (!function_exists('ldap_connect')) {
+            return Jaws_Error::raiseError('Undefined function ldap_connect()',
+                                          'Jaws_Auth_LDAP',
+                                          JAWS_ERROR_ERROR);
+        }
+
+        $this->_LdapConnection = @ldap_connect($this->_Server, $this->_Port);
+        if ($this->_LdapConnection) {
+            $rdn = "uid=" . $user . "," . $this->_DN;
+            $bind = @ldap_bind($this->_LdapConnection, $rdn, $password);
+            if ($bind) {
+                $this->_User   = $user;
+                $this->_AuthID = strtolower('ldap:'.$user);
+                return $this->_AuthID; 
+            }
+        }
+
+        return Jaws_Error::raiseError(_t('GLOBAL_ERROR_LOGIN_WRONG'),
+                                      'Jaws_Auth_LDAP',
+                                      JAWS_ERROR_ERROR);
+    }
+
+    /**
+     * Attributes of logged user
+     *
+     * @access public
+     */
+    function GetAttributes()
+    {
+        $info = array();
+        $info['id']         = $this->_AuthID;
+        $info['internal']   = false;
+        $info['username']   = $this->_User;
+        $info['superadmin'] = false;
+        $info['internal']   = false;
+        $info['groups']     = array();
+        $info['nickname']   = $this->_User;
+        $info['concurrent_logins'] = 0;
+        $info['email']      = '';
+        $info['url']        = '';
+        $info['avatar']     = 'gadgets/Users/images/no-photo.png';
+        $info['language']   = '';
+        $info['theme']      = '';
+        $info['editor']     = '';
+        $info['timezone']   = null;
+        return $info;
+    }
+
+}
\ No newline at end of file

Deleted: trunk/jaws/html/include/Jaws/Auth/LDAPAuthentication.php
===================================================================
--- trunk/jaws/html/include/Jaws/Auth/LDAPAuthentication.php	2012-01-27 16:44:37 UTC (rev 12495)
+++ trunk/jaws/html/include/Jaws/Auth/LDAPAuthentication.php	2012-01-27 16:48:03 UTC (rev 12496)
@@ -1,42 +0,0 @@
-<?php
-/**
- * LDAP Authentication
- *
- * @category   Session
- * @package    Core
- * @author     Pablo Fischer <pablo at pablo.com.mx>
- * @author     Ali Fazelzadeh <afz at php.net>
- * @copyright  2005-2012 Jaws Development Group
- * @license    http://www.gnu.org/copyleft/lesser.html
- */
-define('LDAP_SERVER', 'localhost');
-define('LDAP_PORT',   '389');
-define('LDAP_DN',     'dc=foobar,dc=org');
-
-function LDAPAuthentication($user, $password)
-{
-    require_once JAWS_PATH . 'include/Jaws/User.php';
-    $userModel = new Jaws_User();
-    $ldapuser = $userModel->GetUserInfoByName($user);
-    if (Jaws_Error::IsError($ldapuser)) {
-        return $ldapuser;
-    } elseif (!isset($ldapuser['username'])) {
-        return new Jaws_Error(_t('GLOBAL_ERROR_LOGIN_WRONG'));
-    } elseif (!$ldapuser['enabled']) {
-        return new Jaws_Error(_t('GLOBAL_ERROR_LOGIN_DISABLED'));
-    } elseif (!function_exists('ldap_connect')) {
-        return new Jaws_Error(_t('GLOBAL_ERROR_FUNCTION_DOES_NOT_EXIST', 'ldap_connect'));
-    }
-
-    $ldapconn = @ldap_connect(LDAP_SERVER, LDAP_PORT);
-    if ($ldapconn) {
-        //the params of ldapbind are: resource of ldap_connect, RDN and password
-        $rdn = "uid=" . $user . "," . LDAP_DN;
-        $bind = @ldap_bind($ldapconn, $rdn, $password);
-        if ($bind) {
-            return true;
-        }
-    }
-
-    return new Jaws_Error(_t('GLOBAL_ERROR_LOGIN_WRONG'));
-}

Copied: trunk/jaws/html/include/Jaws/Auth/POP3.php (from rev 12473, trunk/jaws/html/include/Jaws/Auth/POP3Authentication.php)
===================================================================
--- trunk/jaws/html/include/Jaws/Auth/POP3.php	                        (rev 0)
+++ trunk/jaws/html/include/Jaws/Auth/POP3.php	2012-01-27 16:48:03 UTC (rev 12496)
@@ -0,0 +1,103 @@
+<?php
+/**
+ * POP3 authentication class
+ *
+ * @category   Auth
+ * @package    Core
+ * @author     Pablo Fischer <pablo at pablo.com.mx>
+ * @author     Ali Fazelzadeh <afz at php.net>
+ * @copyright  2005-2012 Jaws Development Group
+ * @license    http://www.gnu.org/copyleft/lesser.html
+ */
+class Jaws_Auth_POP3
+{
+    /**
+     * Authentication ID
+     * @access private
+     */
+    var $_AuthID = '';
+
+    /**
+     * username
+     * @access private
+     */
+    var $_User = '';
+
+    /**
+     * POP3 server
+     * @access private
+     */
+    var $_Server = 'localhost';
+
+    /**
+     * POP3 port
+     * @access private
+     */
+    var $_Port = '110';
+
+    /**
+     * Constructor
+     *
+     * @access public
+     */
+    function Jaws_Auth_POP3()
+    {
+        $this->_Server = 'localhost';
+        $this->_Port   = '110';
+    }
+
+    /**
+     * Authenticate user/password
+     *
+     * @access public
+     */
+    function Auth($user, $password)
+    {
+        if (!function_exists('imap_open')) {
+            return Jaws_Error::raiseError('Undefined function imap_open()',
+                                          'Jaws_Auth_POP3',
+                                          JAWS_ERROR_ERROR);
+        }
+
+        $mbox = @imap_open('{'.$this->_Server.'/pop3:'.$this->_Port.'/notls}INBOX',
+                           $user,
+                           $password);
+        if ($mbox) {
+            @imap_close($mbox);
+            $this->_User   = $user;
+            $this->_AuthID = strtolower('pop3:'.$user);
+            return $this->_AuthID; 
+        }
+
+        return Jaws_Error::raiseError(_t('GLOBAL_ERROR_LOGIN_WRONG'),
+                                      'Jaws_Auth_POP3',
+                                      JAWS_ERROR_ERROR);
+    }
+
+    /**
+     * Attributes of logged user
+     *
+     * @access public
+     */
+    function GetAttributes()
+    {
+        $info = array();
+        $info['id']         = $this->_AuthID;
+        $info['internal']   = false;
+        $info['username']   = $this->_User;
+        $info['superadmin'] = false;
+        $info['internal']   = false;
+        $info['groups']     = array();
+        $info['nickname']   = $this->_User;
+        $info['concurrent_logins'] = 0;
+        $info['email']      = '';
+        $info['url']        = '';
+        $info['avatar']     = 'gadgets/Users/images/no-photo.png';
+        $info['language']   = '';
+        $info['theme']      = '';
+        $info['editor']     = '';
+        $info['timezone']   = null;
+        return $info;
+    }
+
+}
\ No newline at end of file

Deleted: trunk/jaws/html/include/Jaws/Auth/POP3Authentication.php
===================================================================
--- trunk/jaws/html/include/Jaws/Auth/POP3Authentication.php	2012-01-27 16:44:37 UTC (rev 12495)
+++ trunk/jaws/html/include/Jaws/Auth/POP3Authentication.php	2012-01-27 16:48:03 UTC (rev 12496)
@@ -1,37 +0,0 @@
-<?php
-/**
- * POP3 Authentication
- *
- * @category   Session
- * @package    Core
- * @author     Pablo Fischer <pablo at pablo.com.mx>
- * @author     Ali Fazelzadeh <afz at php.net>
- * @copyright  2005-2012 Jaws Development Group
- * @license    http://www.gnu.org/copyleft/lesser.html
- */
-define('POP3_SERVER', 'localhost');
-define('POP3_PORT',   '110');
-
-function POP3Authentication($user, $password, $onlyAdmins = false)
-{
-    require_once JAWS_PATH . 'include/Jaws/User.php';
-    $userModel = new Jaws_User();
-    $pop3user = $userModel->GetUserInfoByName($user);
-    if (Jaws_Error::IsError($pop3user)) {
-        return $pop3user;
-    } elseif (!isset($pop3user['username'])) {
-        return new Jaws_Error(_t('GLOBAL_ERROR_LOGIN_WRONG'));
-    } elseif (!$pop3user['enabled']) {
-        return new Jaws_Error(_t('GLOBAL_ERROR_LOGIN_DISABLED'));
-    } elseif (!function_exists('imap_open')) {
-        return new Jaws_Error(_t('GLOBAL_ERROR_FUNCTION_DOES_NOT_EXIST', 'imap_open'));
-    }
-
-    $mbox = @imap_open('{'.POP3_SERVER.'/pop3:'.POP3_PORT.'/notls}INBOX', $user, $password);
-    if ($mbox) {
-        @imap_close($mbox);
-        return true;
-    }
-
-    return new Jaws_Error(_t('GLOBAL_ERROR_LOGIN_WRONG'));
-}

Modified: trunk/jaws/html/include/Jaws/Session.php
===================================================================
--- trunk/jaws/html/include/Jaws/Session.php	2012-01-27 16:44:37 UTC (rev 12495)
+++ trunk/jaws/html/include/Jaws/Session.php	2012-01-27 16:48:03 UTC (rev 12496)
@@ -145,16 +145,20 @@
             $this->_AuthModel = new $className();
             $result = $this->_AuthModel->Auth($username, $password);
             if (!Jaws_Error::isError($result)) {
-                $existSessions = $this->_cache->GetUserSessions($result['id'], true);
-                if (empty($existSessions) ||
-                    empty($result['concurrent_logins']) ||
-                    $result['concurrent_logins'] > $existSessions)
-                {
-                    $info = $this->_AuthModel->GetAttributes();
-                    $this->Create($info, $remember);
-                    return true;
-                } else {
-                    $result = new Jaws_Error(_t('GLOBAL_ERROR_LOGIN_CONCURRENT_REACHED'));
+                $result = $this->_AuthModel->GetAttributes();
+                if (!Jaws_Error::isError($result)) {
+                    $existSessions = 0;
+                    if (!empty($result['concurrent_logins'])) {
+                        $existSessions = $this->_cache->GetUserSessions($result['id'], true);
+                    }
+
+                    if (empty($existSessions) || $result['concurrent_logins'] > $existSessions)
+                    {
+                        $this->Create($result, $remember);
+                        return true;
+                    } else {
+                        $result = new Jaws_Error(_t('GLOBAL_ERROR_LOGIN_CONCURRENT_REACHED'));
+                    }
                 }
             }
 
@@ -290,7 +294,7 @@
     function Create($info = array(), $remember = false)
     {
         if (empty($info)) {
-            $info['id']         = 0;
+            $info['id']         = '';
             $info['internal']   = false;
             $info['username']   = '';
             $info['superadmin'] = false;
@@ -317,7 +321,7 @@
         $this->SetAttribute('concurrent_logins', $info['concurrent_logins']);
         $this->SetAttribute('longevity',  $remember?
                                           (int)$GLOBALS['app']->Registry->Get('/policy/session_remember_timeout')*3600 : 0);
-        $this->SetAttribute('logged',     $info['id'] !== 0);
+        $this->SetAttribute('logged',     !empty($info['id']));
         //profile
         $this->SetAttribute('nickname',   $info['nickname']);
         $this->SetAttribute('email',      $info['email']);
@@ -340,7 +344,7 @@
     function Reset()
     {
         $this->_Attribute = array();
-        $this->SetAttribute('user',       0);
+        $this->SetAttribute('user',       '');
         $this->SetAttribute('salt',       uniqid(mt_rand(), true));
         $this->SetAttribute('type',       APP_TYPE);
         $this->SetAttribute('internal',   false);



More information about the Jaws-commits mailing list