openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1829753 - /openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/openwebbeans/MeecrowaveSecurityService.java
Date Sat, 21 Apr 2018 21:40:25 GMT
Author: rmannibucau
Date: Sat Apr 21 21:40:25 2018
New Revision: 1829753

URL: http://svn.apache.org/viewvc?rev=1829753&view=rev
Log:
extension point for our security service to ensure cdi extensions can extend it without any
coupling

Modified:
    openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/openwebbeans/MeecrowaveSecurityService.java

Modified: openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/openwebbeans/MeecrowaveSecurityService.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/openwebbeans/MeecrowaveSecurityService.java?rev=1829753&r1=1829752&r2=1829753&view=diff
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/openwebbeans/MeecrowaveSecurityService.java
(original)
+++ openwebbeans/meecrowave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/openwebbeans/MeecrowaveSecurityService.java
Sat Apr 21 21:40:25 2018
@@ -18,17 +18,26 @@
  */
 package org.apache.meecrowave.openwebbeans;
 
-import org.apache.webbeans.corespi.security.SimpleSecurityService;
+import java.security.Principal;
+import java.util.function.Supplier;
 
 import javax.enterprise.inject.spi.BeanManager;
 import javax.enterprise.inject.spi.CDI;
 import javax.servlet.http.HttpServletRequest;
-import java.security.Principal;
+
+import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.corespi.security.SimpleSecurityService;
 
 public class MeecrowaveSecurityService extends SimpleSecurityService {
+    private final boolean useWrapper;
+
+    public MeecrowaveSecurityService(final WebBeansContext context) {
+        useWrapper = "true".equalsIgnoreCase(context.getOpenWebBeansConfiguration()
+                .getProperty("org.apache.webbeans.component.PrincipalBean.proxy", "true"));
+    }
     @Override // reason of that class
     public Principal getCurrentPrincipal() {
-        return new MeecrowavePrincipal();
+        return useWrapper ? new MeecrowavePrincipal() : getUserPrincipal();
     }
 
     // ensure it is contextual
@@ -39,12 +48,20 @@ public class MeecrowaveSecurityService e
         }
 
         private Principal unwrap() {
-            final BeanManager beanManager = CDI.current().getBeanManager();
-            return HttpServletRequest.class.cast(
-                    beanManager.getReference(
-                            beanManager.resolve(beanManager.getBeans(HttpServletRequest.class)),
HttpServletRequest.class,
-                            beanManager.createCreationalContext(null)))
-                    .getUserPrincipal();
+            return getUserPrincipal();
+        }
+    }
+
+    private static Principal getUserPrincipal() {
+        final BeanManager beanManager = CDI.current().getBeanManager();
+        final HttpServletRequest request = HttpServletRequest.class.cast(
+                beanManager.getReference(
+                        beanManager.resolve(beanManager.getBeans(HttpServletRequest.class)),
HttpServletRequest.class,
+                        beanManager.createCreationalContext(null)));
+        final Object supplier = request.getAttribute(Principal.class.getName() + ".supplier");
+        if (supplier != null) {
+            return ((Supplier<Principal>) supplier).get();
         }
+        return request.getUserPrincipal();
     }
 }



Mime
View raw message