From 37f67f7b66f80b735c86d3ebaac7787a2a8dbdb6 Mon Sep 17 00:00:00 2001 From: Denisas Date: Wed, 2 Feb 2022 11:37:01 +0200 Subject: [PATCH] bug fix: delegation token deserialization --- .../lighter/backend/yarn/YarnBackend.java | 4 ++- .../lighter/backend/yarn/resources/Token.java | 28 +++++++++++++------ server/src/main/resources/logback.xml | 2 -- .../backend/yarn/resources/TokenTest.groovy | 25 +++++++++++++++++ 4 files changed, 47 insertions(+), 12 deletions(-) create mode 100644 server/src/test/groovy/com/exacaster/lighter/backend/yarn/resources/TokenTest.groovy diff --git a/server/src/main/java/com/exacaster/lighter/backend/yarn/YarnBackend.java b/server/src/main/java/com/exacaster/lighter/backend/yarn/YarnBackend.java index 536c9be2..99440023 100644 --- a/server/src/main/java/com/exacaster/lighter/backend/yarn/YarnBackend.java +++ b/server/src/main/java/com/exacaster/lighter/backend/yarn/YarnBackend.java @@ -9,6 +9,7 @@ import com.exacaster.lighter.backend.Backend; import com.exacaster.lighter.backend.yarn.resources.State; import com.exacaster.lighter.backend.yarn.resources.Token; +import com.exacaster.lighter.backend.yarn.resources.Token.TokenWrapper; import com.exacaster.lighter.backend.yarn.resources.YarnApplication; import com.exacaster.lighter.backend.yarn.resources.YarnApplicationListResponse; import com.exacaster.lighter.backend.yarn.resources.YarnApplicationResponse; @@ -97,7 +98,8 @@ public void kill(Application application) { private Optional getToken() { return kerberosRestTemplate .map(it -> it.getForObject(yarnProperties.getTokenUrl() + TOKEN_ENDPOINT, Token.class)) - .map(Token::getToken); + .map(Token::getTokenWrapper) + .map(TokenWrapper::getToken); } @Override diff --git a/server/src/main/java/com/exacaster/lighter/backend/yarn/resources/Token.java b/server/src/main/java/com/exacaster/lighter/backend/yarn/resources/Token.java index 7f7b3967..9d2bead6 100644 --- a/server/src/main/java/com/exacaster/lighter/backend/yarn/resources/Token.java +++ b/server/src/main/java/com/exacaster/lighter/backend/yarn/resources/Token.java @@ -3,22 +3,32 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonRootName; -import io.micronaut.core.annotation.Introspected; import io.micronaut.core.annotation.Nullable; -@Introspected @JsonIgnoreProperties(ignoreUnknown = true) -@JsonRootName("Token") public class Token { - private final String token; + private final TokenWrapper tokenWrapper; @JsonCreator - public Token(@Nullable @JsonProperty("urlString") String token) { - this.token = token; + public Token(@Nullable @JsonProperty("Token") TokenWrapper tokenWrapper) { + this.tokenWrapper = tokenWrapper; } - public String getToken() { - return token; + public TokenWrapper getTokenWrapper() { + return tokenWrapper; + } + + @JsonIgnoreProperties(ignoreUnknown = true) + public static class TokenWrapper { + private final String token; + + @JsonCreator + public TokenWrapper(@Nullable @JsonProperty("urlString") String token) { + this.token = token; + } + + public String getToken() { + return token; + } } } diff --git a/server/src/main/resources/logback.xml b/server/src/main/resources/logback.xml index 257fa82f..d4c7222d 100644 --- a/server/src/main/resources/logback.xml +++ b/server/src/main/resources/logback.xml @@ -5,8 +5,6 @@ - - diff --git a/server/src/test/groovy/com/exacaster/lighter/backend/yarn/resources/TokenTest.groovy b/server/src/test/groovy/com/exacaster/lighter/backend/yarn/resources/TokenTest.groovy new file mode 100644 index 00000000..1dd36562 --- /dev/null +++ b/server/src/test/groovy/com/exacaster/lighter/backend/yarn/resources/TokenTest.groovy @@ -0,0 +1,25 @@ +package com.exacaster.lighter.backend.yarn.resources + +import com.fasterxml.jackson.databind.ObjectMapper +import spock.lang.Specification + +class TokenTest extends Specification { + + def "deserialize token"() { + given: + def token = ''' + { + "Token": { + "urlString": "KQAJZXhhY2FzdGVyB2xpZ2h0ZXIAigF-uY9SkIoBft2b1pCNODxOjgJxFDKUzUCmoGSSlWPLpH4UD2uHgDyXEldFQkhERlMgZGVsZWdhdGlvbhIxOTIuMTY4LjQwLjQxOjgwMjA" + } + } + ''' + + when: + def result = new ObjectMapper().readValue(token, Token.class) + + then: + result.getTokenWrapper() != null + result.getTokenWrapper().getToken() != null + } +}