knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lmc...@apache.org
Subject [1/2] Another iteration of work toward KNOX-37 in the investigation of OAuth/OpenID for identity federation. Also fixed issues with provider resolution by name and various refactorings.
Date Wed, 10 Apr 2013 15:18:01 GMT
Updated Branches:
  refs/heads/master eddbe5457 -> 61ca72e10


http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/61ca72e1/gateway-spi/src/main/java/org/apache/hadoop/gateway/topology/Topology.java
----------------------------------------------------------------------
diff --git a/gateway-spi/src/main/java/org/apache/hadoop/gateway/topology/Topology.java b/gateway-spi/src/main/java/org/apache/hadoop/gateway/topology/Topology.java
index 4c68ae3..2fb2595 100644
--- a/gateway-spi/src/main/java/org/apache/hadoop/gateway/topology/Topology.java
+++ b/gateway-spi/src/main/java/org/apache/hadoop/gateway/topology/Topology.java
@@ -62,8 +62,13 @@ public class Topology {
   public Provider getProvider( String role, String name ) {
     Provider provider = null;
     Map<String,Provider> nameMap = providerMap.get( role );
-    if( nameMap != null ) {
-      provider = nameMap.get( name );
+    if( nameMap != null) { 
+      if( name != null ) {
+        provider = nameMap.get( name );
+      }
+      else {
+        provider = (Provider) nameMap.values().toArray()[0];
+      }
     }
     return provider;
   }

http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/61ca72e1/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayBasicFuncTest.java
----------------------------------------------------------------------
diff --git a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayBasicFuncTest.java
b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayBasicFuncTest.java
index 7493861..21d7429 100644
--- a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayBasicFuncTest.java
+++ b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayBasicFuncTest.java
@@ -119,8 +119,12 @@ public class GatewayBasicFuncTest {
                 .addTag( "value" ).addText( "simple" ).gotoParent()
               .addTag( "param" )
                 .addTag( "name" ).addText( "urls./**" )
-                .addTag( "value" ).addText( "authcBasic" ).gotoParent()
-        .gotoRoot()
+                .addTag( "value" ).addText( "authcBasic" ).gotoParent().gotoParent()
+            .addTag( "provider" )
+              .addTag( "role" ).addText( "identity-assertion" )
+              .addTag( "enabled" ).addText( "true" )
+              .addTag( "name" ).addText( "Pseudo" ).gotoParent()
+          .gotoRoot()
           .addTag( "service" )
             .addTag( "role" ).addText( "NAMENODE" )
             .addTag( "url" ).addText( driver.getRealUrl( "NAMENODE" ) ).gotoParent()
@@ -604,7 +608,7 @@ public class GatewayBasicFuncTest {
 
     /* Submit the job
     curl -d user.name=hdfs -d jar=wordcount/hadoop-examples.jar -d class=org.apache.org.apache.hadoop.examples.WordCount
-d arg=wordcount/input -d arg=wordcount/output 'http://localhost:8888/org.apache.org.apache.hadoop.gateway/cluster/templeton/api/v1/mapreduce/jar'
-    {"id":"job_201210301335_0059"}
+    {"id":"job_201210301335_0059"}
     */
     String job = driver.submitJava(
         user, pass,

http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/61ca72e1/gateway-util-common/pom.xml
----------------------------------------------------------------------
diff --git a/gateway-util-common/pom.xml b/gateway-util-common/pom.xml
index 4decd49..cda8702 100644
--- a/gateway-util-common/pom.xml
+++ b/gateway-util-common/pom.xml
@@ -48,6 +48,10 @@
     </build>
 
     <dependencies>
+				<dependency>
+					<groupId>com.fasterxml.jackson.core</groupId>
+					<artifactId>jackson-databind</artifactId>
+				</dependency>
 
         <!-- ********** ********** ********** ********** ********** ********** -->
         <!-- ********** Test Dependencies                           ********** -->

http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/61ca72e1/gateway-util-common/src/main/java/org/apache/hadoop/gateway/util/JsonUtils.java
----------------------------------------------------------------------
diff --git a/gateway-util-common/src/main/java/org/apache/hadoop/gateway/util/JsonUtils.java
b/gateway-util-common/src/main/java/org/apache/hadoop/gateway/util/JsonUtils.java
new file mode 100644
index 0000000..82b4478
--- /dev/null
+++ b/gateway-util-common/src/main/java/org/apache/hadoop/gateway/util/JsonUtils.java
@@ -0,0 +1,72 @@
+/**
+ * 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.hadoop.gateway.util;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import com.fasterxml.jackson.core.JsonFactory;
+import com.fasterxml.jackson.core.JsonGenerationException;
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+
+public class JsonUtils {
+  
+  public static String renderAsJsonString(Map<String, Object> map) {
+    String json = null;
+    ObjectMapper mapper = new ObjectMapper();
+    
+    try {
+      // write JSON to a file
+      json = mapper.writeValueAsString((Object)map);
+   
+    } catch (JsonGenerationException e) {
+      e.printStackTrace();
+    } catch (JsonMappingException e) {
+      e.printStackTrace();
+    } catch (IOException e) {
+      e.printStackTrace();
+    }
+    return json;
+  }
+  
+  public static Map<String, String> getMapFromJsonString(String json) {
+    Map<String, String> map = null;
+    JsonFactory factory = new JsonFactory(); 
+    ObjectMapper mapper = new ObjectMapper(factory); 
+    TypeReference<HashMap<String,String>> typeRef 
+          = new TypeReference<HashMap<String,String>>() {}; 
+    try {
+      map = mapper.readValue(json, typeRef);
+    } catch (JsonParseException e) {
+      // TODO Auto-generated catch block
+      e.printStackTrace();
+    } catch (JsonMappingException e) {
+      // TODO Auto-generated catch block
+      e.printStackTrace();
+    } catch (IOException e) {
+      // TODO Auto-generated catch block
+      e.printStackTrace();
+    } 
+    return map;
+  }   
+}

http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/61ca72e1/gateway-util-common/src/test/java/org/apache/hadoop/gateway/util/JsonUtilsTest.java
----------------------------------------------------------------------
diff --git a/gateway-util-common/src/test/java/org/apache/hadoop/gateway/util/JsonUtilsTest.java
b/gateway-util-common/src/test/java/org/apache/hadoop/gateway/util/JsonUtilsTest.java
new file mode 100644
index 0000000..294f5a4
--- /dev/null
+++ b/gateway-util-common/src/test/java/org/apache/hadoop/gateway/util/JsonUtilsTest.java
@@ -0,0 +1,49 @@
+/**
+ * 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.hadoop.gateway.util;
+
+import java.util.HashMap;
+
+import org.junit.Test;
+
+import junit.framework.TestCase;
+
+public class JsonUtilsTest extends TestCase {
+  String test = '{' + "\"expires_in\":\"1364487943100\",\"token_type\":\"Bearer\",\"access_token\":\"ksdfh3489tyiodhfjk\""
+ '}';
+  
+  @Test
+  public void testRenderAsJson() throws Exception {
+    HashMap map = new HashMap();
+    map.put("access_token", "ksdfh3489tyiodhfjk");
+    map.put("token_type", "Bearer");
+    map.put("expires_in", "1364487943100");
+    
+    String result = JsonUtils.renderAsJsonString(map);
+//    System.out.println(result);
+    assertEquals(test, result);
+  }
+  
+  @Test
+  public void testGetMapFromString() throws Exception {
+    HashMap map = (HashMap) JsonUtils.getMapFromJsonString(test);
+    assertEquals("ksdfh3489tyiodhfjk", map.get("access_token"));
+    assertEquals("Bearer", map.get("token_type"));
+    assertEquals("1364487943100", map.get("expires_in"));
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/61ca72e1/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 0503056..0d8cac9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -141,8 +141,13 @@
                     <excludeSubProjects>false</excludeSubProjects>
                     <excludes>
                         <exclude>.git/**</exclude>
+                        <exclude>.gitignore/**</exclude>
                         <exclude>.svn/**</exclude>
                         <exclude>.idea/**</exclude>
+                        <exclude>**/.gitignore/**</exclude>
+												<exclude>**/.project/**</exclude>
+												<exclude>**/.settings/**</exclude>
+												<exclude>**/.classpath/**</exclude>
                         <exclude>src/stage.txt</exclude>
                         <exclude>src/vote.txt</exclude>
                         <exclude>**/*.iml</exclude>
@@ -506,7 +511,7 @@
                     </exclusion>
                     <exclusion>
                         <groupId>org.codehaus.jackson</groupId>
-                        <artifactId>ackson-mapper-asl</artifactId>
+                        <artifactId>jackson-mapper-asl</artifactId>
                     </exclusion>
                     <exclusion>
                         <groupId>net.java.dev.jets3t</groupId>
@@ -535,6 +540,12 @@
                 </exclusions>
             </dependency>
 
+						<dependency>
+							<groupId>com.fasterxml.jackson.core</groupId>
+							<artifactId>jackson-databind</artifactId>
+							<version>2.1.4</version>
+						</dependency>
+
             <dependency>
                 <groupId>org.apache.httpcomponents</groupId>
                 <artifactId>httpclient</artifactId>


Mime
View raw message