tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jlmonte...@apache.org
Subject [tomee] branch master updated: Quick fixes for NPE TOMEE-2513 and TOMEE-2514
Date Thu, 02 May 2019 22:32:30 GMT
This is an automated email from the ASF dual-hosted git repository.

jlmonteiro pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomee.git


The following commit(s) were added to refs/heads/master by this push:
     new 9bdcd7a  Quick fixes for NPE TOMEE-2513 and TOMEE-2514
     new 5d1bc8e  Merge branch 'master' of https://gitbox.apache.org/repos/asf/tomee
9bdcd7a is described below

commit 9bdcd7ae5d2dcce204e62273f7610283d69f1e10
Author: Jean-Louis Monteiro <jeanouii@gmail.com>
AuthorDate: Fri May 3 00:31:50 2019 +0200

    Quick fixes for NPE TOMEE-2513 and TOMEE-2514
---
 .../org/apache/openejb/cdi/ManagedSecurityService.java |  6 +++++-
 .../apache/tomee/microprofile/jwt/cdi/ClaimBean.java   | 18 +++++++++++++-----
 2 files changed, 18 insertions(+), 6 deletions(-)

diff --git a/container/openejb-core/src/main/java/org/apache/openejb/cdi/ManagedSecurityService.java
b/container/openejb-core/src/main/java/org/apache/openejb/cdi/ManagedSecurityService.java
index c5aba9d..018cc7c 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/cdi/ManagedSecurityService.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/cdi/ManagedSecurityService.java
@@ -80,7 +80,11 @@ public class ManagedSecurityService implements org.apache.webbeans.spi.SecurityS
             proxy = Principal.class.cast(Proxy.newProxyInstance(loader, interfaceList.toArray(new
Class[0]), new InvocationHandler() {
                 @Override
                 public Object invoke(final Object proxy, final Method method, final Object[]
args) throws Throwable {
-                    return method.invoke(doGetPrincipal(), args);
+                    final Principal principal = doGetPrincipal();
+                    if (principal == null) {
+                        return null;
+                    }
+                    return method.invoke(principal, args);
                 }
             }));
         }
diff --git a/mp-jwt/src/main/java/org/apache/tomee/microprofile/jwt/cdi/ClaimBean.java b/mp-jwt/src/main/java/org/apache/tomee/microprofile/jwt/cdi/ClaimBean.java
index f2948f2..67d9067 100644
--- a/mp-jwt/src/main/java/org/apache/tomee/microprofile/jwt/cdi/ClaimBean.java
+++ b/mp-jwt/src/main/java/org/apache/tomee/microprofile/jwt/cdi/ClaimBean.java
@@ -16,6 +16,7 @@
  */
 package org.apache.tomee.microprofile.jwt.cdi;
 
+import org.apache.xbean.propertyeditor.PropertyEditorRegistry;
 import org.apache.xbean.propertyeditor.PropertyEditors;
 import org.eclipse.microprofile.jwt.Claim;
 import org.eclipse.microprofile.jwt.ClaimValue;
@@ -50,6 +51,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Optional;
 import java.util.Set;
+import java.util.logging.Level;
 import java.util.logging.Logger;
 
 @Vetoed
@@ -71,6 +73,7 @@ public class ClaimBean<T> implements Bean<T>, PassivationCapable
{
     private final Set<Type> types;
     private final String id;
     private final Class<? extends Annotation> scope;
+    private final PropertyEditorRegistry propertyEditorRegistry = new PropertyEditorRegistry();
 
     public ClaimBean(final BeanManager bm, final Type type) {
         this.bm = bm;
@@ -79,6 +82,7 @@ public class ClaimBean<T> implements Bean<T>, PassivationCapable
{
         rawType = getRawType(type);
         this.id = "ClaimBean_" + types;
         scope = Dependent.class;
+        propertyEditorRegistry.registerDefaults();
     }
 
     private Class getRawType(final Type type) {
@@ -245,13 +249,17 @@ public class ClaimBean<T> implements Bean<T>, PassivationCapable
{
             return (T) toJson(key);
 
         } else if (PropertyEditors.canConvert((Class<?>) ip.getType())) {
+            final Class<?> type = (Class<?>) ip.getType();
             try {
-                final Class<?> type = (Class<?>) ip.getType();
-                final String claimValue = getClaimValue(key).toString();
-                return (T) PropertyEditors.getValue(type, claimValue);
-            } catch (Exception e) {
-                logger.warning(e.getMessage());
+                final Object claimObject = getClaimValue(key);
+                if (claimObject == null) {
+                    return null;
+                }
+                return (T) propertyEditorRegistry.getValue(type, String.valueOf(claimObject));
+            } catch (final Exception e) {
+                logger.log(Level.WARNING, String.format("Cannot convert claim %s into type
%s", key, type), e);
             }
+
         } else {
             // handle Raw types
             return getClaimValue(key);


Mime
View raw message