in commit-status-publisher-server/src/main/java/jetbrains/buildServer/commitPublisher/tfs/TfsPublisherSettings.java [145:202]
public PropertiesProcessor getParametersProcessor(@NotNull BuildTypeIdentity buildTypeOrTemplate) {
return new PropertiesProcessor() {
private boolean checkNotEmpty(@NotNull final Map<String, String> properties,
@NotNull final String key,
@NotNull final String message,
@NotNull final Collection<InvalidProperty> res) {
if (isEmpty(properties, key)) {
res.add(new InvalidProperty(key, message));
return true;
}
return false;
}
private boolean isEmpty(@NotNull final Map<String, String> properties,
@NotNull final String key) {
return StringUtil.isEmptyOrSpaces(properties.get(key));
}
@NotNull
public Collection<InvalidProperty> process(@Nullable final Map<String, String> p) {
final Collection<InvalidProperty> result = new ArrayList<InvalidProperty>();
if (p == null) return result;
String authType = p.getOrDefault(TfsConstants.AUTHENTICATION_TYPE, TfsConstants.AUTH_TYPE_TOKEN);
if (TfsConstants.AUTH_TYPE_TOKEN.equals(authType)) {
//PAT token was set via magic button
final String authUsername = p.get(TfsConstants.AUTH_USER);
final String authProviderId = p.get(TfsConstants.AUTH_PROVIDER_ID);
if (authUsername != null && authProviderId != null) {
final User currentUser = mySecurityContext.getAuthorityHolder().getAssociatedUser();
if (currentUser != null && currentUser instanceof SUser) {
for (OAuthToken token : myOAuthTokensStorage.getUserTokens(authProviderId, (SUser)currentUser, buildTypeOrTemplate.getProject(), false)) {
if (token.getOauthLogin().equals(authUsername)) {
p.put(TfsConstants.ACCESS_TOKEN, token.getAccessToken());
p.remove(TfsConstants.AUTH_USER);
p.remove(TfsConstants.AUTH_PROVIDER_ID);
}
}
}
}
checkNotEmpty(p, TfsConstants.ACCESS_TOKEN, "Personal Access Token must be specified", result);
p.remove(TfsConstants.TOKEN_ID);
} else if (TfsConstants.AUTH_TYPE_STORED_TOKEN.equals(authType)) {
checkNotEmpty(p, TfsConstants.TOKEN_ID, "No token configured", result);
p.remove(TfsConstants.ACCESS_TOKEN);
p.remove(TfsConstants.AUTH_USER);
p.remove(TfsConstants.AUTH_PROVIDER_ID);
} else {
result.add(new InvalidProperty(TfsConstants.AUTHENTICATION_TYPE, "Unsupported authentication type"));
}
return result;
}
};
}