Added user action and versioning for login attempt.
This commit is contained in:
@@ -38,18 +38,12 @@ public class LoginAttemptDao {
|
|||||||
public LoginAttemptEntity createLoginAttempt(LoginAttemptEntity loginAttemptEntity) {
|
public LoginAttemptEntity createLoginAttempt(LoginAttemptEntity loginAttemptEntity) {
|
||||||
|
|
||||||
VersionActionTypeEnum actionType;
|
VersionActionTypeEnum actionType;
|
||||||
LoginAttemptEntity oldLoginAttemptEntity = Utils.getClonedEntityForData(loginAttemptEntity);
|
|
||||||
loginAttemptEntity.setAttemptDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
|
loginAttemptEntity.setAttemptDate(DateTimeUtil.DateServerToUTC(LocalDateTime.now()));
|
||||||
if(loginAttemptEntity.getId() != null ) {
|
loginAttemptEntity = loginAttemptRepository.save(loginAttemptEntity);
|
||||||
actionType = VersionActionTypeEnum.UPDATE;
|
|
||||||
}else{
|
|
||||||
actionType = VersionActionTypeEnum.INSERT;
|
|
||||||
oldLoginAttemptEntity = null;
|
|
||||||
}
|
|
||||||
loginAttemptEntity = loginAttemptRepository.save(loginAttemptEntity);
|
|
||||||
|
|
||||||
/** This code is responsible for adding a version history log for "Create Login Attempt" operation. **/
|
/** This code is responsible for adding a version history log for "Create Login Attempt" operation. **/
|
||||||
loggingUtil.addVersionHistoryWithoutToken(VersionHistoryRequest.builder().actionType(actionType).request(request).oldData(oldLoginAttemptEntity).newData(loginAttemptEntity).build());
|
loggingUtil.addVersionHistoryWithoutToken(
|
||||||
|
VersionHistoryRequest.builder().actionType(VersionActionTypeEnum.INSERT).request(request).oldData(null).newData(loginAttemptEntity).build());
|
||||||
|
|
||||||
return loginAttemptEntity;
|
return loginAttemptEntity;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,7 +98,11 @@ public enum UserActionContextEnum {
|
|||||||
DELETE_DOCUMENT("DELETE_DOCUMENT"),
|
DELETE_DOCUMENT("DELETE_DOCUMENT"),
|
||||||
UPDATE_DOCUMENT("UPDATE_DOCUEMENT"),
|
UPDATE_DOCUMENT("UPDATE_DOCUEMENT"),
|
||||||
UPDATE_IMAGES("UPDATE_IMAGES"),
|
UPDATE_IMAGES("UPDATE_IMAGES"),
|
||||||
GET_DOCUMENT("GET_DOCUMENT");
|
GET_DOCUMENT("GET_DOCUMENT"),
|
||||||
|
|
||||||
|
/** Login attempt action context **/
|
||||||
|
GET_LOGIN_ATTEMPT_LIST("GET_LOGIN_ATTEMPT_LIST"),
|
||||||
|
ADD_LOGIN_ATTEMPT("ADD_LOGIN_ATTEMPT");
|
||||||
|
|
||||||
private final String value;
|
private final String value;
|
||||||
|
|
||||||
|
|||||||
@@ -5,11 +5,15 @@ import net.gepafin.tendermanagement.config.Translator;
|
|||||||
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
import net.gepafin.tendermanagement.constants.GepafinConstant;
|
||||||
import net.gepafin.tendermanagement.entities.LoginAttemptEntity;
|
import net.gepafin.tendermanagement.entities.LoginAttemptEntity;
|
||||||
import net.gepafin.tendermanagement.entities.UserEntity;
|
import net.gepafin.tendermanagement.entities.UserEntity;
|
||||||
|
import net.gepafin.tendermanagement.enums.UserActionContextEnum;
|
||||||
|
import net.gepafin.tendermanagement.enums.UserActionLogsEnum;
|
||||||
import net.gepafin.tendermanagement.model.request.LoginAttemptReq;
|
import net.gepafin.tendermanagement.model.request.LoginAttemptReq;
|
||||||
|
import net.gepafin.tendermanagement.model.request.UserActionRequest;
|
||||||
import net.gepafin.tendermanagement.model.response.LoginAttemptPageableResponseBean;
|
import net.gepafin.tendermanagement.model.response.LoginAttemptPageableResponseBean;
|
||||||
import net.gepafin.tendermanagement.model.util.Response;
|
import net.gepafin.tendermanagement.model.util.Response;
|
||||||
import net.gepafin.tendermanagement.service.LoginAttemptService;
|
import net.gepafin.tendermanagement.service.LoginAttemptService;
|
||||||
import net.gepafin.tendermanagement.service.UserService;
|
import net.gepafin.tendermanagement.service.UserService;
|
||||||
|
import net.gepafin.tendermanagement.util.LoggingUtil;
|
||||||
import net.gepafin.tendermanagement.util.Validator;
|
import net.gepafin.tendermanagement.util.Validator;
|
||||||
import net.gepafin.tendermanagement.web.rest.api.LoginAttemptApi;
|
import net.gepafin.tendermanagement.web.rest.api.LoginAttemptApi;
|
||||||
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
import net.gepafin.tendermanagement.web.rest.api.errors.Status;
|
||||||
@@ -38,8 +42,15 @@ public class LoginAttemptApiController implements LoginAttemptApi {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private UserService userService;
|
private UserService userService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private LoggingUtil loggingUtil;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResponseEntity<LoginAttemptPageableResponseBean<List<LoginAttemptEntity>>> getLoginAttemptsList(HttpServletRequest request, Integer pageNo, Integer pageLimit) {
|
public ResponseEntity<LoginAttemptPageableResponseBean<List<LoginAttemptEntity>>> getLoginAttemptsList(HttpServletRequest request, Integer pageNo, Integer pageLimit) {
|
||||||
|
|
||||||
|
/** This code is responsible for creating user action logs for the "Get login attempt list" operation. **/
|
||||||
|
loggingUtil.logUserAction(UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.VIEW).actionContext(UserActionContextEnum.GET_LOGIN_ATTEMPT_LIST).build());
|
||||||
|
|
||||||
LoginAttemptPageableResponseBean<List<LoginAttemptEntity>> response = loginAttemptService.getLoginAttemptsList(request, pageNo, pageLimit);
|
LoginAttemptPageableResponseBean<List<LoginAttemptEntity>> response = loginAttemptService.getLoginAttemptsList(request, pageNo, pageLimit);
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(response);
|
return ResponseEntity.status(HttpStatus.OK).body(response);
|
||||||
}
|
}
|
||||||
@@ -50,6 +61,10 @@ public class LoginAttemptApiController implements LoginAttemptApi {
|
|||||||
String userIdString = (String) userInfo.get("userId");
|
String userIdString = (String) userInfo.get("userId");
|
||||||
UserEntity currentUser = userService.getUserEntityById(Long.parseLong(userIdString));
|
UserEntity currentUser = userService.getUserEntityById(Long.parseLong(userIdString));
|
||||||
loginAttemptReq.setUserName(currentUser.getEmail());
|
loginAttemptReq.setUserName(currentUser.getEmail());
|
||||||
|
|
||||||
|
/** This code is responsible for creating user action logs for the "add login attempt" operation. **/
|
||||||
|
loggingUtil.logUserAction(UserActionRequest.builder().request(request).actionType(UserActionLogsEnum.INSERT).actionContext(UserActionContextEnum.ADD_LOGIN_ATTEMPT).build());
|
||||||
|
|
||||||
loginAttemptService.createLoginAttempt(loginAttemptReq, request);
|
loginAttemptService.createLoginAttempt(loginAttemptReq, request);
|
||||||
return ResponseEntity.status(HttpStatus.CREATED).body(new Response<Void>(null, Status.SUCCESS, Translator.toLocale(GepafinConstant.LOGIN_ATTEMPTED_CREATED_SUCCESSFULLY)));
|
return ResponseEntity.status(HttpStatus.CREATED).body(new Response<Void>(null, Status.SUCCESS, Translator.toLocale(GepafinConstant.LOGIN_ATTEMPTED_CREATED_SUCCESSFULLY)));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user