- private void print(Token t) {
- GregorianCalendar exp_date = new GregorianCalendar();
- exp_date.add(GregorianCalendar.SECOND, t.getExpiresIn());
- System.out.printf("Access Token\n\tToken:\t\t%s\n\tToken Type:\t%s\n\tExpires In:\t%d (%s)\n\tScope:\t\t%s\n\tRefresh Token:\t%s\n",
- t.getAccessToken(),
- t.getTokenType(),
- t.getExpiresIn(),
- Chrono.timeStamp(new Date(System.currentTimeMillis()+(t.getExpiresIn()*1000))),
- t.getScope(),
- t.getRefreshToken());
- }
-
- private void print(Introspect ti) {
- if(ti==null || ti.getClientId()==null) {
- System.out.println("Empty Introspect");
- return;
- }
- Date exp = new Date(ti.getExp()*1000); // seconds
- System.out.printf("Introspect\n"
- + "\tAccessToken:\t%s\n"
- + "\tClient-id:\t%s\n"
- + "\tClient Type:\t%s\n"
- + "\tActive: \t%s\n"
- + "\tUserName:\t%s\n"
- + "\tExpires: \t%d (%s)\n"
- + "\tScope:\t\t%s\n"
- + "\tContent:\t\t%s\n",
- ti.getAccessToken(),
- ti.getClientId(),
- ti.getClientType(),
- ti.isActive()?Boolean.TRUE.toString():Boolean.FALSE.toString(),
- ti.getUsername(),
- ti.getExp(),
- Chrono.timeStamp(exp),
- ti.getScope(),
- ti.getContent()==null?"":ti.getContent());
-
- System.out.println();
- }
+ tc = tcf.newClient(tokenIntrospectURL, 3000);
+ tc.client_creds(client_id, client_secret);
+ rti = tc.introspect(rtt.value.getAccessToken());
+ if(rti.isOK()) {
+ System.out.print("AAF with ISAM Token ");
+ print(rti.value);
+ } else {
+ System.out.println(rti.code + ' ' + rti.error);
+ if(rti.code!=404) {
+ Assert.fail(rti.code + ' ' + rti.error);
+ }
+ }
+
+ TzClient tzClient = tcf.newTzClient(endServicesURL);
+ tzClient.setToken(client_id, rtt.value);
+ // Note: this is AAF's "Hello" server
+ String rv = serviceCall(tzClient);
+ System.out.println(rv);
+ // Assert.assertEquals("Hello AAF OAuth2\n",rv);
+ } else {
+ System.out.println(rtt.code + ' ' + rtt.error);
+ Assert.fail(rtt.code + ' ' + rtt.error);
+ }
+ } else {
+ System.out.println(rtt.code + ' ' + rtt.error);
+ Assert.fail(rtt.code + ' ' + rtt.error);
+ }
+ } else {
+ Assert.fail(Config.AAF_ALT_OAUTH2_TOKEN_URL + " is required");
+ }
+ }
+ } catch (Exception e) {
+// Assert.fail();
+ }
+ }
+
+
+// private TokenClient testROPCFlow(final String url, final String client_id, final String client_secret, String user, String password, final String ... scope) throws Exception {
+// TokenClient tclient = tcf.newClient(url,3000);
+// tclient.client_creds(client_id, client_secret);
+// if(user!=null && password!=null) {
+// tclient.password(user,password);
+// }
+// Result<TimedToken> rt = tclient.getToken(scope);
+// if(rt.isOK()) {
+// print(rt.value);
+// Result<Introspect> rti = tclient.introspect(rt.value.getAccessToken());
+// if(rti.isOK()) {
+// print(rti.value);
+// } else {
+// printAndFail(rti);
+// }
+// } else {
+// printAndFail(rt);
+// }
+// return tclient;
+// }
+
+ private String serviceCall(TzClient tzClient) throws Exception {
+ return tzClient.best(new Retryable<String>() {
+ @Override
+ public String code(Rcli<?> client) throws CadiException, ConnectException, APIException {
+ Future<String> future = client.read(null,"text/plain");
+ if(future.get(3000)) {
+ return future.value;
+ } else {
+ throw new APIException(future.code() + future.body());
+ }
+ }
+ });
+ }
+// private void printAndFail(Result<?> rt) {
+// System.out.printf("HTTP Code %d: %s\n", rt.code, rt.error);
+// Assert.fail(rt.toString());
+// }
+
+ private void print(Token t) {
+ GregorianCalendar exp_date = new GregorianCalendar();
+ exp_date.add(GregorianCalendar.SECOND, t.getExpiresIn());
+ System.out.printf("Access Token\n\tToken:\t\t%s\n\tToken Type:\t%s\n\tExpires In:\t%d (%s)\n\tScope:\t\t%s\n\tRefresh Token:\t%s\n",
+ t.getAccessToken(),
+ t.getTokenType(),
+ t.getExpiresIn(),
+ Chrono.timeStamp(new Date(System.currentTimeMillis()+(t.getExpiresIn()*1000))),
+ t.getScope(),
+ t.getRefreshToken());
+ }
+
+ private void print(Introspect ti) {
+ if(ti==null || ti.getClientId()==null) {
+ System.out.println("Empty Introspect");
+ return;
+ }
+ Date exp = new Date(ti.getExp()*1000); // seconds
+ System.out.printf("Introspect\n"
+ + "\tAccessToken:\t%s\n"
+ + "\tClient-id:\t%s\n"
+ + "\tClient Type:\t%s\n"
+ + "\tActive: \t%s\n"
+ + "\tUserName:\t%s\n"
+ + "\tExpires: \t%d (%s)\n"
+ + "\tScope:\t\t%s\n"
+ + "\tContent:\t\t%s\n",
+ ti.getAccessToken(),
+ ti.getClientId(),
+ ti.getClientType(),
+ ti.isActive()?Boolean.TRUE.toString():Boolean.FALSE.toString(),
+ ti.getUsername(),
+ ti.getExp(),
+ Chrono.timeStamp(exp),
+ ti.getScope(),
+ ti.getContent()==null?"":ti.getContent());
+
+ System.out.println();
+ }