Search in sources :

Example 6 with OozieCLI

use of org.apache.oozie.cli.OozieCLI in project oozie by apache.

the class TestOozieCLI method testSubmitDoAs.

public void testSubmitDoAs() throws Exception {
    setSystemProperty("oozie.authentication.simple.anonymous.allowed", "false");
    runTest(END_POINTS, SERVLET_CLASSES, IS_SECURITY_ENABLED, new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            String oozieUrl = getContextURL();
            Path appPath = new Path(getFsTestCaseDir(), "app");
            getFileSystem().mkdirs(appPath);
            getFileSystem().create(new Path(appPath, "workflow.xml")).close();
            String[] args = new String[] { "job", "-submit", "-oozie", oozieUrl, "-config", createConfigFile(appPath.toString()), "-doas", getTestUser2() };
            assertEquals(0, new OozieCLI().run(args));
            assertEquals("submit", MockDagEngineService.did);
            assertEquals(getTestUser2(), MockDagEngineService.user);
            return null;
        }
    });
}
Also used : Path(org.apache.hadoop.fs.Path) OozieCLI(org.apache.oozie.cli.OozieCLI)

Example 7 with OozieCLI

use of org.apache.oozie.cli.OozieCLI in project oozie by apache.

the class TestAuthFilterAuthOozieClient method testClientWithoutAnonymous.

public void testClientWithoutAnonymous() throws Exception {
    Configuration conf = new Configuration(false);
    conf.set("oozie.authentication.simple.anonymous.allowed", "false");
    runTest(new Callable<Void>() {

        public Void call() throws Exception {
            String oozieUrl = getContextURL();
            String[] args = new String[] { "admin", "-status", "-oozie", oozieUrl };
            assertEquals(0, new OozieCLI().run(args));
            return null;
        }
    }, conf);
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) OozieCLI(org.apache.oozie.cli.OozieCLI) AuthenticationException(org.apache.hadoop.security.authentication.client.AuthenticationException) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 8 with OozieCLI

use of org.apache.oozie.cli.OozieCLI in project oozie by apache.

the class TestAuthFilterAuthOozieClient method testClientAuthTokenCache.

public void testClientAuthTokenCache() throws Exception {
    Configuration conf = new Configuration(false);
    // However, Hadoop 2.7.0  (HADOOP-10670) also added a FileSignerSecretProvider, which we'll use if it exists
    try {
        if (Class.forName("org.apache.hadoop.security.authentication.util.FileSignerSecretProvider") != null) {
            String secretFile = getTestCaseConfDir() + "/auth-secret";
            conf.set("oozie.authentication.signature.secret.file", secretFile);
            FileWriter fw = null;
            try {
                fw = new FileWriter(secretFile);
                fw.write(SECRET);
            } finally {
                if (fw != null) {
                    fw.close();
                }
            }
        }
    } catch (ClassNotFoundException cnfe) {
    // ignore
    }
    conf.set("oozie.authentication.signature.secret", SECRET);
    conf.set("oozie.authentication.simple.anonymous.allowed", "false");
    // not using cache
    AuthOozieClient.AUTH_TOKEN_CACHE_FILE.delete();
    assertFalse(AuthOozieClient.AUTH_TOKEN_CACHE_FILE.exists());
    runTest(new Callable<Void>() {

        public Void call() throws Exception {
            String oozieUrl = getContextURL();
            String[] args = new String[] { "admin", "-status", "-oozie", oozieUrl };
            assertEquals(0, new OozieCLI().run(args));
            return null;
        }
    }, conf);
    assertFalse(AuthOozieClient.AUTH_TOKEN_CACHE_FILE.exists());
    // using cache
    setSystemProperty("oozie.auth.token.cache", "true");
    AuthOozieClient.AUTH_TOKEN_CACHE_FILE.delete();
    assertFalse(AuthOozieClient.AUTH_TOKEN_CACHE_FILE.exists());
    runTest(new Callable<Void>() {

        public Void call() throws Exception {
            String oozieUrl = getContextURL();
            String[] args = new String[] { "admin", "-status", "-oozie", oozieUrl };
            assertEquals(0, new OozieCLI().run(args));
            return null;
        }
    }, conf);
    assertTrue(AuthOozieClient.AUTH_TOKEN_CACHE_FILE.exists());
    String currentCache = IOUtils.getReaderAsString(new FileReader(AuthOozieClient.AUTH_TOKEN_CACHE_FILE), -1);
    // re-using cache
    setSystemProperty("oozie.auth.token.cache", "true");
    runTest(new Callable<Void>() {

        public Void call() throws Exception {
            String oozieUrl = getContextURL();
            String[] args = new String[] { "admin", "-status", "-oozie", oozieUrl };
            assertEquals(0, new OozieCLI().run(args));
            return null;
        }
    }, conf);
    assertTrue(AuthOozieClient.AUTH_TOKEN_CACHE_FILE.exists());
    String newCache = IOUtils.getReaderAsString(new FileReader(AuthOozieClient.AUTH_TOKEN_CACHE_FILE), -1);
    assertEquals(currentCache, newCache);
    // re-using cache with token that will expire within 5 minutes
    currentCache = writeTokenCache(System.currentTimeMillis() + 300000);
    setSystemProperty("oozie.auth.token.cache", "true");
    runTest(new Callable<Void>() {

        public Void call() throws Exception {
            String oozieUrl = getContextURL();
            String[] args = new String[] { "admin", "-status", "-oozie", oozieUrl };
            assertEquals(0, new OozieCLI().run(args));
            return null;
        }
    }, conf);
    assertTrue(AuthOozieClient.AUTH_TOKEN_CACHE_FILE.exists());
    newCache = IOUtils.getReaderAsString(new FileReader(AuthOozieClient.AUTH_TOKEN_CACHE_FILE), -1);
    assertFalse("Almost expired token should have been updated but was not", currentCache.equals(newCache));
    // re-using cache with expired token
    currentCache = writeTokenCache(System.currentTimeMillis() - 1000);
    setSystemProperty("oozie.auth.token.cache", "true");
    runTest(new Callable<Void>() {

        public Void call() throws Exception {
            String oozieUrl = getContextURL();
            String[] args = new String[] { "admin", "-status", "-oozie", oozieUrl };
            assertEquals(0, new OozieCLI().run(args));
            return null;
        }
    }, conf);
    assertTrue(AuthOozieClient.AUTH_TOKEN_CACHE_FILE.exists());
    newCache = IOUtils.getReaderAsString(new FileReader(AuthOozieClient.AUTH_TOKEN_CACHE_FILE), -1);
    assertFalse("Expired token should have been updated but was not", currentCache.equals(newCache));
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) FileWriter(java.io.FileWriter) FileReader(java.io.FileReader) OozieCLI(org.apache.oozie.cli.OozieCLI) AuthenticationException(org.apache.hadoop.security.authentication.client.AuthenticationException) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 9 with OozieCLI

use of org.apache.oozie.cli.OozieCLI in project oozie by apache.

the class TestAuthFilterAuthOozieClient method testClientWithCustomAuthenticator.

public void testClientWithCustomAuthenticator() throws Exception {
    setSystemProperty("authenticator.class", Authenticator4Test.class.getName());
    Configuration conf = new Configuration(false);
    conf.set("oozie.authentication.simple.anonymous.allowed", "false");
    Authenticator4Test.USED = false;
    runTest(new Callable<Void>() {

        public Void call() throws Exception {
            String oozieUrl = getContextURL();
            String[] args = new String[] { "admin", "-status", "-oozie", oozieUrl };
            assertEquals(0, new OozieCLI().run(args));
            return null;
        }
    }, conf);
    assertTrue(Authenticator4Test.USED);
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) OozieCLI(org.apache.oozie.cli.OozieCLI) AuthenticationException(org.apache.hadoop.security.authentication.client.AuthenticationException) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Aggregations

OozieCLI (org.apache.oozie.cli.OozieCLI)9 IOException (java.io.IOException)5 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)5 AuthenticationException (org.apache.hadoop.security.authentication.client.AuthenticationException)5 Configuration (org.apache.hadoop.conf.Configuration)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 PrintStream (java.io.PrintStream)2 FileReader (java.io.FileReader)1 FileWriter (java.io.FileWriter)1 Path (org.apache.hadoop.fs.Path)1 CLIParser (org.apache.oozie.cli.CLIParser)1