-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert 'KnownUsers' to Java (#3799)
- Loading branch information
1 parent
8c15926
commit 3857edc
Showing
3 changed files
with
48 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 0 additions & 31 deletions
31
src/main/groovy/io/jenkins/infra/repository_permissions_updater/KnownUsers.groovy
This file was deleted.
Oops, something went wrong.
43 changes: 43 additions & 0 deletions
43
src/main/java/io/jenkins/infra/repository_permissions_updater/KnownUsers.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package io.jenkins.infra.repository_permissions_updater; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.net.URL; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.Set; | ||
import java.util.TreeSet; | ||
import com.google.gson.Gson; | ||
import com.google.gson.reflect.TypeToken; | ||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; | ||
|
||
public class KnownUsers { | ||
private static final String ARTIFACTORY_USER_NAMES_URL = System.getProperty("artifactoryUserNamesJsonListUrl", "https://reports.jenkins.io/artifactory-ldap-users-report.json"); | ||
private static final String JIRA_USER_NAMES_URL = System.getProperty("jiraUserNamesJsonListUrl", "https://reports.jenkins.io/jira-users-report.json"); | ||
|
||
private static Set<String> knownArtifactoryUsers = new TreeSet<>(String.CASE_INSENSITIVE_ORDER); | ||
private static Set<String> knownJiraUsers = new TreeSet<>(String.CASE_INSENSITIVE_ORDER); | ||
|
||
static { | ||
try { | ||
knownArtifactoryUsers.addAll(parseJson(new URL(ARTIFACTORY_USER_NAMES_URL))); | ||
knownJiraUsers.addAll(parseJson(new URL(JIRA_USER_NAMES_URL))); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
@SuppressFBWarnings(value = "URLCONNECTION_SSRF_FD", justification = "Not relevant in this situation.") | ||
private static Set<String> parseJson(URL url) throws IOException { | ||
try (InputStreamReader reader = new InputStreamReader(url.openStream(), StandardCharsets.UTF_8)) { | ||
return new Gson().fromJson(reader, new TypeToken<Set<String>>(){}.getType()); | ||
} | ||
} | ||
|
||
public static boolean existsInArtifactory(String username) { | ||
return knownArtifactoryUsers.contains(username); | ||
} | ||
|
||
public static boolean existsInJira(String username) { | ||
return knownJiraUsers.contains(username); | ||
} | ||
} |