use of com.webank.wedatasphere.qualitis.entity.User in project Qualitis by WeBankFinTech.
the class UserSpecPermissionServiceImpl method modifyUserSpecPermission.
@Override
@Transactional(rollbackFor = { RuntimeException.class, UnExpectedRequestException.class })
public GeneralResponse<?> modifyUserSpecPermission(ModifyUserSpecPermissionRequest request) throws UnExpectedRequestException {
// Check Arguments
checkRequest(request);
// Find user permission by id
String uuid = request.getUuid();
UserSpecPermission userSpecPermissionInDb = userSpecPermissionDao.findByUuid(uuid);
if (userSpecPermissionInDb == null) {
throw new UnExpectedRequestException("user_spec_permission id {&DOES_NOT_EXIST}, request: " + request);
}
LOGGER.info("Succeed to find user_permission. uuid: {}, user_id: {}, permission_id: {}, current_user: {}", uuid, userSpecPermissionInDb.getUser().getId(), userSpecPermissionInDb.getPermission().getId(), HttpUtils.getUserName(httpServletRequest));
// Check existence of user and permission
long userId = request.getUserId();
long permissionId = request.getPermissionId();
User userInDb = userDao.findById(userId);
if (userInDb == null) {
throw new UnExpectedRequestException("user id {&DOES_NOT_EXIST}, request: " + request);
}
Permission permissionInDb = permissionDao.findById(permissionId);
if (permissionInDb == null) {
throw new UnExpectedRequestException("permission id {&DOES_NOT_EXIST}, request: " + request);
}
UserSpecPermission userIdAndPermissionIdInDb = userSpecPermissionDao.findByUserAndPermission(userInDb, permissionInDb);
if (userIdAndPermissionIdInDb != null) {
throw new UnExpectedRequestException("user id and permission id {&ALREADY_EXIST}, request: " + request);
}
// Save user permission
userSpecPermissionInDb.setPermission(permissionInDb);
userSpecPermissionInDb.setUser(userInDb);
UserSpecPermission savedUserSpecPermission = userSpecPermissionDao.saveUserSpecPermission(userSpecPermissionInDb);
LOGGER.info("Succeed to find user_permission. uuid: {}, user_id: {}, permission_id: {}, current_user: {}", uuid, savedUserSpecPermission.getUser().getId(), savedUserSpecPermission.getPermission().getId(), HttpUtils.getUserName(httpServletRequest));
return new GeneralResponse<>("200", "{&MODIFY_USER_SPEC_PERMISSION_SUCCESSFULLY}", null);
}
use of com.webank.wedatasphere.qualitis.entity.User in project Qualitis by WeBankFinTech.
the class LoginServiceImpl method addToSession.
@Override
public void addToSession(String username, HttpServletRequest httpServletRequest) {
// Find user by username
User userInDb = userDao.findByUsername(username);
addUserToSession(userInDb, httpServletRequest);
addPermissionsToSession(userInDb, httpServletRequest);
addRandomToSession(httpServletRequest);
}
use of com.webank.wedatasphere.qualitis.entity.User in project Qualitis by WeBankFinTech.
the class LoginServiceImpl method localLogin.
@Override
public GeneralResponse<?> localLogin(LocalLoginRequest request) throws LoginFailedException, UnExpectedRequestException {
// Check Arguments
checkRequest(request);
String username = request.getUsername();
String password = request.getPassword();
long currentLoginTime = System.currentTimeMillis();
User userInDb = userDao.findByUsername(username);
if (userInDb == null) {
throw new LoginFailedException("{&USER_NOT_EXIST}");
}
if (userInDb.getLockTime() != null && (currentLoginTime - userInDb.getLockTime()) / (1000 * 60) < 10) {
String lockTime = SDF.format(new Date(userInDb.getLockTime()));
LOGGER.info("Login locked. user: {}, lock time: {}", username, lockTime);
throw new LoginFailedException("{&LOGIN_LOCKED}" + lockTime);
}
if (localLogin(userInDb, password)) {
addToSession(username, httpRequest);
clearErrorLoginRecord(userInDb);
userDao.saveUser(userInDb);
LOGGER.info("Succeed to login. user: {}, current_user: {}", username, username);
return new GeneralResponse<>("200", "{&LOGIN_SUCCESS}", null);
} else {
// Login failed in first time.
if (userInDb.getLoginErrorTime() == null || userInDb.getLoginErrorCount() == null) {
userInDb.setLoginErrorTime(currentLoginTime);
userInDb.setLoginErrorCount(1);
} else {
// Check error count in 5 minutes decide to lock
boolean consecutiveError = (currentLoginTime - userInDb.getLoginErrorTime()) / (1000 * 60) < 5;
if (consecutiveError) {
userInDb.setLoginErrorCount(userInDb.getLoginErrorCount() + 1);
if (userInDb.getLoginErrorCount() >= 5) {
userInDb.setLockTime(currentLoginTime);
}
} else {
userInDb.setLoginErrorTime(currentLoginTime);
userInDb.setLoginErrorCount(1);
}
}
userDao.saveUser(userInDb);
throw new LoginFailedException("{&LOGIN_FAILED}" + (5 - userInDb.getLoginErrorCount()));
}
}
use of com.webank.wedatasphere.qualitis.entity.User in project Qualitis by WeBankFinTech.
the class ApplicationServiceImpl method filterProjectApplication.
@Override
public GeneralResponse<?> filterProjectApplication(FilterProjectRequest request) throws UnExpectedRequestException {
// Check arguments
FilterProjectRequest.checkRequest(request);
Long userId = HttpUtils.getUserId(httpServletRequest);
User user = userDao.findById(userId);
Integer page = request.getPage();
Integer size = request.getSize();
Long projectId = request.getProjectId();
int total = applicationDao.countByCreateUserAndProject(user.getUserName(), projectId).intValue();
List<Application> applicationList = applicationDao.findByCreateUserAndProject(user.getUserName(), projectId, page, size);
GetAllResponse<ApplicationResponse> getAllResponse = new GetAllResponse<>();
List<ApplicationResponse> applicationResponses = new ArrayList<>();
for (Application application : applicationList) {
List<Task> tasks = taskDao.findByApplication(application);
ApplicationResponse response = new ApplicationResponse(application, tasks, httpServletRequest.getHeader("Content-Language"));
if (application.getCreateUser().equals(user.getUserName()) || application.getExecuteUser().equals(user.getUserName())) {
response.setKillOption(true);
} else {
response.setKillOption(false);
}
applicationResponses.add(response);
}
getAllResponse.setData(applicationResponses);
getAllResponse.setTotal(total);
List<String> applicationIdList = getAllResponse.getData().stream().map(ApplicationResponse::getApplicationId).collect(Collectors.toList());
LOGGER.info("Succeed to find applications. size: {}, id of applications: {}", total, applicationIdList);
return new GeneralResponse<>("200", "{&SUCCEED_TO_GET_APPLICATIONS}", getAllResponse);
}
use of com.webank.wedatasphere.qualitis.entity.User in project Qualitis by WeBankFinTech.
the class ApplicationServiceImpl method getDataSource.
@Override
public GeneralResponse<?> getDataSource(PageRequest request) throws UnExpectedRequestException {
// Check arguments
PageRequest.checkRequest(request);
Long userId = HttpUtils.getUserId(httpServletRequest);
User user = userDao.findById(userId);
long total;
// Find datasource by user
List<Map<String, String>> taskDataSourceMap = taskDataSourceDao.findByUser(user.getUserName());
total = taskDataSourceMap.size();
List<ApplicationClusterResponse> response = new ArrayList<>();
Map<String, ApplicationClusterResponse> map = new HashMap<>(2);
for (Map<String, String> currentMap : taskDataSourceMap) {
putIntoCluster(response, currentMap, map);
}
LOGGER.info("Succeed to find dataSources. size: {}, id of dataSources: {}", total, response);
return new GeneralResponse<>("200", "{&SUCCEED_TO_GET_APPLICATION_DATASOURCE}", response);
}
Aggregations