ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilAuthProviderRadius.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 include_once './Services/Authentication/classes/Provider/class.ilAuthProvider.php';
6 include_once './Services/Authentication/interfaces/interface.ilAuthProviderInterface.php';
7 include_once './Services/Authentication/interfaces/interface.ilAuthProviderAccountMigrationInterface.php';
8 
16 {
17  const CONNECT_TIMEOUT = 3;
18  const RETRIES = 1;
19 
23  private $settings = null;
24 
25  private $external_account = '';
26 
27 
29  {
30  parent::__construct($credentials);
31 
32  include_once './Services/Radius/classes/class.ilRadiusSettings.php';
34  }
35 
36 
42  {
43  }
44 
50  {
51  $radius = radius_auth_open();
52 
53  foreach ($this->settings->getServers() as $server) {
54  $this->getLogger()->debug('Using: ' . $server . ':' . $this->settings->getPort());
55  radius_add_server(
56  $radius,
57  trim($server),
58  $this->settings->getPort(),
59  $this->settings->getSecret(),
60  self::CONNECT_TIMEOUT,
61  self::RETRIES
62  );
63  }
64 
65  radius_create_request($radius, RADIUS_ACCESS_REQUEST);
66  radius_put_attr($radius, RADIUS_USER_NAME, $this->getCredentials()->getUsername());
67  radius_put_attr($radius, RADIUS_USER_PASSWORD, $this->getCredentials()->getPassword());
68 
69  $this->getLogger()->debug('username: ' . $this->getCredentials()->getUsername());
70 
71  $result = radius_send_request($radius);
72 
73  switch ($result) {
74  case RADIUS_ACCESS_ACCEPT:
75  $this->getLogger()->info('Radius authentication successful.');
77 
78  $local_login = ilObjUser::_checkExternalAuthAccount('radius', $this->getCredentials()->getUsername());
79  $status->setAuthenticatedUserId(ilObjUser::_lookupId($local_login));
80  return true;
81 
82  case RADIUS_ACCESS_REJECT:
83  $this->getLogger()->info('Radius authentication rejected with message: ' . radius_strerror($radius));
84  $this->handleAuthenticationFail($status, 'err_wrong_login');
85  return false;
86 
87  case RADIUS_ACCESS_CHALLENGE:
88  $this->getLogger()->info('Radius authentication failed (access challenge): ' . radius_strerror($radius));
89  $this->handleAuthenticationFail($status, 'err_wrong_login');
90  return false;
91 
92  default:
93  $this->getLogger()->error('Radius authentication failed with message: ' . radius_strerror($radius));
94  $this->handleAuthenticationFail($status, 'err_wrong_login');
95  return false;
96  }
97  }
98 
103  public function getExternalAccountName()
104  {
106  }
107 
112  public function getTriggerAuthMode()
113  {
114  return AUTH_RADIUS;
115  }
116 
121  public function getUserAuthModeName()
122  {
123  return 'radius';
124  }
125 
131  {
132  }
133 }
settings()
Definition: settings.php:2
Interface of auth credentials.
getExternalAccountName()
get external account name
$result
getUserAuthModeName()
get user auth mode name
Description of class class.
createNewAccount(\ilAuthStatus $status)
create new account
static _lookupId($a_user_str)
Lookup id by login.
$server
Definition: sabredav.php:48
setAuthenticatedUserId($a_id)
__construct(\ilAuthCredentials $credentials)
Base class for authentication providers (radius, ldap, apache, ...)
Standard interface for auth provider implementations.
setStatus($a_status)
Set auth status.
doAuthentication(\ilAuthStatus $status)
do authentication
static _getInstance()
singleton get instance
static _checkExternalAuthAccount($a_auth, $a_account, $tryFallback=true)
check whether external account and authentication method matches with a user
getLogger()
Get logger.
handleAuthenticationFail(ilAuthStatus $status, $a_reason)
Handle failed authentication.
getTriggerAuthMode()
get trigger auth mode
Auth status implementation.
migrateAccount(ilAuthStatus $status)
Migrate existing account to radius authentication Create new account..
const AUTH_RADIUS