1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.syncope.client.enduser.pages;
20
21 import com.fasterxml.jackson.core.JsonProcessingException;
22 import com.fasterxml.jackson.databind.json.JsonMapper;
23 import org.apache.syncope.client.enduser.SyncopeEnduserSession;
24 import org.apache.syncope.client.enduser.SyncopeWebApplication;
25 import org.apache.syncope.client.enduser.layout.UserFormLayoutInfo;
26 import org.apache.syncope.client.enduser.panels.UserSelfFormPanel;
27 import org.apache.syncope.common.lib.SyncopeConstants;
28 import org.apache.syncope.common.lib.to.UserTO;
29 import org.apache.wicket.markup.html.WebMarkupContainer;
30 import org.apache.wicket.request.mapper.parameter.PageParameters;
31
32 public class SelfRegistration extends BasePage {
33
34 private static final long serialVersionUID = -1100228004207271270L;
35
36 private static final String SELF_REGISTRATION = "page.selfRegistration";
37
38 public static final String NEW_USER_PARAM = "newUser";
39
40 protected static final JsonMapper MAPPER = JsonMapper.builder().findAndAddModules().build();
41
42 public SelfRegistration(final PageParameters parameters) {
43 super(parameters, SELF_REGISTRATION);
44
45 setDomain(parameters);
46 disableSidebar();
47
48 WebMarkupContainer content = new WebMarkupContainer("content");
49 content.setOutputMarkupId(true);
50 contentWrapper.add(content);
51
52 UserSelfFormPanel selfRegistrationPanel = new UserSelfFormPanel(
53 "selfRegistrationPanel",
54 buildNewUserTO(parameters),
55 buildNewUserTO(parameters),
56 SyncopeEnduserSession.get().getAnonymousClient().platform().getUserClasses(),
57 buildFormLayout(),
58 getPageReference());
59 selfRegistrationPanel.setOutputMarkupId(true);
60 content.add(selfRegistrationPanel);
61 }
62
63 private UserFormLayoutInfo buildFormLayout() {
64 UserFormLayoutInfo customlayoutInfo = SyncopeWebApplication.get().getCustomFormLayout();
65 return customlayoutInfo != null ? customlayoutInfo : new UserFormLayoutInfo();
66 }
67
68 private static UserTO buildNewUserTO(final PageParameters parameters) {
69 UserTO userTO = null;
70 if (parameters != null) {
71 if (!parameters.get(NEW_USER_PARAM).isNull()) {
72 try {
73 userTO = MAPPER.readValue(parameters.get(NEW_USER_PARAM).toString(), UserTO.class);
74 } catch (JsonProcessingException e) {
75 LOG.error("While reading user data from social registration", e);
76 }
77 }
78 }
79 if (userTO == null) {
80 userTO = new UserTO();
81 }
82 userTO.setRealm(SyncopeConstants.ROOT_REALM);
83 return userTO;
84 }
85 }