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.ProvisioningUtils;
24  import org.apache.syncope.client.enduser.rest.UserSelfRestClient;
25  import org.apache.syncope.client.ui.commons.markup.html.form.AjaxPasswordFieldPanel;
26  import org.apache.syncope.common.lib.request.PasswordPatch;
27  import org.apache.syncope.common.lib.request.UserUR;
28  import org.apache.syncope.common.lib.to.ProvisioningResult;
29  import org.apache.syncope.common.lib.to.UserTO;
30  import org.apache.syncope.common.lib.types.ExecStatus;
31  import org.apache.wicket.ajax.AjaxRequestTarget;
32  import org.apache.wicket.request.mapper.parameter.PageParameters;
33  import org.apache.wicket.spring.injection.annot.SpringBean;
34  
35  public class EditChangePassword extends AbstractChangePassword {
36  
37      private static final long serialVersionUID = -537205681762708502L;
38  
39      @SpringBean
40      protected UserSelfRestClient userSelfRestClient;
41  
42      public EditChangePassword(final PageParameters parameters) {
43          super(parameters);
44      }
45  
46      @Override
47      protected void doPwdSubmit(final AjaxRequestTarget target, final AjaxPasswordFieldPanel passwordField) {
48          try {
49              UserTO userTO = getPwdLoggedUser();
50              // update and set page paramters according to provisioning result
51              ProvisioningResult<UserTO> provisioningResult =
52                      userSelfRestClient.update(
53                              userTO.getETagValue(),
54                              new UserUR.Builder(userTO.getKey()).
55                                      password(new PasswordPatch.Builder().
56                                              value(passwordField.getModelObject()).onSyncope(true).
57                                              resources(userTO.getResources()).
58                                              build()).
59                                      build());
60              setResponsePage(new SelfResult(provisioningResult,
61                      ProvisioningUtils.managePageParams(EditChangePassword.this, "pwd.change",
62                              !SyncopeWebApplication.get().isReportPropagationErrors()
63                              || provisioningResult.getPropagationStatuses().stream().
64                                      allMatch(ps -> ExecStatus.SUCCESS == ps.getStatus()))));
65          } catch (Exception e) {
66              LOG.error("While changing password for {}", SyncopeEnduserSession.get().getSelfTO().getUsername(), e);
67              SyncopeEnduserSession.get().onException(e);
68              notificationPanel.refresh(target);
69          }
70      }
71  
72      @Override
73      protected UserTO getPwdLoggedUser() {
74          return SyncopeEnduserSession.get().getSelfTO(true);
75      }
76  
77      @Override
78      protected void doPwdCancel() {
79          setResponsePage(getApplication().getHomePage());
80      }
81  }