Biblioteca Java - Blame information for rev 3
Subversion Repositories:
Rev | Author | Line No. | Line |
---|---|---|---|
3 | mihai | 1 | /* |
2 | * WriteFile.java | ||
3 | */ | ||
4 | package lab.scd.sm.custom; | ||
5 | |||
6 | /** | ||
7 | * Class created by @author Mihai HULEA at Apr 3, 2005. | ||
8 | * | ||
9 | * This class is part of the lab3_1_security project. | ||
10 | * | ||
11 | */ | ||
12 | import java.io.*; | ||
13 | |||
14 | class MySecurityManager extends SecurityManager | ||
15 | { | ||
16 | private String pas; | ||
17 | MySecurityManager(String pas) | ||
18 | { | ||
19 | super(); | ||
20 | this.pas=pas; | ||
21 | } | ||
22 | |||
23 | public void checkWrite(String f) | ||
24 | { | ||
25 | } | ||
26 | |||
27 | public void checkWrite(FileDescriptor f) | ||
28 | { | ||
29 | } | ||
30 | |||
31 | public void checkRead(String f) | ||
32 | { | ||
33 | if(!chkPas()) throw new SecurityException("Citire blocata."); | ||
34 | } | ||
35 | |||
36 | public void checkRead(FileDescriptor f) | ||
37 | { | ||
38 | if(!chkPas()) throw new SecurityException("Citire blocata."); | ||
39 | } | ||
40 | |||
41 | private boolean chkPas() | ||
42 | { | ||
43 | try | ||
44 | { | ||
45 | BufferedReader line = new BufferedReader(new InputStreamReader(System.in)); | ||
46 | if(!(line.readLine()).equals(pas)) return false; | ||
47 | }catch(Exception e){} | ||
48 | return true; | ||
49 | } | ||
50 | } | ||
51 | |||
52 | |||
53 | public class WriteFile | ||
54 | { | ||
55 | |||
56 | |||
57 | public static void main(String args[]) | ||
58 | { | ||
59 | try | ||
60 | { | ||
61 | |||
62 | System.setSecurityManager(new MySecurityManager("sm custom")); | ||
63 | |||
64 | |||
65 | FileWriter fw = new FileWriter("file.txt"); | ||
66 | fw.write("ABCD\n"); | ||
67 | fw.write("123\n"); | ||
68 | fw.close(); | ||
69 | |||
70 | BufferedReader fr = new BufferedReader(new FileReader("file.txt")); | ||
71 | System.out.println(fr.readLine()); | ||
72 | fr.close(); | ||
73 | |||
74 | }catch(SecurityException ex) | ||
75 | { | ||
76 | ex.printStackTrace(); | ||
77 | } | ||
78 | catch(Exception e) | ||
79 | { | ||
80 | e.printStackTrace(); | ||
81 | } | ||
82 | |||
83 | } | ||
84 | } |