View Javadoc
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.console.wizards.any;
20  
21  import java.util.List;
22  import org.apache.commons.lang3.StringUtils;
23  import org.apache.syncope.client.ui.commons.Constants;
24  import org.apache.syncope.client.ui.commons.ajax.markup.html.LabelInfo;
25  import org.apache.syncope.client.ui.commons.markup.html.form.AjaxCheckBoxPanel;
26  import org.apache.syncope.client.ui.commons.markup.html.form.AjaxTextFieldPanel;
27  import org.apache.syncope.client.ui.commons.wicket.markup.html.bootstrap.tabs.Accordion;
28  import org.apache.syncope.client.ui.commons.wizards.any.PasswordPanel;
29  import org.apache.syncope.client.ui.commons.wizards.any.UserWrapper;
30  import org.apache.syncope.common.lib.to.UserTO;
31  import org.apache.wicket.Component;
32  import org.apache.wicket.PageReference;
33  import org.apache.wicket.ajax.AjaxRequestTarget;
34  import org.apache.wicket.ajax.markup.html.AjaxLink;
35  import org.apache.wicket.extensions.markup.html.tabs.AbstractTab;
36  import org.apache.wicket.extensions.markup.html.tabs.ITab;
37  import org.apache.wicket.markup.html.basic.Label;
38  import org.apache.wicket.markup.html.panel.Panel;
39  import org.apache.wicket.model.Model;
40  import org.apache.wicket.model.PropertyModel;
41  import org.apache.wicket.model.ResourceModel;
42  
43  public class UserDetails extends Details<UserTO> {
44  
45      private static final long serialVersionUID = 6592027822510220463L;
46  
47      public UserDetails(
48              final UserWrapper wrapper,
49              final boolean templateMode,
50              final boolean includeStatusPanel,
51              final boolean showPasswordManagement,
52              final PageReference pageRef) {
53  
54          super(wrapper, templateMode, includeStatusPanel, pageRef);
55  
56          UserTO userTO = wrapper.getInnerObject();
57  
58          // ------------------------
59          // Username
60          // ------------------------
61          AjaxTextFieldPanel username = new AjaxTextFieldPanel(
62                  Constants.USERNAME_FIELD_NAME, Constants.USERNAME_FIELD_NAME,
63                  new PropertyModel<>(userTO, Constants.USERNAME_FIELD_NAME), false);
64  
65          if (wrapper.getPreviousUserTO() != null && StringUtils.compare(
66                  wrapper.getPreviousUserTO().getUsername(), wrapper.getInnerObject().getUsername()) != 0) {
67  
68              username.showExternAction(new LabelInfo("externalAction", wrapper.getPreviousUserTO().getUsername()));
69          }
70  
71          if (templateMode) {
72              username.enableJexlHelp();
73          } else {
74              username.addRequiredLabel();
75          }
76          add(username);
77          // ------------------------
78  
79          // ------------------------
80          // mustChangePassword
81          // ------------------------
82          AjaxCheckBoxPanel mustChangePassword = new AjaxCheckBoxPanel(
83                  "mustChangePassword", "mustChangePassword", new PropertyModel<>(userTO, "mustChangePassword"));
84  
85          add(mustChangePassword.setOutputMarkupPlaceholderTag(true).setVisible(templateMode));
86          // ------------------------
87  
88          // ------------------------
89          // Password
90          // ------------------------
91          Model<Integer> model = Model.of(-1);
92  
93          Accordion accordion = new Accordion("accordionPanel", List.of(
94                  new AbstractTab(new ResourceModel("password.change", "Change password")) {
95  
96              private static final long serialVersionUID = 1037272333056449378L;
97  
98              @Override
99              public Panel getPanel(final String panelId) {
100                 EditUserPasswordPanel panel = new EditUserPasswordPanel(panelId, wrapper, templateMode);
101                 panel.setEnabled(model.getObject() >= 0);
102                 return panel;
103             }
104         }), model) {
105 
106             private static final long serialVersionUID = -2898628183677758699L;
107 
108             @Override
109             protected Component newTitle(final String markupId, final ITab tab, final Accordion.State state) {
110                 return new AjaxLink<Integer>(markupId) {
111 
112                     private static final long serialVersionUID = 7021195294339489084L;
113 
114                     @Override
115                     public void onClick(final AjaxRequestTarget target) {
116                         model.setObject(model.getObject() == 0 ? -1 : 0);
117                         Component passwordPanel = getParent().get("body:content");
118                         passwordPanel.setEnabled(model.getObject() >= 0);
119                         target.add(passwordPanel);
120                     }
121                 }.setBody(new ResourceModel("password.change", "Change password ..."));
122             }
123         };
124 
125         accordion.setOutputMarkupId(true);
126         accordion.setVisible(showPasswordManagement);
127         add(accordion);
128         // ------------------------
129     }
130 
131     @Override
132     protected AnnotatedBeanPanel getGeneralStatusInformation(final String id, final UserTO anyTO) {
133         return new UserInformationPanel(id, anyTO);
134     }
135 
136     public static class EditUserPasswordPanel extends Panel {
137 
138         private static final long serialVersionUID = -8198836979773590078L;
139 
140         public EditUserPasswordPanel(final String id, final UserWrapper wrapper, final boolean templateMode) {
141             super(id);
142             setOutputMarkupId(true);
143             add(new Label("warning", new ResourceModel("password.change.warning")));
144             add(new PasswordPanel("passwordPanel", wrapper, false, templateMode));
145         }
146     }
147 }