1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.universAAL.ri.gateway.communicator.service.impl;
22
23 import java.util.HashSet;
24 import java.util.Set;
25
26
27 public enum SecurityManager {
28 Instance;
29
30 static{
31 allowImportSecurityEntries = new HashSet<SecurityEntry>();
32 denyImportSecurityEntries = new HashSet<SecurityEntry>();
33
34 allowExportSecurityEntries = new HashSet<SecurityEntry>();
35 denyExportSecurityEntries = new HashSet<SecurityEntry>();
36 }
37
38 private static Set<SecurityEntry> allowImportSecurityEntries;
39 private static Set<SecurityEntry> denyImportSecurityEntries;
40
41 private static Set<SecurityEntry> allowExportSecurityEntries;
42 private static Set<SecurityEntry> denyExportSecurityEntries;
43
44 public static boolean isOperationAllowed(String uri, Type type){
45 switch (type) {
46 case Import:
47 if (matchesAnyValue(denyImportSecurityEntries, uri)){
48 return false;
49 }
50 if (matchesAnyValue(allowImportSecurityEntries, uri)){
51 return true;
52 }
53 break;
54
55 case Export:
56 if (matchesAnyValue(denyExportSecurityEntries, uri)){
57 return false;
58 }
59 if (matchesAnyValue(allowExportSecurityEntries, uri)){
60 return true;
61 }
62 break;
63 }
64 return false;
65 }
66
67 private static boolean matchesAnyValue(Set<SecurityEntry> entries, String value){
68 for(SecurityEntry entry : entries){
69 if (value.matches(entry.getEntryRegex())){
70 return true;
71 }
72 }
73 return false;
74 }
75
76 public Set<SecurityEntry> getAllowImportSecurityEntries() {
77 return allowImportSecurityEntries;
78 }
79
80 public void setAllowImportSecurityEntries(
81 Set<SecurityEntry> allowImportSecurityEntries) {
82 SecurityManager.allowImportSecurityEntries = allowImportSecurityEntries;
83 }
84
85 public Set<SecurityEntry> getDenyImportSecurityEntries() {
86 return denyImportSecurityEntries;
87 }
88
89 public void setDenyImportSecurityEntries(
90 Set<SecurityEntry> denyImportSecurityEntries) {
91 SecurityManager.denyImportSecurityEntries = denyImportSecurityEntries;
92 }
93
94 public Set<SecurityEntry> getAllowExportSecurityEntries() {
95 return allowExportSecurityEntries;
96 }
97
98 public void setAllowExportSecurityEntries(
99 Set<SecurityEntry> allowExportSecurityEntries) {
100 SecurityManager.allowExportSecurityEntries = allowExportSecurityEntries;
101 }
102
103 public Set<SecurityEntry> getDenyExportSecurityEntries() {
104 return denyExportSecurityEntries;
105 }
106
107 public void setDenyExportSecurityEntries(
108 Set<SecurityEntry> denyExportSecurityEntries) {
109 SecurityManager.denyExportSecurityEntries = denyExportSecurityEntries;
110 }
111 }
112
113 enum Type {
114 Import, Export;
115 }
116
117 enum SecurityAction {
118 Allow, Deny;
119 }
120