Skip to content

Commit

Permalink
bug fix: delegation token deserialization
Browse files Browse the repository at this point in the history
  • Loading branch information
Denisas committed Feb 2, 2022
1 parent 4acfbe4 commit 37f67f7
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -97,7 +98,8 @@ public void kill(Application application) {
private Optional<String> getToken() {
return kerberosRestTemplate
.map(it -> it.getForObject(yarnProperties.getTokenUrl() + TOKEN_ENDPOINT, Token.class))
.map(Token::getToken);
.map(Token::getTokenWrapper)
.map(TokenWrapper::getToken);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
2 changes: 0 additions & 2 deletions server/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
</encoder>
</appender>

<logger name="io.micronaut.http.client" level="TRACE"/>

<root level="debug">
<appender-ref ref="STDOUT"/>
</root>
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit 37f67f7

Please sign in to comment.