cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbernha...@apache.org
Subject git commit: Improving JexlClaimsMapper: * Making script resource location more flexible * Adding settter vor JexlEnginge to allow custom engine configuration
Date Mon, 29 Sep 2014 08:45:26 GMT
Repository: cxf
Updated Branches:
  refs/heads/2.7.x-fixes 35d6c3d9f -> 231a17a8b


Improving JexlClaimsMapper:
 * Making script resource location more flexible
 * Adding settter vor JexlEnginge to allow custom engine configuration


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

Branch: refs/heads/2.7.x-fixes
Commit: 231a17a8b3c10b9312ccf795238e27469a69653a
Parents: 35d6c3d
Author: Jan Bernhardt <jbernhardt@talend.com>
Authored: Mon Sep 29 10:27:03 2014 +0200
Committer: Jan Bernhardt <jbernhardt@talend.com>
Committed: Mon Sep 29 10:41:51 2014 +0200

----------------------------------------------------------------------
 .../cxf/sts/claims/mapper/JexlClaimsMapper.java | 29 +++++++++++++++-----
 .../sts/claims/mapper/JexlClaimsMapperTest.java |  4 +--
 2 files changed, 24 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/231a17a8/services/sts/sts-core/src/main/java/org/apache/cxf/sts/claims/mapper/JexlClaimsMapper.java
----------------------------------------------------------------------
diff --git a/services/sts/sts-core/src/main/java/org/apache/cxf/sts/claims/mapper/JexlClaimsMapper.java
b/services/sts/sts-core/src/main/java/org/apache/cxf/sts/claims/mapper/JexlClaimsMapper.java
index 3538e4e..d741534 100644
--- a/services/sts/sts-core/src/main/java/org/apache/cxf/sts/claims/mapper/JexlClaimsMapper.java
+++ b/services/sts/sts-core/src/main/java/org/apache/cxf/sts/claims/mapper/JexlClaimsMapper.java
@@ -21,6 +21,7 @@ package org.apache.cxf.sts.claims.mapper;
 
 import java.io.File;
 import java.io.IOException;
+import java.net.URL;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.logging.Logger;
@@ -29,6 +30,7 @@ import org.apache.commons.jexl2.JexlContext;
 import org.apache.commons.jexl2.JexlEngine;
 import org.apache.commons.jexl2.MapContext;
 import org.apache.commons.jexl2.Script;
+import org.apache.cxf.common.classloader.ClassLoaderUtils;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.sts.claims.ClaimCollection;
 import org.apache.cxf.sts.claims.ClaimsMapper;
@@ -38,19 +40,19 @@ public class JexlClaimsMapper implements ClaimsMapper {
 
     private static final Logger LOG = LogUtils.getL7dLogger(JexlClaimsMapper.class);
 
-    JexlEngine jexl = new JexlEngine();
+    private JexlEngine jexlEngine = new JexlEngine();
     private Script script;
 
     public JexlClaimsMapper() {
         // jexl.setCache(512);
         // jexl.setLenient(false);
-        jexl.setSilent(false);
-        
+        jexlEngine.setSilent(false);
+
         Map<String, Object> functions = new HashMap<String, Object>();
         functions.put("claims", new ClaimUtils());
-        jexl.setFunctions(functions);
+        jexlEngine.setFunctions(functions);
     }
-    
+
     public JexlClaimsMapper(String script) throws IOException {
         this();
 
@@ -86,8 +88,21 @@ public class JexlClaimsMapper implements ClaimsMapper {
         this.script = script;
     }
 
-    public void setScript(String scriptPath) throws IOException {
-        this.script = jexl.createScript(new File(scriptPath));
+    public void setScript(String scriptLocation) throws IOException {
+        URL resource = ClassLoaderUtils.getResource(scriptLocation, this.getClass());
+        if (resource == null) {
+            throw new IllegalArgumentException("Script resource not found!");
+        }
+        
+        this.script = jexlEngine.createScript(new File(resource.getPath()));
+    }
+
+    public JexlEngine getJexlEngine() {
+        return jexlEngine;
+    }
+
+    public void setJexlEngine(JexlEngine jexl) {
+        this.jexlEngine = jexl;
     }
 
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/231a17a8/services/sts/sts-core/src/test/java/org/apache/cxf/sts/claims/mapper/JexlClaimsMapperTest.java
----------------------------------------------------------------------
diff --git a/services/sts/sts-core/src/test/java/org/apache/cxf/sts/claims/mapper/JexlClaimsMapperTest.java
b/services/sts/sts-core/src/test/java/org/apache/cxf/sts/claims/mapper/JexlClaimsMapperTest.java
index ebe7fbb..c46fb85 100644
--- a/services/sts/sts-core/src/test/java/org/apache/cxf/sts/claims/mapper/JexlClaimsMapperTest.java
+++ b/services/sts/sts-core/src/test/java/org/apache/cxf/sts/claims/mapper/JexlClaimsMapperTest.java
@@ -47,9 +47,9 @@ public class JexlClaimsMapperTest extends org.junit.Assert {
     public static Collection<Object[]> data() {
         Object[][] data = new Object[][] {
             {
-                "src/test/resources/jexlClaimMappingsWithoutFunctions.script"
+                "jexlClaimMappingsWithoutFunctions.script"
             }, {
-                "src/test/resources/jexlClaimMappingsWithFunctions.script"
+                "jexlClaimMappingsWithFunctions.script"
             }
         };
         return Arrays.asList(data);


Mime
View raw message