use of edu.uiuc.ncsa.security.core.exceptions.GeneralException in project OA4MP by ncsa.
the class SigningCommands method create.
public void create(InputLine inputLine) throws Exception {
if (showHelp(inputLine)) {
createHelp();
return;
}
// PublicKey publicKey = KeyUtil.g
boolean retry = true;
File publicKeyFile = null;
boolean isInteractive = true;
if (1 < inputLine.size()) {
publicKeyFile = new File(inputLine.getArg(1));
}
if (publicKeyFile == null && isBatchMode()) {
throw new GeneralException("No full path to the file given.");
}
while (retry) {
String publicKeyPath = getInput("Give the file path", "");
if (publicKeyPath.toLowerCase().equals("exit") || publicKeyPath.toLowerCase().equals("quit")) {
return;
}
publicKeyFile = new File(publicKeyPath);
if (publicKeyFile.exists()) {
if (!publicKeyFile.isFile()) {
sayi("Sorry, but you must supply the name of the file as well (or type 'exit' to exit");
} else {
sayi2("The file you gave exists, do you want to over write it? [y/n]");
retry = !isOk(readline());
}
} else {
retry = false;
}
}
retry = true;
sayi2("create a new set of JSON web keys?[y/n]");
if (!isOk(readline())) {
say("create cancelled.");
return;
}
JSONWebKeys keys = new JSONWebKeys(null);
keys.put(createJWK("RS256"));
keys.put(createJWK("RS384"));
keys.put(createJWK("RS512"));
FileWriter writer = new FileWriter(publicKeyFile);
JSONObject jwks = JSONWebKeyUtil.toJSON(keys);
writer.write(jwks.toString(3));
writer.flush();
writer.close();
if (isInteractive) {
sayi("JSONweb keys written");
sayi("Done!");
}
}
use of edu.uiuc.ncsa.security.core.exceptions.GeneralException in project OA4MP by ncsa.
the class ClientStoreCommands method getPublicKeyFile.
protected void getPublicKeyFile(Client client) {
String input;
String fileNotFoundMessage = INDENT + "...uh-oh, I can't find that file. Please enter it again";
String secret = client.getSecret();
if (!isEmpty(secret)) {
secret = secret.substring(0, Math.min(25, secret.length())) + "...";
}
boolean askForFile = true;
while (askForFile) {
input = getInput("enter full path and file name of public key", secret);
if (isEmpty(input)) {
sayi("No file entered. Public key entry skipped");
break;
}
if (input.equals(secret)) {
sayi(" public key entry skipped.");
break;
}
// if this is not the default value, then this *should* be the name of a file.
if (input != null) {
File f = new File(input);
if (!f.exists()) {
say(fileNotFoundMessage);
continue;
}
try {
FileReader fr = new FileReader(f);
BufferedReader br = new BufferedReader(fr);
StringBuffer sb = new StringBuffer();
String x = br.readLine();
while (x != null) {
sb.append(x + "\n");
x = br.readLine();
}
br.close();
try {
KeyUtil.fromX509PEM(sb.toString());
askForFile = false;
} catch (GeneralException gx) {
gx.printStackTrace();
sayi("This does not seem to be in the correct format:" + gx.getMessage());
sayi("Please try again.");
continue;
}
client.setSecret(sb.toString());
} catch (IOException e) {
say(fileNotFoundMessage);
}
}
}
}
use of edu.uiuc.ncsa.security.core.exceptions.GeneralException in project OA4MP by ncsa.
the class AbstractAuthorizationServlet method getAndCheckTransaction.
/*
Get the transaction associated with the authorization grant token and check that it passes sanity
checks. If so, return it, If not, throw the appropriate exception.
*/
protected ServiceTransaction getAndCheckTransaction(String token) throws IOException {
DateUtils.checkTimestamp(token);
AuthorizationGrant grant = MyProxyDelegationServlet.getServiceEnvironment().getTokenForge().getAuthorizationGrant(token);
ServiceTransaction trans = MyProxyDelegationServlet.getServiceEnvironment().getTransactionStore().get(grant);
if (trans == null) {
warn("Error: no delegation request found for " + token);
throw new GeneralException("Error: no delegation request found.");
}
checkClientApproval(trans.getClient());
return trans;
}
use of edu.uiuc.ncsa.security.core.exceptions.GeneralException in project OA4MP by ncsa.
the class AbstractAuthorizationServlet method doIt.
@Override
protected void doIt(HttpServletRequest request, HttpServletResponse response) throws Throwable {
info("*** STARTING request");
// String ag = request.getParameter(CONST(TOKEN_KEY));
String ag = getParam(request, CONST(TOKEN_KEY));
ServiceTransaction trans = null;
if (ag == null) {
throw new GeneralException("Error: Invalid request -- no token. Request rejected.");
}
trans = getAndCheckTransaction(ag);
AuthorizedState pState = new AuthorizedState(getState(request), request, response, trans);
prepare(pState);
preprocess(new TransactionState(request, response, null, trans));
switch(pState.getState()) {
case AUTHORIZATION_ACTION_OK:
// As per the spec, if the code gets to here then authentication worked.
trans.setAuthGrantValid(true);
getTransactionStore().save(trans);
// get the cert and store it. Then forward user.
try {
createRedirect(request, response, trans);
// at this point.
return;
} catch (ConnectionException ce) {
ce.printStackTrace();
request.setAttribute(RETRY_MESSAGE, getServiceEnvironment().getMessages().get(RETRY_MESSAGE));
pState.setState(AUTHORIZATION_ACTION_START);
prepare(pState);
} catch (GeneralSecurityException | NoUsableMyProxyServerFoundException t) {
// CIL-173 fix: process NoUsableMPSFound.
info("Prompting user to retry");
request.setAttribute(RETRY_MESSAGE, getServiceEnvironment().getMessages().get(RETRY_MESSAGE));
pState.setState(AUTHORIZATION_ACTION_START);
prepare(pState);
}
break;
case AUTHORIZATION_ACTION_START:
// no processing needed for initial request.
break;
default:
}
present(pState);
}
use of edu.uiuc.ncsa.security.core.exceptions.GeneralException in project OA4MP by ncsa.
the class AuthorizedServlet method getAndCheckTransaction.
/*
Get the transaction associated with the authorization grant token and check that it passes sanity
checks. If so, return it, If not, throw the appropriate exception.
*/
protected ServiceTransaction getAndCheckTransaction(ProtocolParameters p) throws Throwable {
String token = p.token;
DateUtils.checkTimestamp(token);
AuthorizationGrant grant = MyProxyDelegationServlet.getServiceEnvironment().getTokenForge().getAuthorizationGrant(token);
checkTimestamp(grant.getToken());
ServiceTransaction trans = MyProxyDelegationServlet.getServiceEnvironment().getTransactionStore().get(grant);
if (trans == null) {
warn("Error: no delegation request found for " + token);
throw new GeneralException("Error: no delegation request found.");
}
checkClientApproval(trans.getClient());
return trans;
}
Aggregations