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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations