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.pages;
20  
21  import org.apache.syncope.client.ui.commons.Constants;
22  import org.apache.syncope.client.ui.commons.panels.NotificationPanel;
23  import org.apache.syncope.common.lib.to.UserTO;
24  import org.apache.wicket.AttributeModifier;
25  import org.apache.wicket.ajax.AjaxRequestTarget;
26  import org.apache.wicket.ajax.markup.html.form.AjaxButton;
27  import org.apache.wicket.markup.html.WebPage;
28  import org.apache.wicket.markup.html.form.Button;
29  import org.apache.wicket.markup.html.form.PasswordTextField;
30  import org.apache.wicket.markup.html.form.StatelessForm;
31  import org.apache.wicket.markup.html.form.TextField;
32  import org.apache.wicket.markup.html.form.validation.EqualPasswordInputValidator;
33  import org.apache.wicket.model.Model;
34  import org.apache.wicket.request.mapper.parameter.PageParameters;
35  import org.slf4j.Logger;
36  import org.slf4j.LoggerFactory;
37  
38  public abstract class AbstractMustChangePassword extends WebPage {
39  
40      private static final long serialVersionUID = 5889157642852559004L;
41  
42      protected static final Logger LOG = LoggerFactory.getLogger(AbstractMustChangePassword.class);
43  
44      protected final StatelessForm<Void> form;
45  
46      protected final TextField<String> usernameField;
47  
48      protected final PasswordTextField passwordField;
49  
50      protected final PasswordTextField confirmPasswordField;
51  
52      protected final NotificationPanel notificationPanel = new NotificationPanel(Constants.FEEDBACK);
53  
54      public AbstractMustChangePassword(final PageParameters parameters) {
55          super(parameters);
56  
57          add(notificationPanel);
58  
59          form = new StatelessForm<>("changePassword");
60          form.setOutputMarkupId(true);
61  
62          usernameField = new TextField<>("username", new Model<>(getLoggedUser().getUsername()));
63          usernameField.setMarkupId("username");
64          usernameField.setEnabled(false);
65          form.add(usernameField);
66  
67          passwordField = new PasswordTextField("password", new Model<>());
68          passwordField.setRequired(true);
69          passwordField.setMarkupId("password");
70          passwordField.setResetPassword(true);
71          form.add(passwordField);
72  
73          confirmPasswordField = new PasswordTextField("confirmPassword", new Model<>());
74          confirmPasswordField.setRequired(true);
75          confirmPasswordField.setMarkupId("confirmPassword");
76          confirmPasswordField.setResetPassword(true);
77          form.add(confirmPasswordField);
78  
79          form.add(new EqualPasswordInputValidator(passwordField, confirmPasswordField));
80  
81          AjaxButton submitButton = new AjaxButton("submit", new Model<>(getString("submit"))) {
82  
83              private static final long serialVersionUID = 429178684321093953L;
84  
85              @Override
86              protected void onSubmit(final AjaxRequestTarget target) {
87                  doSubmit(target);
88              }
89  
90              @Override
91              protected void onError(final AjaxRequestTarget target) {
92                  notificationPanel.refresh(target);
93              }
94  
95          };
96          form.add(submitButton);
97          form.setDefaultButton(submitButton);
98  
99          Button cancel = new Button("cancel") {
100 
101             private static final long serialVersionUID = 3669569969172391336L;
102 
103             @Override
104             public void onSubmit() {
105                 doCancel();
106             }
107 
108         };
109         cancel.setOutputMarkupId(true);
110         cancel.setDefaultFormProcessing(false);
111         form.add(cancel);
112 
113         add(form);
114 
115         add(new AttributeModifier("style", "height: \"100%\""));
116     }
117 
118     protected abstract void doSubmit(AjaxRequestTarget target);
119 
120     protected abstract void doCancel();
121 
122     protected abstract UserTO getLoggedUser();
123 }