/
PageSystemConfiguration.java
386 lines (313 loc) · 13.2 KB
/
PageSystemConfiguration.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
/*
* Copyright (c) 2010-2015 Evolveum
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.evolveum.midpoint.web.page.admin.configuration;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import com.evolveum.midpoint.web.application.Url;
import com.evolveum.midpoint.web.page.admin.configuration.component.*;
import com.evolveum.midpoint.web.page.admin.configuration.dto.*;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import org.apache.commons.lang.StringUtils;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.extensions.markup.html.tabs.AbstractTab;
import org.apache.wicket.extensions.markup.html.tabs.ITab;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.request.mapper.parameter.PageParameters;
import org.apache.wicket.util.string.StringValue;
import com.evolveum.midpoint.gui.api.model.LoadableModel;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.gui.api.util.WebModelServiceUtils;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.delta.DiffUtil;
import com.evolveum.midpoint.prism.delta.ObjectDelta;
import com.evolveum.midpoint.schema.GetOperationOptions;
import com.evolveum.midpoint.schema.SelectorOptions;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.security.api.AuthorizationConstants;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.logging.LoggingUtils;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.application.AuthorizationAction;
import com.evolveum.midpoint.web.application.PageDescriptor;
import com.evolveum.midpoint.web.component.AjaxButton;
import com.evolveum.midpoint.web.component.AjaxSubmitButton;
import com.evolveum.midpoint.web.component.TabbedPanel;
import com.evolveum.midpoint.web.component.form.Form;
import com.evolveum.midpoint.web.page.error.PageError;
import com.evolveum.prism.xml.ns._public.types_3.ItemPathType;
/**
* @author lazyman
*/
@PageDescriptor(
urls = {
@Url(mountUrl = "/admin/config", matchUrlForSecurity = "/admin/config"),
@Url(mountUrl = "/admin/config/system"),
},
action = {
@AuthorizationAction(actionUri = PageAdminConfiguration.AUTH_CONFIGURATION_ALL,
label = PageAdminConfiguration.AUTH_CONFIGURATION_ALL_LABEL,
description = PageAdminConfiguration.AUTH_CONFIGURATION_ALL_DESCRIPTION),
@AuthorizationAction(actionUri = AuthorizationConstants.AUTZ_UI_CONFIGURATION_SYSTEM_CONFIG_URL,
label = "PageSystemConfiguration.auth.configSystemConfiguration.label",
description = "PageSystemConfiguration.auth.configSystemConfiguration.description")
})
public class PageSystemConfiguration extends PageAdminConfiguration {
public static final String SELECTED_TAB_INDEX = "tab";
public static final int CONFIGURATION_TAB_BASIC = 0;
public static final int CONFIGURATION_TAB_NOTIFICATION = 1;
public static final int CONFIGURATION_TAB_LOGGING = 2;
public static final int CONFIGURATION_TAB_PROFILING = 3;
public static final int CONFIGURATION_TAB_ADMIN_GUI = 4;
private static final Trace LOGGER = TraceManager.getTrace(PageSystemConfiguration.class);
private static final String DOT_CLASS = PageSystemConfiguration.class.getName() + ".";
private static final String TASK_GET_SYSTEM_CONFIG = DOT_CLASS + "getSystemConfiguration";
private static final String TASK_UPDATE_SYSTEM_CONFIG = DOT_CLASS + "updateSystemConfiguration";
private static final String ID_MAIN_FORM = "mainForm";
private static final String ID_TAB_PANEL = "tabPanel";
private static final String ID_CANCEL = "cancel";
private static final String ID_SAVE = "save";
public static final String ROOT_APPENDER_INHERITANCE_CHOICE = "(Inherit root)";
private LoggingConfigPanel loggingConfigPanel;
private ProfilingConfigPanel profilingConfigPanel;
private SystemConfigPanel systemConfigPanel;
private AdminGuiConfigPanel adminGuiConfigPanel;
private NotificationConfigPanel notificationConfigPanel;
private LoadableModel<SystemConfigurationDto> model;
private boolean initialized;
public PageSystemConfiguration() {
this(null);
}
public PageSystemConfiguration(PageParameters parameters) {
super(parameters);
model = new LoadableModel<SystemConfigurationDto>(false) {
@Override
protected SystemConfigurationDto load() {
return loadSystemConfiguration();
}
};
initLayout();
}
private SystemConfigurationDto loadSystemConfiguration() {
Task task = createSimpleTask(TASK_GET_SYSTEM_CONFIG);
OperationResult result = new OperationResult(TASK_GET_SYSTEM_CONFIG);
Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(
GetOperationOptions.createResolve(), SystemConfigurationType.F_DEFAULT_USER_TEMPLATE,
SystemConfigurationType.F_GLOBAL_PASSWORD_POLICY);
SystemConfigurationDto dto = null;
try {
PrismObject<SystemConfigurationType> systemConfig = WebModelServiceUtils.loadObject(
SystemConfigurationType.class, SystemObjectsType.SYSTEM_CONFIGURATION.value(), options,
this, task, result);
dto = new SystemConfigurationDto(systemConfig);
result.recordSuccess();
} catch (Exception ex) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load system configuration", ex);
result.recordFatalError("Couldn't load system configuration.", ex);
}
// what do you do with null? many components depends on this not to be
// null :)
if (!WebComponentUtil.isSuccessOrHandledError(result) || dto == null) {
showResult(result, false);
throw getRestartResponseException(PageError.class);
}
return dto;
}
private void initLayout() {
Form mainForm = new Form(ID_MAIN_FORM, true);
add(mainForm);
List<ITab> tabs = new ArrayList<>();
tabs.add(new AbstractTab(createStringResource("pageSystemConfiguration.system.title")) {
@Override
public WebMarkupContainer getPanel(String panelId) {
systemConfigPanel = new SystemConfigPanel(panelId, model);
return systemConfigPanel;
}
});
tabs.add(new AbstractTab(createStringResource("pageSystemConfiguration.notifications.title")) {
@Override
public WebMarkupContainer getPanel(String panelId) {
notificationConfigPanel = new NotificationConfigPanel(panelId,
new PropertyModel<NotificationConfigurationDto>(model, "notificationConfig"));
return notificationConfigPanel;
}
});
tabs.add(new AbstractTab(createStringResource("pageSystemConfiguration.logging.title")) {
@Override
public WebMarkupContainer getPanel(String panelId) {
loggingConfigPanel = new LoggingConfigPanel(panelId,
new PropertyModel<LoggingDto>(model, "loggingConfig"));
return loggingConfigPanel;
}
});
tabs.add(new AbstractTab(createStringResource("pageSystemConfiguration.profiling.title")) {
@Override
public WebMarkupContainer getPanel(String panelId) {
profilingConfigPanel = new ProfilingConfigPanel(panelId,
new PropertyModel<ProfilingDto>(model, "profilingDto"), PageSystemConfiguration.this);
return profilingConfigPanel;
}
});
tabs.add(new AbstractTab(createStringResource("pageSystemConfiguration.adminGui.title")) {
@Override
public WebMarkupContainer getPanel(String panelId) {
adminGuiConfigPanel = new AdminGuiConfigPanel(panelId, model);
return adminGuiConfigPanel;
}
});
TabbedPanel tabPanel = new TabbedPanel(ID_TAB_PANEL, tabs) {
@Override
protected void onTabChange(int index) {
PageParameters params = getPageParameters();
params.set(SELECTED_TAB_INDEX, index);
}
};
tabPanel.setOutputMarkupId(true);
mainForm.add(tabPanel);
initButtons(mainForm);
}
@Override
protected void onBeforeRender() {
super.onBeforeRender();
if (!initialized) {
PageParameters params = getPageParameters();
StringValue val = params.get(SELECTED_TAB_INDEX);
String value = null;
if (val != null && !val.isNull()) {
value = val.toString();
}
int index = StringUtils.isNumeric(value) ? Integer.parseInt(value) : CONFIGURATION_TAB_BASIC;
getTabPanel().setSelectedTab(index);
initialized = true;
}
}
private void initButtons(Form mainForm) {
AjaxSubmitButton save = new AjaxSubmitButton(ID_SAVE, createStringResource("PageBase.button.save")) {
@Override
protected void onSubmit(AjaxRequestTarget target,
org.apache.wicket.markup.html.form.Form<?> form) {
savePerformed(target);
}
@Override
protected void onError(AjaxRequestTarget target, org.apache.wicket.markup.html.form.Form form) {
target.add(getFeedbackPanel());
}
};
mainForm.add(save);
AjaxButton cancel = new AjaxButton(ID_CANCEL, createStringResource("PageBase.button.cancel")) {
@Override
public void onClick(AjaxRequestTarget target) {
cancelPerformed(target);
}
};
mainForm.add(cancel);
}
private TabbedPanel getTabPanel() {
return (TabbedPanel) get(createComponentPath(ID_MAIN_FORM, ID_TAB_PANEL));
}
private void savePerformed(AjaxRequestTarget target) {
OperationResult result = new OperationResult(TASK_UPDATE_SYSTEM_CONFIG);
String oid = SystemObjectsType.SYSTEM_CONFIGURATION.value();
Task task = createSimpleTask(TASK_UPDATE_SYSTEM_CONFIG);
try {
SystemConfigurationType newObject = model.getObject().getNewObject();
saveObjectPolicies(newObject);
saveAdminGui(newObject);
ObjectDelta<SystemConfigurationType> delta = DiffUtil.diff(model.getObject().getOldObject(), newObject);
delta.normalize();
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("System configuration delta:\n{}", delta.debugDump());
}
if (delta != null && !delta.isEmpty()) {
getPrismContext().adopt(delta);
getModelService().executeChanges(WebComponentUtil.createDeltaCollection(delta), null, task,
result);
}
result.computeStatusIfUnknown();
} catch (Exception e) {
result.recomputeStatus();
result.recordFatalError("Couldn't save system configuration.", e);
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't save system configuration.", e);
}
showResult(result);
target.add(getFeedbackPanel());
resetPerformed(target);
}
private void saveObjectPolicies(SystemConfigurationType systemConfig) {
if (systemConfigPanel == null) {
return;
}
List<ObjectPolicyConfigurationTypeDto> configList = systemConfigPanel.getModel().getObject()
.getObjectPolicyList();
List<ObjectPolicyConfigurationType> confList = new ArrayList<>();
ObjectPolicyConfigurationType newObjectPolicyConfig;
for (ObjectPolicyConfigurationTypeDto o : configList) {
if (o.isEmpty()){
continue;
}
newObjectPolicyConfig = new ObjectPolicyConfigurationType();
newObjectPolicyConfig.setType(o.getType());
newObjectPolicyConfig.setSubtype(o.getSubtype());
newObjectPolicyConfig.setObjectTemplateRef(o.getTemplateRef());
List<PropertyConstraintType> constraintList = new ArrayList<>();
PropertyConstraintType property;
if (o.getConstraints() != null) {
for (PropertyConstraintTypeDto c : o.getConstraints()) {
if (StringUtils.isNotEmpty(c.getPropertyPath())) {
property = new PropertyConstraintType();
property.setOidBound(c.isOidBound());
property.setPath(new ItemPathType(c.getPropertyPath()));
constraintList.add(property);
}
}
}
newObjectPolicyConfig.getPropertyConstraint().addAll(constraintList);
confList.add(newObjectPolicyConfig);
}
if (confList.isEmpty()){
if (!systemConfig.getDefaultObjectPolicyConfiguration().isEmpty()){
systemConfig.getDefaultObjectPolicyConfiguration().clear();
}
return;
}
systemConfig.getDefaultObjectPolicyConfiguration().clear();
systemConfig.getDefaultObjectPolicyConfiguration().addAll(confList);
}
private void saveAdminGui(SystemConfigurationType systemConfig) {
if (adminGuiConfigPanel == null) {
return;
}
SystemConfigurationDto linksList = adminGuiConfigPanel.getModel().getObject();
//update userDashboardLink list
systemConfig.getAdminGuiConfiguration().getUserDashboardLink().clear();
systemConfig.getAdminGuiConfiguration().getUserDashboardLink().addAll(linksList.getUserDashboardLink());
//update additionalMenu list
systemConfig.getAdminGuiConfiguration().getAdditionalMenuLink().clear();
systemConfig.getAdminGuiConfiguration().getAdditionalMenuLink().addAll(linksList.getAdditionalMenuLink());
}
private void resetPerformed(AjaxRequestTarget target) {
int index = getTabPanel().getSelectedTab();
PageParameters params = new PageParameters();
params.add(SELECTED_TAB_INDEX, index);
PageSystemConfiguration page = new PageSystemConfiguration(params);
setResponsePage(page);
}
private void cancelPerformed(AjaxRequestTarget target) {
resetPerformed(target);
}
}