You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by jl...@apache.org on 2018/12/10 14:47:34 UTC

[31/38] tomee git commit: Attempting to lazily load the keys

Attempting to lazily load the keys


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/e8d3b813
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/e8d3b813
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/e8d3b813

Branch: refs/heads/master
Commit: e8d3b8132fe0eb242d38420d67739898cd8da151
Parents: c2e9b70
Author: Jonathan Gallimore <jo...@jrg.me.uk>
Authored: Mon Nov 26 21:46:44 2018 +0000
Committer: Roberto Cortez <ra...@yahoo.com>
Committed: Fri Dec 7 18:13:05 2018 +0000

----------------------------------------------------------------------
 .../config/ConfigurableJWTAuthContextInfo.java  |  7 +--
 .../tomee/microprofile/jwt/config/Lazy.java     | 54 ++++++++++++++++++++
 pom.xml                                         |  2 +-
 .../jwt/src/test/resources/arquillian.xml       |  2 +-
 4 files changed, 60 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/e8d3b813/mp-jwt/src/main/java/org/apache/tomee/microprofile/jwt/config/ConfigurableJWTAuthContextInfo.java
----------------------------------------------------------------------
diff --git a/mp-jwt/src/main/java/org/apache/tomee/microprofile/jwt/config/ConfigurableJWTAuthContextInfo.java b/mp-jwt/src/main/java/org/apache/tomee/microprofile/jwt/config/ConfigurableJWTAuthContextInfo.java
index 5d41b5e..59decad 100644
--- a/mp-jwt/src/main/java/org/apache/tomee/microprofile/jwt/config/ConfigurableJWTAuthContextInfo.java
+++ b/mp-jwt/src/main/java/org/apache/tomee/microprofile/jwt/config/ConfigurableJWTAuthContextInfo.java
@@ -71,14 +71,15 @@ public class ConfigurableJWTAuthContextInfo {
     @Inject
     private Config config;
 
-    private JWTAuthContextInfo jwtAuthContextInfo;
+    private Supplier<JWTAuthContextInfo> jwtAuthContextInfo;
 
     public void init(@Observes @Initialized(ApplicationScoped.class) ServletContext context) {
-        this.jwtAuthContextInfo = createJWTAuthContextInfo();
+        // load the key set once, lazily
+        this.jwtAuthContextInfo = new Lazy<>(() -> createJWTAuthContextInfo());
     }
 
     public Optional<JWTAuthContextInfo> getJWTAuthContextInfo() {
-        return Optional.ofNullable(jwtAuthContextInfo);
+        return Optional.ofNullable(jwtAuthContextInfo.get());
     }
 
     private Optional<String> getVerifierPublicKey() {

http://git-wip-us.apache.org/repos/asf/tomee/blob/e8d3b813/mp-jwt/src/main/java/org/apache/tomee/microprofile/jwt/config/Lazy.java
----------------------------------------------------------------------
diff --git a/mp-jwt/src/main/java/org/apache/tomee/microprofile/jwt/config/Lazy.java b/mp-jwt/src/main/java/org/apache/tomee/microprofile/jwt/config/Lazy.java
new file mode 100644
index 0000000..2267fe8
--- /dev/null
+++ b/mp-jwt/src/main/java/org/apache/tomee/microprofile/jwt/config/Lazy.java
@@ -0,0 +1,54 @@
+/*
+ *  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.tomee.microprofile.jwt.config;
+
+import org.apache.bval.util.Validate;
+
+import java.util.function.Supplier;
+
+public class Lazy<T> implements Supplier<T> {
+    private T value;
+    private volatile Supplier<T> init;
+
+    public Lazy(Supplier<T> init) {
+        reset(init);
+    }
+
+    public Lazy<T> reset(Supplier<T> init) {
+        this.init = Validate.notNull(init);
+        return this;
+    }
+
+    public synchronized Lazy<T> reset(T value) {
+        this.value = value;
+        this.init = null;
+        return this;
+    }
+
+    @Override
+    public T get() {
+        if (init != null) {
+            synchronized (this) {
+                if (init != null) {
+                    value = init.get();
+                    init = null;
+                }
+            }
+        }
+        return value;
+    }
+}

http://git-wip-us.apache.org/repos/asf/tomee/blob/e8d3b813/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index a433b69..a604001 100644
--- a/pom.xml
+++ b/pom.xml
@@ -200,7 +200,7 @@
     <microprofile.version>2.0</microprofile.version>
     <microprofile.config.version>1.3</microprofile.config.version>
     <microprofile.config.impl.version>1.2</microprofile.config.impl.version>
-    <microprofile.jwt.version>1.1</microprofile.jwt.version>
+    <microprofile.jwt.version>1.1.1</microprofile.jwt.version>
     <microprofile.jwt.impl.version>${project.version}</microprofile.jwt.impl.version>
     <!-- 1.1 Implementation not started yet -->
     <microprofile.fault-tolerance.version>1.0</microprofile.fault-tolerance.version>

http://git-wip-us.apache.org/repos/asf/tomee/blob/e8d3b813/tck/microprofile-tck/jwt/src/test/resources/arquillian.xml
----------------------------------------------------------------------
diff --git a/tck/microprofile-tck/jwt/src/test/resources/arquillian.xml b/tck/microprofile-tck/jwt/src/test/resources/arquillian.xml
index ec0be8a..3243a7c 100644
--- a/tck/microprofile-tck/jwt/src/test/resources/arquillian.xml
+++ b/tck/microprofile-tck/jwt/src/test/resources/arquillian.xml
@@ -24,7 +24,7 @@
 <container qualifier="tomee-remote" default="true">
   <configuration>
     <property name="debug">false</property>
-    <property name="httpPort">-1</property>
+    <property name="httpPort">8080</property>
     <property name="ajpPort">-1</property>
     <property name="stopPort">-1</property>
     <property name="classifier">microprofile</property>