@ -40,6 +40,12 @@ public class RemoteDesignerWorkspaceInfo implements DesignerWorkspaceInfo {
private WorkspaceConnectionInfo connection ;
/ * *
* 标记下新创建的远程工作目录 兼容存留的远程目录客户升级后再回退 读取为密文
* 仅保证当前新增是加密的
* /
private boolean newCreated ;
public static RemoteDesignerWorkspaceInfo create ( WorkspaceConnectionInfo connection ) {
RemoteDesignerWorkspaceInfo info = new RemoteDesignerWorkspaceInfo ( ) ;
info . connection = connection ;
@ -79,12 +85,21 @@ public class RemoteDesignerWorkspaceInfo implements DesignerWorkspaceInfo {
return remindTime ;
}
public boolean isNewCreated ( ) {
return newCreated ;
}
public void setNewCreated ( boolean newCreated ) {
this . newCreated = newCreated ;
}
@Override
public void readXML ( XMLableReader reader ) {
if ( reader . isAttr ( ) ) {
this . name = reader . getAttrAsString ( "name" , StringUtils . EMPTY ) ;
this . remindTime = reader . getAttrAsString ( "remindTime" , StringUtils . EMPTY ) ;
this . newCreated = reader . getAttrAsBoolean ( "newCreated" , false ) ;
}
if ( reader . isChildNode ( ) ) {
String tagName = reader . getTagName ( ) ;
@ -92,32 +107,49 @@ public class RemoteDesignerWorkspaceInfo implements DesignerWorkspaceInfo {
String url = reader . getAttrAsString ( "url" , StringUtils . EMPTY ) ;
String username = reader . getAttrAsString ( "username" , StringUtils . EMPTY ) ;
//密码解密
String password = SecurityToolbox . defaultDecrypt ( reader . getAttrAsString ( "password" , StringUtils . EMPTY ) . replaceAll ( " " , "\r\n" ) ) ;
String password = SecurityToolbox . defaultDecrypt ( reader . getAttrAsString ( "password" , StringUtils . EMPTY ) . replaceAll ( StringUtils . BLANK , "\r\n" ) ) ;
String certPath = reader . getAttrAsString ( "certPath" , StringUtils . EMPTY ) ;
String certSecretKey = reader . getAttrAsString ( "certSecretKey" , StringUtils . EMPTY ) ;
String certSecretKey = readCertSecretKey ( reader ) ;
boolean rememberPwd = reader . getAttrAsBoolean ( "rememberPwd" , true ) ;
this . connection = new WorkspaceConnectionInfo ( url , username , password , certPath , certSecretKey , rememberPwd ) ;
}
}
}
private String readCertSecretKey ( XMLableReader reader ) {
if ( isNewCreated ( ) ) {
return SecurityToolbox . defaultDecrypt ( reader . getAttrAsString ( "certSecretKey" , StringUtils . EMPTY ) . replaceAll ( StringUtils . BLANK , "\r\n" ) ) ;
} else {
return reader . getAttrAsString ( "certSecretKey" , StringUtils . EMPTY ) ;
}
}
@Override
public void writeXML ( XMLPrintWriter writer ) {
writer . attr ( "name" , name ) ;
writer . attr ( "remindTime" , remindTime ) ;
writer . attr ( "newCreated" , isNewCreated ( ) ) ;
if ( this . connection ! = null ) {
writer . startTAG ( "Connection" ) ;
writer . attr ( "url" , connection . getUrl ( ) ) ;
writer . attr ( "username" , connection . getUserName ( ) ) ;
writer . attr ( "password" , SecurityToolbox . defaultEncrypt ( connection . getPassword ( ) ) ) ;
writer . attr ( "certPath" , connection . getCertPath ( ) ) ;
writer . attr ( "certSecretKey" , connection . getCertSecretKey ( ) ) ;
writeCertSecretKey ( writer ) ;
writer . attr ( "rememberPwd" , connection . isRememberPwd ( ) ) ;
writer . end ( ) ;
}
}
private void writeCertSecretKey ( XMLPrintWriter writer ) {
if ( isNewCreated ( ) ) {
writer . attr ( "certSecretKey" , SecurityToolbox . defaultEncrypt ( connection . getCertSecretKey ( ) ) ) ;
} else {
writer . attr ( "certSecretKey" , connection . getCertSecretKey ( ) ) ;
}
}
@Override
@SuppressWarnings ( "squid:S2975" )
public Object clone ( ) throws CloneNotSupportedException {