ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilAuthProviderSoap Class Reference

Class ilAuthProviderSoap. More...

+ Inheritance diagram for ilAuthProviderSoap:
+ Collaboration diagram for ilAuthProviderSoap:

Public Member Functions

 __construct (ilAuthCredentials $credentials)
 
 doAuthentication (ilAuthStatus $status)
 
- Public Member Functions inherited from ilAuthProvider
 __construct (ilAuthCredentials $credentials)
 Constructor. More...
 
 getLogger ()
 Get logger. More...
 
 getCredentials ()
 
- Public Member Functions inherited from ilAuthProviderInterface
 doAuthentication (\ilAuthStatus $status)
 Do authentication. More...
 

Protected Attributes

 $server_host = ''
 
 $server_port = ''
 
 $server_uri = ''
 
 $server_https = ''
 
 $server_nms = ''
 
 $use_dot_net = false
 
 $uri = ''
 
 $client
 
 $logger
 
 $settings
 
 $language
 
 $rbacAdmin
 

Private Member Functions

 initClient ()
 
 handleSoapAuth (ilAuthStatus $status)
 

Additional Inherited Members

- Data Fields inherited from ilAuthProvider
const STATUS_UNDEFINED = 0
 
const STATUS_AUTHENTICATION_SUCCESS = 1
 
const STATUS_AUTHENTICATION_FAILED = 2
 
const STATUS_MIGRATION = 3
 
- Protected Member Functions inherited from ilAuthProvider
 handleAuthenticationFail (ilAuthStatus $status, $a_reason)
 Handle failed authentication. More...
 

Detailed Description

Class ilAuthProviderSoap.

Author
Michael Jansen mjans.nosp@m.en@d.nosp@m.ataba.nosp@m.y.de

Definition at line 8 of file class.ilAuthProviderSoap.php.

Constructor & Destructor Documentation

◆ __construct()

ilAuthProviderSoap::__construct ( ilAuthCredentials  $credentials)

Definition at line 38 of file class.ilAuthProviderSoap.php.

References $DIC, and settings().

39  {
40  global $DIC;
41 
42  $this->settings = $DIC->settings();
43  $this->logger = $DIC->logger()->auth();
44  $this->language = $DIC->language();
45  $this->rbacAdmin = $DIC->rbac()->admin();
46 
47  parent::__construct($credentials);
48  }
settings()
Definition: settings.php:2
global $DIC
Definition: saml.php:7
+ Here is the call graph for this function:

Member Function Documentation

◆ doAuthentication()

ilAuthProviderSoap::doAuthentication ( ilAuthStatus  $status)

Definition at line 79 of file class.ilAuthProviderSoap.php.

References ilAuthStatus\getAuthenticatedUserId(), ilAuthProvider\getCredentials(), ilAuthProvider\getLogger(), handleSoapAuth(), initClient(), ilSession\set(), ilAuthStatus\setStatus(), ilAuthStatus\setTranslatedReason(), ilAuthStatus\STATUS_AUTHENTICATED, and ilAuthStatus\STATUS_AUTHENTICATION_FAILED.

80  {
81  try {
82  $this->initClient();
83  $this->handleSoapAuth($status);
84  } catch (Exception $e) {
85  $this->getLogger()->error($e->getMessage());
86  $status->setTranslatedReason($e->getMessage());
87  }
88 
89  if ($status->getAuthenticatedUserId() > 0) {
90  $this->logger->info('Successfully authenticated user via SOAP: ' . $this->getCredentials()->getUsername());
92  ilSession::set('used_external_auth', true);
93 
94  return true;
95  }
96 
98 
99  return false;
100  }
const STATUS_AUTHENTICATION_FAILED
handleSoapAuth(ilAuthStatus $status)
static set($a_var, $a_val)
Set a value.
getAuthenticatedUserId()
Get authenticated user id.
setTranslatedReason($a_reason)
Set translated reason.
setStatus($a_status)
Set auth status.
getLogger()
Get logger.
+ Here is the call graph for this function:

◆ handleSoapAuth()

ilAuthProviderSoap::handleSoapAuth ( ilAuthStatus  $status)
private
Parameters
ilAuthStatus$status
Returns
bool

Definition at line 106 of file class.ilAuthProviderSoap.php.

References $password, $valid, ilObjUser\_checkExternalAuthAccount(), ilAuthUtils\_generateLogin(), ilObjUser\_lookupId(), ilUtil\generatePasswords(), ilAuthProvider\getCredentials(), IL_PASSWD_CRYPTED, IL_PASSWD_PLAIN, ilAuthStatus\setAuthenticatedUserId(), ilAuthStatus\setReason(), settings(), ilAuthStatus\setTranslatedReason(), and USER_FOLDER_ID.

Referenced by doAuthentication().

106  : bool
107  {
108  $this->logger->debug(sprintf(
109  'Login observer called for SOAP authentication request of ext_account "%s" and auth_mode "%s".',
110  $this->getCredentials()->getUsername(),
111  'soap'
112  ));
113  $this->logger->debug(sprintf(
114  'Trying to find ext_account "%s" for auth_mode "%s".',
115  $this->getCredentials()->getUsername(),
116  'soap'
117  ));
118 
119  $internalLogin = ilObjUser::_checkExternalAuthAccount(
120  'soap',
121  $this->getCredentials()->getUsername()
122  );
123 
124  $isNewUser = false;
125  if ('' === $internalLogin || false === $internalLogin) {
126  $isNewUser = true;
127  }
128 
129  $soapAction = '';
130  $nspref = '';
131  if ($this->use_dot_net) {
132  $soapAction = $this->server_nms . '/isValidSession';
133  $nspref = 'ns1:';
134  }
135 
136  $valid = $this->client->call(
137  'isValidSession',
138  [
139  $nspref . 'ext_uid' => $this->getCredentials()->getUsername(),
140  $nspref . 'soap_pw' => $this->getCredentials()->getPassword(),
141  $nspref . 'new_user' => $isNewUser
142  ],
143  $this->server_nms,
144  $soapAction
145  );
146 
147  if ($valid['valid'] !== true) {
148  $valid['valid'] = false;
149  }
150 
151  if (!$valid['valid']) {
152  $status->setReason('err_wrong_login');
153  return false;
154  }
155 
156  if (!$isNewUser) {
157  $status->setAuthenticatedUserId(ilObjUser::_lookupId($internalLogin));
158  return true;
159  } elseif (!$this->settings->get('soap_auth_create_users')) {
160  // Translate the reasons, otherwise the default failure is displayed
161  $status->setTranslatedReason($this->language->txt('err_valid_login_account_creation_disabled'));
162  return false;
163  }
164 
165  $userObj = new ilObjUser();
166  $internalLogin = ilAuthUtils::_generateLogin($this->getCredentials()->getUsername());
167 
168  $usrData = [];
169  $usrData['firstname'] = $valid['firstname'];
170  $usrData['lastname'] = $valid['lastname'];
171  $usrData['email'] = $valid['email'];
172  $usrData['login'] = $internalLogin;
173  $usrData['passwd'] = '';
174  $usrData['passwd_type'] = IL_PASSWD_CRYPTED;
175 
176  $password = '';
177  if ($this->settings->get('soap_auth_allow_local')) {
178  $passwords = ilUtil::generatePasswords(1);
179  $password = $passwords[0];
180  $usrData['passwd'] = $password;
181  $usrData['passwd_type'] = IL_PASSWD_PLAIN;
182  }
183 
184  $usrData['auth_mode'] = 'soap';
185  $usrData['ext_account'] = $this->getCredentials()->getUsername();
186  $usrData['profile_incomplete'] = 1;
187 
188  $userObj->assignData($usrData);
189  $userObj->setTitle($userObj->getFullname());
190  $userObj->setDescription($userObj->getEmail());
191  $userObj->setLanguage($this->language->getDefaultLanguage());
192 
193  $userObj->setTimeLimitOwner(USER_FOLDER_ID);
194  $userObj->setTimeLimitUnlimited(1);
195  $userObj->setTimeLimitFrom(time());
196  $userObj->setTimeLimitUntil(time());
197  $userObj->setOwner(0);
198  $userObj->create();
199  $userObj->setActive(1);
200  $userObj->updateOwner();
201  $userObj->saveAsNew(false);
202  $userObj->writePrefs();
203 
204  $this->rbacAdmin->assignUser(
205  $this->settings->get('soap_auth_user_default_role', 4),
206  $userObj->getId()
207  );
208 
209  if ($this->settings->get('soap_auth_account_mail', false)) {
210  $registrationSettings = new ilRegistrationSettings();
211  $registrationSettings->setPasswordGenerationStatus(true);
212 
213  $accountMail = new ilAccountRegistrationMail(
214  $registrationSettings,
215  $this->language,
216  $this->logger
217  );
218  $accountMail
219  ->withDirectRegistrationMode()
220  ->send($userObj, $password, false);
221  }
222 
223  $status->setAuthenticatedUserId($userObj->getId());
224  return true;
225  }
const IL_PASSWD_PLAIN
settings()
Definition: settings.php:2
$valid
const IL_PASSWD_CRYPTED
static _generateLogin($a_login)
generate free login by starting with a default string and adding postfix numbers
static _lookupId($a_user_str)
Lookup id by login.
static generatePasswords($a_number)
Generate a number of passwords.
setTranslatedReason($a_reason)
Set translated reason.
setAuthenticatedUserId($a_id)
Class ilAccountRegistrationMail.
setReason($a_reason)
Set reason.
static _checkExternalAuthAccount($a_auth, $a_account, $tryFallback=true)
check whether external account and authentication method matches with a user
$password
Definition: cron.php:14
const USER_FOLDER_ID
Class ilObjUserFolder.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ initClient()

ilAuthProviderSoap::initClient ( )
private

Definition at line 53 of file class.ilAuthProviderSoap.php.

References $server_host, $server_port, $server_uri, and settings().

Referenced by doAuthentication().

54  {
55  $this->server_host = (string) $this->settings->get('soap_auth_server', '');
56  $this->server_port = (string) $this->settings->get('soap_auth_port', '');
57  $this->server_uri = (string) $this->settings->get('soap_auth_uri', '');
58  $this->server_nms = (string) $this->settings->get('soap_auth_namespace', '');
59  $this->server_https = (bool) $this->settings->get('soap_auth_use_https', false);
60  $this->use_dot_net = (bool) $this->settings->get('use_dotnet', false);
61 
62  $this->uri = $this->server_https ? 'https://' : 'http://';
63  $this->uri .= $this->server_host;
64 
65  if ($this->server_port > 0) {
66  $this->uri .= (':' . $this->server_port);
67  }
68  if ($this->server_uri) {
69  $this->uri .= ('/' . $this->server_uri);
70  }
71 
72  require_once './webservice/soap/lib/nusoap.php';
73  $this->client = new nusoap_client($this->uri);
74  }
settings()
Definition: settings.php:2
[nu]soapclient higher level class for easy usage.
Definition: nusoap.php:7072
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $client

ilAuthProviderSoap::$client
protected

Definition at line 25 of file class.ilAuthProviderSoap.php.

◆ $language

ilAuthProviderSoap::$language
protected

Definition at line 31 of file class.ilAuthProviderSoap.php.

◆ $logger

ilAuthProviderSoap::$logger
protected

Definition at line 27 of file class.ilAuthProviderSoap.php.

◆ $rbacAdmin

ilAuthProviderSoap::$rbacAdmin
protected

Definition at line 33 of file class.ilAuthProviderSoap.php.

◆ $server_host

ilAuthProviderSoap::$server_host = ''
protected

Definition at line 11 of file class.ilAuthProviderSoap.php.

Referenced by initClient().

◆ $server_https

ilAuthProviderSoap::$server_https = ''
protected

Definition at line 17 of file class.ilAuthProviderSoap.php.

◆ $server_nms

ilAuthProviderSoap::$server_nms = ''
protected

Definition at line 19 of file class.ilAuthProviderSoap.php.

◆ $server_port

ilAuthProviderSoap::$server_port = ''
protected

Definition at line 13 of file class.ilAuthProviderSoap.php.

Referenced by initClient().

◆ $server_uri

ilAuthProviderSoap::$server_uri = ''
protected

Definition at line 15 of file class.ilAuthProviderSoap.php.

Referenced by initClient().

◆ $settings

ilAuthProviderSoap::$settings
protected

Definition at line 29 of file class.ilAuthProviderSoap.php.

◆ $uri

ilAuthProviderSoap::$uri = ''
protected

Definition at line 23 of file class.ilAuthProviderSoap.php.

◆ $use_dot_net

ilAuthProviderSoap::$use_dot_net = false
protected

Definition at line 21 of file class.ilAuthProviderSoap.php.


The documentation for this class was generated from the following file: