Переглянути джерело

Add a skeleton security policy.

For now this just allows everything (including replacing the
SecurityManager/Policy...) but we can start restricting things
later.

Change-Id: I3627bf06bd35fcebfb42bdc563617b830a999aaa
Reviewed-on: http://gerrit.dmdirc.com/3567
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Greg Holmes <greg@dmdirc.com>
pull/1/head
Chris Smith 10 роки тому
джерело
коміт
0bc8af8c24

+ 51
- 0
src/com/dmdirc/DMDircSecurityPolicy.java Переглянути файл

@@ -0,0 +1,51 @@
1
+/*
2
+ * Copyright (c) 2006-2014 DMDirc Developers
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc;
24
+
25
+import java.security.CodeSource;
26
+import java.security.Permission;
27
+import java.security.PermissionCollection;
28
+import java.security.Policy;
29
+import java.security.ProtectionDomain;
30
+
31
+/**
32
+ * Security policy used by DMDirc.
33
+ */
34
+public class DMDircSecurityPolicy extends Policy {
35
+
36
+    @Override
37
+    public boolean implies(final ProtectionDomain domain, final Permission permission) {
38
+        return true;
39
+    }
40
+
41
+    @Override
42
+    public PermissionCollection getPermissions(final ProtectionDomain domain) {
43
+        return UNSUPPORTED_EMPTY_COLLECTION;
44
+    }
45
+
46
+    @Override
47
+    public PermissionCollection getPermissions(final CodeSource codesource) {
48
+        return UNSUPPORTED_EMPTY_COLLECTION;
49
+    }
50
+
51
+}

+ 8
- 0
src/com/dmdirc/Main.java Переглянути файл

@@ -47,6 +47,7 @@ import com.dmdirc.ui.WarningDialog;
47 47
 import com.google.common.eventbus.EventBus;
48 48
 
49 49
 import java.awt.GraphicsEnvironment;
50
+import java.security.Policy;
50 51
 import java.util.Collection;
51 52
 import java.util.HashSet;
52 53
 import java.util.List;
@@ -150,6 +151,13 @@ public class Main {
150 151
     public static void main(final String[] args) {
151 152
         Thread.setDefaultUncaughtExceptionHandler(new DMDircExceptionHandler());
152 153
 
154
+        try {
155
+            Policy.setPolicy(new DMDircSecurityPolicy());
156
+            System.setSecurityManager(new SecurityManager());
157
+        } catch (SecurityException ex) {
158
+            Logger.appError(ErrorLevel.HIGH, "Unable to set security policy", ex);
159
+        }
160
+
153 161
         try {
154 162
             ClientModule clientModule = new ClientModule();
155 163
             final ObjectGraph graph = ObjectGraph.create(clientModule);

Завантаження…
Відмінити
Зберегти