use of com.sun.identity.diagnostic.base.core.common.DTException in project OpenAM by OpenRock.
the class SunAppSvrJVMVersionValidator method validate.
public void validate(Properties containerProp, String containerPath, String domainPath) throws DTException {
toolOutWriter = WebContainerService.getToolWriter();
if (containerPath != null) {
File containerDir = new File(containerPath);
if (containerDir.exists() && containerDir.isDirectory()) {
toolOutWriter.printStatusMsg(true, "webcontainer-base-dir-check");
String javahome_dir = containerProp.getProperty(WebContainerConstant.JAVAHOME_DIR);
File javahomeDir = new File(containerDir, javahome_dir);
if (javahomeDir.exists() && javahomeDir.isDirectory()) {
toolOutWriter.printStatusMsg(true, "webcontainer-config-dir-check");
String javahomeFileName = containerProp.getProperty(WebContainerConstant.JAVAHOME_FILE);
if (WebContainerConstant.OS_NAME.toLowerCase().indexOf(WebContainerConstant.WINDOWS) >= 0) {
javahomeFileName = javahomeFileName + ".bat";
} else {
javahomeFileName = javahomeFileName + ".conf";
}
LineNumberReader lnRdr = null;
String javahomePath = null;
try {
lnRdr = new LineNumberReader(new FileReader(new File(javahomeDir, javahomeFileName)));
String buffer = null;
String javahomeTag = containerProp.getProperty(WebContainerConstant.JAVAHOME_TAG);
while ((buffer = lnRdr.readLine()) != null) {
String[] s = buffer.split("\\s*" + javahomeTag + "\\s*=");
if ((s.length > 1) || (!s[0].equals(buffer))) {
javahomePath = buffer.substring(buffer.indexOf("=") + 1, buffer.length()).trim();
break;
}
}
} catch (IOException ex) {
throw new DTException(ex.getMessage());
} finally {
if (lnRdr != null) {
try {
lnRdr.close();
} catch (IOException ignored) {
}
}
}
LineNumberReader processLnRdr = null;
try {
toolOutWriter = WebContainerService.getToolWriter();
if (javahomePath.startsWith("\"")) {
javahomePath = javahomePath.substring(1, javahomePath.length());
}
if (javahomePath.endsWith("\"")) {
javahomePath = javahomePath.substring(0, javahomePath.length() - 1);
}
if (javahomePath.endsWith("/") || (javahomePath.endsWith("\\"))) {
javahomePath = javahomePath.substring(0, javahomePath.length() - 1);
}
Process pro = Runtime.getRuntime().exec(javahomePath + "/bin/java -version");
processLnRdr = new LineNumberReader(new InputStreamReader(pro.getErrorStream()));
String buffer = null;
String jvmVersion = null;
while ((buffer = processLnRdr.readLine()) != null) {
int startIndex = buffer.indexOf("\"");
int endIndex = buffer.indexOf("\"", startIndex + 1);
if ((startIndex >= 0) && (endIndex >= 0) && (endIndex > startIndex)) {
jvmVersion = buffer.substring(startIndex + 1, endIndex);
break;
}
}
String startWithMinor = jvmVersion.substring(jvmVersion.indexOf(".") + 1, jvmVersion.length());
int index = -1;
if ((index = startWithMinor.indexOf(".")) >= 0) {
startWithMinor = startWithMinor.substring(0, index);
}
if ((index = startWithMinor.indexOf("_")) >= 0) {
startWithMinor = startWithMinor.substring(0, index + 1);
}
if (Integer.valueOf(startWithMinor) >= WebContainerConstant.SUPPORTED_JVM_MINOR_VERSION) {
toolOutWriter.printResult(jvmVersion);
toolOutWriter.printStatusMsg(true, "webcontainer-container-version");
} else {
toolOutWriter.printError(jvmVersion);
toolOutWriter.printStatusMsg(false, "webcontainer-container-version");
}
} catch (IOException ex) {
throw new DTException(ex.getMessage());
} finally {
if (processLnRdr != null) {
try {
processLnRdr.close();
} catch (Exception ignored) {
}
}
}
} else {
toolOutWriter.printError("webcontainer-config-dir-invalid");
toolOutWriter.printStatusMsg(false, "webcontainer-config-dir-check");
}
} else {
toolOutWriter.printError("webcontainer-base-dir-invalid");
toolOutWriter.printStatusMsg(false, "webcontainer-base-dir-check");
}
} else {
toolOutWriter.printError("webcontainer-base-dir-invalid");
toolOutWriter.printStatusMsg(false, "webcontainer-base-dir-check");
}
}
use of com.sun.identity.diagnostic.base.core.common.DTException in project OpenAM by OpenRock.
the class SunWebServerJVMVersionValidator method validate.
public void validate(Properties containerProp, String containerPath, String domainPath) throws DTException {
toolOutWriter = WebContainerService.getToolWriter();
if (domainPath != null) {
File domainDir = new File(domainPath);
if (domainDir.exists() && domainDir.isDirectory()) {
toolOutWriter.printStatusMsg(true, "webcontainer-domain-dir-check");
String javahome_dir = containerProp.getProperty(WebContainerConstant.JAVAHOME_DIR);
File javahomeDir = new File(domainDir, javahome_dir);
if (javahomeDir.exists() && javahomeDir.isDirectory()) {
toolOutWriter.printStatusMsg(true, "webcontainer-config-dir-check");
String javahomeFileName = containerProp.getProperty(WebContainerConstant.JAVAHOME_FILE);
LineNumberReader lnRdr = null;
String javahomePath = null;
try {
lnRdr = new LineNumberReader(new FileReader(new File(javahomeDir, javahomeFileName)));
String buffer = null;
String javahomeTag = containerProp.getProperty(WebContainerConstant.JAVAHOME_TAG);
while ((buffer = lnRdr.readLine()) != null) {
String[] s = buffer.split("\\s*<" + javahomeTag + ">\\s*");
if ((s.length > 1) || (!s[0].equals(buffer))) {
int equalIndex = buffer.indexOf("<" + javahomeTag + ">");
int endIndex = buffer.indexOf("</" + javahomeTag + ">", equalIndex + javahomeTag.length() + 2);
if (endIndex < 0) {
endIndex = buffer.length();
}
javahomePath = buffer.substring(equalIndex + javahomeTag.length() + 2, endIndex).trim();
break;
}
}
} catch (IOException ex) {
throw new DTException(ex.getMessage());
} finally {
if (lnRdr != null) {
try {
lnRdr.close();
} catch (IOException ignored) {
}
}
}
LineNumberReader processLnRdr = null;
try {
toolOutWriter = WebContainerService.getToolWriter();
if (javahomePath.startsWith("\"")) {
javahomePath = javahomePath.substring(1, javahomePath.length());
}
if (javahomePath.endsWith("\"")) {
javahomePath = javahomePath.substring(0, javahomePath.length() - 1);
}
if (javahomePath.endsWith("/") || (javahomePath.endsWith("\\"))) {
javahomePath = javahomePath.substring(0, javahomePath.length() - 1);
}
Process pro = Runtime.getRuntime().exec(javahomePath + "/bin/java -version");
processLnRdr = new LineNumberReader(new InputStreamReader(pro.getErrorStream()));
String buffer = null;
String jvmVersion = null;
while ((buffer = processLnRdr.readLine()) != null) {
int startIndex = buffer.indexOf("\"");
int endIndex = buffer.indexOf("\"", startIndex + 1);
if ((startIndex >= 0) && (endIndex >= 0) && (endIndex > startIndex)) {
jvmVersion = buffer.substring(startIndex + 1, endIndex);
break;
}
}
String startWithMinor = jvmVersion.substring(jvmVersion.indexOf(".") + 1, jvmVersion.length());
int index = -1;
if ((index = startWithMinor.indexOf(".")) >= 0) {
startWithMinor = startWithMinor.substring(0, index);
}
if ((index = startWithMinor.indexOf("_")) >= 0) {
startWithMinor = startWithMinor.substring(0, index + 1);
}
if (Integer.valueOf(startWithMinor) >= WebContainerConstant.SUPPORTED_JVM_MINOR_VERSION) {
toolOutWriter.printResult(jvmVersion);
toolOutWriter.printStatusMsg(true, "webcontainer-container-version");
} else {
toolOutWriter.printError(jvmVersion);
toolOutWriter.printStatusMsg(false, "webcontainer-container-version");
}
} catch (IOException ex) {
throw new DTException(ex.getMessage());
} finally {
if (processLnRdr != null) {
try {
processLnRdr.close();
} catch (Exception ignored) {
}
}
}
} else {
toolOutWriter.printError("webcontainer-config-dir-invalid");
toolOutWriter.printStatusMsg(false, "webcontainer-config-dir-check");
}
} else {
toolOutWriter.printError("webcontainer-base-dir-invalid");
toolOutWriter.printStatusMsg(false, "webcontainer-base-dir-check");
}
} else {
toolOutWriter.printError("webcontainer-base-dir-invalid");
toolOutWriter.printStatusMsg(false, "webcontainer-base-dir-check");
}
}
use of com.sun.identity.diagnostic.base.core.common.DTException in project OpenAM by OpenRock.
the class SunWebServerPoliciesValidator method validate.
public void validate(Properties containerProp, String containerPath, String domainPath) throws DTException {
toolOutWriter = WebContainerService.getToolWriter();
if (domainPath != null) {
File domainDir = new File(domainPath);
if (domainDir.exists() && domainDir.isDirectory()) {
toolOutWriter.printStatusMsg(true, "webcontainer-domain-dir-check");
String domainConfig_dir = containerProp.getProperty(WebContainerConstant.POLICIES_DIR);
File domainConfigDir = new File(domainDir, domainConfig_dir);
if (domainConfigDir.exists() && domainConfigDir.isDirectory()) {
toolOutWriter.printStatusMsg(true, "webcontainer-domain-config-dir-check");
String policiesFileName = containerProp.getProperty(WebContainerConstant.POLICIES_FILE);
File policiesPatternFile = new File(containerProp.getProperty(WebContainerConstant.POLICIES_PATTERN_FILE));
FileInputStream fin = null;
Properties policiesPatternProp = new Properties();
if (policiesPatternFile.exists() && policiesPatternFile.isFile()) {
try {
fin = new FileInputStream(policiesPatternFile);
policiesPatternProp.load(fin);
} catch (IOException ex) {
throw new DTException(ex.getMessage());
} finally {
if (fin != null) {
try {
fin.close();
} catch (IOException ignored) {
}
}
}
}
LineNumberReader lnRdr = null;
try {
lnRdr = new LineNumberReader(new FileReader(new File(domainConfigDir, policiesFileName)));
String line = null;
StringBuffer buffer = null;
boolean policiesStarted = false;
while ((line = lnRdr.readLine()) != null) {
if (!policiesStarted) {
String[] validStart = line.split(WebContainerConstant.POLICY_GRANT_START_PATTERN);
if ((validStart.length > 1) || (!validStart[0].equals(line))) {
buffer = new StringBuffer();
buffer.append(line).append("\n");
policiesStarted = true;
}
} else {
buffer.append(line).append("\n");
String[] validEnd = line.split(WebContainerConstant.POLICY_GRANT_END_PATTERN);
if ((validEnd.length > 1) || (!validEnd[0].equals(line))) {
policiesStarted = false;
String policies = buffer.toString();
String[] validPolicies = policies.split(WebContainerConstant.POLICY_GRANT_START_PATTERN + "[{]");
if ((validPolicies.length > 1) || (!validPolicies[0].equals(policies))) {
for (Enumeration e = policiesPatternProp.propertyNames(); e.hasMoreElements(); ) {
String name = (String) e.nextElement();
if (name.startsWith(WebContainerConstant.POLICIES_PATTERN)) {
String value = policiesPatternProp.getProperty(name);
String[] answers = policies.split(value);
if ((answers.length > 1) || (!answers[0].equals(policies))) {
policiesPatternProp.remove(name);
int num = Integer.parseInt(name.substring(WebContainerConstant.POLICIES_PATTERN.length(), name.length()));
policiesPatternProp.remove(WebContainerConstant.POLICIES_CLEARTEXT + String.valueOf(num));
}
}
}
}
}
}
}
boolean passed = true;
for (Enumeration e = policiesPatternProp.propertyNames(); e.hasMoreElements(); ) {
String name = (String) e.nextElement();
if (name.startsWith(WebContainerConstant.POLICIES_CLEARTEXT)) {
if (passed) {
toolOutWriter.printError("webcontainer-policies-invalid");
}
toolOutWriter.printError(policiesPatternProp.getProperty(name));
passed = false;
}
}
if (passed) {
toolOutWriter.printStatusMsg(true, "webcontainer-policies-check");
} else {
toolOutWriter.printStatusMsg(false, "webcontainer-policies-check");
}
} catch (IOException ex) {
throw new DTException(ex.getMessage());
} finally {
if (lnRdr != null) {
try {
lnRdr.close();
} catch (IOException ignored) {
}
}
}
} else {
toolOutWriter.printError("webcontainer-domain-config-dir-invalid");
toolOutWriter.printStatusMsg(false, "webcontainer-domain-config-dir-check");
}
} else {
toolOutWriter.printError("webcontainer-domain-dir-invalid");
toolOutWriter.printStatusMsg(false, "webcontainer-domain-dir-check");
}
}
}
Aggregations