@@ -21,9 +21,26 @@ class Authorization(private var authorizationSettings: AuthorizationSettings) {
21
21
import Authorization ._
22
22
23
23
def getRoles (request : Request [_]): List [String ] = {
24
- authorizationSettings.authEnabled match {
25
- case true => getKeyRoles(request.headers.get(authorizationSettings.authHeader))
26
- case false => List (Admin )
24
+ (authorizationSettings.apiKeyAuthEnabled, authorizationSettings.xfccKeyAuthEnabled) match {
25
+ case (true , true ) =>
26
+ if (getKeyRoles(request.headers.get(authorizationSettings.apiKeyAuthHeader)) ==
27
+ getXfccRoles(request.headers.get(authorizationSettings.xfccAuthHeader))) {
28
+ List (Admin )
29
+ } else {
30
+ List .empty
31
+ }
32
+ case (true , false ) => getKeyRoles(request.headers.get(authorizationSettings.apiKeyAuthHeader))
33
+ case (false , true ) => getXfccRoles(request.headers.get(authorizationSettings.xfccAuthHeader))
34
+ case (false , false ) => List (Admin )
35
+ }
36
+ }
37
+
38
+ private def getXfccRoles (key : Option [String ]) = {
39
+ key match {
40
+ case Some (xfcc) =>
41
+ if (xfcc.contains(authorizationSettings.xfccMustContain)) { List (Admin ) }
42
+ else { List .empty }
43
+ case None => List .empty
27
44
}
28
45
}
29
46
@@ -34,17 +51,8 @@ class Authorization(private var authorizationSettings: AuthorizationSettings) {
34
51
}
35
52
}
36
53
37
- def checkAuthorization (request : Request [_]): Boolean =
38
- request.headers
39
- .get(authorizationSettings.authHeader)
40
- .map(validateKey)
41
- .getOrElse(! authorizationSettings.authEnabled)
42
-
43
54
def refreshDelay : Option [FiniteDuration ] = authorizationSettings.ttl.map(_.second)
44
55
45
- private def validateKey (key : String ): Boolean =
46
- authorizationSettings.keyRoles.contains(convertToSha256(key))
47
-
48
56
def reloadSettings (): this .type = {
49
57
ConfigFactory .invalidateCaches()
50
58
authorizationSettings = AuthorizationSettings ()
0 commit comments