001: /*
002: * File : $Source: /usr/local/cvs/opencms/src-setup/org/opencms/setup/comptest/CmsSetupTestFolderPermissions.java,v $
003: * Date : $Date: 2008-02-27 12:05:32 $
004: * Version: $Revision: 1.2 $
005: *
006: * This library is part of OpenCms -
007: * the Open Source Content Management System
008: *
009: * Copyright (c) 2002 - 2008 Alkacon Software GmbH (http://www.alkacon.com)
010: *
011: * This library is free software; you can redistribute it and/or
012: * modify it under the terms of the GNU Lesser General Public
013: * License as published by the Free Software Foundation; either
014: * version 2.1 of the License, or (at your option) any later version.
015: *
016: * This library is distributed in the hope that it will be useful,
017: * but WITHOUT ANY WARRANTY; without even the implied warranty of
018: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: * Lesser General Public License for more details.
020: *
021: * For further information about Alkacon Software GmbH, please see the
022: * company website: http://www.alkacon.com
023: *
024: * For further information about OpenCms, please see the
025: * project website: http://www.opencms.org
026: *
027: * You should have received a copy of the GNU Lesser General Public
028: * License along with this library; if not, write to the Free Software
029: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
030: */
031:
032: package org.opencms.setup.comptest;
033:
034: import org.opencms.setup.CmsSetupBean;
035:
036: import java.io.File;
037: import java.io.FileReader;
038: import java.io.FileWriter;
039: import java.util.Random;
040:
041: /**
042: * Tests the permission on the target installation folders.<p>
043: *
044: * @author Michael Moossen
045: *
046: * @version $Revision: 1.2 $
047: *
048: * @since 6.1.8
049: */
050: public class CmsSetupTestFolderPermissions implements I_CmsSetupTest {
051:
052: /** The test name. */
053: public static final String TEST_NAME = "Folder Permissions";
054:
055: /**
056: * @see org.opencms.setup.comptest.I_CmsSetupTest#getName()
057: */
058: public String getName() {
059:
060: return TEST_NAME;
061: }
062:
063: /**
064: * @see org.opencms.setup.comptest.I_CmsSetupTest#execute(org.opencms.setup.CmsSetupBean)
065: */
066: public CmsSetupTestResult execute(CmsSetupBean setupBean) {
067:
068: CmsSetupTestResult testResult = new CmsSetupTestResult(this );
069:
070: String basePath = setupBean.getWebAppRfsPath();
071: if (!basePath.endsWith(File.separator)) {
072: basePath += File.separator;
073: }
074: File file1;
075: Random rnd = new Random();
076: do {
077: file1 = new File(basePath + "test" + rnd.nextInt(1000));
078: } while (file1.exists());
079: boolean success = false;
080: try {
081: file1.createNewFile();
082: FileWriter fw = new FileWriter(file1);
083: fw.write("aA1");
084: fw.close();
085: success = true;
086: FileReader fr = new FileReader(file1);
087: success = success && (fr.read() == 'a');
088: success = success && (fr.read() == 'A');
089: success = success && (fr.read() == '1');
090: success = success && (fr.read() == -1);
091: fr.close();
092: success = file1.delete();
093: success = !file1.exists();
094: } catch (Exception e) {
095: success = false;
096: }
097: if (!success) {
098: testResult.setRed();
099: testResult
100: .setInfo("OpenCms cannot be installed without read and write privileges for path "
101: + basePath
102: + "! Please check you are running your servlet container with the right user and privileges.");
103: testResult
104: .setHelp("Not enough permissions to create/read/write a file");
105: testResult.setResult(RESULT_FAILED);
106: } else {
107: testResult.setGreen();
108: testResult.setResult(RESULT_PASSED);
109: }
110: return testResult;
111: }
112: }
|