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.commons.EnduserConstants;
24  import org.apache.syncope.client.enduser.rest.UserSelfRestClient;
25  import org.apache.syncope.client.ui.commons.Constants;
26  import org.apache.syncope.client.ui.commons.markup.html.form.AjaxPasswordFieldPanel;
27  import org.apache.syncope.common.lib.to.UserTO;
28  import org.apache.wicket.ajax.AjaxRequestTarget;
29  import org.apache.wicket.request.mapper.parameter.PageParameters;
30  import org.apache.wicket.spring.injection.annot.SpringBean;
31  
32  public class MustChangePassword extends AbstractChangePassword {
33  
34      private static final long serialVersionUID = 8581970794722709800L;
35  
36      @SpringBean
37      protected UserSelfRestClient userSelfRestClient;
38  
39      public MustChangePassword(final PageParameters parameters) {
40          super(parameters);
41  
42          setDomain(parameters);
43          disableSidebar();
44      }
45  
46      @Override
47      protected void doPwdSubmit(final AjaxRequestTarget target, final AjaxPasswordFieldPanel passwordField) {
48          try {
49              userSelfRestClient.mustChangePassword(passwordField.getModelObject());
50  
51              SyncopeEnduserSession.get().success(getString(Constants.OPERATION_SUCCEEDED));
52              SyncopeEnduserSession.get().invalidate();
53  
54              PageParameters parameters = new PageParameters();
55              parameters.add(EnduserConstants.STATUS, Constants.OPERATION_SUCCEEDED);
56              parameters.add(Constants.NOTIFICATION_TITLE_PARAM, getString("self.pwd.change.success.msg"));
57              parameters.add(Constants.NOTIFICATION_MSG_PARAM, getString("self.pwd.change.success"));
58              parameters.add(
59                      EnduserConstants.LANDING_PAGE,
60                      SyncopeWebApplication.get().getPageClass("profile", Dashboard.class).getName());
61              setResponsePage(getApplication().getHomePage(), parameters);
62          } catch (Exception e) {
63              LOG.error("While changing password for {}",
64                      SyncopeEnduserSession.get().getSelfTO().getUsername(), e);
65              SyncopeEnduserSession.get().onException(e);
66              notificationPanel.refresh(target);
67          }
68      }
69  
70      @Override
71      protected UserTO getPwdLoggedUser() {
72          return SyncopeEnduserSession.get().getSelfTO();
73      }
74  
75      @Override
76      protected void doPwdCancel() {
77          SyncopeEnduserSession.get().invalidate();
78          setResponsePage(getApplication().getHomePage(), new PageParameters());
79      }
80  }