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:32:14 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 665eb259f -> 51db79ca7


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/51db79ca
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/51db79ca
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/51db79ca

Branch: refs/heads/master
Commit: 51db79ca7bd2c703a4dbbd42d7761c97af3bad84
Parents: 665eb25
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:27:03 2014 +0200

----------------------------------------------------------------------
 .../cxf/sts/claims/mapper/JexlClaimsMapper.java | 29 +++++++++++++++-----
 .../sts/claims/mapper/JexlClaimsMapperTest.java |  4 +--
 .../claims/mapper/JexlIssueSamlClaimsTest.java  |  2 +-
 3 files changed, 25 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/51db79ca/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 9226453..47a97d0 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.ClaimsMapper;
 import org.apache.cxf.sts.claims.ClaimsParameters;
@@ -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/51db79ca/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 a36486e..e4cd5ae 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
@@ -48,9 +48,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);

http://git-wip-us.apache.org/repos/asf/cxf/blob/51db79ca/services/sts/sts-core/src/test/java/org/apache/cxf/sts/claims/mapper/JexlIssueSamlClaimsTest.java
----------------------------------------------------------------------
diff --git a/services/sts/sts-core/src/test/java/org/apache/cxf/sts/claims/mapper/JexlIssueSamlClaimsTest.java
b/services/sts/sts-core/src/test/java/org/apache/cxf/sts/claims/mapper/JexlIssueSamlClaimsTest.java
index 159fb72..50cb9fd 100644
--- a/services/sts/sts-core/src/test/java/org/apache/cxf/sts/claims/mapper/JexlIssueSamlClaimsTest.java
+++ b/services/sts/sts-core/src/test/java/org/apache/cxf/sts/claims/mapper/JexlIssueSamlClaimsTest.java
@@ -257,7 +257,7 @@ public class JexlIssueSamlClaimsTest extends org.junit.Assert {
         Relationship rs = new Relationship();
         JexlClaimsMapper claimsMapper = new JexlClaimsMapper();
         try {
-            claimsMapper.setScript("src/test/resources/jexlIssueSamlClaimsTest.script");
+            claimsMapper.setScript("jexlIssueSamlClaimsTest.script");
         } catch (IOException e) {
             fail(e.getMessage());
         }


Mime
View raw message