1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.syncope.client.console.pages;
20
21 import java.io.Serializable;
22 import java.lang.reflect.Constructor;
23 import java.time.Duration;
24 import java.util.List;
25 import java.util.stream.StreamSupport;
26 import org.apache.commons.lang3.StringUtils;
27 import org.apache.commons.lang3.tuple.Pair;
28 import org.apache.syncope.client.console.BookmarkablePageLinkBuilder;
29 import org.apache.syncope.client.console.SyncopeConsoleSession;
30 import org.apache.syncope.client.console.SyncopeWebApplication;
31 import org.apache.syncope.client.console.annotations.AMPage;
32 import org.apache.syncope.client.console.annotations.IdMPage;
33 import org.apache.syncope.client.console.panels.DelegationSelectionPanel;
34 import org.apache.syncope.client.console.rest.SyncopeRestClient;
35 import org.apache.syncope.client.console.wicket.markup.head.MetaHeaderItem;
36 import org.apache.syncope.client.console.wicket.markup.html.form.IndicatingOnConfirmAjaxLink;
37 import org.apache.syncope.client.console.widgets.ExtAlertWidget;
38 import org.apache.syncope.client.ui.commons.Constants;
39 import org.apache.syncope.client.ui.commons.HttpResourceStream;
40 import org.apache.syncope.client.ui.commons.ajax.form.IndicatorAjaxFormComponentUpdatingBehavior;
41 import org.apache.syncope.client.ui.commons.annotations.ExtPage;
42 import org.apache.syncope.client.ui.commons.pages.BaseWebPage;
43 import org.apache.syncope.client.ui.commons.rest.ResponseHolder;
44 import org.apache.syncope.common.lib.SyncopeConstants;
45 import org.apache.syncope.common.lib.info.SystemInfo;
46 import org.apache.syncope.common.lib.types.IdRepoEntitlement;
47 import org.apache.wicket.AttributeModifier;
48 import org.apache.wicket.Component;
49 import org.apache.wicket.Page;
50 import org.apache.wicket.PageReference;
51 import org.apache.wicket.ajax.AjaxRequestTarget;
52 import org.apache.wicket.ajax.attributes.AjaxCallListener;
53 import org.apache.wicket.ajax.attributes.AjaxRequestAttributes;
54 import org.apache.wicket.ajax.markup.html.AjaxLink;
55 import org.apache.wicket.authroles.authorization.strategies.role.metadata.MetaDataRoleAuthorizationStrategy;
56 import org.apache.wicket.behavior.AttributeAppender;
57 import org.apache.wicket.behavior.Behavior;
58 import org.apache.wicket.markup.ComponentTag;
59 import org.apache.wicket.markup.head.HeaderItem;
60 import org.apache.wicket.markup.head.IHeaderResponse;
61 import org.apache.wicket.markup.head.OnDomReadyHeaderItem;
62 import org.apache.wicket.markup.head.PriorityHeaderItem;
63 import org.apache.wicket.markup.html.WebMarkupContainer;
64 import org.apache.wicket.markup.html.WebPage;
65 import org.apache.wicket.markup.html.basic.Label;
66 import org.apache.wicket.markup.html.form.TextField;
67 import org.apache.wicket.markup.html.link.BookmarkablePageLink;
68 import org.apache.wicket.markup.html.link.Link;
69 import org.apache.wicket.markup.html.list.ListItem;
70 import org.apache.wicket.markup.html.list.ListView;
71 import org.apache.wicket.model.Model;
72 import org.apache.wicket.model.ResourceModel;
73 import org.apache.wicket.request.handler.resource.ResourceStreamRequestHandler;
74 import org.apache.wicket.request.mapper.parameter.PageParameters;
75 import org.apache.wicket.request.resource.ContentDisposition;
76 import org.apache.wicket.spring.injection.annot.SpringBean;
77
78 public class BasePage extends BaseWebPage {
79
80 private static final long serialVersionUID = 1571997737305598502L;
81
82 protected static final HeaderItem META_IE_EDGE = new MetaHeaderItem("X-UA-Compatible", "IE=edge");
83
84 @SpringBean
85 protected SyncopeRestClient syncopeRestClient;
86
87 public BasePage() {
88 this(null);
89 }
90
91 public BasePage(final PageParameters parameters) {
92 super(parameters);
93
94 Serializable leftMenuCollapse = SyncopeConsoleSession.get().getAttribute(Constants.MENU_COLLAPSE);
95 if ((leftMenuCollapse instanceof Boolean) && ((Boolean) leftMenuCollapse)) {
96 body.add(new AttributeAppender("class", " sidebar-collapse"));
97 }
98 add(body);
99
100
101 String username = SyncopeConsoleSession.get().getSelfTO().getUsername();
102 if (SyncopeConsoleSession.get().getDelegatedBy() != null) {
103 username += " (" + SyncopeConsoleSession.get().getDelegatedBy() + ")";
104 }
105 body.add(new Label("username", username));
106
107
108 Pair<String, String> gitAndBuildInfo = SyncopeConsoleSession.get().gitAndBuildInfo();
109 Label version = new Label("version", gitAndBuildInfo.getRight());
110 String versionLink = StringUtils.isNotBlank(gitAndBuildInfo.getLeft())
111 && gitAndBuildInfo.getRight().endsWith("-SNAPSHOT")
112 ? "https://gitbox.apache.org/repos/asf?p=syncope.git;a=commit;h="
113 + gitAndBuildInfo.getLeft()
114 : "https://cwiki.apache.org/confluence/display/SYNCOPE/Maggiore";
115 version.add(new AttributeModifier("onclick", "window.open('" + versionLink + "', '_blank')"));
116 body.add(version);
117
118 SystemInfo systemInfo = SyncopeConsoleSession.get().getSystemInfo();
119 body.add(new Label("hostname", systemInfo.getHostname()));
120 body.add(new Label("processors", systemInfo.getAvailableProcessors()));
121 body.add(new Label("os", systemInfo.getOs()));
122 body.add(new Label("jvm", systemInfo.getJvm()));
123
124 Model<Integer> tableThresholdModel = Model.of(100);
125 body.add(new TextField<>("tableThreshold", tableThresholdModel).add(
126 new IndicatorAjaxFormComponentUpdatingBehavior(Constants.ON_CHANGE) {
127
128 private static final long serialVersionUID = -1107858522700306810L;
129
130 @Override
131 protected void onUpdate(final AjaxRequestTarget target) {
132
133 }
134 }));
135
136 Link<Void> dbExportLink = new Link<>("dbExportLink") {
137
138 private static final long serialVersionUID = -4331619903296515985L;
139
140 @Override
141 public void onClick() {
142 try {
143 HttpResourceStream stream = new HttpResourceStream(new ResponseHolder(
144 syncopeRestClient.exportInternalStorageContent(tableThresholdModel.getObject())));
145
146 ResourceStreamRequestHandler rsrh = new ResourceStreamRequestHandler(stream);
147 rsrh.setFileName(stream.getFilename() == null
148 ? SyncopeConsoleSession.get().getDomain() + "Content.xml"
149 : stream.getFilename());
150 rsrh.setContentDisposition(ContentDisposition.ATTACHMENT);
151 rsrh.setCacheDuration(Duration.ZERO);
152
153 getRequestCycle().scheduleRequestHandlerAfterCurrent(rsrh);
154 } catch (Exception e) {
155 SyncopeConsoleSession.get().onException(e);
156 }
157 }
158 };
159 MetaDataRoleAuthorizationStrategy.authorize(dbExportLink, WebPage.RENDER, IdRepoEntitlement.KEYMASTER);
160 body.add(dbExportLink);
161
162
163 WebMarkupContainer liContainer = new WebMarkupContainer(getLIContainerId("dashboard"));
164 body.add(liContainer);
165 liContainer.add(BookmarkablePageLinkBuilder.build("dashboard", Dashboard.class));
166
167 liContainer = new WebMarkupContainer(getLIContainerId("realms"));
168 body.add(liContainer);
169
170 BookmarkablePageLink<? extends BasePage> link = BookmarkablePageLinkBuilder.build("realms", Realms.class);
171 MetaDataRoleAuthorizationStrategy.authorize(link, WebPage.RENDER, IdRepoEntitlement.REALM_SEARCH);
172
173 liContainer.add(link);
174
175 liContainer = new WebMarkupContainer(getLIContainerId("engagements"));
176 body.add(liContainer);
177 link = BookmarkablePageLinkBuilder.build("engagements", Engagements.class);
178 MetaDataRoleAuthorizationStrategy.authorize(link, WebPage.RENDER,
179 String.format("%s,%s", IdRepoEntitlement.TASK_LIST, IdRepoEntitlement.IMPLEMENTATION_LIST));
180 liContainer.add(link);
181
182 liContainer = new WebMarkupContainer(getLIContainerId("reports"));
183 body.add(liContainer);
184 link = BookmarkablePageLinkBuilder.build("reports", Reports.class);
185 MetaDataRoleAuthorizationStrategy.authorize(link, WebPage.RENDER, IdRepoEntitlement.REPORT_LIST);
186 liContainer.add(link);
187
188 List<Class<? extends BasePage>> idmPageClasses = SyncopeWebApplication.get().getLookup().getIdMPageClasses();
189 ListView<Class<? extends BasePage>> idmPages = new ListView<>("idmPages", idmPageClasses) {
190
191 private static final long serialVersionUID = 4949588177564901031L;
192
193 @Override
194 protected void populateItem(final ListItem<Class<? extends BasePage>> item) {
195 WebMarkupContainer containingLI = new WebMarkupContainer("idmPageLI");
196 item.add(containingLI);
197
198 IdMPage ann = item.getModelObject().getAnnotation(IdMPage.class);
199
200 BookmarkablePageLink<Page> link = new BookmarkablePageLink<>("idmPage", item.getModelObject());
201 link.add(new Label("idmPageLabel", ann.label()));
202 if (StringUtils.isNotBlank(ann.listEntitlement())) {
203 MetaDataRoleAuthorizationStrategy.authorize(link, WebPage.RENDER, ann.listEntitlement());
204 }
205 if (item.getModelObject().equals(BasePage.this.getClass())) {
206 link.add(new Behavior() {
207
208 private static final long serialVersionUID = 1469628524240283489L;
209
210 @Override
211 public void onComponentTag(final Component component, final ComponentTag tag) {
212 tag.append("class", "active", " ");
213 }
214 });
215 }
216 containingLI.add(link);
217
218 Label idmPageIcon = new Label("idmPageIcon");
219 idmPageIcon.add(new AttributeModifier("class", "nav-icon " + ann.icon()));
220 link.add(idmPageIcon);
221 }
222 };
223 idmPages.setRenderBodyOnly(true);
224 idmPages.setOutputMarkupId(true);
225 body.add(idmPages);
226
227 List<Class<? extends BasePage>> amPageClasses = SyncopeWebApplication.get().getLookup().getAMPageClasses();
228 ListView<Class<? extends BasePage>> amPages = new ListView<>("amPages", amPageClasses) {
229
230 private static final long serialVersionUID = -9112553137618363167L;
231
232 @Override
233 protected void populateItem(final ListItem<Class<? extends BasePage>> item) {
234 WebMarkupContainer containingLI = new WebMarkupContainer("amPageLI");
235 item.add(containingLI);
236
237 AMPage ann = item.getModelObject().getAnnotation(AMPage.class);
238
239 BookmarkablePageLink<Page> link = new BookmarkablePageLink<>("amPage", item.getModelObject());
240 link.add(new Label("amPageLabel", ann.label()));
241 if (StringUtils.isNotBlank(ann.listEntitlement())) {
242 MetaDataRoleAuthorizationStrategy.authorize(link, WebPage.RENDER, ann.listEntitlement());
243 }
244 if (item.getModelObject().equals(BasePage.this.getClass())) {
245 link.add(new Behavior() {
246
247 private static final long serialVersionUID = 1469628524240283489L;
248
249 @Override
250 public void onComponentTag(final Component component, final ComponentTag tag) {
251 tag.append("class", "active", " ");
252 }
253 });
254 }
255 containingLI.add(link);
256
257 Label amPageIcon = new Label("amPageIcon");
258 amPageIcon.add(new AttributeModifier("class", "nav-icon " + ann.icon()));
259 link.add(amPageIcon);
260 }
261 };
262 amPages.setRenderBodyOnly(true);
263 amPages.setOutputMarkupId(true);
264 body.add(amPages);
265
266 WebMarkupContainer keymasterLIContainer = new WebMarkupContainer(getLIContainerId("keymaster"));
267 body.add(keymasterLIContainer);
268 WebMarkupContainer keymasterULContainer = new WebMarkupContainer(getULContainerId("keymaster"));
269 keymasterLIContainer.add(keymasterULContainer);
270
271 liContainer = new WebMarkupContainer(getLIContainerId("domains"));
272 keymasterULContainer.add(liContainer);
273 link = BookmarkablePageLinkBuilder.build("domains", Domains.class);
274 liContainer.add(link);
275 if (SyncopeConstants.MASTER_DOMAIN.equals(SyncopeConsoleSession.get().getDomain())) {
276 MetaDataRoleAuthorizationStrategy.authorize(link, WebPage.RENDER, IdRepoEntitlement.KEYMASTER);
277 } else {
278 link.setOutputMarkupPlaceholderTag(true).setEnabled(false).setVisible(false);
279 }
280
281 liContainer = new WebMarkupContainer(getLIContainerId("networkservices"));
282 keymasterULContainer.add(liContainer);
283 link = BookmarkablePageLinkBuilder.build("networkservices", NetworkServices.class);
284 liContainer.add(link);
285 if (SyncopeConstants.MASTER_DOMAIN.equals(SyncopeConsoleSession.get().getDomain())) {
286 MetaDataRoleAuthorizationStrategy.authorize(link, WebPage.RENDER, IdRepoEntitlement.KEYMASTER);
287 } else {
288 link.setOutputMarkupPlaceholderTag(true).setEnabled(false).setVisible(false);
289 }
290
291 liContainer = new WebMarkupContainer(getLIContainerId("parameters"));
292 keymasterULContainer.add(liContainer);
293 link = BookmarkablePageLinkBuilder.build("parameters", Parameters.class);
294 MetaDataRoleAuthorizationStrategy.authorize(link, WebPage.RENDER, IdRepoEntitlement.KEYMASTER);
295 liContainer.add(link);
296
297 WebMarkupContainer confLIContainer = new WebMarkupContainer(getLIContainerId("configuration"));
298 body.add(confLIContainer);
299 WebMarkupContainer confULContainer = new WebMarkupContainer(getULContainerId("configuration"));
300 confLIContainer.add(confULContainer);
301
302 liContainer = new WebMarkupContainer(getLIContainerId("audit"));
303 confULContainer.add(liContainer);
304 link = BookmarkablePageLinkBuilder.build("audit", Audit.class);
305 MetaDataRoleAuthorizationStrategy.authorize(link, WebPage.RENDER, IdRepoEntitlement.AUDIT_LIST);
306 liContainer.add(link);
307
308 liContainer = new WebMarkupContainer(getLIContainerId("implementations"));
309 confULContainer.add(liContainer);
310 link = BookmarkablePageLinkBuilder.build("implementations", Implementations.class);
311 MetaDataRoleAuthorizationStrategy.authorize(link, WebPage.RENDER, IdRepoEntitlement.IMPLEMENTATION_LIST);
312 liContainer.add(link);
313
314 liContainer = new WebMarkupContainer(getLIContainerId("logs"));
315 confULContainer.add(liContainer);
316 link = BookmarkablePageLinkBuilder.build("logs", Logs.class);
317 MetaDataRoleAuthorizationStrategy.authorize(link, WebPage.RENDER, IdRepoEntitlement.LOGGER_LIST);
318 liContainer.add(link);
319
320 liContainer = new WebMarkupContainer(getLIContainerId("types"));
321 confULContainer.add(liContainer);
322 link = BookmarkablePageLinkBuilder.build("types", Types.class);
323 MetaDataRoleAuthorizationStrategy.authorize(link, WebPage.RENDER, IdRepoEntitlement.ANYTYPECLASS_LIST);
324 liContainer.add(link);
325
326 liContainer = new WebMarkupContainer(getLIContainerId("security"));
327 confULContainer.add(liContainer);
328 link = BookmarkablePageLinkBuilder.build("security", Security.class);
329 liContainer.add(link);
330
331 liContainer = new WebMarkupContainer(getLIContainerId("policies"));
332 confULContainer.add(liContainer);
333 link = BookmarkablePageLinkBuilder.build("policies", Policies.class);
334 MetaDataRoleAuthorizationStrategy.authorize(link, WebPage.RENDER, IdRepoEntitlement.POLICY_LIST);
335 liContainer.add(link);
336
337 liContainer = new WebMarkupContainer(getLIContainerId("notifications"));
338 confULContainer.add(liContainer);
339 link = BookmarkablePageLinkBuilder.build("notifications", Notifications.class);
340 MetaDataRoleAuthorizationStrategy.authorize(link, WebPage.RENDER, IdRepoEntitlement.NOTIFICATION_LIST);
341 liContainer.add(link);
342
343 body.add(new AjaxLink<Void>("collapse") {
344
345 private static final long serialVersionUID = -7978723352517770644L;
346
347 @Override
348 public void onClick(final AjaxRequestTarget target) {
349 SyncopeConsoleSession.get().setAttribute(Constants.MENU_COLLAPSE,
350 SyncopeConsoleSession.get().getAttribute(Constants.MENU_COLLAPSE) == null
351 ? true
352 : !(Boolean) SyncopeConsoleSession.get().getAttribute(Constants.MENU_COLLAPSE));
353 }
354 });
355
356 body.add(new Label("domain", SyncopeConsoleSession.get().getDomain()));
357
358 WebMarkupContainer delegationsContainer = new WebMarkupContainer("delegationsContainer");
359 body.add(delegationsContainer.setOutputMarkupPlaceholderTag(true).
360 setVisible(!SyncopeConsoleSession.get().getDelegations().isEmpty()));
361 delegationsContainer.add(new Label("delegationsHeader", new ResourceModel("delegations")));
362 delegationsContainer.add(new ListView<>("delegations", SyncopeConsoleSession.get().getDelegations()) {
363
364 private static final long serialVersionUID = -9112553137618363167L;
365
366 @Override
367 protected void populateItem(final ListItem<String> item) {
368 item.add(new DelegationSelectionPanel("delegation", item.getModelObject()));
369 }
370 });
371
372 body.add(new IndicatingOnConfirmAjaxLink<String>("endDelegation", "confirmDelegation", true) {
373
374 private static final long serialVersionUID = 1632838687547839512L;
375
376 @Override
377 public void onClick(final AjaxRequestTarget target) {
378 SyncopeConsoleSession.get().setDelegatedBy(null);
379 setResponsePage(Dashboard.class);
380 }
381 }.setOutputMarkupId(true).setOutputMarkupPlaceholderTag(true).
382 setVisible(SyncopeConsoleSession.get().getDelegatedBy() != null));
383
384 @SuppressWarnings("unchecked")
385 Class<? extends WebPage> beforeLogout = (Class<? extends WebPage>) SyncopeConsoleSession.get().
386 getAttribute(Constants.BEFORE_LOGOUT_PAGE);
387 if (beforeLogout == null) {
388 body.add(new BookmarkablePageLink<>("logout", Logout.class));
389 } else {
390 body.add(new AjaxLink<Page>("logout") {
391
392 private static final long serialVersionUID = -7978723352517770644L;
393
394 @Override
395 protected void updateAjaxAttributes(final AjaxRequestAttributes attributes) {
396 super.updateAjaxAttributes(attributes);
397
398 AjaxCallListener ajaxCallListener = new AjaxCallListener();
399 ajaxCallListener.onPrecondition("return confirm('" + getString("confirmGlobalLogout") + "');");
400 attributes.getAjaxCallListeners().add(ajaxCallListener);
401 }
402
403 @Override
404 public void onClick(final AjaxRequestTarget target) {
405 setResponsePage(beforeLogout);
406 }
407 });
408 }
409
410
411
412 WebMarkupContainer containingLI = (WebMarkupContainer) body.get(
413 getLIContainerId(getClass().getSimpleName().toLowerCase()));
414
415 if (containingLI == null) {
416 containingLI = (WebMarkupContainer) keymasterULContainer.get(
417 getLIContainerId(getClass().getSimpleName().toLowerCase()));
418 }
419
420 if (containingLI == null) {
421 containingLI = (WebMarkupContainer) confULContainer.get(
422 getLIContainerId(getClass().getSimpleName().toLowerCase()));
423 }
424
425 if (containingLI != null) {
426 StreamSupport.stream(containingLI.spliterator(), false).filter(Link.class::isInstance).
427 forEach(child -> child.add(new Behavior() {
428
429 private static final long serialVersionUID = -5775607340182293596L;
430
431 @Override
432 public void onComponentTag(final Component component, final ComponentTag tag) {
433 tag.append("class", "active", " ");
434 }
435 }));
436
437 if (keymasterULContainer.getId().equals(containingLI.getParent().getId())) {
438 keymasterULContainer.add(new Behavior() {
439
440 private static final long serialVersionUID = -5775607340182293596L;
441
442 @Override
443 public void renderHead(final Component component, final IHeaderResponse response) {
444 response.render(OnDomReadyHeaderItem.forScript(
445 "$('#keymasterLink').addClass('active')"));
446 }
447
448 @Override
449 public void onComponentTag(final Component component, final ComponentTag tag) {
450 tag.put("class", "nav nav-treeview");
451 tag.put("style", "display: block;");
452 }
453 });
454
455 keymasterLIContainer.add(new Behavior() {
456
457 private static final long serialVersionUID = -5775607340182293596L;
458
459 @Override
460 public void onComponentTag(final Component component, final ComponentTag tag) {
461 tag.put("class", "nav-item has-treeview menu-open");
462 }
463 });
464 } else if (confULContainer.getId().equals(containingLI.getParent().getId())) {
465 confULContainer.add(new Behavior() {
466
467 private static final long serialVersionUID = 3109256773218160485L;
468
469 @Override
470 public void renderHead(final Component component, final IHeaderResponse response) {
471 response.render(OnDomReadyHeaderItem.forScript(
472 "$('#configurationLink').addClass('active')"));
473 }
474
475 @Override
476 public void onComponentTag(final Component component, final ComponentTag tag) {
477 tag.put("class", "nav nav-treeview");
478 tag.put("style", "display: block;");
479 }
480 });
481
482 confLIContainer.add(new Behavior() {
483
484 private static final long serialVersionUID = 3109256773218160485L;
485
486 @Override
487 public void onComponentTag(final Component component, final ComponentTag tag) {
488 tag.put("class", "nav-item has-treeview menu-open");
489 }
490 });
491 }
492 }
493
494
495 List<Class<? extends ExtAlertWidget<?>>> extAlertWidgetClasses =
496 SyncopeWebApplication.get().getLookup().getExtAlertWidgetClasses();
497 ListView<Class<? extends ExtAlertWidget<?>>> extAlertWidgets = new ListView<>(
498 "extAlertWidgets", extAlertWidgetClasses) {
499
500 private static final long serialVersionUID = -9112553137618363167L;
501
502 @Override
503 protected void populateItem(final ListItem<Class<? extends ExtAlertWidget<?>>> item) {
504 try {
505 Constructor<? extends ExtAlertWidget<?>> constructor =
506 item.getModelObject().getDeclaredConstructor(String.class, PageReference.class);
507 ExtAlertWidget<?> widget = constructor.newInstance("extAlertWidget", getPageReference());
508
509 SyncopeConsoleSession.get().setAttribute(widget.getClass().getName(), widget);
510
511 item.add(widget.setRenderBodyOnly(true));
512 } catch (Exception e) {
513 LOG.error("Could not instantiate {}", item.getModelObject().getName(), e);
514 }
515 }
516 };
517 body.add(extAlertWidgets);
518
519 List<Class<? extends BaseExtPage>> extPageClasses =
520 SyncopeWebApplication.get().getLookup().getClasses(BaseExtPage.class);
521
522 WebMarkupContainer extensionsLI = new WebMarkupContainer(getLIContainerId("extensions"));
523 extensionsLI.setOutputMarkupPlaceholderTag(true);
524 extensionsLI.setVisible(!extPageClasses.isEmpty());
525 body.add(extensionsLI);
526
527 ListView<Class<? extends BaseExtPage>> extPages =
528 new ListView<>("extPages", extPageClasses) {
529
530 private static final long serialVersionUID = 4949588177564901031L;
531
532 @Override
533 protected void populateItem(final ListItem<Class<? extends BaseExtPage>> item) {
534 WebMarkupContainer containingLI = new WebMarkupContainer("extPageLI");
535 item.add(containingLI);
536
537 ExtPage ann = item.getModelObject().getAnnotation(ExtPage.class);
538
539 BookmarkablePageLink<Page> link = new BookmarkablePageLink<>("extPage", item.getModelObject());
540 link.add(new Label("extPageLabel", ann.label()));
541 if (StringUtils.isNotBlank(ann.listEntitlement())) {
542 MetaDataRoleAuthorizationStrategy.authorize(link, WebPage.RENDER, ann.listEntitlement());
543 }
544 if (item.getModelObject().equals(BasePage.this.getClass())) {
545 link.add(new Behavior() {
546
547 private static final long serialVersionUID = 1469628524240283489L;
548
549 @Override
550 public void renderHead(final Component component, final IHeaderResponse response) {
551 response.render(OnDomReadyHeaderItem.forScript(
552 "$('#extensionsLink').addClass('active')"));
553 }
554
555 @Override
556 public void onComponentTag(final Component component, final ComponentTag tag) {
557 tag.append("class", "active", " ");
558 }
559 });
560 }
561 containingLI.add(link);
562
563 Label extPageIcon = new Label("extPageIcon");
564 extPageIcon.add(new AttributeModifier("class", "nav-icon " + ann.icon()));
565 link.add(extPageIcon);
566 }
567 };
568 extPages.setRenderBodyOnly(true);
569 extPages.setOutputMarkupId(true);
570 extensionsLI.add(extPages);
571
572 if (getPage() instanceof BaseExtPage) {
573 extPages.add(new Behavior() {
574
575 private static final long serialVersionUID = 1469628524240283489L;
576
577 @Override
578 public void onComponentTag(final Component component, final ComponentTag tag) {
579 tag.put("class", "nav nav-treeview");
580 tag.put("style", "display: block;");
581 }
582 });
583
584 extensionsLI.add(new Behavior() {
585
586 private static final long serialVersionUID = 1469628524240283489L;
587
588 @Override
589 public void onComponentTag(final Component component, final ComponentTag tag) {
590 tag.put("class", "nav-item has-treeview menu-open");
591 }
592 });
593 }
594 }
595
596 @Override
597 public void renderHead(final IHeaderResponse response) {
598 super.renderHead(response);
599 response.render(new PriorityHeaderItem(META_IE_EDGE));
600 }
601
602 private static String getLIContainerId(final String linkId) {
603 return linkId + "LI";
604 }
605
606 private static String getULContainerId(final String linkId) {
607 return linkId + "UL";
608 }
609 }