Commit 62b1db25992ffebd74dbb812a71564eb73d01b1e

Authored by Neil Blakey-Milner
1 parent 7479c60a

Helper functions for handling authentication.

getAuthenticatorForUser($oUser) gets the correct authenticator based on
the user's authentication source, from the authentication provider
associated with the authentication source.

checkPassword($oUser, $sPassword) uses the above function to get the
authenticator for the user, and then calls its checkPassword method with
the same parameters.


git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@4200 c91229c3-7414-0410-bfa2-8a42b809f60b
lib/authentication/authenticationutil.inc.php 0 → 100644
  1 +<?php
  2 +
  3 +require_once(KT_LIB_DIR . '/authentication/authenticationsource.inc.php');
  4 +require_once(KT_LIB_DIR . '/authentication/builtinauthenticationprovider.inc.php');
  5 +require_once(KT_LIB_DIR . '/authentication/authenticationproviderregistry.inc.php');
  6 +
  7 +class KTAuthenticationUtil {
  8 + function checkPassword ($oUser, $sPassword) {
  9 + $oUser =& KTUtil::getObject('User', $oUser);
  10 + $oAuthenticator =& KTAuthenticationUtil::getAuthenticatorForUser($oUser);
  11 + return $oAuthenticator->checkPassword($oUser, $sPassword);
  12 + }
  13 +
  14 + function &getAuthenticatorForUser($oUser) {
  15 + $iAuthenticationSourceId = $oUser->getAuthenticationSourceId();
  16 + if (empty($iAuthenticationSourceId)) {
  17 + $oProvider = new KTBuiltinAuthenticationProvider;
  18 + } else {
  19 + $oSource = KTAuthenticationSource::get($iAuthenticationSourceId);
  20 + $sProvider = $oSource->getAuthenticationProvider();
  21 + $oRegistry =& KTAuthenticationProviderRegistry::getSingleton();
  22 + $oProvider = $oRegistry->getAuthenticationProvider($sProvider);
  23 + }
  24 + return $oProvider->getAuthenticator($oSource);
  25 + }
  26 +}