[GitHub] [cxf] amarkevich opened a new pull request #652: CXF-8243 JwtAccessTokenValidator using the JWK Set URL

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

[GitHub] [cxf] amarkevich opened a new pull request #652: CXF-8243 JwtAccessTokenValidator using the JWK Set URL

GitBox
amarkevich opened a new pull request #652: CXF-8243 JwtAccessTokenValidator using the JWK Set URL
URL: https://github.com/apache/cxf/pull/652
 
 
   

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[hidden email]


With regards,
Apache Git Services
Reply | Threaded
Open this post in threaded view
|

[GitHub] [cxf] coheigea commented on a change in pull request #652: CXF-8243 JwtAccessTokenValidator using the JWK Set URL

GitBox
coheigea commented on a change in pull request #652: CXF-8243 JwtAccessTokenValidator using the JWK Set URL
URL: https://github.com/apache/cxf/pull/652#discussion_r395486090
 
 

 ##########
 File path: systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oidc/filters/OIDCFiltersTest.java
 ##########
 @@ -111,45 +101,6 @@ public void testClientCodeRequestFilter() throws Exception {
         assertEquals(returnedBook.getId(), 123L);
     }
 
-    @org.junit.Test
 
 Review comment:
   Why is it being removed?

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[hidden email]


With regards,
Apache Git Services
Reply | Threaded
Open this post in threaded view
|

[GitHub] [cxf] coheigea commented on a change in pull request #652: CXF-8243 JwtAccessTokenValidator using the JWK Set URL

GitBox
In reply to this post by GitBox
coheigea commented on a change in pull request #652: CXF-8243 JwtAccessTokenValidator using the JWK Set URL
URL: https://github.com/apache/cxf/pull/652#discussion_r395481214
 
 

 ##########
 File path: rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/filters/JwsJwksJwtAccessTokenValidator.java
 ##########
 @@ -0,0 +1,106 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.rs.security.oauth2.filters;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.function.Predicate;
+
+import javax.ws.rs.core.MediaType;
+
+import org.apache.cxf.jaxrs.client.WebClient;
+import org.apache.cxf.rs.security.jose.jaxrs.JsonWebKeysProvider;
+import org.apache.cxf.rs.security.jose.jwk.JsonWebKey;
+import org.apache.cxf.rs.security.jose.jwk.JsonWebKeys;
+import org.apache.cxf.rs.security.jose.jwk.PublicKeyUse;
+import org.apache.cxf.rs.security.jose.jws.JwsHeaders;
+import org.apache.cxf.rs.security.jose.jws.JwsSignatureVerifier;
+import org.apache.cxf.rs.security.jose.jws.JwsUtils;
+
 
 Review comment:
   Can you add some javadoc explaining what the new validator is doing?

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[hidden email]


With regards,
Apache Git Services
Reply | Threaded
Open this post in threaded view
|

[GitHub] [cxf] coheigea commented on a change in pull request #652: CXF-8243 JwtAccessTokenValidator using the JWK Set URL

GitBox
In reply to this post by GitBox
coheigea commented on a change in pull request #652: CXF-8243 JwtAccessTokenValidator using the JWK Set URL
URL: https://github.com/apache/cxf/pull/652#discussion_r395485495
 
 

 ##########
 File path: rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/filters/JwsJwksJwtAccessTokenValidator.java
 ##########
 @@ -0,0 +1,106 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.rs.security.oauth2.filters;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.function.Predicate;
+
+import javax.ws.rs.core.MediaType;
+
+import org.apache.cxf.jaxrs.client.WebClient;
+import org.apache.cxf.rs.security.jose.jaxrs.JsonWebKeysProvider;
+import org.apache.cxf.rs.security.jose.jwk.JsonWebKey;
+import org.apache.cxf.rs.security.jose.jwk.JsonWebKeys;
+import org.apache.cxf.rs.security.jose.jwk.PublicKeyUse;
+import org.apache.cxf.rs.security.jose.jws.JwsHeaders;
+import org.apache.cxf.rs.security.jose.jws.JwsSignatureVerifier;
+import org.apache.cxf.rs.security.jose.jws.JwsUtils;
+
+public class JwsJwksJwtAccessTokenValidator extends JwtAccessTokenValidator {
+
+    final Map<String, JwkHolder> jsonWebKeys = new ConcurrentHashMap<>();
+
+    private String jwksURL;
+
+    @Override
+    protected JwsSignatureVerifier getInitializedSignatureVerifier(JwsHeaders jwsHeaders) {
+        Objects.requireNonNull(jwsHeaders.getKeyId());
+        return jsonWebKeys.computeIfAbsent(jwsHeaders.getKeyId(), keyId -> updateJwk(keyId)).getJwsSignatureVerifier();
+    }
+
+    public void setJwksURL(String jwksURL) {
+        this.jwksURL = jwksURL;
+    }
+
+    @Override
+    public void setJwsVerifier(JwsSignatureVerifier theJwsVerifier) {
+        throw new IllegalArgumentException("Actual JwsSignatureVerifier will be populated from the JWK Set URL");
+    }
+
+    private JwkHolder updateJwk(String keyId) {
+        Objects.requireNonNull(jwksURL, "JWK Set URL must be specified");
+        JwkHolder jwkHolder = null;
+        final Set<String> kids = new HashSet<>();
+        for (JsonWebKey jwk : getJsonWebKeys().getKeys()) {
+            if (PublicKeyUse.ENCRYPT != jwk.getPublicKeyUse()) {
+                final String kid = jwk.getKeyId();
+                kids.add(kid);
+                final JwkHolder h = new JwkHolder(jwk);
+                if (keyId.equals(kid)) {
+                    jwkHolder = h;
+                } else {
+                    jsonWebKeys.putIfAbsent(kid, h);
 
 Review comment:
   I find it hard to follow the logic in this method. Why is the JwkHolder added to jsonWebKeys for kid if the key ids don't match (and then removed on line 77?)

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[hidden email]


With regards,
Apache Git Services
Reply | Threaded
Open this post in threaded view
|

[GitHub] [cxf] amarkevich commented on a change in pull request #652: CXF-8243 JwtAccessTokenValidator using the JWK Set URL

GitBox
In reply to this post by GitBox
amarkevich commented on a change in pull request #652: CXF-8243 JwtAccessTokenValidator using the JWK Set URL
URL: https://github.com/apache/cxf/pull/652#discussion_r395542369
 
 

 ##########
 File path: rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/filters/JwsJwksJwtAccessTokenValidator.java
 ##########
 @@ -0,0 +1,106 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.rs.security.oauth2.filters;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.function.Predicate;
+
+import javax.ws.rs.core.MediaType;
+
+import org.apache.cxf.jaxrs.client.WebClient;
+import org.apache.cxf.rs.security.jose.jaxrs.JsonWebKeysProvider;
+import org.apache.cxf.rs.security.jose.jwk.JsonWebKey;
+import org.apache.cxf.rs.security.jose.jwk.JsonWebKeys;
+import org.apache.cxf.rs.security.jose.jwk.PublicKeyUse;
+import org.apache.cxf.rs.security.jose.jws.JwsHeaders;
+import org.apache.cxf.rs.security.jose.jws.JwsSignatureVerifier;
+import org.apache.cxf.rs.security.jose.jws.JwsUtils;
+
+public class JwsJwksJwtAccessTokenValidator extends JwtAccessTokenValidator {
+
+    final Map<String, JwkHolder> jsonWebKeys = new ConcurrentHashMap<>();
+
+    private String jwksURL;
+
+    @Override
+    protected JwsSignatureVerifier getInitializedSignatureVerifier(JwsHeaders jwsHeaders) {
+        Objects.requireNonNull(jwsHeaders.getKeyId());
+        return jsonWebKeys.computeIfAbsent(jwsHeaders.getKeyId(), keyId -> updateJwk(keyId)).getJwsSignatureVerifier();
+    }
+
+    public void setJwksURL(String jwksURL) {
+        this.jwksURL = jwksURL;
+    }
+
+    @Override
+    public void setJwsVerifier(JwsSignatureVerifier theJwsVerifier) {
+        throw new IllegalArgumentException("Actual JwsSignatureVerifier will be populated from the JWK Set URL");
+    }
+
+    private JwkHolder updateJwk(String keyId) {
+        Objects.requireNonNull(jwksURL, "JWK Set URL must be specified");
+        JwkHolder jwkHolder = null;
+        final Set<String> kids = new HashSet<>();
+        for (JsonWebKey jwk : getJsonWebKeys().getKeys()) {
+            if (PublicKeyUse.ENCRYPT != jwk.getPublicKeyUse()) {
+                final String kid = jwk.getKeyId();
+                kids.add(kid);
+                final JwkHolder h = new JwkHolder(jwk);
+                if (keyId.equals(kid)) {
+                    jwkHolder = h;
+                } else {
+                    jsonWebKeys.putIfAbsent(kid, h);
 
 Review comment:
   added new jwk only; at L77 old keys removed
   this case covered in JwsJwksJwtAccessTokenValidatorTest

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[hidden email]


With regards,
Apache Git Services
Reply | Threaded
Open this post in threaded view
|

[GitHub] [cxf] amarkevich commented on a change in pull request #652: CXF-8243 JwtAccessTokenValidator using the JWK Set URL

GitBox
In reply to this post by GitBox
amarkevich commented on a change in pull request #652: CXF-8243 JwtAccessTokenValidator using the JWK Set URL
URL: https://github.com/apache/cxf/pull/652#discussion_r395543255
 
 

 ##########
 File path: systests/rs-security/src/test/java/org/apache/cxf/systest/jaxrs/security/oidc/filters/OIDCFiltersTest.java
 ##########
 @@ -111,45 +101,6 @@ public void testClientCodeRequestFilter() throws Exception {
         assertEquals(returnedBook.getId(), 123L);
     }
 
-    @org.junit.Test
 
 Review comment:
   Initially this test was introduced exactly for AT signature validation using JWKS but its more complex to configure and do not support key rotation

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[hidden email]


With regards,
Apache Git Services
Reply | Threaded
Open this post in threaded view
|

[GitHub] [cxf] amarkevich merged pull request #652: CXF-8243 JwtAccessTokenValidator using the JWK Set URL

GitBox
In reply to this post by GitBox
amarkevich merged pull request #652: CXF-8243 JwtAccessTokenValidator using the JWK Set URL
URL: https://github.com/apache/cxf/pull/652
 
 
   

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[hidden email]


With regards,
Apache Git Services