예제 #1
0
 /**
  * Returns if the current or specified user was authenticated
  * via LDAP.
  *
  * @param   JUser|integer|array  $user  Optional user id (if null then uses current user).
  *
  * @return  boolean  True if user is Ldap authenticated or False otherwise.
  *
  * @since   2.0
  * @deprecated  [2.1] Use SHAdapterMap::getUser instead.
  */
 public static function isUserLdap($user = null)
 {
     // This is inefficient but has to be done to prevent issues with numeric usernames
     if (!($id = JUserHelper::getUserId($user))) {
         $id = $user;
     }
     if ($links = SHAdapterMap::getUser($id, true)) {
         if (strtolower($links[0]['adapter']) === 'ldap') {
             return true;
         }
     }
     return false;
 }
예제 #2
0
 /**
  * Gets the user adapter for the user specified. Creates a new user
  * adapter if one doesnt already exist for the user.
  *
  * @param   array|string  $user     Either a username string or array of credentials including JUser ID and domain.
  * @param   string        $type     Type of adapter (e.g. ldap, xml, federated).
  * @param   array         $options  An array of optional options including isNew.
  *
  * @return  SHUserAdapter  Object to user adapter.
  *
  * @since   2.0
  * @throws  Exception
  */
 public static function getUserAdapter($user, $type = null, $options = array())
 {
     if (is_array($user)) {
         $username = strtolower(JArrayHelper::getValue($user, 'username', null, 'string'));
         $credentials = $user;
     } else {
         $username = strtolower((string) $user);
         $credentials = array('username' => $username);
     }
     if (empty($username)) {
         throw new RuntimeException(JText::_('LIB_SHFACTORY_ERR_2121'), 2121);
     }
     if (!isset(self::$adapters[$username])) {
         $config = self::getConfig();
         // Check if this user is in the blacklist
         if ($blacklist = (array) json_decode($config->get('user.blacklist'))) {
             if (in_array($username, $blacklist)) {
                 throw new RuntimeException(JText::sprintf('LIB_SHFACTORY_ERR_2125', $username), 2125);
             }
         }
         // Attempts to get the user linking entry to determine domain and type of user
         //TODO: allow multiple domains from links
         if ($links = SHAdapterMap::getUser($username)) {
             if ((bool) $config->get('user.usedomain', true)) {
                 if (!isset($credentials['domain'])) {
                     // Attempt to get the domain for this user
                     $credentials['domain'] = $links[0]['domain'];
                 }
             } else {
                 unset($credentials['domain']);
             }
             if (!isset($credentials['type']) && is_null($type)) {
                 // Attempt to get the User Adapter name
                 $type = $links[0]['adapter'];
             }
         }
         if (is_null($type)) {
             // Get the default/primary user adapter type from the database
             $type = $config->get('user.type', 'Default');
         }
         // Camel case friendly for class name
         $type = ucfirst(strtolower($type));
         $class = "SHUserAdapters{$type}";
         if (class_exists($class)) {
             // Create the adapter (note: remember to unset if using multiple adapters!)
             self::$adapters[$username] = new $class($credentials, null, $options);
         } else {
             throw new RuntimeException(JText::sprintf('LIB_SHFACTORY_ERR_2123', $class), 2123);
         }
     } else {
         // Update credentials if required
         if ($password = JArrayHelper::getValue($user, 'password', false)) {
             self::$adapters[$username]->updateCredential($password, $options);
         }
     }
     return self::$adapters[$username];
 }
예제 #3
0
 /**
  * Method is called on user login failure.
  *
  * @param   array  $response  The authentication response.
  *
  * @return  void
  *
  * @since   2.0
  */
 public function onUserLoginFailure($response)
 {
     if ($username = JArrayHelper::getValue($response, 'username', false, 'string')) {
         // Check if the user exists in the J! database
         if ($id = JUserHelper::getUserId($username)) {
             // Check if the attempted login was an adapter user, if so then fire the event
             if ($userLink = SHAdapterMap::getUser($id, true)) {
                 SHAdapterEventHelper::triggerEvent($userLink[0]['adapter'], 'onUserLoginFailure', array($response));
             }
         }
     }
 }