ConfigTransferspublic class ConfigTransfers extends Object implements BaseModule
Fields Summary |
---|
private static final String | SECMODDB | private com.sun.enterprise.util.i18n.StringManager | stringManager | private Logger | logger | private Vector | recoveryList | private CommonInfoModel | commonInfo |
Constructors Summary |
---|
public ConfigTransfers()Creates a new instance of ConfigTransfers
|
Methods Summary |
---|
private boolean | backup(java.lang.String filename)Method to backup the server.policy file before processing
try{
File targetFile = new File(filename);
boolean renamed = targetFile.renameTo(new File(filename +".bak"));
if(!renamed){
// This is possible if user is running the upgrade again
//and .bak is already created.
renamed = targetFile.delete();
}
if(renamed){
targetFile = new File(filename);
targetFile.createNewFile();
BufferedReader reader = new BufferedReader(new InputStreamReader
(new FileInputStream(filename + ".bak")));
PrintWriter writer = new PrintWriter(new FileOutputStream(targetFile));
String readLine = null;
while((readLine = reader.readLine()) != null){
writer.println(readLine);
}
writer.flush();
writer.close();
reader.close();
return true;
} else {
//Log a error message : Rename Failure
logger.log(Level.SEVERE, stringManager.getString(
"upgrade.configTransfers.serverPolicy.renameFailureMessage"));
}
}catch(Exception ex){
// Log a error message
logger.log(Level.SEVERE, stringManager.getString(
"upgrade.configTransfers.serverPolicy.startFailureMessage"),ex);
}
return false;
| public java.lang.String | getName()
return stringManager.getString("upgrade.configTransfers.moduleName");
| public void | recovery(CommonInfoModel commonInfo)
Enumeration e = recoveryList.elements();
while(e.hasMoreElements()){
String recoverPath = (String)e.nextElement();
String backupPath = recoverPath + ".bak";
try {
UpgradeUtils.copyFile(backupPath, recoverPath);
new File(backupPath).delete();
} catch (IOException ioe) {
logger.log(Level.SEVERE, stringManager.getString("upgrade.realm.recoveryFailureMessage",ioe.getMessage()),new Object[]{recoverPath,ioe});
}
}
| private void | transferSecModDb(CommonInfoModel commonInfo)
String sourcePath = commonInfo.getSourceDomainPath();
String targetPath = commonInfo.getDestinationDomainPath();
File sourceFile = new File(sourcePath + File.separator + "config" + File.separator + SECMODDB);
File targetFile = new File(targetPath + File.separator + "config" + File.separator + SECMODDB);
if(!sourceFile.exists()) return;
if(targetFile.exists()) {
backup(targetFile.getAbsolutePath());
}
try {
UpgradeUtils.copyFile(sourceFile.getAbsolutePath(),
targetFile.getAbsolutePath());
} catch(IOException e) {
logger.log(Level.WARNING, stringManager.getString("upgrade.configTransfers.secModDb.failureMessage") + e.getLocalizedMessage());
}
| private void | transferServerPolicy(java.lang.String sourcePolicyFileName, java.lang.String destPolicyFileName)transferSeverPolicy uses sun.security.provider.PolicyParser from the jdk
to parse the source and target server.policy files
Also transfers user added grants and permissions
//Backup the existing server.policy file
if (! backup(destPolicyFileName)) {
logger.log(Level.SEVERE, stringManager.getString(
"upgrade.configTransfers.serverPolicy.backupFailureMessage"));
logger.log(Level.SEVERE, stringManager.getString(
"upgrade.configTransfers.serverPolicy.startFailureMessage"));
return;
}
logger.log(Level.INFO, stringManager.getString(
"upgrade.configTransfers.serverPolicy.startMessage"));
//Read source and target policy files into respective PolicyParser objects
PolicyParser sourcePolicy = new PolicyParser();
PolicyParser targetPolicy = new PolicyParser();
try {
sourcePolicy.read(new FileReader(sourcePolicyFileName));
targetPolicy.read(new FileReader(destPolicyFileName));
} catch (PolicyParser.ParsingException pe) {
logger.log(Level.SEVERE, stringManager.getString(
"upgrade.configTransfers.serverPolicy.startFailureMessage")
+ pe.getLocalizedMessage());
return;
} catch (IOException ioe) {
logger.log(Level.SEVERE, stringManager.getString(
"upgrade.configTransfers.serverPolicy.startFailureMessage"),
ioe.getMessage());
return;
}
//Get source and target grant elements
Enumeration sourceElements = sourcePolicy.grantElements();
Enumeration targetElements = targetPolicy.grantElements();
//Get matching grant entries and add required permissions
while(sourceElements.hasMoreElements()) {
PolicyParser.GrantEntry sourceGrantEntry =
(PolicyParser.GrantEntry)sourceElements.nextElement();
boolean matchedGrantEntry = false;
while (targetElements.hasMoreElements()) {
PolicyParser.GrantEntry targetGrantEntry =
(PolicyParser.GrantEntry)targetElements.nextElement();
if(targetGrantEntry.codeBase == null &&
sourceGrantEntry.codeBase == null) {
matchedGrantEntry = true;
} else if (targetGrantEntry.codeBase != null &&
sourceGrantEntry.codeBase != null) {
if (targetGrantEntry.codeBase.equals(sourceGrantEntry.codeBase)) {
//found a matched codeBase
matchedGrantEntry = true;
}
}
if(matchedGrantEntry) {
//Check if target has all the permissions of the source
//If not, add the missing permissions
Enumeration sourcePermissions = sourceGrantEntry.permissionElements();
while(sourcePermissions.hasMoreElements()) {
boolean matchedPermission = false;
PolicyParser.PermissionEntry sourcePermission =
(PolicyParser.PermissionEntry)sourcePermissions.nextElement();
Enumeration targetPermissions = targetGrantEntry.permissionElements();
while(targetPermissions.hasMoreElements()) {
PolicyParser.PermissionEntry targetPermission =
(PolicyParser.PermissionEntry)targetPermissions.nextElement();
if(targetPermission.equals(sourcePermission)) {
matchedPermission = true;
break;
}
}
if(!matchedPermission){
targetGrantEntry.add(sourcePermission);
}
}
//Check if target has all the principals of the source
//If not, add the missing principals
Iterator sourcePrincipalIterator = sourceGrantEntry.principals.iterator();
while(sourcePrincipalIterator.hasNext()) {
boolean matchedPrincipal = false;
PolicyParser.PrincipalEntry sourcePrincipalEntry =
(PolicyParser.PrincipalEntry)sourcePrincipalIterator.next();
Iterator targetPrincipalIterator = targetGrantEntry.principals.iterator();
while(targetPrincipalIterator.hasNext()) {
PolicyParser.PrincipalEntry targetPrincipalEntry =
(PolicyParser.PrincipalEntry)targetPrincipalIterator.next();
if(targetPrincipalEntry.equals(sourcePrincipalEntry)) {
matchedPrincipal = true;
break;
}
}
if(!matchedPrincipal) {
targetGrantEntry.principals.add(sourcePrincipalEntry);
}
}
break;
}
}
if (!matchedGrantEntry) {
targetPolicy.add(sourceGrantEntry);
}
}
//Add other permissions required
if(commonInfo.checkUpgradefrom8xeeto9x() && commonInfo.isInPlace()) {
PolicyParser.PermissionEntry pe = new PolicyParser.PermissionEntry();
PolicyParser.GrantEntry geDerby = new PolicyParser.GrantEntry();
PolicyParser.GrantEntry geMfwk = new PolicyParser.GrantEntry();
pe.permission = "java.security.AllPermission";
geDerby.codeBase = "file:${com.sun.aas.derbyRoot}/lib/-";
geDerby.add(pe);
targetPolicy.add(geDerby);
geMfwk.codeBase = "file:${com.sun.aas.mfwkHome}/lib/mfwk_instrum_tk.jar";
geMfwk.add(pe);
targetPolicy.add(geMfwk);
}
try {
targetPolicy.write(new FileWriter(destPolicyFileName));
} catch (IOException ioe) {
logger.log(Level.SEVERE, stringManager.getString(
"upgrade.configTransfers.serverPolicy.startFailureMessage"),
ioe.getMessage());
return;
}
| public boolean | upgrade(CommonInfoModel commonInfo)Method to start upgrade of miscellaneous configuration
this.commonInfo = commonInfo;
//Transfer Server.policy file
String sourceServerPolicy = commonInfo.getSourceServerPolicyFileName();
String targetServerPolicy = commonInfo.getTargetServerPolicyFileName();
transferServerPolicy(sourceServerPolicy, targetServerPolicy);
//Transform wss-server-config xml file is upgrade is from EE
if(commonInfo.getSourceEdition().equals(UpgradeConstants.EDITION_EE)) {
String targetWssServerConfig = commonInfo.getTargetWssServerConfigXML();
new WssServerConfigXMLTransfer().transform(targetWssServerConfig);
return true;
}
//Transform default-web xml file
String targetDefaultWebXML = commonInfo.getTargetDefaultWebXMLFileName();
new DefaultWebXMLTransfer(commonInfo).transform(targetDefaultWebXML);
//Transform sun-acc xml file
String sourceSunACCFile = commonInfo.getSourceSunACCFileName();
String targetSunACCFile = commonInfo.getTargetSunACCFileName();
new SunACCTransfer().transform(sourceSunACCFile, targetSunACCFile);
if(commonInfo.getSourceVersion().equals(UpgradeConstants.VERSION_7X)){
new InitConfTransfer(commonInfo).transform();
}
return true;
|
|