871b417a57cab3336793a845810383ceae4233cbMark de Reeper * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
871b417a57cab3336793a845810383ceae4233cbMark de Reeper * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved.
871b417a57cab3336793a845810383ceae4233cbMark de Reeper * The contents of this file are subject to the terms
871b417a57cab3336793a845810383ceae4233cbMark de Reeper * of the Common Development and Distribution License
871b417a57cab3336793a845810383ceae4233cbMark de Reeper * (the License). You may not use this file except in
871b417a57cab3336793a845810383ceae4233cbMark de Reeper * compliance with the License.
871b417a57cab3336793a845810383ceae4233cbMark de Reeper * You can obtain a copy of the License at
871b417a57cab3336793a845810383ceae4233cbMark de Reeper * https://opensso.dev.java.net/public/CDDLv1.0.html or
871b417a57cab3336793a845810383ceae4233cbMark de Reeper * See the License for the specific language governing
871b417a57cab3336793a845810383ceae4233cbMark de Reeper * permission and limitations under the License.
871b417a57cab3336793a845810383ceae4233cbMark de Reeper * When distributing Covered Code, include this CDDL
871b417a57cab3336793a845810383ceae4233cbMark de Reeper * Header Notice in each file and include the License file
871b417a57cab3336793a845810383ceae4233cbMark de Reeper * If applicable, add the following below the CDDL Header,
871b417a57cab3336793a845810383ceae4233cbMark de Reeper * with the fields enclosed by brackets [] replaced by
871b417a57cab3336793a845810383ceae4233cbMark de Reeper * your own identifying information:
871b417a57cab3336793a845810383ceae4233cbMark de Reeper * "Portions Copyrighted [year] [name of copyright owner]"
871b417a57cab3336793a845810383ceae4233cbMark de Reeper * $Id: ConfigDirValidator.java,v 1.1 2009/01/21 18:43:53 kanduls Exp $
5c39d8f041417518a02ce2c941d96c2d33b2a364Mark de Reeper * Portions Copyrighted 2013 ForgeRock AS.
871b417a57cab3336793a845810383ceae4233cbMark de Reeperpackage com.sun.identity.agents.tools.jetty.v7;
871b417a57cab3336793a845810383ceae4233cbMark de Reeperimport com.sun.identity.install.tools.configurator.IStateAccess;
871b417a57cab3336793a845810383ceae4233cbMark de Reeperimport com.sun.identity.install.tools.configurator.InstallException;
871b417a57cab3336793a845810383ceae4233cbMark de Reeperimport com.sun.identity.install.tools.configurator.ValidationResult;
871b417a57cab3336793a845810383ceae4233cbMark de Reeperimport com.sun.identity.install.tools.configurator.ValidationResultStatus;
871b417a57cab3336793a845810383ceae4233cbMark de Reeperimport com.sun.identity.install.tools.configurator.ValidatorBase;
871b417a57cab3336793a845810383ceae4233cbMark de Reeperimport com.sun.identity.install.tools.util.Debug;
871b417a57cab3336793a845810383ceae4233cbMark de Reeperimport com.sun.identity.install.tools.util.LocalizedMessage;
871b417a57cab3336793a845810383ceae4233cbMark de Reeperpublic class ConfigDirValidator extends ValidatorBase implements IConstants, IConfigKeys {
871b417a57cab3336793a845810383ceae4233cbMark de Reeper public ConfigDirValidator() throws InstallException {
871b417a57cab3336793a845810383ceae4233cbMark de Reeper * Method isConfigDirValid
871b417a57cab3336793a845810383ceae4233cbMark de Reeper * @param configDir
871b417a57cab3336793a845810383ceae4233cbMark de Reeper * @param props
871b417a57cab3336793a845810383ceae4233cbMark de Reeper * @param state
871b417a57cab3336793a845810383ceae4233cbMark de Reeper * @return ValidationResult
871b417a57cab3336793a845810383ceae4233cbMark de Reeper public ValidationResult isConfigDirValid(String configDir, Map props, IStateAccess state) {
871b417a57cab3336793a845810383ceae4233cbMark de Reeper ValidationResultStatus validRes = ValidationResultStatus.STATUS_FAILED;
871b417a57cab3336793a845810383ceae4233cbMark de Reeper if ((configDir != null) && (configDir.trim().length() >= 0)) {
871b417a57cab3336793a845810383ceae4233cbMark de Reeper // The config dir has been normalized to have "/" only
871b417a57cab3336793a845810383ceae4233cbMark de Reeper String serverXmlFile = configDir + STR_FORWARD_SLASH + STR_SERVER_XML;
871b417a57cab3336793a845810383ceae4233cbMark de Reeper Debug.log("ConfigDirValidator.isConfigDirValid(): Server XML file path is: " + serverXmlFile);
871b417a57cab3336793a845810383ceae4233cbMark de Reeper if (isValid(configDir) && isValid(serverXmlFile)) {
871b417a57cab3336793a845810383ceae4233cbMark de Reeper state.put(STR_KEY_JETTY_SERVER_XML_FILE, serverXmlFile);
871b417a57cab3336793a845810383ceae4233cbMark de Reeper validRes = ValidationResultStatus.STATUS_SUCCESS;
871b417a57cab3336793a845810383ceae4233cbMark de Reeper if (validRes.getIntValue() == ValidationResultStatus.INT_STATUS_FAILED)
871b417a57cab3336793a845810383ceae4233cbMark de Reeper Debug.log("ConfigDirValidator.isConfigDirValid(): Is Jetty Server Config dir "
871b417a57cab3336793a845810383ceae4233cbMark de Reeper + configDir + " valid ? " + validRes.isSuccessful());
871b417a57cab3336793a845810383ceae4233cbMark de Reeper return new ValidationResult(validRes, null, returnMessage);
871b417a57cab3336793a845810383ceae4233cbMark de Reeper boolean valid = false;
871b417a57cab3336793a845810383ceae4233cbMark de Reeper if (file.exists() && file.canRead() && file.canWrite()) {
871b417a57cab3336793a845810383ceae4233cbMark de Reeper Debug.log("ConfigDirValidator.isValid(): " + fileName + " does not exist");
871b417a57cab3336793a845810383ceae4233cbMark de Reeper Debug.log("ConfigDirValidator.isValid(): " + fileName + " does not have read and write permissions");
871b417a57cab3336793a845810383ceae4233cbMark de Reeper public void initializeValidatorMap() throws InstallException {
871b417a57cab3336793a845810383ceae4233cbMark de Reeper Class[] paramObjs = {String.class, Map.class, IStateAccess.class};
871b417a57cab3336793a845810383ceae4233cbMark de Reeper getValidatorMap().put("VALID_JETTY_CONFIG_DIR", this.getClass().getMethod("isConfigDirValid", paramObjs));
871b417a57cab3336793a845810383ceae4233cbMark de Reeper Debug.log("ConfigDirValidator: NoSuchMethodException thrown while loading method :", nsme);
871b417a57cab3336793a845810383ceae4233cbMark de Reeper throw new InstallException(LocalizedMessage.get(LOC_VA_ERR_VAL_METHOD_NOT_FOUND), nsme);
871b417a57cab3336793a845810383ceae4233cbMark de Reeper Debug.log("ConfigDirValidator: SecurityException thrown while loading method :", se);
871b417a57cab3336793a845810383ceae4233cbMark de Reeper throw new InstallException(LocalizedMessage.get(LOC_VA_ERR_VAL_METHOD_NOT_FOUND), se);
871b417a57cab3336793a845810383ceae4233cbMark de Reeper Debug.log("ConfigDirValidator: Exception thrown while loading method :", ex);