diff --git a/src/main/java/com/microsoft/jenkins/azuread/ObjId2FullSidMap.java b/src/main/java/com/microsoft/jenkins/azuread/ObjId2FullSidMap.java index 92dbe017..fb5717e5 100644 --- a/src/main/java/com/microsoft/jenkins/azuread/ObjId2FullSidMap.java +++ b/src/main/java/com/microsoft/jenkins/azuread/ObjId2FullSidMap.java @@ -20,6 +20,10 @@ public String getOrOriginal(String objectId) { if (containsKey(objectId)) { return get(objectId); } + String extractedObjectId = extractObjectId(objectId); + if (containsKey(extractedObjectId)) { + return get(extractedObjectId); + } for (String value : values()) { if (value.startsWith(objectId + " (")) { return value; diff --git a/src/test/java/com/microsoft/jenkins/azuread/ObjId2FullSidMapTest.java b/src/test/java/com/microsoft/jenkins/azuread/ObjId2FullSidMapTest.java index 72af4ce8..300fb14b 100644 --- a/src/test/java/com/microsoft/jenkins/azuread/ObjId2FullSidMapTest.java +++ b/src/test/java/com/microsoft/jenkins/azuread/ObjId2FullSidMapTest.java @@ -5,14 +5,15 @@ public class ObjId2FullSidMapTest { - public static final String FULL_SID_1 = "Smith (00000000-00000000-00000000-00000000)"; + public static final String FULL_SID_1 = "Smith@test (00000000-00000000-00000000-00000000)"; + + public static final String EMAIL_1 = "Smith@test"; public static final String NAME_1 = "Smith"; public static final String OBJECT_ID_1 = "00000000-00000000-00000000-00000000"; @Test public void testFullSId() { - - final String fullSid = ObjId2FullSidMap.generateFullSid(NAME_1, OBJECT_ID_1); + final String fullSid = ObjId2FullSidMap.generateFullSid(EMAIL_1, OBJECT_ID_1); Assert.assertEquals(FULL_SID_1, fullSid); Assert.assertEquals(OBJECT_ID_1, ObjId2FullSidMap.extractObjectId(fullSid)); Assert.assertNull(ObjId2FullSidMap.extractObjectId("some string")); @@ -24,7 +25,8 @@ public void testPutAndGet() { map.putFullSid(FULL_SID_1); Assert.assertEquals(FULL_SID_1, map.get(OBJECT_ID_1)); Assert.assertEquals(FULL_SID_1, map.getOrOriginal(OBJECT_ID_1)); - Assert.assertEquals(FULL_SID_1, map.getOrOriginal(NAME_1)); + Assert.assertEquals(FULL_SID_1, map.getOrOriginal(EMAIL_1)); + Assert.assertEquals(FULL_SID_1, map.getOrOriginal(ObjId2FullSidMap.generateFullSid(NAME_1, OBJECT_ID_1))); Assert.assertEquals("some string", map.getOrOriginal("some string")); } }