lmccay commented on code in PR #1531:
URL: https://github.com/apache/knox/pull/1531#discussion_r4636437982


##########
gateway-service-knoxidf/src/main/java/org/apache/knox/gateway/service/knoxidf/RegistrationResource.java:
##########
@@ -212,6 +224,33 @@ private boolean isAnonymousCaller() {
         return 
ANONYMOUS_PRINCIPAL.equalsIgnoreCase(SubjectUtils.getCurrentEffectivePrincipalName());
     }
 
+    /**
+     * @return {@code true} when the request must be rejected because the 
caller is itself a registered
+     * client (its subject is the id of a CLIENT_ID token) while client 
callers have not been explicitly
+     * allowed. Such a client would own the clients it registers, each with 
its own per-user token limit.
+     */
+    boolean clientCallerDenied() {
+        return clientCallersDenied && isClientCaller();
+    }
+
+    private boolean isClientCaller() {
+        // The primary principal is the subject as authenticated. The 
effective principal is the result of
+        // identity-assertion mapping (e.g. lowercase), which can turn a 
client id into an unknown name.
+        final Subject subject = SubjectUtils.getCurrentSubject();
+        final String subjectName = subject == null ? null : 
SubjectUtils.getPrimaryPrincipalName(subject);

Review Comment:
   Do we not need to use effective user here which would include the 
impersonated user as well, IIRC?



##########
gateway-service-knoxidf/src/main/java/org/apache/knox/gateway/service/knoxidf/RegistrationResource.java:
##########
@@ -212,6 +224,33 @@ private boolean isAnonymousCaller() {
         return 
ANONYMOUS_PRINCIPAL.equalsIgnoreCase(SubjectUtils.getCurrentEffectivePrincipalName());
     }
 
+    /**
+     * @return {@code true} when the request must be rejected because the 
caller is itself a registered
+     * client (its subject is the id of a CLIENT_ID token) while client 
callers have not been explicitly
+     * allowed. Such a client would own the clients it registers, each with 
its own per-user token limit.
+     */
+    boolean clientCallerDenied() {
+        return clientCallersDenied && isClientCaller();
+    }
+
+    private boolean isClientCaller() {
+        // The primary principal is the subject as authenticated. The 
effective principal is the result of
+        // identity-assertion mapping (e.g. lowercase), which can turn a 
client id into an unknown name.
+        final Subject subject = SubjectUtils.getCurrentSubject();
+        final String subjectName = subject == null ? null : 
SubjectUtils.getPrimaryPrincipalName(subject);
+        // Without token state there is no client id to look up.

Review Comment:
   I also wonder if we should check whether there is an ActorChainPrincipal and 
reject those as well. Do we want to allow delegated auth tokens to be able to 
register clients?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to