use of com.cinchapi.concourse.thrift.SecurityException in project concourse by cinchapi.
the class ConcourseShell method main.
/**
* Run the program...
*
* @param args
* @throws Exception
*/
public static void main(String... args) throws Exception {
try {
ConcourseShell cash = new ConcourseShell();
Options opts = new Options();
JCommander parser = null;
try {
parser = new JCommander(opts, args);
} catch (Exception e) {
die(e.getMessage());
}
parser.setProgramName("concourse-shell");
if (opts.help) {
parser.usage();
System.exit(1);
}
if (!Strings.isNullOrEmpty(opts.prefs)) {
opts.prefs = FileOps.expandPath(opts.prefs, System.getProperty("user.dir.real"));
ConcourseClientPreferences prefs = ConcourseClientPreferences.from(Paths.get(opts.prefs));
opts.username = prefs.getUsername();
opts.password = new String(prefs.getPasswordExplicit());
opts.host = prefs.getHost();
opts.port = prefs.getPort();
opts.environment = prefs.getEnvironment();
}
if (Strings.isNullOrEmpty(opts.password)) {
cash.setExpandEvents(false);
opts.password = cash.console.readLine("Password [" + opts.username + "]: ", '*');
}
try {
cash.concourse = Concourse.connect(opts.host, opts.port, opts.username, opts.password, opts.environment);
cash.whoami = opts.username;
} catch (Exception e) {
if (e.getCause() instanceof TTransportException) {
die("Unable to connect to the Concourse Server at " + opts.host + ":" + opts.port);
} else if (e.getCause() instanceof SecurityException) {
die("Invalid username/password combination.");
} else {
die(e.getMessage());
}
}
if (!opts.ignoreRunCommands) {
cash.loadExternalScript(opts.ext);
}
if (!Strings.isNullOrEmpty(opts.run)) {
try {
String result = cash.evaluate(opts.run);
System.out.println(result);
cash.concourse.exit();
System.exit(0);
} catch (IrregularEvaluationResult e) {
die(e.getMessage());
}
} else {
try {
cash.enableInteractiveSettings();
} catch (PermissionException e) {
die(e.getMessage());
}
boolean running = true;
String input = "";
while (running) {
boolean extraLineBreak = true;
boolean clearInput = true;
boolean clearPrompt = false;
try {
input = input + cash.console.readLine().trim();
String result = cash.evaluate(input);
System.out.println(result);
} catch (UserInterruptException e) {
if (Strings.isNullOrEmpty(e.getPartialLine()) && Strings.isNullOrEmpty(input)) {
cash.console.println("Type EXIT to quit.");
}
} catch (HelpRequest e) {
String text = getHelpText(e.topic);
if (!Strings.isNullOrEmpty(text)) {
Process p = Runtime.getRuntime().exec(new String[] { "sh", "-c", "echo \"" + text + "\" | less > /dev/tty" });
p.waitFor();
}
cash.console.getHistory().removeLast();
} catch (ExitRequest e) {
running = false;
cash.console.getHistory().removeLast();
} catch (NewLineRequest e) {
extraLineBreak = false;
} catch (ProgramCrash e) {
die(e.getMessage());
} catch (MultiLineRequest e) {
extraLineBreak = false;
clearInput = false;
clearPrompt = true;
} catch (IrregularEvaluationResult e) {
System.err.println(e.getMessage());
} finally {
if (extraLineBreak) {
cash.console.print("\n");
}
if (clearInput) {
input = "";
}
if (clearPrompt) {
cash.console.setPrompt("> ");
} else {
cash.console.setPrompt(cash.defaultPrompt);
}
}
}
cash.concourse.exit();
System.exit(0);
}
} finally {
TerminalFactory.get().restore();
}
}
use of com.cinchapi.concourse.thrift.SecurityException in project concourse by cinchapi.
the class AccessTokenVerificationAdvice method invoke.
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
AccessToken token = null;
TransactionToken transaction = null;
Object[] args = invocation.getArguments();
int index = 0;
while (token == null && (transaction == null || index < args.length)) {
Object arg = args[index];
if (arg instanceof AccessToken) {
token = (AccessToken) arg;
} else if (arg instanceof TransactionToken) {
transaction = (TransactionToken) arg;
}
++index;
}
if (token != null) {
ConcourseServer concourse = (ConcourseServer) invocation.getThis();
if (concourse.inspector().isValidToken(token)) {
if (transaction == null || (transaction != null && transaction.getAccessToken().equals(token) && concourse.inspector().isValidTransaction(transaction))) {
return invocation.proceed();
} else {
throw new IllegalArgumentException("Invalid transaction");
}
} else {
throw new SecurityException("Invalid access token");
}
} else {
throw new SecurityException("Unauthorized");
}
}
Aggregations