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.enduser.panels.any;
20  
21  import de.agilecoders.wicket.extensions.markup.html.bootstrap.form.password.strength.PasswordStrengthBehavior;
22  import java.util.List;
23  import java.util.Optional;
24  import org.apache.commons.lang3.StringUtils;
25  import org.apache.syncope.client.ui.commons.ajax.markup.html.LabelInfo;
26  import org.apache.syncope.client.ui.commons.markup.html.form.AjaxDropDownChoicePanel;
27  import org.apache.syncope.client.ui.commons.markup.html.form.AjaxTextFieldPanel;
28  import org.apache.syncope.client.ui.commons.markup.html.form.FieldPanel;
29  import org.apache.syncope.client.ui.commons.markup.html.form.SyncopePasswordStrengthConfig;
30  import org.apache.syncope.client.ui.commons.wizards.any.PasswordPanel;
31  import org.apache.syncope.client.ui.commons.wizards.any.UserWrapper;
32  import org.apache.syncope.common.lib.SyncopeConstants;
33  import org.apache.syncope.common.lib.to.UserTO;
34  import org.apache.wicket.PageReference;
35  import org.apache.wicket.markup.html.basic.Label;
36  import org.apache.wicket.markup.html.panel.Panel;
37  import org.apache.wicket.model.PropertyModel;
38  import org.apache.wicket.model.ResourceModel;
39  
40  public class UserDetails extends Details<UserTO> {
41  
42      private static final long serialVersionUID = 6592027822510220463L;
43  
44      protected final AjaxTextFieldPanel username;
45  
46      protected final UserTO userTO;
47  
48      public UserDetails(final String id, final UserWrapper wrapper, final PageReference pageRef) {
49          super(id, pageRef);
50  
51          userTO = wrapper.getInnerObject();
52          // ------------------------
53          // Username
54          // ------------------------
55          username = new AjaxTextFieldPanel("username", "username", new PropertyModel<>(userTO, "username"), false);
56  
57          if (wrapper.getPreviousUserTO() != null && StringUtils.
58                  compare(wrapper.getPreviousUserTO().getUsername(), wrapper.getInnerObject().getUsername()) != 0) {
59              username.showExternAction(new LabelInfo("externalAction", wrapper.getPreviousUserTO().getUsername()));
60          }
61  
62          username.addRequiredLabel();
63          add(username);
64          // ------------------------
65  
66          // ------------------------
67          // Realm
68          // ------------------------
69          add(buildDestinationRealm());
70      }
71  
72      protected FieldPanel<String> buildDestinationRealm() {
73          AjaxDropDownChoicePanel<String> destinationRealm = new AjaxDropDownChoicePanel<>(
74                  "destinationRealm", "destinationRealm", new PropertyModel<>(userTO, "realm"), false);
75          destinationRealm.setNullValid(false);
76          destinationRealm.setChoices(List.of(
77                  Optional.ofNullable(userTO.getRealm()).orElse(SyncopeConstants.ROOT_REALM)));
78          return destinationRealm;
79      }
80  
81      protected static class EditUserPasswordPanel extends Panel {
82  
83          private static final long serialVersionUID = -8198836979773590078L;
84  
85          protected EditUserPasswordPanel(final String id, final UserWrapper wrapper) {
86              super(id);
87              setOutputMarkupId(true);
88              add(new Label("warning", new ResourceModel("password.change.warning")));
89              add(new PasswordPanel(
90                      "passwordPanel",
91                      wrapper,
92                      false,
93                      wrapper.getInnerObject().getKey() == null,
94                      new PasswordStrengthBehavior(new SyncopePasswordStrengthConfig())));
95          }
96      }
97  }