Skip to content
This repository was archived by the owner on Dec 9, 2025. It is now read-only.

Commit b173162

Browse files
author
sachin-maheshwari
authored
Merge pull request #23 from appirio-tech/dev
"Change Password" endpoint for Auth0
2 parents f6fe80e + d8a71a6 commit b173162

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ workflows:
145145
context : org-global
146146
filters:
147147
branches:
148-
only: [dev, test,dev-pg]
148+
only: [dev, 'feature/RS256-Auth0']
149149
# Production build is executed on "master" branch only.
150150
- "build-prod":
151151
context : org-global

src/main/java/com/appirio/tech/core/service/identity/resource/UserResource.java

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,61 @@ public ApiResponse roles(
790790
return ApiResponseFactory.createResponse(user);
791791
}
792792

793+
/**
794+
* API to change password for a user (by email)
795+
* This is supposed to be called from Auth0 custom connection.
796+
* @param email
797+
* @param password
798+
* @param request
799+
* @return
800+
* @throws Exception
801+
*/
802+
@POST
803+
@Path("/changePassword")
804+
@Timed
805+
public ApiResponse changePassword(
806+
@FormParam("email") String email,
807+
@FormParam("password") String password,
808+
@Context HttpServletRequest request) throws Exception {
809+
810+
logger.info("auth0 change password request");
811+
812+
if(Utils.isEmpty(email))
813+
throw new APIRuntimeException(SC_BAD_REQUEST, String.format(MSG_TEMPLATE_MANDATORY, "email"));
814+
815+
User user = userDao.findUserByEmail(email);
816+
user.setCredential(new Credential());
817+
user.getCredential().setPassword(password);
818+
819+
if(user==null) {
820+
throw new APIRuntimeException(SC_UNAUTHORIZED, "Credentials are incorrect.");
821+
}
822+
823+
String error = user.validatePassoword();
824+
if (error != null) {
825+
throw new APIRuntimeException(SC_BAD_REQUEST, error);
826+
}
827+
828+
User dbUser = null;
829+
if(dbUser==null && user.getEmail()!=null) {
830+
logger.debug(String.format("Auth0: findUserByEmail(%s)", user.getEmail()));
831+
dbUser = this.userDao.findUserByEmail(user.getEmail());
832+
}
833+
834+
if(dbUser==null) {
835+
throw new APIRuntimeException(SC_NOT_FOUND, MSG_TEMPLATE_USER_NOT_FOUND);
836+
}
837+
838+
if(dbUser.getCredential()==null)
839+
dbUser.setCredential(new Credential());
840+
dbUser.getCredential().setPassword(user.getCredential().getPassword());
841+
842+
logger.debug(String.format("Auth0: updating password for user: %s", dbUser.getHandle()));
843+
userDao.updatePassword(dbUser);
844+
845+
return ApiResponseFactory.createResponse("password updated successfully.");
846+
}
847+
793848
//TODO: should be PATCH?
794849
@PUT
795850
@Path("/activate")

0 commit comments

Comments
 (0)