[Java][jersey2] Add debugging to OAuth (#6757)

* add debugging to oauth

* use fine instead
This commit is contained in:
William Cheng 2020-06-26 16:25:55 +08:00 committed by GitHub
parent 8b9c070e5d
commit 919b3b6bef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 414 additions and 384 deletions

View File

@ -461,7 +461,7 @@ public class ApiClient {
public ApiClient setOauthCredentials(String clientId, String clientSecret) { public ApiClient setOauthCredentials(String clientId, String clientSecret) {
for (Authentication auth : authentications.values()) { for (Authentication auth : authentications.values()) {
if (auth instanceof OAuth) { if (auth instanceof OAuth) {
((OAuth) auth).setCredentials(clientId, clientSecret); ((OAuth) auth).setCredentials(clientId, clientSecret, isDebugging());
return this; return this;
} }
} }

View File

@ -91,6 +91,7 @@ public class OAuth implements Authentication {
public synchronized OAuth2AccessToken obtainAccessToken(String refreshToken) throws ApiException { public synchronized OAuth2AccessToken obtainAccessToken(String refreshToken) throws ApiException {
if (service == null) { if (service == null) {
log.log(Level.FINE, "service is null in obtainAccessToken.");
return null; return null;
} }
try { try {
@ -115,6 +116,9 @@ public class OAuth implements Authentication {
break; break;
case application: case application:
accessToken = service.getAccessTokenClientCredentialsGrant(scope); accessToken = service.getAccessTokenClientCredentialsGrant(scope);
break;
default:
log.log(Level.SEVERE, "Invalid flow in obtainAccessToken: " + flow);
} }
} catch (OAuthException | InterruptedException | ExecutionException | IOException e) { } catch (OAuthException | InterruptedException | ExecutionException | IOException e) {
throw new ApiException(e); throw new ApiException(e);
@ -141,10 +145,16 @@ public class OAuth implements Authentication {
return this; return this;
} }
public OAuth setCredentials(String clientId, String clientSecret) { public OAuth setCredentials(String clientId, String clientSecret, Boolean debug) {
if (Boolean.TRUE.equals(debug)) {
service = new ServiceBuilder(clientId)
.apiSecret(clientSecret).debug()
.build(authApi);
} else {
service = new ServiceBuilder(clientId) service = new ServiceBuilder(clientId)
.apiSecret(clientSecret) .apiSecret(clientSecret)
.build(authApi); .build(authApi);
}
return this; return this;
} }

View File

@ -379,7 +379,7 @@ public class ApiClient {
public ApiClient setOauthCredentials(String clientId, String clientSecret) { public ApiClient setOauthCredentials(String clientId, String clientSecret) {
for (Authentication auth : authentications.values()) { for (Authentication auth : authentications.values()) {
if (auth instanceof OAuth) { if (auth instanceof OAuth) {
((OAuth) auth).setCredentials(clientId, clientSecret); ((OAuth) auth).setCredentials(clientId, clientSecret, isDebugging());
return this; return this;
} }
} }

View File

@ -102,6 +102,7 @@ public class OAuth implements Authentication {
public synchronized OAuth2AccessToken obtainAccessToken(String refreshToken) throws ApiException { public synchronized OAuth2AccessToken obtainAccessToken(String refreshToken) throws ApiException {
if (service == null) { if (service == null) {
log.log(Level.FINE, "service is null in obtainAccessToken.");
return null; return null;
} }
try { try {
@ -126,6 +127,9 @@ public class OAuth implements Authentication {
break; break;
case application: case application:
accessToken = service.getAccessTokenClientCredentialsGrant(scope); accessToken = service.getAccessTokenClientCredentialsGrant(scope);
break;
default:
log.log(Level.SEVERE, "Invalid flow in obtainAccessToken: " + flow);
} }
} catch (OAuthException | InterruptedException | ExecutionException | IOException e) { } catch (OAuthException | InterruptedException | ExecutionException | IOException e) {
throw new ApiException(e); throw new ApiException(e);
@ -152,10 +156,16 @@ public class OAuth implements Authentication {
return this; return this;
} }
public OAuth setCredentials(String clientId, String clientSecret) { public OAuth setCredentials(String clientId, String clientSecret, Boolean debug) {
if (Boolean.TRUE.equals(debug)) {
service = new ServiceBuilder(clientId)
.apiSecret(clientSecret).debug()
.build(authApi);
} else {
service = new ServiceBuilder(clientId) service = new ServiceBuilder(clientId)
.apiSecret(clientSecret) .apiSecret(clientSecret)
.build(authApi); .build(authApi);
}
return this; return this;
} }

View File

@ -458,7 +458,7 @@ public class ApiClient {
public ApiClient setOauthCredentials(String clientId, String clientSecret) { public ApiClient setOauthCredentials(String clientId, String clientSecret) {
for (Authentication auth : authentications.values()) { for (Authentication auth : authentications.values()) {
if (auth instanceof OAuth) { if (auth instanceof OAuth) {
((OAuth) auth).setCredentials(clientId, clientSecret); ((OAuth) auth).setCredentials(clientId, clientSecret, isDebugging());
return this; return this;
} }
} }

View File

@ -102,6 +102,7 @@ public class OAuth implements Authentication {
public synchronized OAuth2AccessToken obtainAccessToken(String refreshToken) throws ApiException { public synchronized OAuth2AccessToken obtainAccessToken(String refreshToken) throws ApiException {
if (service == null) { if (service == null) {
log.log(Level.FINE, "service is null in obtainAccessToken.");
return null; return null;
} }
try { try {
@ -126,6 +127,9 @@ public class OAuth implements Authentication {
break; break;
case application: case application:
accessToken = service.getAccessTokenClientCredentialsGrant(scope); accessToken = service.getAccessTokenClientCredentialsGrant(scope);
break;
default:
log.log(Level.SEVERE, "Invalid flow in obtainAccessToken: " + flow);
} }
} catch (OAuthException | InterruptedException | ExecutionException | IOException e) { } catch (OAuthException | InterruptedException | ExecutionException | IOException e) {
throw new ApiException(e); throw new ApiException(e);
@ -152,10 +156,16 @@ public class OAuth implements Authentication {
return this; return this;
} }
public OAuth setCredentials(String clientId, String clientSecret) { public OAuth setCredentials(String clientId, String clientSecret, Boolean debug) {
if (Boolean.TRUE.equals(debug)) {
service = new ServiceBuilder(clientId)
.apiSecret(clientSecret).debug()
.build(authApi);
} else {
service = new ServiceBuilder(clientId) service = new ServiceBuilder(clientId)
.apiSecret(clientSecret) .apiSecret(clientSecret)
.build(authApi); .build(authApi);
}
return this; return this;
} }