ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
ApacheAuthSettingsForm.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use ilAuthUtils;
30use ILIAS\UI\Factory as UIFactory;
31use ilLanguage;
32use ilLDAPServer;
33use ilObject;
34use ilRbacReview;
35use ilRbacSystem;
36
38{
39 private UIFactory $ui_factory;
44 private FieldFactory $ui_field;
45
49 public function __construct(
50 private int $ref_id,
51 private object $parentObject,
52 private string $show_command,
53 private string $save_command,
54 private array $values = [],
55 ?UIFactory $ui_factory = null,
56 ?ilLanguage $lng = null,
60 ) {
61 global $DIC;
62
63 $this->ui_factory = $ui_factory ?? $DIC->ui()->factory();
64 $this->lng = $lng ?? $DIC->language();
65 $this->rbac_system = $rbac_system ?? $DIC->rbac()->system();
66 $this->rbac_review = $rbac_review ?? $DIC->rbac()->review();
67 $this->ctrl = $ctrl ?? $DIC->ctrl();
68
69 $this->ui_field = $this->ui_factory->input()->field();
70
71 $this->lng->loadLanguageModule('auth');
72 }
73
74 public function buildForm(): StandardForm
75 {
76 $access = $this->rbac_system->checkAccess('write', $this->ref_id);
77 $inputs = [
78 'apache_enable_auth' => $this->buildEnableAuthInput(),
79 'apache_enable_local' => $this->ui_field->checkbox($this->lng->txt('apache_enable_local'))
80 ->withValue((bool) ($this->values['apache_enable_local'] ?? true)),
81 'apache_enable_ldap' => $this->buildLdapEnableInput(),
82 'apache_auth_indicator_name' => $this->ui_field->text($this->lng->txt('apache_auth_indicator_name'))
83 ->withRequired(true)
84 ->withValue($this->values['apache_auth_indicator_name'] ?? ''),
85 'apache_auth_indicator_value' => $this->ui_field->text($this->lng->txt('apache_auth_indicator_value'))
86 ->withRequired(true)
87 ->withValue($this->values['apache_auth_indicator_value'] ?? ''),
88 'apache_auth_enable_override_login_page' => $this->buildAuthEnableOverrideLoginPageInput(),
89 'apache_auth_authenticate_on_login_page' => $this->ui_field->checkbox($this->lng->txt('apache_auth_authenticate_on_login_page'))
90 ->withValue((bool) ($this->values['apache_auth_authenticate_on_login_page'] ?? true)),
91 'apache_auth_username_config' => $this->ui_field->section([
92 'apache_auth_username_config_type' => $this->buildAuthUsernameConfigTypeInput()
93 ], $this->lng->txt('apache_auth_username_config')),
94 'apache_auth_security' => $this->ui_field->section([
95 'apache_auth_domains' => $this->ui_field->textarea(
96 $this->lng->txt('apache_auth_domains'),
97 $this->lng->txt('apache_auth_domains_description')
98 )->withValue($this->values['apache_auth_domains'] ?? '')
99 ], $this->lng->txt('apache_auth_security'))
100 ];
101
102 if (!$access) {
103 foreach ($inputs as $key => $input) {
104 $inputs[$key] = $input->withDisabled(true);
105 }
106 }
107
108
109 $form = $this->ui_factory->input()->container()->form()->standard(
110 $this->ctrl->getFormAction($this->parentObject, $access ? $this->save_command : $this->show_command),
111 $inputs
112 );
113
114 if (!$access) {
115 $form = $form->withSubmitLabel($this->lng->txt('refresh'));
116 }
117
118 return $form;
119 }
120
122 {
123 $roleOptions = [];
124 foreach ($this->rbac_review->getGlobalRolesArray() as $role) {
125 $roleOptions[$role['obj_id']] = ilObject::_lookupTitle($role['obj_id']);
126 }
127
128 $apache_default_role = $this->ui_field->select(
129 $this->lng->txt('apache_default_role'),
130 $roleOptions
131 );
132
133 $apache_local_autocreate = $this->ui_field->optionalGroup([
134 'apache_default_role' => $apache_default_role
135 ], $this->lng->txt('apache_autocreate'));
136
137 return $this->ui_field->optionalGroup([
138 'apache_local_autocreate' => $apache_local_autocreate
139 ], $this->lng->txt('apache_enable_auth'))
140 ->withValue(
141 $this->checkGroupEnabled('apache_enable_auth')
142 ? [
143 'apache_local_autocreate' => $this->checkGroupEnabled('apache_local_autocreate')
144 ? [
145 'apache_default_role' => $this->values['apache_default_role'] ?? 4
146 ]
147 : null
148 ]
149 : null
150 );
151 }
152
154 {
155 $servers = ilLDAPServer::getServerIds();
156
157 if ($servers !== []) {
158 $options[0] = $this->lng->txt('select_one');
159 foreach ($servers as $server_id) {
160 $ldap_server = new ilLDAPServer($server_id);
161 $options[$server_id] = $ldap_server->getName();
162 }
163
164 $apache_enable_ldap = $this->ui_field->optionalGroup([
165 'apache_ldap_sid' => $this->ui_field->select($this->lng->txt('auth_ldap_server_ds'), $options)
166 ->withRequired(true)
167 ], $this->lng->txt('apache_enable_ldap'), $this->lng->txt('apache_ldap_hint_ldap_must_be_configured'))
168 ->withValue(
169 $this->checkGroupEnabled('apache_enable_ldap')
170 ? [
171 'apache_ldap_sid' => $this->values['apache_ldap_sid'] ?? ilLDAPServer::getDataSource(ilAuthUtils::AUTH_APACHE)
172 ]
173 : null
174 );
175 } else {
176 $apache_enable_ldap = $this->ui_field->checkbox(
177 $this->lng->txt('apache_enable_ldap'),
178 $this->lng->txt('apache_ldap_hint_ldap_must_be_configured')
179 )->withValue((bool) ($this->values['apache_enable_ldap'] ?? true));
180 }
181
182 return $apache_enable_ldap;
183 }
184
186 {
187 return $this->ui_field->optionalGroup([
188 'apache_auth_target_override_login_page' => $this->ui_field->text($this->lng->txt('apache_auth_target_override_login'))
189 ->withRequired(true)
190 ], $this->lng->txt('apache_auth_enable_override_login'))
191 ->withValue(
192 $this->checkGroupEnabled('apache_auth_enable_override_login_page')
193 ? [
194 'apache_auth_target_override_login_page' => $this->values['apache_auth_target_override_login_page'] ?? ''
195 ]
196 : null
197 );
198 }
199
201 {
202 return $this->ui_field->switchableGroup([
203 '1' => $this->ui_field->group([
204 'apache_auth_username_direct_mapping_fieldname' => $this->ui_field->text(
205 $this->lng->txt('apache_auth_username_direct_mapping_fieldname')
206 )->withValue($this->values['apache_auth_username_direct_mapping_fieldname'] ?? '')
207 ], $this->lng->txt('apache_auth_username_direct_mapping')),
208 '2' => $this->ui_field->group([], $this->lng->txt('apache_auth_username_extended_mapping'))->withDisabled(true),
209 '3' => $this->ui_field->group([], $this->lng->txt('apache_auth_username_by_function')),
210 ], $this->lng->txt('apache_auth_username_config_type'))
211 ->withValue(
212 isset($this->values['apache_auth_username_config_type']) &&
213 $this->values['apache_auth_username_config_type'] !== '' ?
214 $this->values['apache_auth_username_config_type'] :
215 '1'
216 );
217 }
218
219 private function checkGroupEnabled(string $post_var): bool
220 {
221 return isset($this->values[$post_var]) && $this->values[$post_var];
222 }
223}
__construct(private int $ref_id, private object $parentObject, private string $show_command, private string $save_command, private array $values=[], ?UIFactory $ui_factory=null, ?ilLanguage $lng=null, ?ilRbacSystem $rbac_system=null, ?ilRbacReview $rbac_review=null, ?ilCtrlInterface $ctrl=null)
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
const int AUTH_APACHE
static getDataSource(int $a_auth_mode)
static getServerIds()
Get all server ids.
language handling
Class ilObject Basic functions for all objects.
static _lookupTitle(int $obj_id)
class ilRbacReview Contains Review functions of core Rbac.
class ilRbacSystem system function like checkAccess, addActiveRole ... Supporting system functions ar...
This describes a standard form.
Definition: Standard.php:30
This describes checkbox inputs.
Definition: Checkbox.php:29
This is what a factory for input fields looks like.
Definition: Factory.php:31
This describes optional group inputs.
This describes switchable group inputs.
withValue($value)
Get an input like this with another value displayed on the client side.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$ref_id
Definition: ltiauth.php:66
global $DIC
Definition: shib_login.php:26