1414
1515public final class EidPermissionIndex {
1616
17- // bitmask for which fields are present in a permission
18- private static final int INSERTER = 1 ; // 0001
19- private static final int SOURCE = 2 ; // 0010
20- private static final int MATCHER = 4 ; // 0100
21- private static final int MM = 8 ; // 1000
17+ // Bitmask for which fields are present in the EID permission
18+ private static final int INSERTER = 1 << 0 ;
19+ private static final int SOURCE = 1 << 1 ;
20+ private static final int MATCHER = 1 << 2 ;
21+ private static final int MM = 1 << 3 ;
2222 private static final String WILDCARD_BIDDER = "*" ;
2323
2424 private final Map <Integer , Map <Key , Set <String >>> ruleIndexByMask ;
@@ -66,25 +66,17 @@ public static EidPermissionIndex build(List<ExtRequestPrebidDataEidPermissions>
6666 }
6767
6868 private static int maskOf (String inserter , String source , String matcher , Integer mm ) {
69- int mask = 0 ;
70-
71- if (inserter != null ) {
72- mask |= INSERTER ;
73- }
74- if (source != null ) {
75- mask |= SOURCE ;
76- }
77- if (matcher != null ) {
78- mask |= MATCHER ;
79- }
80- if (mm != null ) {
81- mask |= MM ;
82- }
83-
84- return mask ;
69+ return (inserter != null ? INSERTER : 0 )
70+ | (source != null ? SOURCE : 0 )
71+ | (matcher != null ? MATCHER : 0 )
72+ | (mm != null ? MM : 0 );
8573 }
8674
8775 public boolean isAllowed (Eid eid , String bidder ) {
76+ if (ObjectUtils .isEmpty (ruleIndexByMask )) {
77+ return true ;
78+ }
79+
8880 final int eidMask = maskOf (eid .getInserter (), eid .getSource (), eid .getMatcher (), eid .getMm ());
8981
9082 boolean ruleMatched = false ;
@@ -93,8 +85,7 @@ public boolean isAllowed(Eid eid, String bidder) {
9385 for (Map .Entry <Integer , Map <Key , Set <String >>> ruleBucket : ruleIndexByMask .entrySet ()) {
9486 final int ruleMask = ruleBucket .getKey ();
9587
96- // rule can only match if all its required fields exist on the Eid
97- if ((ruleMask & eidMask ) != ruleMask ) {
88+ if (!isMaskMatched (ruleMask , eidMask )) {
9889 continue ;
9990 }
10091
@@ -112,7 +103,11 @@ public boolean isAllowed(Eid eid, String bidder) {
112103 }
113104 }
114105
115- // allow-by- default: if no rule matched at all, allow
106+ // Allow by default if no rule matched at all
116107 return !ruleMatched ;
117108 }
109+
110+ private boolean isMaskMatched (int ruleMaks , int eidMask ) {
111+ return (ruleMaks & eidMask ) == ruleMaks ;
112+ }
118113}
0 commit comments