11package com .uid2 .core .util ;
2- import com .uid2 .core .Const ;
32import com .uid2 .shared .auth .IAuthorizable ;
43import com .uid2 .shared .auth .OperatorKey ;
54import com .uid2 .shared .auth .OperatorType ;
6- import io .vertx .core .http .HttpServerRequest ;
75import io .vertx .ext .web .RoutingContext ;
8-
9- import java .util .regex .Matcher ;
10- import java .util .regex .Pattern ;
11- import com .uid2 .core .model .ConfigStore ;
126import org .slf4j .Logger ;
137import org .slf4j .LoggerFactory ;
14-
15- import static com .uid2 .shared .Const .Config .encryptionSupportVersion ;
16- import static com .uid2 .shared .Const .Http .AppVersionHeader ;
178import static com .uid2 .shared .middleware .AuthMiddleware .API_CLIENT_PROP ;
189
1910/**
@@ -53,54 +44,6 @@ public static OperatorInfo getOperatorInfo(RoutingContext rc) throws Exception {
5344 }
5445
5546 static boolean supportsEncryption (RoutingContext rc ) {
56- String appVersion = rc .request ().getHeader (AppVersionHeader );
57- if (appVersion == null ) {
58- logger .warn ("AppVersion header is missing." );
59- return false ;
60- }
61- String [] versions = appVersion .split (";" );
62- for (String version : versions ) {
63- if (version .startsWith ("uid2-operator=" )) {
64- String operatorVersion = version .substring ("uid2-operator=" .length ());
65- boolean isSupported = isVersionGreaterOrEqual (operatorVersion , ConfigStore .Global .getOrDefault (encryptionSupportVersion , "9999" ));
66- logger .debug ("Operator version: {}, {}" ,
67- operatorVersion , isSupported ? "Supports encryption" : "Does not support encryption" );
68- return isSupported ;
69- }
70- }
71- return false ;
72- }
73-
74- /*
75- Returns if the version of a semvar v1 is greater or equal to v2
76- */
77- static boolean isVersionGreaterOrEqual (String v1 , String v2 ) {
78- Pattern pattern = Pattern .compile ("(\\ d+)(?:\\ .(\\ d+))?(?:\\ .(\\ d+))?" );
79- Matcher m1 = pattern .matcher (v1 );
80- Matcher m2 = pattern .matcher (v2 );
81-
82- int [] parts1 = extractParts (m1 );
83- int [] parts2 = extractParts (m2 );
84-
85- for (int i = 0 ; i < Math .max (parts1 .length , parts2 .length ); i ++) {
86- int p1 = i < parts1 .length ? parts1 [i ] : 0 ;
87- int p2 = i < parts2 .length ? parts2 [i ] : 0 ;
88- if (p1 != p2 ) {
89- return p1 > p2 ;
90- }
91- }
92-
93- return true ;
94- }
95-
96- private static int [] extractParts (Matcher matcher ) {
97- int [] parts = new int [3 ];
98- if (matcher .find ()) {
99- for (int i = 1 ; i <= 3 ; i ++) {
100- String group = matcher .group (i );
101- parts [i - 1 ] = group != null ? Integer .parseInt (group ) : 0 ;
102- }
103- }
104- return parts ;
47+ return Boolean .parseBoolean (rc .request ().getHeader ("Encrypted" ));
10548 }
10649}
0 commit comments