use of com.sun.identity.diagnostic.base.core.common.DTException in project OpenAM by OpenRock.
the class SunWebServerJVMOptionsValidator 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.JVMOPTIONS_DIR);
File domainConfigDir = new File(domainDir, domainConfig_dir);
if (domainConfigDir.exists() && domainConfigDir.isDirectory()) {
toolOutWriter.printStatusMsg(true, "webcontainer-domain-config-dir-check");
String domainFileName = 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(domainConfigDir, domainFileName)));
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-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");
}
} else {
toolOutWriter.printError("webcontainer-domain-dir-invalid");
toolOutWriter.printStatusMsg(false, "webcontainer-domain-dir-check");
}
}
use of com.sun.identity.diagnostic.base.core.common.DTException in project OpenAM by OpenRock.
the class CheckSumValidator method detectTamper.
public void detectTamper(String configPath, String backupPath, Set<String> dirFilter, Set<String> fileFilter) throws DTException {
try {
toolOutWriter = TamperDetectionService.getToolWriter();
toolOutWriter.printMessage("tamper-detect-msg");
File configDir = new File(configPath);
Properties checksum = TamperDetectionUtils.getChecksum(TamperDetectionUtils.SHA1, configDir, dirFilter, fileFilter);
FileInputStream fin = null;
Properties oldChecksum = new Properties();
try {
fin = new FileInputStream(backupPath);
oldChecksum.load(fin);
} finally {
if (fin != null) {
try {
fin.close();
} catch (IOException ignored) {
}
}
}
Properties fileLost = new Properties();
for (Enumeration e = oldChecksum.propertyNames(); e.hasMoreElements(); ) {
String key = (String) e.nextElement();
String value = oldChecksum.getProperty(key);
String newValue = checksum.getProperty(key);
if (newValue != null) {
if (value.equals(newValue)) {
checksum.remove(key);
}
} else {
fileLost.setProperty(key, value);
}
}
if (!checksum.isEmpty() || !fileLost.isEmpty()) {
toolOutWriter.printMessage(PARA_SEP_1);
toolOutWriter.printMessage("tamper-detect-files-msg");
toolOutWriter.printMessage(PARA_SEP_1);
if (!checksum.isEmpty()) {
toolOutWriter.printMessage("tamper-detect-files-modified");
toolOutWriter.printMessage(SMALL_LINE_SEP_1);
}
for (Enumeration e = checksum.propertyNames(); e.hasMoreElements(); ) {
toolOutWriter.printResult((String) e.nextElement());
}
if (!fileLost.isEmpty()) {
toolOutWriter.printMessage("\n");
toolOutWriter.printMessage("tamper-detect-files-deleted");
toolOutWriter.printMessage(SMALL_LINE_SEP_1);
}
for (Enumeration e = fileLost.propertyNames(); e.hasMoreElements(); ) {
toolOutWriter.printResult((String) e.nextElement());
}
toolOutWriter.printStatusMsg(false, "tamper-detect-status");
} else {
toolOutWriter.printStatusMsg(true, "tamper-detect-status");
}
} catch (Exception ex) {
throw new DTException(ex.getMessage());
}
}
use of com.sun.identity.diagnostic.base.core.common.DTException in project OpenAM by OpenRock.
the class BEAWeblogicJVMOptionsValidator 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.JVMOPTIONS_DIR);
File domainConfigDir = new File(domainDir, domainConfig_dir);
if (domainConfigDir.exists() && domainConfigDir.isDirectory()) {
toolOutWriter.printStatusMsg(true, "webcontainer-domain-bin-dir-check");
String domainFileName = containerProp.getProperty(WebContainerConstant.JVMOPTIONS_FILE);
if (WebContainerConstant.OS_NAME.toLowerCase().indexOf(WebContainerConstant.WINDOWS) >= 0) {
domainFileName = domainFileName + ".cmd";
} else {
domainFileName = domainFileName + ".sh";
}
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(domainConfigDir, domainFileName)));
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-domain-bin-dir-invalid");
toolOutWriter.printStatusMsg(false, "webcontainer-domain-bin-dir-check");
}
} else {
toolOutWriter.printError("webcontainer-domain-dir-invalid");
toolOutWriter.printStatusMsg(false, "webcontainer-domain-dir-check");
}
} else {
toolOutWriter.printError("webcontainer-domain-dir-invalid");
toolOutWriter.printStatusMsg(false, "webcontainer-domain-dir-check");
}
}
use of com.sun.identity.diagnostic.base.core.common.DTException in project OpenAM by OpenRock.
the class IBMWebSpherePoliciesValidator 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 profileProp_dir = containerProp.getProperty(WebContainerConstant.POLICIES_DIR);
File profilePropDir = new File(profileDir, profileProp_dir);
if (profilePropDir.exists() && profilePropDir.isDirectory()) {
toolOutWriter.printStatusMsg(true, "webcontainer-properties-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(profilePropDir, 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-properties-dir-invalid");
toolOutWriter.printStatusMsg(false, "webcontainer-properties-dir-check");
}
} else {
toolOutWriter.printError("webcontainer-profile-dir-invalid");
toolOutWriter.printStatusMsg(false, "webcontainer-profile-dir-invalid");
}
}
}
use of com.sun.identity.diagnostic.base.core.common.DTException in project OpenAM by OpenRock.
the class SunAppSvrJVMOptionsValidator 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.JVMOPTIONS_DIR);
File domainConfigDir = new File(domainDir, domainConfig_dir);
if (domainConfigDir.exists() && domainConfigDir.isDirectory()) {
toolOutWriter.printStatusMsg(true, "webcontainer-domain-config-dir-check");
String domainFileName = 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(domainConfigDir, domainFileName)));
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-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");
}
} else {
toolOutWriter.printError("webcontainer-domain-dir-invalid");
toolOutWriter.printStatusMsg(false, "webcontainer-domain-dir-check");
}
}
Aggregations