Search in sources :

Example 41 with GeneralException

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!");
    }
}
Also used : GeneralException(edu.uiuc.ncsa.security.core.exceptions.GeneralException) JSONObject(net.sf.json.JSONObject) JSONWebKeys(edu.uiuc.ncsa.security.util.jwk.JSONWebKeys) FileWriter(java.io.FileWriter) File(java.io.File)

Example 42 with GeneralException

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);
            }
        }
    }
}
Also used : GeneralException(edu.uiuc.ncsa.security.core.exceptions.GeneralException) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) IOException(java.io.IOException) File(java.io.File)

Example 43 with GeneralException

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;
}
Also used : GeneralException(edu.uiuc.ncsa.security.core.exceptions.GeneralException) ServiceTransaction(edu.uiuc.ncsa.security.delegation.server.ServiceTransaction) AuthorizationGrant(edu.uiuc.ncsa.security.delegation.token.AuthorizationGrant)

Example 44 with GeneralException

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);
}
Also used : TransactionState(edu.uiuc.ncsa.security.delegation.servlet.TransactionState) NoUsableMyProxyServerFoundException(edu.uiuc.ncsa.myproxy.NoUsableMyProxyServerFoundException) GeneralException(edu.uiuc.ncsa.security.core.exceptions.GeneralException) ServiceTransaction(edu.uiuc.ncsa.security.delegation.server.ServiceTransaction) GeneralSecurityException(java.security.GeneralSecurityException) ConnectionException(edu.uiuc.ncsa.security.core.exceptions.ConnectionException)

Example 45 with GeneralException

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;
}
Also used : GeneralException(edu.uiuc.ncsa.security.core.exceptions.GeneralException) ServiceTransaction(edu.uiuc.ncsa.security.delegation.server.ServiceTransaction) AuthorizationGrant(edu.uiuc.ncsa.security.delegation.token.AuthorizationGrant)

Aggregations

GeneralException (edu.uiuc.ncsa.security.core.exceptions.GeneralException)53 ServiceTransaction (edu.uiuc.ncsa.security.delegation.server.ServiceTransaction)9 SQLException (java.sql.SQLException)8 Connection (java.sql.Connection)7 PreparedStatement (java.sql.PreparedStatement)7 ResultSet (java.sql.ResultSet)7 Identifier (edu.uiuc.ncsa.security.core.Identifier)5 BasicIdentifier (edu.uiuc.ncsa.security.core.util.BasicIdentifier)5 MyPKCS10CertRequest (edu.uiuc.ncsa.security.util.pkcs.MyPKCS10CertRequest)5 X509Certificate (java.security.cert.X509Certificate)5 AssetResponse (edu.uiuc.ncsa.myproxy.oa4mp.client.AssetResponse)4 TransactionState (edu.uiuc.ncsa.security.delegation.servlet.TransactionState)4 AccessToken (edu.uiuc.ncsa.security.delegation.token.AccessToken)4 AuthorizationGrant (edu.uiuc.ncsa.security.delegation.token.AuthorizationGrant)4 OA2SE (edu.uiuc.ncsa.myproxy.oa4mp.oauth2.OA2SE)3 OA2ServiceTransaction (edu.uiuc.ncsa.myproxy.oa4mp.oauth2.OA2ServiceTransaction)3 ColumnMap (edu.uiuc.ncsa.security.storage.sql.internals.ColumnMap)3 File (java.io.File)3 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3