Skip to content

Commit 765365c

Browse files
authored
Merge pull request #390 from alex268/fix_oauth2_provider_npe
Fixed possible NPE in OAuth2 Provider
2 parents 8f16222 + 0da1abd commit 765365c

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

auth-providers/oauth2-provider/src/main/java/tech/ydb/auth/OAuth2TokenExchangeProvider.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@ public static Builder fromFile(File configFile) {
184184
configFile = expandUserHomeDir(configFile);
185185
try (BufferedReader br = new BufferedReader(new FileReader(configFile))) {
186186
JsonConfig cfg = GSON.fromJson(br, JsonConfig.class);
187+
if (cfg == null) {
188+
throw new RuntimeException("Empty config");
189+
}
187190

188191
if (cfg.getTokenEndpoint() != null) {
189192
builder.withTokenEndpoint(cfg.getTokenEndpoint());
@@ -312,6 +315,9 @@ private Token updateToken() throws IOException {
312315

313316
try (Reader reader = new InputStreamReader(response.getEntity().getContent())) {
314317
OAuth2Response json = GSON.fromJson(reader, OAuth2Response.class);
318+
if (json == null) {
319+
throw new UnexpectedResultException("Empty OAuth2 response", Status.of(StatusCode.INTERNAL_ERROR));
320+
}
315321

316322
if (!"Bearer".equalsIgnoreCase(json.getTokenType())) {
317323
throw new UnexpectedResultException(

0 commit comments

Comments
 (0)