Search in sources :

Example 36 with ResponseResult

use of com.vartech.common.app.beans.ResponseResult in project varsql by varsqlinfo.

the class GlobalExceptionHandler method databaseBlockingExceptionHandler.

/**
 * @method  : databaseBlockingExceptionHandler
 * @desc : database  차된
 * @author   : ytkim
 * @date   : 2021. 8. 19.
 * @param ex
 * @param request
 * @param response
 */
@ExceptionHandler(value = DatabaseBlockingException.class)
public void databaseBlockingExceptionHandler(DatabaseBlockingException ex, HttpServletRequest request, HttpServletResponse response) {
    ResponseResult result = new ResponseResult();
    exceptionRequestHandle(ex, request, response, result, "blockingDatabase");
}
Also used : ResponseResult(com.vartech.common.app.beans.ResponseResult) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler)

Example 37 with ResponseResult

use of com.vartech.common.app.beans.ResponseResult in project varsql by varsqlinfo.

the class VarsqlBasicAuthenticationEntryPoint method commence.

@Override
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authEx) throws IOException {
    logger.warn("VarsqlBasicAuthenticationEntryPoint url : {}, parameter : {} ", request.getRequestURL(), HttpUtils.getServletRequestParam(request));
    logger.warn("cookie values : {} ", HttpUtils.getAllCookieString(request));
    logger.warn("request header : {} ", HttpUtils.getAllReqHeaderString(request));
    logger.warn("response header : {} ", HttpUtils.getAllResHeaderString(response));
    logger.warn("varsqlBasicAuthenticationEntryPoint commence : {}", authEx.getMessage(), authEx);
    response.addHeader("WWW-Authenticate", "Basic realm=" + getRealmName());
    if (VarsqlUtils.isAjaxRequest(request)) {
        ResponseResult result = new ResponseResult();
        response.setContentType(VarsqlConstants.JSON_CONTENT_TYPE);
        response.setStatus(HttpStatus.OK.value());
        result.setResultCode(RequestResultCode.PRECONDITION_FAILED);
        try (Writer writer = response.getWriter()) {
            writer.write(VartechUtils.objectToJsonString(result));
        } catch (IOException e) {
            logger.error("exceptionRequestHandle Cause :" + e.getMessage(), e);
        }
    } else {
        try {
            RequestDispatcher dispatcher = request.getRequestDispatcher("/error/invalidToken");
            dispatcher.forward(request, response);
        } catch (ServletException | IOException e1) {
            logger.error("commence Cause :" + e1.getMessage(), e1);
        }
    }
// response.sendError(HttpStatus.UNAUTHORIZED.value(), HttpStatus.UNAUTHORIZED.getReasonPhrase());
}
Also used : ServletException(javax.servlet.ServletException) ResponseResult(com.vartech.common.app.beans.ResponseResult) IOException(java.io.IOException) Writer(java.io.Writer) RequestDispatcher(javax.servlet.RequestDispatcher)

Example 38 with ResponseResult

use of com.vartech.common.app.beans.ResponseResult in project varsql by varsqlinfo.

the class AdminDbMgmtServiceImpl method viewVtConntionPwInfo.

/**
 * @method  : viewVtConntionPwInfo
 * @desc : view db password
 * @author   : ytkim
 * @date   : 2020. 7. 4.
 * @param vconnid
 * @return ResponseResult
 */
public ResponseResult viewVtConntionPwInfo(String vconnid, String userPw) {
    ResponseResult resultObject = new ResponseResult();
    if (!userService.passwordCheck(SecurityUtil.loginName(), userPw)) {
        resultObject.setResultCode(RequestResultCode.ERROR);
        resultObject.setMessage("password not valid");
        return resultObject;
    }
    DBConnectionEntity dbInfo = dbConnectionModelRepository.findOne(DBConnectionSpec.detailInfo(vconnid)).orElseThrow(NullPointerException::new);
    try {
        resultObject.setItemOne(DBPasswordCryptionFactory.getInstance().decrypt(dbInfo.getVpw()));
    } catch (EncryptDecryptException e) {
        resultObject.setItemOne("password decrypt error");
    }
    return resultObject;
}
Also used : ResponseResult(com.vartech.common.app.beans.ResponseResult) DBConnectionEntity(com.varsql.web.model.entity.db.DBConnectionEntity) EncryptDecryptException(com.vartech.common.crypto.EncryptDecryptException)

Example 39 with ResponseResult

use of com.vartech.common.app.beans.ResponseResult in project varsql by varsqlinfo.

the class AdminDbMgmtServiceImpl method connectionCheck.

/**
 * @Method Name  : connectionCheck
 * @Method 설명 : 커넥션 체크.
 * @작성자   : ytkim
 * @작성일   : 2018. 1. 22.
 * @변경이력  :
 * @param vtConnection
 * @return
 * @throws EncryptDecryptException
 */
public ResponseResult connectionCheck(DBConnectionRequestDTO vtConnection) throws EncryptDecryptException {
    ResponseResult resultObject = new ResponseResult();
    this.dbConnectionModelRepository.findByConnInfo(vtConnection.getVconnid());
    logger.debug("connection check object param :  {}", VartechUtils.reflectionToString(vtConnection));
    String username = vtConnection.getVid();
    DBConnectionEntity dbInfo = this.dbConnectionModelRepository.findOne(DBConnectionSpec.detailInfo(vtConnection.getVconnid())).orElseThrow(NullPointerException::new);
    DBTypeDriverProviderEntity driverProviderEntity = dbInfo.getDbTypeDriverProvider();
    String url = vtConnection.getVurl();
    String defaultDriverValidationQuery = ValidationProperty.getInstance().validationQuery(driverProviderEntity.getDbType());
    if (!"Y".equals(driverProviderEntity.getDirectYn())) {
        DBTypeDriverEntity dbDriverModel = this.dbTypeDriverModelRepository.findByDriverId(driverProviderEntity.getDriverId());
        if (!"Y".equals(vtConnection.getUrlDirectYn())) {
            url = VarsqlJdbcUtil.getJdbcUrl(dbDriverModel.getUrlFormat(), JdbcURLFormatParam.builder().serverIp(vtConnection.getVserverip()).port(vtConnection.getVport()).databaseName(vtConnection.getVdatabasename()).build());
        }
        defaultDriverValidationQuery = StringUtils.isBlank(dbDriverModel.getValidationQuery()) ? defaultDriverValidationQuery : dbDriverModel.getValidationQuery();
    }
    logger.debug("connection check url :  {}", url);
    String validation_query = driverProviderEntity.getValidationQuery();
    validation_query = StringUtils.isBlank(validation_query) ? defaultDriverValidationQuery : validation_query;
    String failMessage = "";
    PreparedStatement pstmt = null;
    Connection connChk = null;
    VarsqlAppCode resultCode = VarsqlAppCode.SUCCESS;
    try {
        String pwd = vtConnection.getVpw();
        if (pwd == null || "".equals(pwd))
            pwd = dbInfo.getVpw();
        pwd = (pwd == null) ? "" : pwd;
        pwd = DBPasswordCryptionFactory.getInstance().decrypt(pwd);
        Properties p = new Properties();
        p.setProperty("user", username);
        p.setProperty("password", pwd);
        List<FileInfo> driverJarFiles;
        if (PathType.PATH.equals(PathType.getPathType(driverProviderEntity.getPathType()))) {
            driverJarFiles = FileServiceUtils.getFileInfos(driverProviderEntity.getDriverPath().split(";"));
        } else {
            driverJarFiles = FileServiceUtils.getFileInfos(dbTypeDriverFileEntityRepository.findByFileContId(driverProviderEntity.getDriverProviderId()));
        }
        JDBCDriverInfo jdbcDriverInfo = new JDBCDriverInfo(dbInfo.getDbTypeDriverProvider().getDriverProviderId(), dbInfo.getDbTypeDriverProvider().getDriverClass());
        jdbcDriverInfo.setDriverFiles(driverJarFiles);
        Driver dbDriver = JdbcDriverLoader.checkDriver(jdbcDriverInfo);
        connChk = dbDriver.connect(url, p);
        pstmt = connChk.prepareStatement(validation_query);
        pstmt.executeQuery();
        connChk.close();
    } catch (EncryptDecryptException e) {
        resultCode = VarsqlAppCode.ERROR;
        failMessage = "password decrypt error : " + e.getMessage();
        logger.error(getClass().getName(), (Throwable) e);
    } catch (ClassNotFoundException e) {
        resultCode = VarsqlAppCode.ERROR;
        failMessage = e.getMessage();
        logger.error("url :{}", url);
        logger.error(getClass().getName(), e);
    } catch (Exception e) {
        resultCode = VarsqlAppCode.ERROR;
        failMessage = e.getMessage();
        logger.error(getClass().getName(), e);
    } finally {
        JdbcUtils.close(connChk, pstmt, null);
    }
    resultObject.setResultCode(resultCode);
    resultObject.setMessage(failMessage);
    return resultObject;
}
Also used : DBTypeDriverProviderEntity(com.varsql.web.model.entity.db.DBTypeDriverProviderEntity) Connection(java.sql.Connection) Driver(java.sql.Driver) DBTypeDriverEntity(com.varsql.web.model.entity.db.DBTypeDriverEntity) PreparedStatement(java.sql.PreparedStatement) Properties(java.util.Properties) EncryptDecryptException(com.vartech.common.crypto.EncryptDecryptException) InvocationTargetException(java.lang.reflect.InvocationTargetException) BeansException(org.springframework.beans.BeansException) FileInfo(com.varsql.core.common.beans.FileInfo) ResponseResult(com.vartech.common.app.beans.ResponseResult) DBConnectionEntity(com.varsql.web.model.entity.db.DBConnectionEntity) JDBCDriverInfo(com.varsql.core.connection.beans.JDBCDriverInfo) EncryptDecryptException(com.vartech.common.crypto.EncryptDecryptException) VarsqlAppCode(com.varsql.core.common.code.VarsqlAppCode)

Example 40 with ResponseResult

use of com.vartech.common.app.beans.ResponseResult in project varsql by varsqlinfo.

the class AdminDbMgmtServiceImpl method jdbcProviderList.

public ResponseResult jdbcProviderList(SearchParameter searchParameter) {
    Sort sort = Sort.by(Sort.Direction.ASC, DBTypeDriverProviderEntity.DB_TYPE).and(Sort.by(Sort.Direction.ASC, DBTypeDriverProviderEntity.PROVIDER_NAME));
    List<DBTypeDriverProviderEntity> result = dbTypeDriverProviderRepository.findAll(DBTypeDriverProviderSpec.searchField(searchParameter), sort);
    List<DBTypeDriverProviderResponseDTO> list = result.stream().map(item -> {
        DBTypeDriverProviderResponseDTO dto = new DBTypeDriverProviderResponseDTO();
        dto.setDbType(item.getDbType());
        dto.setProviderName(item.getProviderName());
        dto.setDriverProviderId(item.getDriverProviderId());
        dto.setDriverId(item.getDriverId());
        dto.setDirectYn(item.getDirectYn());
        return dto;
    }).collect(Collectors.toList());
    return VarsqlUtils.getResponseResultItemList(list);
}
Also used : Arrays(java.util.Arrays) Connection(java.sql.Connection) PropertyUtils(org.apache.commons.beanutils.PropertyUtils) DBConnectionRequestDTO(com.varsql.web.dto.db.DBConnectionRequestDTO) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) VarsqlUtils(com.varsql.web.util.VarsqlUtils) BeanWrapperImpl(org.springframework.beans.BeanWrapperImpl) DBTypeEntity(com.varsql.web.model.entity.db.DBTypeEntity) DBTypeDriverProviderSpec(com.varsql.web.repository.spec.DBTypeDriverProviderSpec) VarsqlJdbcUtil(com.varsql.core.common.util.VarsqlJdbcUtil) Map(java.util.Map) ConnectionFactory(com.varsql.core.connection.ConnectionFactory) EncryptDecryptException(com.vartech.common.crypto.EncryptDecryptException) SearchParameter(com.vartech.common.app.beans.SearchParameter) Sort(org.springframework.data.domain.Sort) DBTypeEntityRepository(com.varsql.web.repository.db.DBTypeEntityRepository) DBTypeDriverProviderRepository(com.varsql.web.repository.db.DBTypeDriverProviderRepository) JdbcURLFormatParam(com.varsql.core.connection.beans.JdbcURLFormatParam) RequestResultCode(com.vartech.common.constants.RequestResultCode) DBConnectionEntityRepository(com.varsql.web.repository.db.DBConnectionEntityRepository) Set(java.util.Set) ValidationProperty(com.varsql.core.configuration.prop.ValidationProperty) PreparedStatement(java.sql.PreparedStatement) Page(org.springframework.data.domain.Page) Collectors(java.util.stream.Collectors) DBTypeDriverEntity(com.varsql.web.model.entity.db.DBTypeDriverEntity) InvocationTargetException(java.lang.reflect.InvocationTargetException) List(java.util.List) PathType(com.varsql.core.common.constants.PathType) UserService(com.varsql.web.security.UserService) DBTypeDriverEntityRepository(com.varsql.web.repository.db.DBTypeDriverEntityRepository) DBManagerEntityRepository(com.varsql.web.repository.db.DBManagerEntityRepository) JDBCDriverInfo(com.varsql.core.connection.beans.JDBCDriverInfo) BeanUtils(org.springframework.beans.BeanUtils) JdbcDriverLoader(com.varsql.core.common.util.JdbcDriverLoader) ResourceConfigConstants(com.varsql.web.constants.ResourceConfigConstants) JdbcUtils(com.varsql.core.sql.util.JdbcUtils) BeanWrapper(org.springframework.beans.BeanWrapper) HashMap(java.util.HashMap) DBTypeDriverProviderEntity(com.varsql.web.model.entity.db.DBTypeDriverProviderEntity) ResponseResult(com.vartech.common.app.beans.ResponseResult) SecurityUtil(com.varsql.core.common.util.SecurityUtil) HashSet(java.util.HashSet) VartechUtils(com.vartech.common.utils.VartechUtils) CacheManager(org.springframework.cache.CacheManager) Service(org.springframework.stereotype.Service) Qualifier(org.springframework.beans.factory.annotation.Qualifier) DBConnectionMapper(com.varsql.web.model.mapper.db.DBConnectionMapper) FileInfo(com.varsql.core.common.beans.FileInfo) DBConnectionDetailMapper(com.varsql.web.model.mapper.db.DBConnectionDetailMapper) Properties(java.util.Properties) Logger(org.slf4j.Logger) AbstractService(com.varsql.web.common.service.AbstractService) FileServiceUtils(com.varsql.web.util.FileServiceUtils) DBPasswordCryptionFactory(com.varsql.core.crypto.DBPasswordCryptionFactory) StringUtils(com.vartech.common.utils.StringUtils) DBTypeDriverFileEntityRepository(com.varsql.web.repository.db.DBTypeDriverFileEntityRepository) BeansException(org.springframework.beans.BeansException) DBConnectionEntity(com.varsql.web.model.entity.db.DBConnectionEntity) Driver(java.sql.Driver) VarsqlBeanUtils(com.varsql.web.util.VarsqlBeanUtils) DBGroupMappingDbEntityRepository(com.varsql.web.repository.db.DBGroupMappingDbEntityRepository) VarsqlAppCode(com.varsql.core.common.code.VarsqlAppCode) DBTypeDriverProviderResponseDTO(com.varsql.web.dto.db.DBTypeDriverProviderResponseDTO) CacheUtils(com.varsql.web.common.cache.CacheUtils) DBConnectionSpec(com.varsql.web.repository.spec.DBConnectionSpec) Transactional(org.springframework.transaction.annotation.Transactional) DBTypeDriverProviderResponseDTO(com.varsql.web.dto.db.DBTypeDriverProviderResponseDTO) DBTypeDriverProviderEntity(com.varsql.web.model.entity.db.DBTypeDriverProviderEntity) Sort(org.springframework.data.domain.Sort)

Aggregations

ResponseResult (com.vartech.common.app.beans.ResponseResult)75 ExceptionHandler (org.springframework.web.bind.annotation.ExceptionHandler)15 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)14 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)13 Transactional (org.springframework.transaction.annotation.Transactional)12 MetaControlBean (com.varsql.core.db.MetaControlBean)10 DBTypeDriverProviderEntity (com.varsql.web.model.entity.db.DBTypeDriverProviderEntity)8 HashMap (java.util.HashMap)8 DBConnectionEntity (com.varsql.web.model.entity.db.DBConnectionEntity)6 EncryptDecryptException (com.vartech.common.crypto.EncryptDecryptException)6 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 Map (java.util.Map)6 ObjectError (org.springframework.validation.ObjectError)6 FileInfoEntity (com.varsql.web.model.entity.app.FileInfoEntity)5 SQLException (java.sql.SQLException)5 FileInfo (com.varsql.core.common.beans.FileInfo)4 JDBCDriverInfo (com.varsql.core.connection.beans.JDBCDriverInfo)4 DBMetadataException (com.varsql.core.exception.DBMetadataException)4 DBTypeDriverEntity (com.varsql.web.model.entity.db.DBTypeDriverEntity)4