use of com.sun.identity.diagnostic.base.core.common.DTException in project OpenAM by OpenRock.
the class ChecksumCreator method detectTamper.
public void detectTamper(String configPath, String backupFile, Set<String> dirFilter, Set<String> fileFilter) throws DTException {
try {
toolOutWriter = TamperDetectionService.getToolWriter();
toolOutWriter.printMessage("tamper-checksum-creating");
File configDir = new File(configPath);
Properties checksum = TamperDetectionUtils.getChecksum(TamperDetectionUtils.SHA1, configDir, dirFilter, fileFilter);
FileOutputStream fout = null;
try {
fout = new FileOutputStream(backupFile);
checksum.store(fout, "");
toolOutWriter.printStatusMsg(true, "tamper-checksum-created");
} finally {
if (fout != null) {
fout.close();
}
}
} catch (Exception ex) {
toolOutWriter.printStatusMsg(false, "tamper-checksum-created");
throw new DTException(ex.getMessage());
}
}
use of com.sun.identity.diagnostic.base.core.common.DTException in project OpenAM by OpenRock.
the class BEAWeblogicPoliciesValidator method validate.
public void validate(Properties containerProp, String instancePath, String domainPath) throws DTException {
toolOutWriter = WebContainerService.getToolWriter();
if (domainPath != null) {
File instanceDir = new File(instancePath);
if (instanceDir.exists() && instanceDir.isDirectory()) {
toolOutWriter.printStatusMsg(true, "webcontainer-instance-dir-check");
String instanceLib_dir = containerProp.getProperty(WebContainerConstant.POLICIES_DIR);
File instanceLibDir = new File(instanceDir, instanceLib_dir);
System.out.println();
if (instanceLibDir.exists() && instanceLibDir.isDirectory()) {
toolOutWriter.printStatusMsg(true, "webcontainer-instance-lib-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(instanceLibDir, 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-instance-lib-dir-invalid");
toolOutWriter.printStatusMsg(false, "webcontainer-instance-lib-dir-check");
}
} else {
toolOutWriter.printError("webcontainer-instance-dir-invalid");
toolOutWriter.printStatusMsg(false, "webcontainer-instance-dir-check");
}
}
}
use of com.sun.identity.diagnostic.base.core.common.DTException in project OpenAM by OpenRock.
the class IBMWebSphereJVMOptionsValidator method validate.
public void validate(Properties containerProp, String profilePath, String serverPath) throws DTException {
toolOutWriter = WebContainerService.getToolWriter();
if (serverPath != null) {
File serverDir = new File(serverPath);
if (serverDir.exists() && serverDir.isDirectory()) {
toolOutWriter.printStatusMsg(true, "webcontainer-server-dir-check");
String serverFileName = containerProp.getProperty(WebContainerConstant.JVMOPTIONS_FILE);
File jvmoptionsFile = new File(containerProp.getProperty(WebContainerConstant.JVMOPTIONS_PATTERN_FILE));
FileInputStream fin = null;
Properties jvmoptionsProp = new Properties();
if (jvmoptionsFile.exists() && jvmoptionsFile.isFile()) {
try {
fin = new FileInputStream(jvmoptionsFile);
jvmoptionsProp.load(fin);
} catch (IOException ex) {
throw new DTException(ex.getMessage());
} finally {
if (fin != null) {
try {
fin.close();
} catch (IOException ignored) {
}
}
}
}
LineNumberReader lnRdr = null;
String javahomePath = null;
try {
lnRdr = new LineNumberReader(new FileReader(new File(serverDir, serverFileName)));
String buffer = null;
while ((buffer = lnRdr.readLine()) != null) {
for (Enumeration e = jvmoptionsProp.propertyNames(); e.hasMoreElements(); ) {
String name = (String) e.nextElement();
if (name.startsWith(WebContainerConstant.JVMOPTIONS_PATTERN)) {
String value = jvmoptionsProp.getProperty(name);
String[] answers = buffer.split(value);
if ((answers.length > 1) || (!answers[0].equals(buffer))) {
jvmoptionsProp.remove(name);
int num = Integer.parseInt(name.substring(WebContainerConstant.JVMOPTIONS_PATTERN.length(), name.length()));
jvmoptionsProp.remove(WebContainerConstant.JVMOPTIONS_CLEARTEXT + String.valueOf(num));
}
}
}
}
boolean passed = true;
for (Enumeration e = jvmoptionsProp.propertyNames(); e.hasMoreElements(); ) {
String name = (String) e.nextElement();
if (name.startsWith(WebContainerConstant.JVMOPTIONS_CLEARTEXT)) {
if (passed) {
toolOutWriter.printError("webcontainer-jvm-options-invalid");
}
toolOutWriter.printError(jvmoptionsProp.getProperty(name));
passed = false;
}
}
if (passed) {
toolOutWriter.printStatusMsg(true, "webcontainer-jvm-options-check");
} else {
toolOutWriter.printStatusMsg(false, "webcontainer-jvm-options-check");
}
} catch (IOException ex) {
throw new DTException(ex.getMessage());
} finally {
if (lnRdr != null) {
try {
lnRdr.close();
} catch (IOException ignored) {
}
}
}
} else {
toolOutWriter.printError("webcontainer-server-dir-invalid");
toolOutWriter.printStatusMsg(false, "webcontainer-server-dir-check");
}
} else {
toolOutWriter.printError("webcontainer-server-dir-invalid");
toolOutWriter.printStatusMsg(false, "webcontainer-server-dir-check");
}
}
use of com.sun.identity.diagnostic.base.core.common.DTException in project OpenAM by OpenRock.
the class IBMWebSphereJVMVersionValidator method validate.
public void validate(Properties containerProp, String profilePath, String serverPath) throws DTException {
toolOutWriter = WebContainerService.getToolWriter();
if (profilePath != null) {
File profileDir = new File(profilePath);
if (profileDir.exists() && profileDir.isDirectory()) {
toolOutWriter.printStatusMsg(true, "webcontainer-profile-dir-check");
String javahome_dir = containerProp.getProperty(WebContainerConstant.JAVAHOME_DIR);
File javahomeDir = new File(profileDir, javahome_dir);
if (javahomeDir.exists() && javahomeDir.isDirectory()) {
toolOutWriter.printStatusMsg(true, "webcontainer-properties-dir-check");
String javahomeFileName = containerProp.getProperty(WebContainerConstant.JAVAHOME_FILE);
if (WebContainerConstant.OS_NAME.toLowerCase().indexOf(WebContainerConstant.WINDOWS) >= 0) {
javahomeFileName = javahomeFileName + ".bat";
} else {
javahomeFileName = javahomeFileName + ".sh";
}
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-properties-dir-invalid");
toolOutWriter.printStatusMsg(false, "webcontainer-properties-dir-check");
}
} else {
toolOutWriter.printError("webcontainer-profile-dir-invalid");
toolOutWriter.printStatusMsg(false, "webcontainer-profile-dir-check");
}
} else {
toolOutWriter.printError("webcontainer-profile-dir-invalid");
toolOutWriter.printStatusMsg(false, "webcontainer-profile-dir-check");
}
}
use of com.sun.identity.diagnostic.base.core.common.DTException in project OpenAM by OpenRock.
the class SunAppSvrPoliciesValidator 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