Skip to content

Commit 2c956eb

Browse files
TatoniMatteoilgrosso
authored andcommitted
[SYNCOPE-1984] Add support to realm-based enduser formLayout configuration (#1457)
1 parent 5bc25ae commit 2c956eb

3 files changed

Lines changed: 97 additions & 18 deletions

File tree

client/idrepo/enduser/src/main/java/org/apache/syncope/client/enduser/SyncopeWebApplication.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.util.Optional;
3030
import org.apache.syncope.client.enduser.init.ClassPathScanImplementationLookup;
3131
import org.apache.syncope.client.enduser.layout.UserFormLayoutInfo;
32+
import org.apache.syncope.client.enduser.layout.UserFormLayouts;
3233
import org.apache.syncope.client.enduser.pages.BasePage;
3334
import org.apache.syncope.client.enduser.pages.Dashboard;
3435
import org.apache.syncope.client.enduser.pages.Login;
@@ -46,7 +47,9 @@
4647
import org.apache.syncope.client.ui.commons.themes.AdminLTE;
4748
import org.apache.syncope.common.keymaster.client.api.ServiceOps;
4849
import org.apache.syncope.common.keymaster.client.api.model.NetworkService;
50+
import org.apache.syncope.common.lib.SyncopeConstants;
4951
import org.apache.syncope.common.lib.jackson.SyncopeJsonMapper;
52+
import org.apache.syncope.common.lib.to.UserTO;
5053
import org.apache.wicket.Page;
5154
import org.apache.wicket.Session;
5255
import org.apache.wicket.WicketRuntimeException;
@@ -93,7 +96,7 @@ public static SyncopeWebApplication get() {
9396

9497
protected final List<IResource> resources;
9598

96-
protected UserFormLayoutInfo customFormLayout;
99+
protected UserFormLayouts customFormLayouts;
97100

98101
protected final DynamicMenuStringResourceLoader dynamicMenuStringResourceLoader;
99102

@@ -229,7 +232,7 @@ public IResource getResource() {
229232
getResourceSettings().getStringResourceLoaders().add(dynamicMenuStringResourceLoader);
230233

231234
try (InputStream is = resourceLoader.getResource(props.getCustomFormLayout()).getInputStream()) {
232-
customFormLayout = MAPPER.readValue(is, new TypeReference<>() {
235+
customFormLayouts = MAPPER.readValue(is, new TypeReference<>() {
233236
});
234237
} catch (Exception e) {
235238
throw new WicketRuntimeException("Could not read " + props.getCustomFormLayout(), e);
@@ -272,7 +275,16 @@ public ClassPathScanImplementationLookup getLookup() {
272275
}
273276

274277
public UserFormLayoutInfo getCustomFormLayout() {
275-
return customFormLayout;
278+
String userRealm = SyncopeConstants.ROOT_REALM;
279+
try {
280+
UserTO userTO = SyncopeEnduserSession.get().getSelfTO(true);
281+
if (userTO != null) {
282+
userRealm = userTO.getRealm();
283+
}
284+
} catch (Exception e) {
285+
LOG.warn("Could not get user realm from self", e);
286+
}
287+
return customFormLayouts.getLayout(userRealm);
276288
}
277289

278290
public Class<? extends Sidebar> getSidebar() {
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.syncope.client.enduser.layout;
20+
21+
import com.fasterxml.jackson.annotation.JsonCreator;
22+
import com.fasterxml.jackson.annotation.JsonProperty;
23+
import java.io.Serializable;
24+
import java.util.HashMap;
25+
import java.util.Map;
26+
import org.apache.commons.lang3.StringUtils;
27+
import org.apache.syncope.common.lib.SyncopeConstants;
28+
29+
public class UserFormLayouts implements Serializable {
30+
31+
private static final long serialVersionUID = 9106933641699158419L;
32+
33+
private final Map<String, UserFormLayoutInfo> layouts;
34+
35+
@JsonCreator
36+
public UserFormLayouts(@JsonProperty("layouts") final Map<String, UserFormLayoutInfo> layouts) {
37+
this.layouts = layouts == null ? new HashMap<>() : new HashMap<>(layouts);
38+
this.layouts.putIfAbsent(SyncopeConstants.ROOT_REALM, new UserFormLayoutInfo());
39+
}
40+
41+
public Map<String, UserFormLayoutInfo> getLayouts() {
42+
return layouts;
43+
}
44+
45+
public UserFormLayoutInfo getLayout(final String realm) {
46+
if (!StringUtils.isBlank(realm)) {
47+
UserFormLayoutInfo layout = layouts.get(realm);
48+
if (layout != null) {
49+
return layout;
50+
}
51+
52+
String current = StringUtils.substringBeforeLast(realm, "/");
53+
while (!SyncopeConstants.ROOT_REALM.equals(current)) {
54+
layout = layouts.get(current);
55+
if (layout != null) {
56+
return layout;
57+
}
58+
59+
current = StringUtils.substringBeforeLast(current, "/");
60+
}
61+
}
62+
return layouts.get(SyncopeConstants.ROOT_REALM);
63+
}
64+
}
Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
{
2-
"formClass": "org.apache.syncope.client.enduser.panels.UserFormPanel",
3-
"auxClasses": true,
4-
"groups": true,
5-
"plainAttrs": true,
6-
"derAttrs": true,
7-
"resources": true,
8-
"whichPlainAttrs": {},
9-
"whichDerAttrs": {},
10-
"passwordManagement": true,
11-
"detailsManagement": true,
12-
"sidebarLayout": {
13-
"editUserEnabled": true,
14-
"passwordManagementEnabled": true,
15-
"securityQuestionManagementEnabled": true,
16-
"extensionsEnabled": {
2+
"layouts": {
3+
"/": {
4+
"formClass": "org.apache.syncope.client.enduser.panels.UserFormPanel",
5+
"auxClasses": true,
6+
"groups": true,
7+
"plainAttrs": true,
8+
"derAttrs": true,
9+
"resources": true,
10+
"whichPlainAttrs": {},
11+
"whichDerAttrs": {},
12+
"passwordManagement": true,
13+
"detailsManagement": true,
14+
"sidebarLayout": {
15+
"editUserEnabled": true,
16+
"passwordManagementEnabled": true,
17+
"securityQuestionManagementEnabled": true,
18+
"extensionsEnabled": {}
19+
}
1720
}
1821
}
1922
}

0 commit comments

Comments
 (0)