cleaned up UsernamePasswordToken

Removed the caching of the token on the request context. Caching is now handled by the InternalAuthenticationService

Original commit: elastic/x-pack-elasticsearch@d60bc7af67
This commit is contained in:
uboness 2014-09-04 09:16:19 +02:00
parent 2aa52a3113
commit 5cc7d55568
3 changed files with 2 additions and 17 deletions

View File

@ -52,7 +52,7 @@ public class InternalAuthenticationService extends AbstractComponent implements
@Override
@SuppressWarnings("unchecked")
public AuthenticationToken token(String action, TransportMessage<?> message, AuthenticationToken defaultToken) {
AuthenticationToken token = (AuthenticationToken) message.getContext().get(TOKEN_CTX_KEY);
AuthenticationToken token = message.getFromContext(TOKEN_CTX_KEY);
if (token != null) {
return token;
}

View File

@ -49,17 +49,8 @@ public class UsernamePasswordToken implements AuthenticationToken {
}
public static UsernamePasswordToken extractToken(TransportMessage<?> message, UsernamePasswordToken defaultToken) {
UsernamePasswordToken token = (UsernamePasswordToken) message.getContext().get(TOKEN_KEY);
if (token != null) {
return token;
}
String authStr = message.getHeader(BASIC_AUTH_HEADER);
if (authStr == null) {
if (defaultToken == null) {
return null;
}
message.putInContext(TOKEN_KEY, defaultToken);
return defaultToken;
}
@ -73,9 +64,7 @@ public class UsernamePasswordToken implements AuthenticationToken {
if (i < 0) {
throw new AuthenticationException("Invalid basic authentication header value");
}
token = new UsernamePasswordToken(userpasswd.substring(0, i), userpasswd.substring(i+1).toCharArray());
message.putInContext(TOKEN_KEY, token);
return token;
return new UsernamePasswordToken(userpasswd.substring(0, i), userpasswd.substring(i+1).toCharArray());
}
public static void putTokenHeader(TransportRequest request, UsernamePasswordToken token) {

View File

@ -49,10 +49,6 @@ public class UsernamePasswordTokenTests extends ElasticsearchTestCase {
assertThat(token, notNullValue());
assertThat(token.principal(), equalTo("user1"));
assertThat(new String(token.credentials()), equalTo("test123"));
// making sure that indeed, once resolved the instance is reused across multiple resolve calls
UsernamePasswordToken token2 = UsernamePasswordToken.extractToken(request, null);
assertThat(token, is(token2));
}
@Test