ILIAS  trunk Revision v13.0_alpha-52-g21c366bbdd4
class.ilAuthProviderSoap.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
23
25{
27 protected ilLogger $logger;
31
33 {
34 global $DIC;
35
36 $this->settings = $DIC->settings();
37 $this->logger = $DIC->logger()->auth();
38 $this->language = $DIC->language();
39 $this->rbac_admin = $DIC->rbac()->admin();
40
42 }
43
44 private function initClient(): void
45 {
46 $this->client = (new SoapAuthEndpoint($this->settings))->createValidationClient();
47 }
48
52 public function doAuthentication(ilAuthStatus $status): bool
53 {
54 try {
55 $this->initClient();
56 $this->handleSoapAuth($status);
57 } catch (Exception $e) {
58 $this->getLogger()->error($e->getMessage());
59 $this->getLogger()->error($e->getTraceAsString());
60
61 $this->handleAuthenticationFail($status, 'err_wrong_login');
62
63 return false;
64 }
65
66 if ($status->getAuthenticatedUserId() > 0 && $status->getAuthenticatedUserId() !== ANONYMOUS_USER_ID) {
67 $this->logger->info('Successfully authenticated user via SOAP: ' . $this->getCredentials()->getUsername());
69 ilSession::set('used_external_auth_mode', ilAuthUtils::AUTH_SOAP);
70
71 return true;
72 }
73
74 $this->handleAuthenticationFail($status, 'err_wrong_login');
75
76 return false;
77 }
78
79 private function handleSoapAuth(ilAuthStatus $status): bool
80 {
81 $this->logger->debug(sprintf(
82 'Login observer called for SOAP authentication request of ext_account "%s" and auth_mode "%s".',
83 $this->getCredentials()->getUsername(),
84 'soap'
85 ));
86 $this->logger->debug(sprintf(
87 'Trying to find ext_account "%s" for auth_mode "%s".',
88 $this->getCredentials()->getUsername(),
89 'soap'
90 ));
91
93 'soap',
94 $this->getCredentials()->getUsername()
95 );
96
97 $is_new_user = false;
98 if ($internal_login === '' || $internal_login === null) {
99 $is_new_user = true;
100 }
101
102 $valid = $this->client->validateSession(
103 $this->getCredentials()->getUsername(),
104 $this->getCredentials()->getPassword(),
105 $is_new_user
106 )->validation;
107
108 if ($valid['valid'] !== true) {
109 $valid['valid'] = false;
110 }
111
112 if (!$valid['valid']) {
113 $status->setReason('err_wrong_login');
114 return false;
115 }
116
117 if (!$is_new_user) {
118 $status->setAuthenticatedUserId(ilObjUser::_lookupId($internal_login));
119 return true;
120 }
121
122 if (!$this->settings->get('soap_auth_create_users')) {
123 $status->setTranslatedReason($this->language->txt('err_valid_login_account_creation_disabled'));
124 return false;
125 }
126
127 $user_obj = new ilObjUser();
128 $internal_login = ilAuthUtils::_generateLogin($this->getCredentials()->getUsername());
129
130 $usr_data = [];
131 $usr_data['firstname'] = $valid['firstname'];
132 $usr_data['lastname'] = $valid['lastname'];
133 $usr_data['email'] = $valid['email'];
134 $usr_data['login'] = $internal_login;
135 $usr_data['passwd'] = '';
136 $usr_data['passwd_type'] = ilObjUser::PASSWD_CRYPTED;
137
138 $password = '';
139 if ($this->settings->get('soap_auth_allow_local')) {
141 $password = $passwords[0];
142 $usr_data['passwd'] = $password;
143 $usr_data['passwd_type'] = ilObjUser::PASSWD_PLAIN;
144 }
145
146 $usr_data['auth_mode'] = 'soap';
147 $usr_data['ext_account'] = $this->getCredentials()->getUsername();
148 $usr_data['profile_incomplete'] = 1;
149
150 $user_obj->assignData($usr_data);
151 $user_obj->setTitle($user_obj->getFullname());
152 $user_obj->setDescription($user_obj->getEmail());
153 $user_obj->setLanguage($this->language->getDefaultLanguage());
154
155 $user_obj->setTimeLimitOwner(USER_FOLDER_ID);
156 $user_obj->setTimeLimitUnlimited(true);
157 $user_obj->setTimeLimitFrom(time());
158 $user_obj->setTimeLimitUntil(time());
159 $user_obj->setOwner(0);
160 $user_obj->create();
161 $user_obj->setActive(true);
162 $user_obj->saveAsNew();
163 $user_obj->updateOwner();
164 $user_obj->writePrefs();
165
166 $this->rbac_admin->assignUser(
167 (int) $this->settings->get('soap_auth_user_default_role', '4'),
168 $user_obj->getId()
169 );
170
171 if ($this->settings->get('soap_auth_account_mail', '0')) {
172 $registration_settings = new ilRegistrationSettings();
173 $registration_settings->setPasswordGenerationStatus(true);
174
175 $account_mail = new ilAccountRegistrationMail(
176 $registration_settings,
177 $this->language,
178 $this->logger
179 );
180 $account_mail
181 ->withDirectRegistrationMode()
182 ->send($user_obj, $password, false);
183 }
184
185 $status->setAuthenticatedUserId($user_obj->getId());
186 return true;
187 }
188}
Class ilAccountRegistrationMail.
SessionValidationClient $client
handleSoapAuth(ilAuthStatus $status)
doAuthentication(ilAuthStatus $status)
@inheritDoc
__construct(ilAuthCredentials $credentials)
handleAuthenticationFail(ilAuthStatus $status, string $a_reason)
ilAuthCredentials $credentials
setTranslatedReason(string $a_reason)
Set translated reason.
setReason(string $a_reason)
Set reason.
setAuthenticatedUserId(int $a_id)
setStatus(int $a_status)
Set auth status.
const int STATUS_AUTHENTICATED
getAuthenticatedUserId()
Get authenticated user id.
const int AUTH_SOAP
static _generateLogin(string $a_login)
generate free login by starting with a default string and adding postfix numbers
language handling
Component logger with individual log levels by component id.
User class.
const PASSWD_CRYPTED
const PASSWD_PLAIN
static _lookupId(string|array $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 ilRbacAdmin Core functions for role based access control.
Class ilObjAuthSettingsGUI.
static generatePasswords(int $a_number)
Generate a number of passwords.
static set(string $a_var, $a_val)
Set a value.
ILIAS Setting Class.
const USER_FOLDER_ID
Definition: constants.php:33
const ANONYMOUS_USER_ID
Definition: constants.php:27
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26