Skip to content

Commit 3395eb9

Browse files
author
Varun Deep Saini
committed
AMM-118: Add time-based account lockout with auto-unlock
Signed-off-by: Varun Deep Saini <varun.23bcs10048@ms.sst.scaler.com>
1 parent a1a0027 commit 3395eb9

6 files changed

Lines changed: 267 additions & 125 deletions

File tree

src/main/java/com/iemr/common/controller/users/IEMRAdminController.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,4 +1230,42 @@ public ResponseEntity<?> getUserDetails(@PathVariable("userName") String userNam
12301230
}
12311231

12321232
}
1233+
1234+
@Operation(summary = "Unlock user account locked due to failed login attempts")
1235+
@RequestMapping(value = "/unlockUserAccount", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON, headers = "Authorization")
1236+
public String unlockUserAccount(@RequestBody String request) {
1237+
OutputResponse response = new OutputResponse();
1238+
try {
1239+
Long userId = parseUserIdFromRequest(request);
1240+
boolean unlocked = iemrAdminUserServiceImpl.unlockUserAccount(userId);
1241+
response.setResponse(unlocked ? "User account successfully unlocked" : "User account was not locked");
1242+
} catch (Exception e) {
1243+
logger.error("Error unlocking user account: " + e.getMessage(), e);
1244+
response.setError(e);
1245+
}
1246+
return response.toString();
1247+
}
1248+
1249+
@Operation(summary = "Get user account lock status")
1250+
@RequestMapping(value = "/getUserLockStatus", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON, headers = "Authorization")
1251+
public String getUserLockStatus(@RequestBody String request) {
1252+
OutputResponse response = new OutputResponse();
1253+
try {
1254+
Long userId = parseUserIdFromRequest(request);
1255+
String lockStatusJson = iemrAdminUserServiceImpl.getUserLockStatusJson(userId);
1256+
response.setResponse(lockStatusJson);
1257+
} catch (Exception e) {
1258+
logger.error("Error getting user lock status: " + e.getMessage(), e);
1259+
response.setError(e);
1260+
}
1261+
return response.toString();
1262+
}
1263+
1264+
private Long parseUserIdFromRequest(String request) throws IEMRException {
1265+
JsonObject requestObj = JsonParser.parseString(request).getAsJsonObject();
1266+
if (!requestObj.has("userId") || requestObj.get("userId").isJsonNull()) {
1267+
throw new IEMRException("userId is required");
1268+
}
1269+
return requestObj.get("userId").getAsLong();
1270+
}
12331271
}

src/main/java/com/iemr/common/data/users/User.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,10 @@ public class User implements Serializable {
213213
@Column(name = "dhistoken")
214214
private String dhistoken;
215215

216+
@Expose
217+
@Column(name = "lock_timestamp")
218+
private Timestamp lockTimestamp;
219+
216220
/*
217221
* protected User() { }
218222
*/

src/main/java/com/iemr/common/repository/users/IEMRUserRepositoryCustom.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ UserSecurityQMapping verifySecurityQuestionAnswers(@Param("UserID") Long UserID,
7575

7676
@Query("SELECT u FROM User u WHERE u.userID=5718")
7777
User getAllExistingUsers();
78-
78+
7979
User findByUserID(Long userID);
8080

8181
}

src/main/java/com/iemr/common/service/users/IEMRAdminUserService.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ public List<ServiceRoleScreenMapping> getUserServiceRoleMappingForProvider(Integ
123123

124124
List<User> getUserIdbyUserName(String userName) throws IEMRException;
125125

126+
boolean unlockUserAccount(Long userId) throws IEMRException;
127+
128+
String getUserLockStatusJson(Long userId) throws IEMRException;
126129

127-
128130
}

0 commit comments

Comments
 (0)