Search in sources :

Example 11 with KnoxSession

use of org.apache.knox.gateway.shell.KnoxSession in project knox by apache.

the class TokenTest method testRevokeToken.

private void testRevokeToken(boolean setDoAsUser, String doAsUser) throws Exception {
    final String testToken = "REVOKE+ABCDEFG123456";
    final KnoxSession knoxSession = createMockKnoxSession();
    Revoke.Request request = (setDoAsUser) ? Token.revoke(knoxSession, testToken, doAsUser) : Token.revoke(knoxSession, testToken);
    if (setDoAsUser) {
        assertEquals(doAsUser, request.getDoAsUser());
    } else {
        assertNull(request.getDoAsUser());
    }
    testTokenLifecyle(request, testToken);
    assertSame(knoxSession, request.getSession());
    verify(knoxSession);
}
Also used : KnoxSession(org.apache.knox.gateway.shell.KnoxSession)

Example 12 with KnoxSession

use of org.apache.knox.gateway.shell.KnoxSession in project knox by apache.

the class TokenTest method testRenewToken.

private void testRenewToken(boolean setDoAsUser, String doAsUser) throws Exception {
    final String testToken = "RENEW+ABCDEFG123456";
    final KnoxSession knoxSession = createMockKnoxSession();
    Renew.Request request = (setDoAsUser) ? Token.renew(knoxSession, testToken, doAsUser) : Token.renew(knoxSession, testToken);
    if (setDoAsUser) {
        assertEquals(doAsUser, request.getDoAsUser());
    } else {
        assertNull(request.getDoAsUser());
    }
    testTokenLifecyle(request, testToken);
    assertSame(knoxSession, request.getSession());
    verify(knoxSession);
}
Also used : KnoxSession(org.apache.knox.gateway.shell.KnoxSession)

Example 13 with KnoxSession

use of org.apache.knox.gateway.shell.KnoxSession in project knox by apache.

the class KnoxTokenWorkerThread method run.

@Override
public void run() {
    try {
        LOG.knoxTokenWorkerName(action);
        final KnoxSession gatewayKnoxSession = KnoxSession.login(configuration.getUseCaseUrl(USE_CASE_NAME, "gateway"), configuration.getGatewayUser(), configuration.getGatewayPassword());
        final KnoxSession tokenBasedKnoxSession = KnoxSession.login(configuration.getUseCaseUrl(USE_CASE_NAME, "tokenbased"), configuration.getGatewayUser(), configuration.getGatewayPassword());
        final long testDuration = Long.parseLong(configuration.getUseCaseParam(USE_CASE_NAME, PARAM_DURATION_IN_SECONDS));
        final long lowerBound = Long.parseLong(configuration.getUseCaseParam(USE_CASE_NAME, PARAM_REQUEST_DELAY_LOWERBOUND));
        final long upperBound = Long.parseLong(configuration.getUseCaseParam(USE_CASE_NAME, PARAM_REQUEST_DELAY_UPPERBOUND));
        this.startTime = Instant.now();
        int requestCount = 0;
        while (shouldRun(testDuration)) {
            executeAction(gatewayKnoxSession, tokenBasedKnoxSession);
            if (requestCount > 0) {
                TimeUnit.SECONDS.sleep(calculateSleepTime(lowerBound, upperBound));
            }
            requestCount++;
        }
    } catch (Exception e) {
        LOG.failedToRunKnoxTokenWorker(action, e.getMessage(), e);
    } finally {
        LOG.finishKnoxTokenWorker();
    }
}
Also used : KnoxSession(org.apache.knox.gateway.shell.KnoxSession) IOException(java.io.IOException) KnoxShellException(org.apache.knox.gateway.shell.KnoxShellException)

Example 14 with KnoxSession

use of org.apache.knox.gateway.shell.KnoxSession in project knox by apache.

the class LoginCommand method execute.

@SuppressWarnings("unchecked")
@Override
public Object execute(List<String> args) {
    KnoxSession session = null;
    KnoxLoginDialog dlg = new KnoxLoginDialog();
    try {
        dlg.collect();
        if (dlg.ok) {
            session = KnoxSession.login(args.get(0), dlg.username, new String(dlg.pass));
            getVariables().put("__knoxsession", session);
        }
    } catch (CredentialCollectionException | URISyntaxException e) {
        e.printStackTrace();
    }
    return "Session established for: " + args.get(0);
}
Also used : CredentialCollectionException(org.apache.knox.gateway.shell.CredentialCollectionException) KnoxSession(org.apache.knox.gateway.shell.KnoxSession) URISyntaxException(java.net.URISyntaxException)

Example 15 with KnoxSession

use of org.apache.knox.gateway.shell.KnoxSession in project knox by apache.

the class WebHDFSCommand method mkdir.

private String mkdir(Map<String, String> mounts, String path, String perms) {
    String result = null;
    String mountPoint = determineMountPoint(path);
    KnoxSession session = getSessionForMountPoint(mounts, mountPoint);
    if (session != null) {
        String targetPath = determineTargetPath(path, mountPoint);
        if (!exists(session, targetPath)) {
            try {
                if (perms != null) {
                    Hdfs.mkdir(sessions.get(mountPoint)).dir(targetPath).now().getString();
                } else {
                    Hdfs.mkdir(session).dir(targetPath).perm(perms).now().getString();
                }
                result = "Successfully created directory: " + targetPath;
            } catch (KnoxShellException | IOException e) {
                e.printStackTrace();
                result = "Exception ocurred: " + e.getMessage();
            }
        } else {
            result = targetPath + " already exists";
        }
    } else {
        result = "No session established for mountPoint: " + mountPoint + " Use :fs mount {topology-url} {mountpoint-name}";
    }
    return result;
}
Also used : KnoxSession(org.apache.knox.gateway.shell.KnoxSession) IOException(java.io.IOException) KnoxShellException(org.apache.knox.gateway.shell.KnoxShellException)

Aggregations

KnoxSession (org.apache.knox.gateway.shell.KnoxSession)22 IOException (java.io.IOException)12 Callable (java.util.concurrent.Callable)6 Test (org.junit.Test)6 KnoxShellException (org.apache.knox.gateway.shell.KnoxShellException)5 URISyntaxException (java.net.URISyntaxException)2 HttpEntity (org.apache.http.HttpEntity)2 UrlEncodedFormEntity (org.apache.http.client.entity.UrlEncodedFormEntity)2 HttpPost (org.apache.http.client.methods.HttpPost)2 HttpRequestBase (org.apache.http.client.methods.HttpRequestBase)2 CredentialCollectionException (org.apache.knox.gateway.shell.CredentialCollectionException)2 HashMap (java.util.HashMap)1 CredentialCollector (org.apache.knox.gateway.shell.CredentialCollector)1 KnoxShellTable (org.apache.knox.gateway.shell.table.KnoxShellTable)1