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