-
Notifications
You must be signed in to change notification settings - Fork 8
/
MatchIdConverterUtil.java
118 lines (105 loc) · 5.11 KB
/
MatchIdConverterUtil.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
* SNE-XACML: A high performance XACML evaluation engine.
*
* Copyright (C) 2013-2014 Canh Ngo <canhnt@gmail.com>
* System and Network Engineering Group, University of Amsterdam.
* All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package nl.uva.sne.xacml.policy.parsers.util;
public class MatchIdConverterUtil {
public enum OperatorType {
GREATER_THAN,
GREATER_THAN_OR_EQUAL,
LESS_THAN,
LESS_THAN_OR_EQUAL,
EQUAL
}
public static final String[] EQUAL_OPERATORS = new String[]{
"urn:oasis:names:tc:xacml:1.0:function:string-equal",
"urn:oasis:names:tc:xacml:1.0:function:integer-equal",
"urn:oasis:names:tc:xacml:1.0:function:double-equal",
"urn:oasis:names:tc:xacml:1.0:function:boolean-equal",
"urn:oasis:names:tc:xacml:1.0:function:date-equal",
"urn:oasis:names:tc:xacml:1.0:function:time-equal",
"urn:oasis:names:tc:xacml:1.0:function:dateTime-equal",
"urn:oasis:names:tc:xacml:1.0:function:dayTimeDuration-equal",
"urn:oasis:names:tc:xacml:1.0:function:yearMonthDuration-equal",
"urn:oasis:names:tc:xacml:1.0:function:rfc822Name-equal",
"urn:oasis:names:tc:xacml:1.0:function:x500Name-equal",
"urn:oasis:names:tc:xacml:1.0:function:anyURI-equal",
"urn:oasis:names:tc:xacml:1.0:function:base64Binary-equal"
};
public static final String[] GREATER_THAN_OPERATORS = new String[]{
"urn:oasis:names:tc:xacml:1.0:function:string-greater-than",
"urn:oasis:names:tc:xacml:1.0:function:integer-greater-than",
"urn:oasis:names:tc:xacml:1.0:function:double-greater-than",
"urn:oasis:names:tc:xacml:1.0:function:date-greater-than",
"urn:oasis:names:tc:xacml:1.0:function:time-greater-than",
"urn:oasis:names:tc:xacml:1.0:function:dateTime-greater-than"
};
public static final String[] GREATER_THAN_OR_EQUAL_OPERATORS = new String[]{
"urn:oasis:names:tc:xacml:1.0:function:string-greater-than-or-equal",
"urn:oasis:names:tc:xacml:1.0:function:integer-greater-than-or-equal",
"urn:oasis:names:tc:xacml:1.0:function:double-greater-than-or-equal",
"urn:oasis:names:tc:xacml:1.0:function:date-greater-than-or-equal",
"urn:oasis:names:tc:xacml:1.0:function:time-greater-than-or-equal",
"urn:oasis:names:tc:xacml:1.0:function:dateTime-greater-than-or-equal"
};
public static final String[] LESS_THAN_OPERATORS = new String[]{
"urn:oasis:names:tc:xacml:1.0:function:string-less-than",
"urn:oasis:names:tc:xacml:1.0:function:integer-less-than",
"urn:oasis:names:tc:xacml:1.0:function:double-less-than",
"urn:oasis:names:tc:xacml:1.0:function:date-less-than",
"urn:oasis:names:tc:xacml:1.0:function:time-less-than",
"urn:oasis:names:tc:xacml:1.0:function:dateTime-less-than"
};
public static final String[] LESS_THAN_OR_EQUAL_OPERATORS = new String[]{
"urn:oasis:names:tc:xacml:1.0:function:string-less-than-or-equal",
"urn:oasis:names:tc:xacml:1.0:function:integer-less-than-or-equal",
"urn:oasis:names:tc:xacml:1.0:function:double-less-than-or-equal",
"urn:oasis:names:tc:xacml:1.0:function:date-less-than-or-equal",
"urn:oasis:names:tc:xacml:1.0:function:time-less-than-or-equal",
"urn:oasis:names:tc:xacml:1.0:function:dateTime-less-than-or-equal"
};
public static OperatorType getOperator(String matchId) {
if (find(matchId, EQUAL_OPERATORS)) {
return OperatorType.EQUAL;
}
if (find(matchId, GREATER_THAN_OPERATORS)) {
return OperatorType.GREATER_THAN;
}
if (find(matchId, GREATER_THAN_OR_EQUAL_OPERATORS)) {
return OperatorType.GREATER_THAN_OR_EQUAL;
}
if (find(matchId, LESS_THAN_OPERATORS)) {
return OperatorType.LESS_THAN;
}
if (find(matchId, LESS_THAN_OR_EQUAL_OPERATORS)) {
return OperatorType.LESS_THAN_OR_EQUAL;
}
throw new UnsupportedOperationException("Unknown operator");
}
private static boolean find(String matchId, String[] operators) {
for (int i = 0; i < operators.length; i++) {
if (operators[i].equals(matchId)) {
return true;
}
}
return false;
}
}