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);
}
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);
}
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();
}
}
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);
}
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;
}
Aggregations