Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug fix: delegation token deserialization #19

Merged
merged 1 commit into from
Feb 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}