ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
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

string $server_host = ''
 
string $server_port = ''
 
string $server_uri = ''
 
bool $server_https = false
 
string $server_nms = ''
 
bool $use_dot_net = false
 
string $uri = ''
 
nusoap_client $client
 
ilLogger $logger
 
ilSetting $settings
 
ilLanguage $language
 
ilRbacAdmin $rbacAdmin
 

Private Member Functions

 initClient ()
 
 handleSoapAuth (ilAuthStatus $status)
 

Additional Inherited Members

- Protected Member Functions inherited from ilAuthProvider
 handleAuthenticationFail (ilAuthStatus $status, string $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 24 of file class.ilAuthProviderSoap.php.

Constructor & Destructor Documentation

◆ __construct()

ilAuthProviderSoap::__construct ( ilAuthCredentials  $credentials)

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

References $DIC, ILIAS\MetaData\Repository\Validation\Data\__construct(), ILIAS\UI\examples\Symbol\Glyph\Language\language(), ILIAS\Repository\logger(), and ILIAS\Repository\settings().

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

Member Function Documentation

◆ doAuthentication()

ilAuthProviderSoap::doAuthentication ( ilAuthStatus  $status)

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

References Vendor\Package\$e, ANONYMOUS_USER_ID, ilAuthUtils\AUTH_SOAP, ilAuthStatus\getAuthenticatedUserId(), ilAuthProvider\getCredentials(), ilAuthProvider\getLogger(), handleSoapAuth(), initClient(), ILIAS\Repository\logger(), ilSession\set(), ilAuthStatus\setStatus(), ilAuthStatus\setTranslatedReason(), ilAuthStatus\STATUS_AUTHENTICATED, and ilAuthStatus\STATUS_AUTHENTICATION_FAILED.

77  : bool
78  {
79  try {
80  $this->initClient();
81  $this->handleSoapAuth($status);
82  } catch (Exception $e) {
83  $this->getLogger()->error($e->getMessage());
84  $this->getLogger()->error($e->getTraceAsString());
85  $status->setTranslatedReason($e->getMessage());
86  }
87 
88  if ($status->getAuthenticatedUserId() > 0 && $status->getAuthenticatedUserId() !== ANONYMOUS_USER_ID) {
89  $this->logger->info('Successfully authenticated user via SOAP: ' . $this->getCredentials()->getUsername());
91  ilSession::set('used_external_auth_mode', ilAuthUtils::AUTH_SOAP);
92 
93  return true;
94  }
95 
97 
98  return false;
99  }
const ANONYMOUS_USER_ID
Definition: constants.php:27
const STATUS_AUTHENTICATION_FAILED
handleSoapAuth(ilAuthStatus $status)
getAuthenticatedUserId()
Get authenticated user id.
setStatus(int $a_status)
Set auth status.
getLogger()
Get logger.
setTranslatedReason(string $a_reason)
Set translated reason.
static set(string $a_var, $a_val)
Set a value.
+ Here is the call graph for this function:

◆ handleSoapAuth()

ilAuthProviderSoap::handleSoapAuth ( ilAuthStatus  $status)
private

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

References $valid, ilObjUser\_checkExternalAuthAccount(), ilAuthUtils\_generateLogin(), ilObjUser\_lookupId(), ilSecuritySettingsChecker\generatePasswords(), ilAuthProvider\getCredentials(), ILIAS\UI\examples\Symbol\Glyph\Language\language(), ILIAS\Repository\logger(), ilObjUser\PASSWD_CRYPTED, ilObjUser\PASSWD_PLAIN, ilAuthStatus\setAuthenticatedUserId(), ilAuthStatus\setReason(), ILIAS\Repository\settings(), ilAuthStatus\setTranslatedReason(), and USER_FOLDER_ID.

Referenced by doAuthentication().

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

◆ initClient()

ilAuthProviderSoap::initClient ( )
private

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

References $server_host, $server_port, $server_uri, and ILIAS\Repository\settings().

Referenced by doAuthentication().

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

Field Documentation

◆ $client

nusoap_client ilAuthProviderSoap::$client
protected

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

◆ $language

ilLanguage ilAuthProviderSoap::$language
protected

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

◆ $logger

ilLogger ilAuthProviderSoap::$logger
protected

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

◆ $rbacAdmin

ilRbacAdmin ilAuthProviderSoap::$rbacAdmin
protected

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

◆ $server_host

string ilAuthProviderSoap::$server_host = ''
protected

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

Referenced by initClient().

◆ $server_https

bool ilAuthProviderSoap::$server_https = false
protected

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

◆ $server_nms

string ilAuthProviderSoap::$server_nms = ''
protected

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

◆ $server_port

string ilAuthProviderSoap::$server_port = ''
protected

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

Referenced by initClient().

◆ $server_uri

string ilAuthProviderSoap::$server_uri = ''
protected

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

Referenced by initClient().

◆ $settings

ilSetting ilAuthProviderSoap::$settings
protected

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

◆ $uri

string ilAuthProviderSoap::$uri = ''
protected

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

◆ $use_dot_net

bool ilAuthProviderSoap::$use_dot_net = false
protected

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


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