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.ui.commons.wizards.any;
20  
21  import de.agilecoders.wicket.extensions.markup.html.bootstrap.form.password.strength.PasswordStrengthBehavior;
22  import org.apache.syncope.client.ui.commons.markup.html.form.AjaxCheckBoxPanel;
23  import org.apache.syncope.client.ui.commons.markup.html.form.AjaxPasswordFieldPanel;
24  import org.apache.syncope.client.ui.commons.markup.html.form.AjaxTextFieldPanel;
25  import org.apache.wicket.markup.html.form.Form;
26  import org.apache.wicket.markup.html.form.PasswordTextField;
27  import org.apache.wicket.markup.html.form.validation.EqualPasswordInputValidator;
28  import org.apache.wicket.markup.html.panel.Panel;
29  import org.apache.wicket.model.Model;
30  import org.apache.wicket.model.PropertyModel;
31  import org.apache.wicket.model.ResourceModel;
32  
33  public class PasswordPanel extends Panel {
34  
35      private static final long serialVersionUID = 6592027822510220463L;
36  
37      public PasswordPanel(
38              final String id,
39              final UserWrapper wrapper,
40              final Boolean storePasswordInSyncope,
41              final boolean templateMode) {
42  
43          this(id, wrapper, templateMode, storePasswordInSyncope, null);
44      }
45  
46      public PasswordPanel(
47              final String id,
48              final UserWrapper wrapper,
49              final boolean templateMode,
50              final Boolean storePasswordInSyncope,
51              final PasswordStrengthBehavior passwordStrengthBehavior) {
52  
53          super(id);
54          setOutputMarkupId(true);
55  
56          Form<?> form = new Form<>("passwordInnerForm");
57          add(form);
58  
59          AjaxPasswordFieldPanel confirmPasswordField = new AjaxPasswordFieldPanel(
60                  "confirmPassword", "confirmPassword", Model.of(), false);
61          ((PasswordTextField) confirmPasswordField.getField()).setResetPassword(false);
62          form.add(confirmPasswordField.setPlaceholder("confirmPassword").setMarkupId("confirmPassword"));
63  
64          if (templateMode) {
65              confirmPasswordField.setEnabled(false);
66              confirmPasswordField.setVisible(false);
67  
68              AjaxTextFieldPanel passwordField = new AjaxTextFieldPanel(
69                      "password", "password", new PropertyModel<>(wrapper.getInnerObject(), "password"), false);
70              passwordField.setRequired(false); // [SYNCOPE-1227]
71              passwordField.setMarkupId("password");
72              passwordField.setPlaceholder("password");
73              form.add(passwordField);
74              passwordField.enableJexlHelp();
75          } else {
76              AjaxPasswordFieldPanel passwordField = new AjaxPasswordFieldPanel(
77                      "password",
78                      "password",
79                      new PropertyModel<>(wrapper.getInnerObject(), "password"),
80                      false,
81                      passwordStrengthBehavior);
82              passwordField.setRequired(true);
83              passwordField.setMarkupId("password");
84              passwordField.setPlaceholder("password");
85              ((PasswordTextField) passwordField.getField()).setResetPassword(false);
86              form.add(passwordField);
87              form.add(new EqualPasswordInputValidator(passwordField.getField(), confirmPasswordField.getField()));
88          }
89  
90          AjaxCheckBoxPanel storePasswordInSyncopePanel = new AjaxCheckBoxPanel("storePasswordInSyncope",
91                  "storePasswordInSyncope", new PropertyModel<>(wrapper, "storePasswordInSyncope"));
92          storePasswordInSyncopePanel.getField().setLabel(new ResourceModel("storePasswordInSyncope"));
93          storePasswordInSyncopePanel.setOutputMarkupId(true);
94          storePasswordInSyncopePanel.setOutputMarkupPlaceholderTag(true);
95          if (storePasswordInSyncope) {
96              storePasswordInSyncopePanel.getField().setDefaultModelObject(Boolean.TRUE);
97          } else {
98              storePasswordInSyncopePanel.setVisible(false);
99          }
100         form.add(storePasswordInSyncopePanel);
101     }
102 }