Search in sources :

Example 21 with User

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);
}
Also used : GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) UnExpectedRequestException(com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException) User(com.webank.wedatasphere.qualitis.entity.User) UserSpecPermission(com.webank.wedatasphere.qualitis.entity.UserSpecPermission) Permission(com.webank.wedatasphere.qualitis.entity.Permission) UserSpecPermission(com.webank.wedatasphere.qualitis.entity.UserSpecPermission) Transactional(org.springframework.transaction.annotation.Transactional)

Example 22 with User

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);
}
Also used : User(com.webank.wedatasphere.qualitis.entity.User)

Example 23 with User

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()));
    }
}
Also used : GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) LoginFailedException(com.webank.wedatasphere.qualitis.exception.LoginFailedException) User(com.webank.wedatasphere.qualitis.entity.User) Date(java.util.Date)

Example 24 with User

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);
}
Also used : Task(com.webank.wedatasphere.qualitis.entity.Task) User(com.webank.wedatasphere.qualitis.entity.User) ApplicationResponse(com.webank.wedatasphere.qualitis.response.ApplicationResponse) ArrayList(java.util.ArrayList) GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) GetAllResponse(com.webank.wedatasphere.qualitis.response.GetAllResponse) Application(com.webank.wedatasphere.qualitis.entity.Application)

Example 25 with User

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);
}
Also used : User(com.webank.wedatasphere.qualitis.entity.User) ApplicationClusterResponse(com.webank.wedatasphere.qualitis.response.ApplicationClusterResponse) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) GeneralResponse(com.webank.wedatasphere.qualitis.response.GeneralResponse) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

User (com.webank.wedatasphere.qualitis.entity.User)54 GeneralResponse (com.webank.wedatasphere.qualitis.response.GeneralResponse)38 UnExpectedRequestException (com.webank.wedatasphere.qualitis.exception.UnExpectedRequestException)30 Transactional (org.springframework.transaction.annotation.Transactional)23 ArrayList (java.util.ArrayList)22 UserRole (com.webank.wedatasphere.qualitis.entity.UserRole)21 Department (com.webank.wedatasphere.qualitis.entity.Department)15 List (java.util.List)14 RuleMetric (com.webank.wedatasphere.qualitis.entity.RuleMetric)13 PermissionDeniedRequestException (com.webank.wedatasphere.qualitis.exception.PermissionDeniedRequestException)13 GetAllResponse (com.webank.wedatasphere.qualitis.response.GetAllResponse)12 RuleMetricDepartmentUser (com.webank.wedatasphere.qualitis.entity.RuleMetricDepartmentUser)10 Project (com.webank.wedatasphere.qualitis.project.entity.Project)10 ProjectUser (com.webank.wedatasphere.qualitis.project.entity.ProjectUser)7 Application (com.webank.wedatasphere.qualitis.entity.Application)6 Task (com.webank.wedatasphere.qualitis.entity.Task)6 HttpServletRequest (javax.servlet.http.HttpServletRequest)6 UserDao (com.webank.wedatasphere.qualitis.dao.UserDao)5 ApplicationResponse (com.webank.wedatasphere.qualitis.response.ApplicationResponse)5 Rule (com.webank.wedatasphere.qualitis.rule.entity.Rule)5