?????????????????????????????Щ????????????????????????????????????????????н????????????????????????·???????????????????????е???÷????????????÷?????decrypt??
/**
*????????????????????????????????????????????
* @author
*/
public abstract class AbstractBackupService implements BackupService{
protected final APDPlatLogger LOG = new APDPlatLogger(getClass());
protected static final StandardPBEStringEncryptor encryptor;
protected static final String username;
protected static final String password;
//??????????л??????????????????????????????????????????
static{
EnvironmentStringPBEConfig config=new EnvironmentStringPBEConfig();
config.setAlgorithm("PBEWithMD5AndDES");
config.setPassword("config");
encryptor=new StandardPBEStringEncryptor();
encryptor.setConfig(config);
String uname=PropertyHolder.getProperty("db.username");
String pwd=PropertyHolder.getProperty("db.password");
if(uname!=null && uname.contains("ENC(") && uname.contains(")")){
uname=uname.substring(4??uname.length()-1);
username=decrypt(uname);
}else{
username=uname;
}
if(pwd!=null && pwd.contains("ENC(") && pwd.contains(")")){
pwd=pwd.substring(4??pwd.length()-1);
password=decrypt(pwd);
}else{
password=pwd;
}
}
@Override
public String getBackupFilePath(){
String path="/WEB-INF/backup/"+PropertyHolder.getProperty("jpa.database")+"/";
path=FileUtils.getAbsolutePath(path);
File file=new File(path);
if(!file.exists()){
file.mkdirs();
}
return path;
}
@Override
public File getNewestBackupFile(){
Map<String??File> map = new HashMap<>();
List<String> list = new ArrayList<>();
String path=getBackupFilePath();
File dir=new File(path);
File[] files=dir.listFiles();
for(File file : files){
String name=file.getName();
if(!name.contains("bak")) {
continue;
}
map.put(name?? file);
list.add(name);
}
if(list.isEmpty()){
return null;
}
//?????????????
Collections.sort(list);
//?±?????????
Collections.reverse(list);
String name = list.get(0);
File file = map.get(name);
//????????????
list.clear();
map.clear();
return file;
}    @Override
public List<String> getExistBackupFileNames(){
List<String> result=new ArrayList<>();
String path=getBackupFilePath();
File dir=new File(path);
File[] files=dir.listFiles();
for(File file : files){
String name=file.getName();
if(!name.contains("bak")) {
continue;
}
name=name.substring(0?? name.length()-4);
String[] temp=name.split("-");
String y=temp[0];
String m=temp[1];
String d=temp[2];
String h=temp[3];
String mm=temp[4];
String s=temp[5];
name=y+"-"+m+"-"+d+" "+h+":"+mm+":"+s;
result.add(name);
}
//?????????????
Collections.sort(result);
//?±?????????
Collections.reverse(result);
return result;
}
/**
* ???????????????
* @param encryptedMessage ?????????????????
* @return ?????????????????
*/
protected static String decrypt(String encryptedMessage){
String plain=encryptor.decrypt(encryptedMessage);
return plain;
}
}