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.panels;
20
21 import java.util.List;
22 import java.util.stream.Collectors;
23 import org.apache.syncope.client.console.SyncopeWebApplication;
24 import org.apache.syncope.client.console.commons.RealmPolicyProvider;
25 import org.apache.syncope.client.console.rest.ImplementationRestClient;
26 import org.apache.syncope.client.console.wicket.markup.html.form.ActionsPanel;
27 import org.apache.syncope.client.ui.commons.Constants;
28 import org.apache.syncope.client.ui.commons.markup.html.form.AjaxPalettePanel;
29 import org.apache.syncope.client.ui.commons.markup.html.form.AjaxTextFieldPanel;
30 import org.apache.syncope.client.ui.commons.markup.html.form.FieldPanel;
31 import org.apache.syncope.common.lib.SyncopeConstants;
32 import org.apache.syncope.common.lib.to.ImplementationTO;
33 import org.apache.syncope.common.lib.to.RealmTO;
34 import org.apache.syncope.common.lib.types.IdRepoImplementationType;
35 import org.apache.wicket.markup.html.WebMarkupContainer;
36 import org.apache.wicket.markup.html.panel.Fragment;
37 import org.apache.wicket.markup.html.panel.Panel;
38 import org.apache.wicket.markup.repeater.RepeatingView;
39 import org.apache.wicket.model.IModel;
40 import org.apache.wicket.model.LoadableDetachableModel;
41 import org.apache.wicket.model.PropertyModel;
42 import org.apache.wicket.model.util.ListModel;
43 import org.apache.wicket.spring.injection.annot.SpringBean;
44 import org.slf4j.Logger;
45 import org.slf4j.LoggerFactory;
46
47 public class RealmDetails extends Panel {
48
49 private static final long serialVersionUID = -1100228004207271270L;
50
51 protected static final Logger LOG = LoggerFactory.getLogger(RealmDetails.class);
52
53 protected final IModel<List<String>> logicActions = new LoadableDetachableModel<>() {
54
55 private static final long serialVersionUID = 5275935387613157437L;
56
57 @Override
58 protected List<String> load() {
59 return implementationRestClient.list(IdRepoImplementationType.LOGIC_ACTIONS).stream().
60 map(ImplementationTO::getKey).sorted().collect(Collectors.toList());
61 }
62 };
63
64 protected final LoadableDetachableModel<List<String>> resources = new LoadableDetachableModel<>() {
65
66 private static final long serialVersionUID = 5275935387613157437L;
67
68 @Override
69 protected List<String> load() {
70 return SyncopeWebApplication.get().getResourceProvider().get();
71 }
72 };
73
74 private final ActionsPanel<RealmTO> actionsPanel;
75
76 @SpringBean
77 protected ImplementationRestClient implementationRestClient;
78
79 @SpringBean
80 private RealmPolicyProvider realmPolicyProvider;
81
82 private final WebMarkupContainer container;
83
84 public RealmDetails(final String id, final RealmTO realmTO) {
85 this(id, realmTO, null, true);
86 }
87
88 public RealmDetails(
89 final String id,
90 final RealmTO realmTO,
91 final ActionsPanel<RealmTO> actionsPanel,
92 final boolean unwrapped) {
93
94 super(id);
95
96 this.actionsPanel = actionsPanel;
97
98 container = new WebMarkupContainer("container");
99 container.setOutputMarkupId(true);
100 container.setRenderBodyOnly(unwrapped);
101 add(container);
102
103 final WebMarkupContainer generics = new WebMarkupContainer("generics");
104 container.add(generics.setVisible(unwrapped));
105
106 FieldPanel<String> name = new AjaxTextFieldPanel(
107 Constants.NAME_FIELD_NAME, Constants.NAME_FIELD_NAME,
108 new PropertyModel<>(realmTO, Constants.NAME_FIELD_NAME), false);
109 name.addRequiredLabel();
110 generics.add(name);
111
112 FieldPanel<String> fullPath = new AjaxTextFieldPanel(
113 "fullPath", "fullPath", new PropertyModel<>(realmTO, "fullPath"), false);
114 fullPath.setEnabled(false);
115 generics.add(fullPath);
116
117 RepeatingView policies = new RepeatingView("policies");
118 realmPolicyProvider.add(realmTO, policies);
119 container.add(policies);
120
121 AjaxPalettePanel<String> actions = new AjaxPalettePanel.Builder<String>().
122 setAllowMoveAll(true).setAllowOrder(true).
123 build("actions",
124 new PropertyModel<>(realmTO, "actions"),
125 new ListModel<>(logicActions.getObject()));
126 actions.setOutputMarkupId(true);
127 container.add(actions);
128
129 container.add(new AjaxPalettePanel.Builder<String>().build("resources",
130 new PropertyModel<>(realmTO, "resources"),
131 new ListModel<>(resources.getObject())).
132 setOutputMarkupId(true).
133 setEnabled(!SyncopeConstants.ROOT_REALM.equals(realmTO.getName())).
134 setVisible(!SyncopeConstants.ROOT_REALM.equals(realmTO.getName())));
135
136 if (actionsPanel == null) {
137 add(new Fragment("actions", "emptyFragment", this).setRenderBodyOnly(true));
138 } else {
139 Fragment fragment = new Fragment("actions", "actionsFragment", this);
140 fragment.add(actionsPanel);
141 add(fragment.setRenderBodyOnly(true));
142 }
143 }
144
145 public RealmDetails setContentEnabled(final boolean enable) {
146 container.setEnabled(enable);
147 return this;
148 }
149
150 public ActionsPanel<RealmTO> getActionsPanel() {
151 return actionsPanel;
152 }
153 }