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.pages;
20  
21  import org.apache.syncope.client.enduser.SyncopeEnduserSession;
22  import org.apache.syncope.client.enduser.SyncopeWebApplication;
23  import org.apache.syncope.client.enduser.panels.ChangePasswordPanel;
24  import org.apache.syncope.client.ui.commons.Constants;
25  import org.apache.syncope.client.ui.commons.markup.html.form.AjaxPasswordFieldPanel;
26  import org.apache.syncope.common.lib.to.UserTO;
27  import org.apache.wicket.AttributeModifier;
28  import org.apache.wicket.ajax.AjaxRequestTarget;
29  import org.apache.wicket.markup.html.WebMarkupContainer;
30  import org.apache.wicket.request.mapper.parameter.PageParameters;
31  
32  public abstract class AbstractChangePassword extends BasePage {
33  
34      private static final long serialVersionUID = 5889157642852559004L;
35  
36      private static final String CHANGE_PASSWORD = "page.changePassword";
37  
38      public AbstractChangePassword(final PageParameters parameters) {
39          super(parameters, CHANGE_PASSWORD);
40  
41          WebMarkupContainer content = new WebMarkupContainer("content");
42          content.setOutputMarkupId(true);
43          contentWrapper.add(content);
44  
45          ChangePasswordPanel changePasswordPanel = getPasswordPanel();
46          content.add(changePasswordPanel);
47          content.add(new AttributeModifier("style", "height: \"100%\""));
48      }
49  
50      protected ChangePasswordPanel getPasswordPanel() {
51          ChangePasswordPanel changePasswordPanel = new ChangePasswordPanel("changePasswordPanel", notificationPanel) {
52  
53              private static final long serialVersionUID = 5195544218030499386L;
54  
55              @Override
56              protected void doSubmit(final AjaxRequestTarget target, final AjaxPasswordFieldPanel passwordField) {
57                  boolean checked = true;
58                  if (SyncopeWebApplication.get().isCaptchaEnabled()) {
59                      checked = captcha.check();
60                  }
61                  if (!checked) {
62                      SyncopeEnduserSession.get().error(getString(Constants.CAPTCHA_ERROR));
63                      getNotificationPanel().refresh(target);
64                  } else {
65                      doPwdSubmit(target, passwordField);
66                  }
67              }
68  
69              @Override
70              protected void doCancel() {
71                  doPwdCancel();
72              }
73  
74              @Override
75              protected UserTO getLoggedUser() {
76                  return getPwdLoggedUser();
77              }
78          };
79  
80          changePasswordPanel.setOutputMarkupId(true);
81          return changePasswordPanel;
82      }
83  
84      protected abstract void doPwdSubmit(AjaxRequestTarget target, AjaxPasswordFieldPanel passwordField);
85  
86      protected abstract void doPwdCancel();
87  
88      protected abstract UserTO getPwdLoggedUser();
89  }