@Test public void test_getIdOfTheSprintUser_success() throws Exception { String userEmail = "testuser@sprint.com"; Response response = new Response(); response.setHttpstatus(HttpStatus.OK); response.setSuccess(true); response.setResponse(null); when(httpUtils.getHttpClient()).thenReturn(httpClient); when(httpClient.execute(any())).thenReturn(httpResponse); when(httpResponse.getStatusLine()).thenReturn(statusLine); when(statusLine.getStatusCode()).thenReturn(200); when(httpResponse.getEntity()).thenReturn(mockHttpEntity); String userIdResponseString = "{\"id\": \"abcdefg\", \"onPremisesSyncEnabled\":null, \"displayName\":\"testgroup1\"}"; when(mockHttpEntity.getContent()).thenReturn(new ByteArrayInputStream(userIdResponseString.getBytes())); ReflectionTestUtils.setField(oidcUtil, "ssoGetUserEndpoint", "testgroupurl"); ReflectionTestUtils.setField(oidcUtil, "sprintMailTailText", "sprint.com"); String userId = oidcUtil.getIdOfTheUser("testssotoken", userEmail); assertEquals("abcdefg", userId); }
public String getIdOfTheUser(String accessToken, String userEmail) { String userId = null; JsonParser jsonParser = new JsonParser(); HttpClient httpClient = httpUtils.getHttpClient(); if (httpClient == null) { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder() .put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)) .put(LogMessage.ACTION, SSLCertificateConstants.GET_ID_USER_STRING) .put(LogMessage.MESSAGE, "Failed to initialize httpClient") .put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).build())); return null; } String filterSearch = ""; if (userEmail.toLowerCase().endsWith(sprintMailTailText)) { filterSearch = "?$filter=startsWith%28mail%2C'" + userEmail + "'%29"; } else { filterSearch = userEmail; } String api = ssoGetUserEndpoint + filterSearch; HttpGet getRequest = new HttpGet(api); getRequest.addHeader("Authorization", "Bearer " + accessToken); StringBuilder jsonResponse = new StringBuilder(); try { HttpResponse apiResponse = httpClient.execute(getRequest); if (apiResponse.getStatusLine().getStatusCode() == 200) { userId = parseAndGetIdFromAADResponse(userId, jsonParser, jsonResponse, apiResponse); log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder() .put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)) .put(LogMessage.ACTION, SSLCertificateConstants.GET_ID_USER_STRING) .put(LogMessage.MESSAGE, String.format("Retrieved %s user id from AAD", userId)) .put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).build())); return userId; } log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder() .put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)) .put(LogMessage.ACTION, SSLCertificateConstants.GET_ID_USER_STRING) .put(LogMessage.MESSAGE, "Failed to retrieve user id from AAD") .put(LogMessage.STATUS, String.valueOf(apiResponse.getStatusLine().getStatusCode())) .put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).build())); } catch (IOException e) { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder() .put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)) .put(LogMessage.ACTION, SSLCertificateConstants.GET_ID_USER_STRING) .put(LogMessage.MESSAGE, "Failed to parse AAD user api response") .put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).build())); } return userId; }
OIDCUtil { public String getIdOfTheUser(String accessToken, String userEmail) { String userId = null; JsonParser jsonParser = new JsonParser(); HttpClient httpClient = httpUtils.getHttpClient(); if (httpClient == null) { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder() .put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)) .put(LogMessage.ACTION, SSLCertificateConstants.GET_ID_USER_STRING) .put(LogMessage.MESSAGE, "Failed to initialize httpClient") .put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).build())); return null; } String filterSearch = ""; if (userEmail.toLowerCase().endsWith(sprintMailTailText)) { filterSearch = "?$filter=startsWith%28mail%2C'" + userEmail + "'%29"; } else { filterSearch = userEmail; } String api = ssoGetUserEndpoint + filterSearch; HttpGet getRequest = new HttpGet(api); getRequest.addHeader("Authorization", "Bearer " + accessToken); StringBuilder jsonResponse = new StringBuilder(); try { HttpResponse apiResponse = httpClient.execute(getRequest); if (apiResponse.getStatusLine().getStatusCode() == 200) { userId = parseAndGetIdFromAADResponse(userId, jsonParser, jsonResponse, apiResponse); log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder() .put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)) .put(LogMessage.ACTION, SSLCertificateConstants.GET_ID_USER_STRING) .put(LogMessage.MESSAGE, String.format("Retrieved %s user id from AAD", userId)) .put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).build())); return userId; } log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder() .put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)) .put(LogMessage.ACTION, SSLCertificateConstants.GET_ID_USER_STRING) .put(LogMessage.MESSAGE, "Failed to retrieve user id from AAD") .put(LogMessage.STATUS, String.valueOf(apiResponse.getStatusLine().getStatusCode())) .put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).build())); } catch (IOException e) { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder() .put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)) .put(LogMessage.ACTION, SSLCertificateConstants.GET_ID_USER_STRING) .put(LogMessage.MESSAGE, "Failed to parse AAD user api response") .put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).build())); } return userId; } }
OIDCUtil { public String getIdOfTheUser(String accessToken, String userEmail) { String userId = null; JsonParser jsonParser = new JsonParser(); HttpClient httpClient = httpUtils.getHttpClient(); if (httpClient == null) { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder() .put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)) .put(LogMessage.ACTION, SSLCertificateConstants.GET_ID_USER_STRING) .put(LogMessage.MESSAGE, "Failed to initialize httpClient") .put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).build())); return null; } String filterSearch = ""; if (userEmail.toLowerCase().endsWith(sprintMailTailText)) { filterSearch = "?$filter=startsWith%28mail%2C'" + userEmail + "'%29"; } else { filterSearch = userEmail; } String api = ssoGetUserEndpoint + filterSearch; HttpGet getRequest = new HttpGet(api); getRequest.addHeader("Authorization", "Bearer " + accessToken); StringBuilder jsonResponse = new StringBuilder(); try { HttpResponse apiResponse = httpClient.execute(getRequest); if (apiResponse.getStatusLine().getStatusCode() == 200) { userId = parseAndGetIdFromAADResponse(userId, jsonParser, jsonResponse, apiResponse); log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder() .put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)) .put(LogMessage.ACTION, SSLCertificateConstants.GET_ID_USER_STRING) .put(LogMessage.MESSAGE, String.format("Retrieved %s user id from AAD", userId)) .put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).build())); return userId; } log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder() .put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)) .put(LogMessage.ACTION, SSLCertificateConstants.GET_ID_USER_STRING) .put(LogMessage.MESSAGE, "Failed to retrieve user id from AAD") .put(LogMessage.STATUS, String.valueOf(apiResponse.getStatusLine().getStatusCode())) .put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).build())); } catch (IOException e) { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder() .put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)) .put(LogMessage.ACTION, SSLCertificateConstants.GET_ID_USER_STRING) .put(LogMessage.MESSAGE, "Failed to parse AAD user api response") .put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).build())); } return userId; } OIDCUtil(); }
OIDCUtil { public String getIdOfTheUser(String accessToken, String userEmail) { String userId = null; JsonParser jsonParser = new JsonParser(); HttpClient httpClient = httpUtils.getHttpClient(); if (httpClient == null) { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder() .put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)) .put(LogMessage.ACTION, SSLCertificateConstants.GET_ID_USER_STRING) .put(LogMessage.MESSAGE, "Failed to initialize httpClient") .put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).build())); return null; } String filterSearch = ""; if (userEmail.toLowerCase().endsWith(sprintMailTailText)) { filterSearch = "?$filter=startsWith%28mail%2C'" + userEmail + "'%29"; } else { filterSearch = userEmail; } String api = ssoGetUserEndpoint + filterSearch; HttpGet getRequest = new HttpGet(api); getRequest.addHeader("Authorization", "Bearer " + accessToken); StringBuilder jsonResponse = new StringBuilder(); try { HttpResponse apiResponse = httpClient.execute(getRequest); if (apiResponse.getStatusLine().getStatusCode() == 200) { userId = parseAndGetIdFromAADResponse(userId, jsonParser, jsonResponse, apiResponse); log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder() .put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)) .put(LogMessage.ACTION, SSLCertificateConstants.GET_ID_USER_STRING) .put(LogMessage.MESSAGE, String.format("Retrieved %s user id from AAD", userId)) .put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).build())); return userId; } log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder() .put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)) .put(LogMessage.ACTION, SSLCertificateConstants.GET_ID_USER_STRING) .put(LogMessage.MESSAGE, "Failed to retrieve user id from AAD") .put(LogMessage.STATUS, String.valueOf(apiResponse.getStatusLine().getStatusCode())) .put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).build())); } catch (IOException e) { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder() .put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)) .put(LogMessage.ACTION, SSLCertificateConstants.GET_ID_USER_STRING) .put(LogMessage.MESSAGE, "Failed to parse AAD user api response") .put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).build())); } return userId; } OIDCUtil(); String fetchMountAccessorForOidc(String token); OIDCEntityResponse getEntityLookUpResponse(String authMountResponse); Response updateGroupPolicies(String token, String groupName, List<String> policies,
			List<String> currentPolicies, String id); Response deleteGroupByName(String token, String name); OIDCGroup getIdentityGroupDetails(String groupName, String token); String getSSOToken(); String getGroupObjectResponse(String ssoToken, String groupName); String updateIdentityGroupByName(String token, OIDCIdentityGroupRequest oidcIdentityGroupRequest); Response createGroupAlias(String token, GroupAliasRequest groupAliasRequest); ResponseEntity<OIDCEntityResponse> oidcFetchEntityDetails(String token, String username, UserDetails userDetails); ResponseEntity<OIDCEntityResponse> entityLookUp(String token,
			OIDCLookupEntityRequest oidcLookupEntityRequest); Response deleteGroupAliasByID(String token, String id); Response updateOIDCEntity(List<String> policies, String entityName); Response updateEntityByName(String token, OIDCEntityRequest oidcEntityRequest); void renewUserToken(String token); List<String> getPoliciedFromTokenLookUp(String authMountResponse); List<String> tokenLookUp(String token); Response createEntityAlias(String token, OidcEntityAliasRequest oidcEntityAliasRequest); String getUserName(String email); List<DirectoryGroup> getGroupsFromAAD(String ssoToken, String groupName); String getIdOfTheUser(String accessToken, String userEmail); List<String> getSelfServiceGroupsFromAADById(String accessToken, String userAADId, String userName); }
OIDCUtil { public String getIdOfTheUser(String accessToken, String userEmail) { String userId = null; JsonParser jsonParser = new JsonParser(); HttpClient httpClient = httpUtils.getHttpClient(); if (httpClient == null) { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder() .put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)) .put(LogMessage.ACTION, SSLCertificateConstants.GET_ID_USER_STRING) .put(LogMessage.MESSAGE, "Failed to initialize httpClient") .put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).build())); return null; } String filterSearch = ""; if (userEmail.toLowerCase().endsWith(sprintMailTailText)) { filterSearch = "?$filter=startsWith%28mail%2C'" + userEmail + "'%29"; } else { filterSearch = userEmail; } String api = ssoGetUserEndpoint + filterSearch; HttpGet getRequest = new HttpGet(api); getRequest.addHeader("Authorization", "Bearer " + accessToken); StringBuilder jsonResponse = new StringBuilder(); try { HttpResponse apiResponse = httpClient.execute(getRequest); if (apiResponse.getStatusLine().getStatusCode() == 200) { userId = parseAndGetIdFromAADResponse(userId, jsonParser, jsonResponse, apiResponse); log.debug(JSONUtil.getJSON(ImmutableMap.<String, String>builder() .put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)) .put(LogMessage.ACTION, SSLCertificateConstants.GET_ID_USER_STRING) .put(LogMessage.MESSAGE, String.format("Retrieved %s user id from AAD", userId)) .put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).build())); return userId; } log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder() .put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)) .put(LogMessage.ACTION, SSLCertificateConstants.GET_ID_USER_STRING) .put(LogMessage.MESSAGE, "Failed to retrieve user id from AAD") .put(LogMessage.STATUS, String.valueOf(apiResponse.getStatusLine().getStatusCode())) .put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).build())); } catch (IOException e) { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder() .put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)) .put(LogMessage.ACTION, SSLCertificateConstants.GET_ID_USER_STRING) .put(LogMessage.MESSAGE, "Failed to parse AAD user api response") .put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)).build())); } return userId; } OIDCUtil(); String fetchMountAccessorForOidc(String token); OIDCEntityResponse getEntityLookUpResponse(String authMountResponse); Response updateGroupPolicies(String token, String groupName, List<String> policies,
			List<String> currentPolicies, String id); Response deleteGroupByName(String token, String name); OIDCGroup getIdentityGroupDetails(String groupName, String token); String getSSOToken(); String getGroupObjectResponse(String ssoToken, String groupName); String updateIdentityGroupByName(String token, OIDCIdentityGroupRequest oidcIdentityGroupRequest); Response createGroupAlias(String token, GroupAliasRequest groupAliasRequest); ResponseEntity<OIDCEntityResponse> oidcFetchEntityDetails(String token, String username, UserDetails userDetails); ResponseEntity<OIDCEntityResponse> entityLookUp(String token,
			OIDCLookupEntityRequest oidcLookupEntityRequest); Response deleteGroupAliasByID(String token, String id); Response updateOIDCEntity(List<String> policies, String entityName); Response updateEntityByName(String token, OIDCEntityRequest oidcEntityRequest); void renewUserToken(String token); List<String> getPoliciedFromTokenLookUp(String authMountResponse); List<String> tokenLookUp(String token); Response createEntityAlias(String token, OidcEntityAliasRequest oidcEntityAliasRequest); String getUserName(String email); List<DirectoryGroup> getGroupsFromAAD(String ssoToken, String groupName); String getIdOfTheUser(String accessToken, String userEmail); List<String> getSelfServiceGroupsFromAADById(String accessToken, String userAADId, String userName); static final Logger log; }