Search in sources :

Example 6 with JSONWebKeys

use of edu.uiuc.ncsa.security.util.jwk.JSONWebKeys 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)

Aggregations

JSONWebKeys (edu.uiuc.ncsa.security.util.jwk.JSONWebKeys)6 File (java.io.File)5 JSONObject (net.sf.json.JSONObject)3 GeneralException (edu.uiuc.ncsa.security.core.exceptions.GeneralException)2 JSONWebKey (edu.uiuc.ncsa.security.util.jwk.JSONWebKey)1 FileWriter (java.io.FileWriter)1 PrintWriter (java.io.PrintWriter)1 ConfigurationNode (org.apache.commons.configuration.tree.ConfigurationNode)1