use of com.vartech.common.crypto.EncryptDecryptException 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;
}
use of com.vartech.common.crypto.EncryptDecryptException 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;
}
use of com.vartech.common.crypto.EncryptDecryptException in project varsql by varsqlinfo.
the class SimpleConnectionInfoDao method getConnectionInfo.
@Override
public ConnectionInfo getConnectionInfo(String connid) {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
conn = ConnectionFactory.getInstance().getConnection();
StringBuffer querySb = new StringBuffer();
querySb.append(" select ");
querySb.append(" a.* ");
querySb.append(" , b.DRIVER_PROVIDER_ID, b.DRIVER_CLASS, b.VALIDATION_QUERY, b.DB_TYPE, b.PATH_TYPE, b.DRIVER_PATH ");
querySb.append(" , c.URL_FORMAT ");
querySb.append(" from ");
querySb.append(" VTCONNECTION a left outer join VTDBTYPE_DRIVER_PROVIDER b on a.VDRIVER = b.DRIVER_PROVIDER_ID ");
querySb.append(" left outer join VTDBTYPE_DRIVER_TYPE c on b.DRIVER_ID = c.DRIVER_ID ");
querySb.append(" where 1=1 ");
querySb.append(" and a.VCONNID = ? ");
pstmt = conn.prepareStatement(querySb.toString());
pstmt.setString(1, connid);
rs = pstmt.executeQuery();
if (rs == null)
throw new ConnectionFactoryException("not valid connection infomation :" + connid);
rs.next();
ConnectionInfo connInfo = new ConnectionInfo();
connInfo.setConnid(rs.getString("VCONNID"));
connInfo.setAliasName(rs.getString("VNAME"));
connInfo.setType(rs.getString("VTYPE").toLowerCase());
String urlDirectYn = rs.getString("URL_DIRECT_YN");
if ("Y".equals(urlDirectYn)) {
connInfo.setUrl(rs.getString("VURL"));
} else {
connInfo.setUrl(VarsqlJdbcUtil.getJdbcUrl(rs.getString("URL_FORMAT"), JdbcURLFormatParam.builder().serverIp(rs.getString("VSERVERIP")).port(Integer.parseInt(rs.getString("VPORT"))).databaseName(rs.getString("VDATABASENAME")).build()));
}
connInfo.setUsername(rs.getString("VID"));
if ("varsql".equals(connInfo.getConnid())) {
connInfo.setPassword(rs.getString("VPW"));
} else {
String str = rs.getString("VPW");
connInfo.setPassword("");
if (str != null && !"".equals(str))
connInfo.setPassword(DBPasswordCryptionFactory.getInstance().decrypt(rs.getString("VPW")));
}
connInfo.setPoolOptions(rs.getString("VPOOLOPT"));
connInfo.setConnectionOptions(rs.getString("VCONNOPT"));
connInfo.setMaxActive(NumberUtils.toInt(rs.getString("MAX_ACTIVE"), 10));
connInfo.setMinIdle(NumberUtils.toInt(rs.getString("MIN_IDLE"), 3));
connInfo.setConnectionTimeOut(NumberUtils.toInt(rs.getString("TIMEOUT"), 18000));
connInfo.setExportCount(NumberUtils.toInt(rs.getString("EXPORTCOUNT"), 1000));
connInfo.setTestWhileIdle("Y".equals(rs.getString("TEST_WHILE_IDLE")));
String conn_query = rs.getString("VQUERY");
String dbvalidation_query = rs.getString("VALIDATION_QUERY");
conn_query = (conn_query == null) ? "" : conn_query;
dbvalidation_query = (dbvalidation_query == null) ? "" : dbvalidation_query;
String validation_query = !"".equals(conn_query.trim()) ? conn_query : (!"".equals(dbvalidation_query.trim()) ? dbvalidation_query : ValidationProperty.getInstance().validationQuery(connInfo.getType()));
this.logger.debug("valication_query : {}", validation_query);
connInfo.setValidationQuery(validation_query);
String driverProviderId = rs.getString("DRIVER_PROVIDER_ID");
pstmt.close();
pstmt = conn.prepareStatement(" select FILE_NAME,FILE_PATH,FILE_EXT from VTDBTYPE_DRIVER_FILE where FILE_CONT_ID = ? ");
pstmt.setString(1, driverProviderId);
rs.close();
rs = pstmt.executeQuery();
if (rs == null) {
throw new ConnectionFactoryException("jdbc driver file not found :" + connid);
}
List<FileInfo> jarFileList = new ArrayList<>();
while (rs.next()) {
FileInfo fi = new FileInfo();
fi.setName(rs.getString("FILE_NAME"));
fi.setPath(Paths.get(VarsqlConstants.UPLOAD_PATH).toAbsolutePath().resolve(rs.getString("FILE_PATH")).normalize().toAbsolutePath().toString());
fi.setExt(rs.getString("FILE_EXT"));
jarFileList.add(fi);
}
JDBCDriverInfo jdbcDriverInfo = new JDBCDriverInfo(rs.getString("DRIVER_PROVIDER_ID"), rs.getString("DRIVER_CLASS"));
jdbcDriverInfo.setDriverFiles(jarFileList);
connInfo.setJdbcDriverInfo(jdbcDriverInfo);
return connInfo;
} catch (EncryptDecryptException e) {
this.logger.error("password decrypt error", e);
throw new ConnectionFactoryException("password decrypt error", e);
} catch (Exception e) {
this.logger.error("empty connection info", e);
throw new ConnectionFactoryException("empty connection info : [" + connid + "]", e);
} finally {
JdbcUtils.close(conn, pstmt, rs);
}
}
use of com.vartech.common.crypto.EncryptDecryptException in project varsql by varsqlinfo.
the class DriverProvierMgmtServiceImpl method driverCheck.
public ResponseResult driverCheck(DBTypeDriverProviderRequestDTO dto) throws EncryptDecryptException {
ResponseResult resultObject = new ResponseResult();
String driverProviderId = dto.getDriverProviderId();
DBTypeDriverProviderEntity entity = dbTypeDriverProviderRepository.findByDriverProviderId(driverProviderId);
if (entity == null) {
resultObject.setResultCode(RequestResultCode.NOT_FOUND);
resultObject.setMessage("db jdbc provider not found : " + driverProviderId);
return resultObject;
}
StringBuffer errorMsg = new StringBuffer();
try {
List<FileInfo> driverJarFiles;
if (PathType.PATH.equals(PathType.getPathType(dto.getPathType()))) {
driverJarFiles = FileServiceUtils.getFileInfos(dto.getDriverPath().split(";"));
} else {
driverJarFiles = FileServiceUtils.getFileInfos(dbTypeDriverFileEntityRepository.findByFileContId(entity.getDriverProviderId()));
}
JDBCDriverInfo jdbcDriverInfo = new JDBCDriverInfo(dto.getDriverProviderId(), dto.getDriverClass());
jdbcDriverInfo.setDriverFiles(driverJarFiles);
if (JdbcDriverLoader.checkDriver(jdbcDriverInfo) != null) {
resultObject.setResultCode(VarsqlAppCode.SUCCESS);
} else {
resultObject.setMessage("driver null");
resultObject.setResultCode(VarsqlAppCode.ERROR);
}
resultObject.setResultCode(VarsqlAppCode.SUCCESS);
} catch (ClassNotFoundException e) {
resultObject.setResultCode(VarsqlAppCode.ERROR);
resultObject.setMessage("class not found : " + dto.getDriverClass() + "\nerror message : " + e.getMessage());
logger.error(getClass().getName(), e);
} catch (Exception e) {
resultObject.setResultCode(VarsqlAppCode.ERROR);
resultObject.setMessage(e.getMessage() + BlankConstants.NEW_LINE + errorMsg);
logger.error(getClass().getName(), e);
}
return resultObject;
}
Aggregations