1 // Copyright (C) 2009 Red Hat, Inc.
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
16 
17 package net.sourceforge.jnlp.services;
18 
19 import java.io.File;
20 import java.io.IOException;
21 
22 import javax.jnlp.ExtendedService;
23 import javax.jnlp.FileContents;
24 
25 import net.sourceforge.jnlp.security.SecurityDialogs.AccessType;
26 
27 /**
28  * Implementation of ExtendedService
29  *
30  * @author <a href="mailto:omajid@redhat.com">Omair Majid</a>
31  *
32  */
33 public class XExtendedService implements ExtendedService {
34 
openFile(File file)35     public FileContents openFile(File file) throws IOException {
36 
37         File secureFile = new File(file.getPath());
38 
39         /* FIXME: this opens a file with read/write mode, not just read or write */
40         if (ServiceUtil.checkAccess(AccessType.READ_FILE, new Object[] { secureFile.getAbsolutePath() })) {
41             return (FileContents) ServiceUtil.createPrivilegedProxy(FileContents.class,
42                     new XFileContents(secureFile));
43         } else {
44             return null;
45         }
46 
47     }
48 
openFiles(File[] files)49     public FileContents[] openFiles(File[] files) throws IOException {
50         FileContents[] contents = new FileContents[files.length];
51         for (int i = 0; i < files.length; i++) {
52             contents[i] = openFile(files[i]);
53         }
54         return contents;
55     }
56 
57 }
58