Search in sources :

Example 1 with Access

use of com.yahoo.athenz.zms.Access in project athenz by yahoo.

the class ZMSTLSClient method main.

public static void main(String[] args) {
    // parse our command line to retrieve required input
    CommandLine cmd = parseCommandLine(args);
    final String resource = cmd.getOptionValue("resource").toLowerCase();
    final String action = cmd.getOptionValue("action").toLowerCase();
    final String principal = cmd.getOptionValue("principal").toLowerCase();
    final String zmsUrl = cmd.getOptionValue("zmsurl");
    final String keyPath = cmd.getOptionValue("key");
    final String certPath = cmd.getOptionValue("cert");
    final String trustStorePath = cmd.getOptionValue("trustStorePath");
    final String trustStorePassword = cmd.getOptionValue("trustStorePassword");
    try {
        KeyRefresher keyRefresher = Utils.generateKeyRefresher(trustStorePath, trustStorePassword, certPath, keyPath);
        SSLContext sslContext = Utils.buildSSLContext(keyRefresher.getKeyManagerProxy(), keyRefresher.getTrustManagerProxy());
        try (ZMSClient zmsClient = new ZMSClient(zmsUrl, sslContext)) {
            try {
                Access access = zmsClient.getAccess(action, resource, null, principal);
                System.out.println("Access: " + access.getGranted());
            } catch (ZMSClientException ex) {
                System.out.println("Unable to carry out access check: " + ex.getMessage());
                System.exit(2);
            }
        }
    } catch (Exception ex) {
        System.out.println("Exception: " + ex.getMessage());
        ex.printStackTrace();
        System.exit(1);
    }
}
Also used : CommandLine(org.apache.commons.cli.CommandLine) Access(com.yahoo.athenz.zms.Access) SSLContext(javax.net.ssl.SSLContext) ZMSClient(com.yahoo.athenz.zms.ZMSClient) KeyRefresher(com.oath.auth.KeyRefresher) ZMSClientException(com.yahoo.athenz.zms.ZMSClientException) ParseException(org.apache.commons.cli.ParseException) ZMSClientException(com.yahoo.athenz.zms.ZMSClientException)

Aggregations

KeyRefresher (com.oath.auth.KeyRefresher)1 Access (com.yahoo.athenz.zms.Access)1 ZMSClient (com.yahoo.athenz.zms.ZMSClient)1 ZMSClientException (com.yahoo.athenz.zms.ZMSClientException)1 SSLContext (javax.net.ssl.SSLContext)1 CommandLine (org.apache.commons.cli.CommandLine)1 ParseException (org.apache.commons.cli.ParseException)1