Search in sources :

Example 1 with KeyRefresher

use of com.oath.auth.KeyRefresher in project athenz by yahoo.

the class HttpTLSClient method main.

public static void main(String[] args) {
    // parse our command line to retrieve required input
    CommandLine cmd = parseCommandLine(args);
    final String url = cmd.getOptionValue("url");
    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());
        HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());
        HttpsURLConnection con = (HttpsURLConnection) new URL(url).openConnection();
        con.setReadTimeout(15000);
        con.setDoOutput(true);
        con.connect();
        try (BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()))) {
            StringBuilder sb = new StringBuilder();
            String line;
            while ((line = br.readLine()) != null) {
                sb.append(line);
            }
            System.out.println("Data output: " + sb.toString());
        }
    } catch (Exception ex) {
        System.out.println("Exception: " + ex.getMessage());
        ex.printStackTrace();
        System.exit(1);
    }
}
Also used : CommandLine(org.apache.commons.cli.CommandLine) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) SSLContext(javax.net.ssl.SSLContext) KeyRefresher(com.oath.auth.KeyRefresher) HttpsURLConnection(javax.net.ssl.HttpsURLConnection) URL(java.net.URL) ParseException(org.apache.commons.cli.ParseException)

Example 2 with KeyRefresher

use of com.oath.auth.KeyRefresher in project athenz by yahoo.

the class ZTSAWSCredsClient method main.

public static void main(String[] args) {
    // parse our command line to retrieve required input
    CommandLine cmd = parseCommandLine(args);
    final String domainName = cmd.getOptionValue("domain").toLowerCase();
    final String roleName = cmd.getOptionValue("role").toLowerCase();
    final String ztsUrl = cmd.getOptionValue("ztsurl");
    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());
        // obtain temporary credential provider for our domain and role
        AWSCredentialsProviderImpl awsCredProvider = new AWSCredentialsProviderImpl(ztsUrl, sslContext, domainName, roleName);
        // retrieve and display aws temporary creds. Typically you just pass
        // the AWSCredentialsProvider object to any AWS api that requires it.
        // for example, when creating an AWS S3 client
        // AmazonS3 s3client = AmazonS3ClientBuilder.standard()
        // .withCredentials(awsCredProvider).withClientConfiguration(cltConf)
        // .withRegion(getRegion()).build();
        retrieveAWSTempCreds(awsCredProvider);
        // once we're done with our api and we no longer need our
        // provider we need to make sure to close it
        awsCredProvider.close();
    } catch (Exception ex) {
        System.out.println("Exception: " + ex.getMessage());
        ex.printStackTrace();
        System.exit(1);
    }
}
Also used : CommandLine(org.apache.commons.cli.CommandLine) AWSCredentialsProviderImpl(com.yahoo.athenz.zts.AWSCredentialsProviderImpl) SSLContext(javax.net.ssl.SSLContext) KeyRefresher(com.oath.auth.KeyRefresher) ZTSClientException(com.yahoo.athenz.zts.ZTSClientException) ParseException(org.apache.commons.cli.ParseException)

Example 3 with KeyRefresher

use of com.oath.auth.KeyRefresher in project athenz by yahoo.

the class ZTSTLSClient method main.

public static void main(String[] args) {
    // parse our command line to retrieve required input
    CommandLine cmd = parseCommandLine(args);
    final String domainName = cmd.getOptionValue("domain").toLowerCase();
    final String serviceName = cmd.getOptionValue("service").toLowerCase();
    final String keyId = cmd.getOptionValue("keyid").toLowerCase();
    final String ztsUrl = cmd.getOptionValue("ztsurl");
    final String keyPath = cmd.getOptionValue("key");
    final String certPath = cmd.getOptionValue("cert");
    final String trustStorePath = cmd.getOptionValue("trustStorePath");
    final String trustStorePassword = cmd.getOptionValue("trustStorePassword");
    final String proxyUrl = cmd.getOptionValue("proxy");
    try {
        KeyRefresher keyRefresher = Utils.generateKeyRefresher(trustStorePath, trustStorePassword, certPath, keyPath);
        SSLContext sslContext = Utils.buildSSLContext(keyRefresher.getKeyManagerProxy(), keyRefresher.getTrustManagerProxy());
        try (ZTSClient ztsClient = new ZTSClient(ztsUrl, proxyUrl, sslContext)) {
            try {
                PublicKeyEntry publicKey = ztsClient.getPublicKeyEntry(domainName, serviceName, keyId);
                System.out.println("PublicKey: " + publicKey.getKey());
            } catch (ZTSClientException ex) {
                System.out.println("Unable to retrieve public key: " + ex.getMessage());
                System.exit(2);
            }
        }
    } catch (Exception ex) {
        System.out.println("Exception: " + ex.getMessage());
        ex.printStackTrace();
        System.exit(1);
    }
}
Also used : PublicKeyEntry(com.yahoo.athenz.zts.PublicKeyEntry) CommandLine(org.apache.commons.cli.CommandLine) ZTSClient(com.yahoo.athenz.zts.ZTSClient) ZTSClientException(com.yahoo.athenz.zts.ZTSClientException) SSLContext(javax.net.ssl.SSLContext) KeyRefresher(com.oath.auth.KeyRefresher) ZTSClientException(com.yahoo.athenz.zts.ZTSClientException) ParseException(org.apache.commons.cli.ParseException)

Example 4 with KeyRefresher

use of com.oath.auth.KeyRefresher 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)4 SSLContext (javax.net.ssl.SSLContext)4 CommandLine (org.apache.commons.cli.CommandLine)4 ParseException (org.apache.commons.cli.ParseException)4 ZTSClientException (com.yahoo.athenz.zts.ZTSClientException)2 Access (com.yahoo.athenz.zms.Access)1 ZMSClient (com.yahoo.athenz.zms.ZMSClient)1 ZMSClientException (com.yahoo.athenz.zms.ZMSClientException)1 AWSCredentialsProviderImpl (com.yahoo.athenz.zts.AWSCredentialsProviderImpl)1 PublicKeyEntry (com.yahoo.athenz.zts.PublicKeyEntry)1 ZTSClient (com.yahoo.athenz.zts.ZTSClient)1 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 URL (java.net.URL)1 HttpsURLConnection (javax.net.ssl.HttpsURLConnection)1