-
Notifications
You must be signed in to change notification settings - Fork 59
/
ObjId2FullSidMap.java
56 lines (48 loc) · 1.73 KB
/
ObjId2FullSidMap.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package com.microsoft.jenkins.azuread;
import java.util.HashMap;
public class ObjId2FullSidMap extends HashMap<String, String> {
public void putFullSid(String fullSid) {
String objectId = extractObjectId(fullSid);
if (objectId != null) {
put(objectId, fullSid);
}
}
public String getOrOriginal(String objectId) {
if (containsKey(objectId)) {
return get(objectId);
}
String extractedObjectId = extractObjectId(objectId);
if (containsKey(extractedObjectId)) {
return get(extractedObjectId);
}
String objValuesPrefix = objectId + " (";
for (String value : values()) {
if (value.startsWith(objValuesPrefix)) {
return value;
}
}
return objectId;
}
static String extractObjectId(String fullSid) {
// full sid should be in the form of "<username> (<object_id>)".
// this code previously used regex: (.*) \((.*)\), which was shown to be a CPU hotspot in certain
// Jenkins installations
if (fullSid.isEmpty()) {
return null;
}
if (fullSid.charAt(fullSid.length() - 1) != ')') {
return null;
}
int openingParenthesesPosition = fullSid.lastIndexOf('(');
if (openingParenthesesPosition <= 0) {
return null;
}
if (fullSid.charAt(openingParenthesesPosition - 1) != ' ') {
return null;
}
return fullSid.substring(openingParenthesesPosition + 1, fullSid.length() - 1);
}
static String generateFullSid(final String displayName, final String objectId) {
return String.format("%s (%s)", displayName, objectId);
}
}