diff --git a/api-docs/apiLive.htm b/api-docs/apiLive.htm index f85a5ce412c..abd6867f458 100644 --- a/api-docs/apiLive.htm +++ b/api-docs/apiLive.htm @@ -3360,6 +3360,14 @@

Self Service

+ + Update User + self/user + + + Update User + + Clients self/clients @@ -42919,6 +42927,38 @@

Fetch authenticated user details

+   +
+
+

Update User

+

This API can be used by Self Service user to update their own user information. Currently, "password" and "repeatPassword" are the only parameters accepted.

+
+
+ +PUT https://DomainName/api/v1/self/user + + +PUT self/user +Content-Type: application/json + +{ + "password":"Abcd1234", + "repeatPassword":"Abcd1234" +} + +

Example response

+ +{ + "officeId": 1, + "resourceId": 6, + "changes": { + "passwordEncoded": "6a72a630795be86fe926ce540fc45b6b922fe5ba130f185fe806a26b5e5efcdd" + } +} + +
+
+  
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 00000000000..76de0b3922d --- /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 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>() {}.getType(); + this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, + apiRequestBodyAsJson, + this.supportedParameters); + + final AppUser appUser = this.context.authenticatedUser(); + return this.usersApiResource.update(appUser.getId(), apiRequestBodyAsJson); + } + +}