ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From voze...@apache.org
Subject [08/11] ignite git commit: IGNITE-3202: Test for kerberos name mapper.
Date Mon, 30 May 2016 16:05:18 GMT
IGNITE-3202: Test for kerberos name mapper.


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

Branch: refs/heads/ignite-3202
Commit: 23948313f498b9caba23c3c6b7b7f14186a76dcc
Parents: fca684d
Author: vozerov-gridgain <vozerov@gridgain.com>
Authored: Mon May 30 16:48:04 2016 +0300
Committer: vozerov-gridgain <vozerov@gridgain.com>
Committed: Mon May 30 16:48:04 2016 +0300

----------------------------------------------------------------------
 .../hadoop/util/ChainedUserNameMapper.java      |  94 +++++++++++++++++
 .../hadoop/util/KerberosUserNameMapper.java     |   6 +-
 .../util/BasicUserNameMapperSelfTest.java       |   2 +-
 .../util/KerberosUserNameMapperSelfTest.java    | 101 +++++++++++++++++++
 .../testsuites/IgniteHadoopTestSuite.java       |   3 +-
 5 files changed, 201 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/23948313/modules/hadoop/src/main/java/org/apache/ignite/hadoop/util/ChainedUserNameMapper.java
----------------------------------------------------------------------
diff --git a/modules/hadoop/src/main/java/org/apache/ignite/hadoop/util/ChainedUserNameMapper.java
b/modules/hadoop/src/main/java/org/apache/ignite/hadoop/util/ChainedUserNameMapper.java
new file mode 100644
index 0000000..7635e25
--- /dev/null
+++ b/modules/hadoop/src/main/java/org/apache/ignite/hadoop/util/ChainedUserNameMapper.java
@@ -0,0 +1,94 @@
+/*
+ * 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.ignite.hadoop.util;
+
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.lifecycle.LifecycleAware;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.Arrays;
+
+/**
+ * Chained user name mapper. Delegate name conversion to child mappers.
+ */
+public class ChainedUserNameMapper implements UserNameMapper, LifecycleAware {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** Child mappers. */
+    private UserNameMapper[] mappers;
+
+    /** {@inheritDoc} */
+    @Nullable @Override public String map(String name) {
+        for (UserNameMapper mapper : mappers)
+            name = mapper.map(name);
+
+        return name;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void start() throws IgniteException {
+        if (mappers == null)
+            throw new IgniteException("Mappers cannot be null.");
+
+        for (int i = 0; i < mappers.length; i++) {
+            if (mappers[i] == null)
+                throw new IgniteException("Mapper cannot be null [index=" + i + ']');
+        }
+
+        for (UserNameMapper mapper : mappers) {
+            if (mapper instanceof LifecycleAware)
+                ((LifecycleAware)mapper).start();
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public void stop() throws IgniteException {
+        assert mappers != null;
+
+        for (UserNameMapper mapper : mappers) {
+            if (mapper instanceof LifecycleAware)
+                ((LifecycleAware)mapper).stop();
+        }
+    }
+
+    /**
+     * Get child mappers.
+     *
+     * @return Child mappers.
+     */
+    public UserNameMapper[] getMappers() {
+        return mappers;
+    }
+
+    /**
+     * Set child mappers.
+     *
+     * @param mappers Child mappers.
+     */
+    public void setMappers(UserNameMapper... mappers) {
+        this.mappers = mappers;
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(ChainedUserNameMapper.class, this,
+            "mappers", mappers != null ? Arrays.toString(mappers) : null);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/23948313/modules/hadoop/src/main/java/org/apache/ignite/hadoop/util/KerberosUserNameMapper.java
----------------------------------------------------------------------
diff --git a/modules/hadoop/src/main/java/org/apache/ignite/hadoop/util/KerberosUserNameMapper.java
b/modules/hadoop/src/main/java/org/apache/ignite/hadoop/util/KerberosUserNameMapper.java
index b250be8..433fb82 100644
--- a/modules/hadoop/src/main/java/org/apache/ignite/hadoop/util/KerberosUserNameMapper.java
+++ b/modules/hadoop/src/main/java/org/apache/ignite/hadoop/util/KerberosUserNameMapper.java
@@ -18,6 +18,7 @@
 package org.apache.ignite.hadoop.util;
 
 import org.apache.ignite.IgniteException;
+import org.apache.ignite.internal.processors.igfs.IgfsUtils;
 import org.apache.ignite.internal.util.typedef.F;
 import org.apache.ignite.internal.util.typedef.internal.S;
 import org.apache.ignite.lifecycle.LifecycleAware;
@@ -44,6 +45,8 @@ public class KerberosUserNameMapper implements UserNameMapper, LifecycleAware
{
     @Nullable @Override public String map(String name) {
         assert state != null;
 
+        name = IgfsUtils.fixUserName(name);
+
         switch (state) {
             case NAME:
                 return name;
@@ -63,9 +66,6 @@ public class KerberosUserNameMapper implements UserNameMapper, LifecycleAware
{
 
     /** {@inheritDoc} */
     @Override public void start() throws IgniteException {
-        if (realm.startsWith("@"))
-            throw new IgniteException("Realm should not start with '@' character: " + realm);
-
         if (!F.isEmpty(instance))
             state = F.isEmpty(realm) ? State.NAME_INSTANCE : State.NAME_INSTANCE_REALM;
         else

http://git-wip-us.apache.org/repos/asf/ignite/blob/23948313/modules/hadoop/src/test/java/org/apache/ignite/hadoop/util/BasicUserNameMapperSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/hadoop/src/test/java/org/apache/ignite/hadoop/util/BasicUserNameMapperSelfTest.java
b/modules/hadoop/src/test/java/org/apache/ignite/hadoop/util/BasicUserNameMapperSelfTest.java
index 6e257b0..54b03f9 100644
--- a/modules/hadoop/src/test/java/org/apache/ignite/hadoop/util/BasicUserNameMapperSelfTest.java
+++ b/modules/hadoop/src/test/java/org/apache/ignite/hadoop/util/BasicUserNameMapperSelfTest.java
@@ -17,8 +17,8 @@
 
 package org.apache.ignite.hadoop.util;
 
-import org.apache.avro.reflect.Nullable;
 import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.jetbrains.annotations.Nullable;
 
 import java.util.HashMap;
 import java.util.Map;

http://git-wip-us.apache.org/repos/asf/ignite/blob/23948313/modules/hadoop/src/test/java/org/apache/ignite/hadoop/util/KerberosUserNameMapperSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/hadoop/src/test/java/org/apache/ignite/hadoop/util/KerberosUserNameMapperSelfTest.java
b/modules/hadoop/src/test/java/org/apache/ignite/hadoop/util/KerberosUserNameMapperSelfTest.java
new file mode 100644
index 0000000..fbd8975
--- /dev/null
+++ b/modules/hadoop/src/test/java/org/apache/ignite/hadoop/util/KerberosUserNameMapperSelfTest.java
@@ -0,0 +1,101 @@
+/*
+ * 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.ignite.hadoop.util;
+
+import org.apache.ignite.internal.processors.igfs.IgfsUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.Map;
+
+/**
+ * Tests for Kerberos name mapper.
+ */
+public class KerberosUserNameMapperSelfTest extends GridCommonAbstractTest {
+    /** Test instance. */
+    private static final String INSTANCE = "test_instance";
+
+    /** Test realm. */
+    private static final String REALM = "test_realm";
+
+    /**
+     * Test mapper without instance and realm components.
+     *
+     * @throws Exception If failed.
+     */
+    public void testMapper() throws Exception {
+        KerberosUserNameMapper mapper = create(null, null);
+
+        assertEquals(IgfsUtils.fixUserName(null), mapper.map(null));
+        assertEquals("test", mapper.map("test"));
+    }
+
+    /**
+     * Test mapper with instance component.
+     *
+     * @throws Exception If failed.
+     */
+    public void testMapperInstance() throws Exception {
+        KerberosUserNameMapper mapper = create(INSTANCE, null);
+
+        assertEquals(IgfsUtils.fixUserName(null) + "/" + INSTANCE, mapper.map(null));
+        assertEquals("test" + "/" + INSTANCE, mapper.map("test"));
+    }
+
+    /**
+     * Test mapper with realm.
+     *
+     * @throws Exception If failed.
+     */
+    public void testMapperRealm() throws Exception {
+        KerberosUserNameMapper mapper = create(null, REALM);
+
+        assertEquals(IgfsUtils.fixUserName(null) + "@" + REALM, mapper.map(null));
+        assertEquals("test" + "@" + REALM, mapper.map("test"));
+    }
+
+    /**
+     * Test mapper with instance and realm components.
+     *
+     * @throws Exception If failed.
+     */
+    public void testMapperInstanceAndRealm() throws Exception {
+        KerberosUserNameMapper mapper = create(INSTANCE, REALM);
+
+        assertEquals(IgfsUtils.fixUserName(null) + "/" + INSTANCE + "@" + REALM, mapper.map(null));
+        assertEquals("test" + "/" + INSTANCE + "@" + REALM, mapper.map("test"));
+    }
+
+    /**
+     * Create mapper.
+     *
+     * @param instance Instance.
+     * @param realm Realm.
+     * @return Mapper.
+     */
+    private KerberosUserNameMapper create(@Nullable String instance, @Nullable String realm)
{
+        KerberosUserNameMapper mapper = new KerberosUserNameMapper();
+
+        mapper.setInstance(instance);
+        mapper.setRealm(realm);
+
+        mapper.start();
+
+        return mapper;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/23948313/modules/hadoop/src/test/java/org/apache/ignite/testsuites/IgniteHadoopTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/hadoop/src/test/java/org/apache/ignite/testsuites/IgniteHadoopTestSuite.java
b/modules/hadoop/src/test/java/org/apache/ignite/testsuites/IgniteHadoopTestSuite.java
index 9edf71f..f7c5691 100644
--- a/modules/hadoop/src/test/java/org/apache/ignite/testsuites/IgniteHadoopTestSuite.java
+++ b/modules/hadoop/src/test/java/org/apache/ignite/testsuites/IgniteHadoopTestSuite.java
@@ -26,8 +26,8 @@ import org.apache.ignite.client.hadoop.HadoopClientProtocolEmbeddedSelfTest;
 import org.apache.ignite.client.hadoop.HadoopClientProtocolSelfTest;
 import org.apache.ignite.hadoop.cache.HadoopTxConfigCacheTest;
 import org.apache.ignite.hadoop.fs.KerberosHadoopFileSystemFactorySelfTest;
-import org.apache.ignite.hadoop.util.BasicUserNameMapper;
 import org.apache.ignite.hadoop.util.BasicUserNameMapperSelfTest;
+import org.apache.ignite.hadoop.util.KerberosUserNameMapper;
 import org.apache.ignite.igfs.Hadoop1OverIgfsDualAsyncTest;
 import org.apache.ignite.igfs.Hadoop1OverIgfsDualSyncTest;
 import org.apache.ignite.igfs.HadoopFIleSystemFactorySelfTest;
@@ -107,6 +107,7 @@ public class IgniteHadoopTestSuite extends TestSuite {
         TestSuite suite = new TestSuite("Ignite Hadoop MR Test Suite");
 
         suite.addTest(new TestSuite(ldr.loadClass(BasicUserNameMapperSelfTest.class.getName())));
+        suite.addTest(new TestSuite(ldr.loadClass(KerberosUserNameMapper.class.getName())));
 
         suite.addTest(new TestSuite(ldr.loadClass(KerberosHadoopFileSystemFactorySelfTest.class.getName())));
 


Mime
View raw message