You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@fineract.apache.org by na...@apache.org on 2016/10/26 12:00:59 UTC
incubator-fineract git commit: Add API to allow self service user to
change their password
Repository: incubator-fineract
Updated Branches:
refs/heads/develop 525e8becb -> b3c4f75f1
Add API to allow self service user to change their password
Project: http://git-wip-us.apache.org/repos/asf/incubator-fineract/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-fineract/commit/b3c4f75f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-fineract/tree/b3c4f75f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-fineract/diff/b3c4f75f
Branch: refs/heads/develop
Commit: b3c4f75f11cea259a2b0ce2fb1f1ec64b1975fec
Parents: 525e8be
Author: Adi Narayana Raju <ad...@confluxtechnologies.com>
Authored: Tue Oct 25 14:08:22 2016 +0530
Committer: Adi Narayana Raju <ad...@confluxtechnologies.com>
Committed: Tue Oct 25 14:08:22 2016 +0530
----------------------------------------------------------------------
api-docs/apiLive.htm | 40 +++++++++++
.../self/security/api/SelfUserApiResource.java | 74 ++++++++++++++++++++
2 files changed, 114 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/b3c4f75f/api-docs/apiLive.htm
----------------------------------------------------------------------
diff --git a/api-docs/apiLive.htm b/api-docs/apiLive.htm
index f85a5ce..abd6867 100644
--- a/api-docs/apiLive.htm
+++ b/api-docs/apiLive.htm
@@ -3361,6 +3361,14 @@
<td></td>
</tr>
<tr>
+ <td><a href="#selfuser">Update User</a></td>
+ <td>self/user</td>
+ <td></td>
+ <td></td>
+ <td><a href="#selfuser">Update User</a></td>
+ <td></td>
+ </tr>
+ <tr>
<td><a href="#selflistclients">Clients</a></td>
<td>self/clients</td>
<td></td>
@@ -42919,6 +42927,38 @@ No Request Body
</div>
</div>
+ <a id="selfuser" name="selfuser" class="old-syle-anchor"> </a>
+ <div class="method-section">
+ <div class="method-description">
+ <h4>Update User</h4>
+ <p>This API can be used by Self Service user to update their own user information. Currently, "password" and "repeatPassword" are the only parameters accepted.</p>
+ </div>
+ <div class="method-example">
+ <code class="method-declaration">
+PUT https://DomainName/api/v1/self/user
+ </code>
+ <code class="method-request">
+PUT self/user
+Content-Type: application/json
+
+{
+ "password":"Abcd1234",
+ "repeatPassword":"Abcd1234"
+}
+ </code>
+ <p>Example response</p>
+<code class="method-response">
+{
+ "officeId": 1,
+ "resourceId": 6,
+ "changes": {
+ "passwordEncoded": "6a72a630795be86fe926ce540fc45b6b922fe5ba130f185fe806a26b5e5efcdd"
+ }
+}
+</code>
+ </div>
+ </div>
+
<a id="selflistclients" name="selflistclients" class="old-syle-anchor"> </a>
<div class="method-section">
<div class="method-description">
http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/b3c4f75f/fineract-provider/src/main/java/org/apache/fineract/portfolio/self/security/api/SelfUserApiResource.java
----------------------------------------------------------------------
diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/self/security/api/SelfUserApiResource.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/self/security/api/SelfUserApiResource.java
new file mode 100644
index 0000000..76de0b3
--- /dev/null
+++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/self/security/api/SelfUserApiResource.java
@@ -0,0 +1,74 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.fineract.portfolio.self.security.api;
+
+import java.lang.reflect.Type;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.fineract.infrastructure.core.exception.InvalidJsonException;
+import org.apache.fineract.infrastructure.core.serialization.FromJsonHelper;
+import org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
+import org.apache.fineract.useradministration.api.UsersApiResource;
+import org.apache.fineract.useradministration.domain.AppUser;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import com.google.gson.reflect.TypeToken;
+
+@Path("/self/user")
+@Component
+public class SelfUserApiResource {
+
+ private final UsersApiResource usersApiResource;
+ private final PlatformSecurityContext context;
+ private final FromJsonHelper fromApiJsonHelper;
+ private final Set<String> supportedParameters = new HashSet<>(Arrays.asList("password", "repeatPassword"));
+
+ @Autowired
+ public SelfUserApiResource(final UsersApiResource usersApiResource,
+ final PlatformSecurityContext context,
+ final FromJsonHelper fromApiJsonHelper){
+
+ this.usersApiResource = usersApiResource;
+ this.context = context;
+ this.fromApiJsonHelper = fromApiJsonHelper;
+ }
+
+ @PUT
+ public String update(final String apiRequestBodyAsJson) {
+ if (StringUtils.isBlank(apiRequestBodyAsJson)) { throw new InvalidJsonException(); }
+
+ final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
+ this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap,
+ apiRequestBodyAsJson,
+ this.supportedParameters);
+
+ final AppUser appUser = this.context.authenticatedUser();
+ return this.usersApiResource.update(appUser.getId(), apiRequestBodyAsJson);
+ }
+
+}