Conversion from AccessToken to OAuthUserInfo
Minor refactoring extrating the common parts of
converting an access token to user info and
retrieving the display name.
Change-Id: Id5635601cafa6198208017620f6b47b36a90e3b6
Signed-off-by: Michael Ochmann <michael.ochmann@sap.com>
diff --git a/src/main/java/com/googlesource/gerrit/plugins/cfoauth/CFOAuthService.java b/src/main/java/com/googlesource/gerrit/plugins/cfoauth/CFOAuthService.java
index 23968a2..4569a18 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/cfoauth/CFOAuthService.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/cfoauth/CFOAuthService.java
@@ -76,10 +76,7 @@
if (token == null) {
throw new UAAClientException("Must provide an access token");
}
- AccessToken accessToken = uaaClient.toAccessToken(token.getToken());
- UserInfo userInfo = accessToken.getUserInfo();
- userInfo.setDisplayName(uaaClient.getDisplayName(token.getToken()));
- return getAsOAuthUserInfo(userInfo);
+ return getAsOAuthUserInfo(uaaClient.toAccessToken(token.getToken()));
}
@Override
@@ -111,10 +108,7 @@
// token; if that succeeds the user is authenticated
accessToken = uaaClient.getAccessToken(username, secret);
}
- UserInfo userInfo = accessToken.getUserInfo();
- userInfo.setDisplayName(
- uaaClient.getDisplayName(accessToken.getValue()));
- return getAsOAuthUserInfo(userInfo);
+ return getAsOAuthUserInfo(accessToken);
}
} catch (UAAClientException e) {
throw new IOException("Authentication error", e);
@@ -135,7 +129,10 @@
return new OAuthToken(accessToken.getValue(), null, null);
}
- private static OAuthUserInfo getAsOAuthUserInfo(UserInfo userInfo) {
+ private OAuthUserInfo getAsOAuthUserInfo(AccessToken accessToken) {
+ UserInfo userInfo = accessToken.getUserInfo();
+ userInfo.setDisplayName(
+ uaaClient.getDisplayName(accessToken.getValue()));
return new OAuthUserInfo(userInfo.getExternalId(),
userInfo.getUserName(), userInfo.getEmailAddress(),
userInfo.getDisplayName(), null);