@Test public void test_getGroupObjectResponse_404() throws Exception { String group = "group1"; String token = "test4ig8L3EpsJZSLAMg"; 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 groupResponseString = "{\"value\": [ ]}"; when(mockHttpEntity.getContent()).thenReturn( new ByteArrayInputStream(groupResponseString.getBytes())); ReflectionTestUtils.setField(oidcUtil, "ssoGroupsEndpoint", "testgroupurl"); String actualResponse = oidcUtil.getGroupObjectResponse(token, group); assertEquals(null, actualResponse); }
public String getGroupObjectResponse(String ssoToken, String groupName) { JsonParser jsonParser = new JsonParser(); HttpClient httpClient = httpUtils.getHttpClient(); String groupObjectId = null; if (httpClient == null) { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)). put(LogMessage.ACTION, "getGroupObjectResponse"). put(LogMessage.MESSAGE, "Failed to initialize httpClient"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)). build())); return null; } String filterSearch = "$filter=displayName%20eq%20'"+groupName+"'"; String api = ssoGroupsEndpoint + filterSearch; HttpGet getRequest = new HttpGet(api); getRequest.addHeader("accept", TVaultConstants.HTTP_CONTENT_TYPE_JSON); getRequest.addHeader("Authorization", "Bearer " + ssoToken); String output = ""; StringBuilder jsonResponse = new StringBuilder(); try { HttpResponse apiResponse = httpClient.execute(getRequest); if (apiResponse.getStatusLine().getStatusCode() != 200) { return null; } BufferedReader br = new BufferedReader(new InputStreamReader((apiResponse.getEntity().getContent()))); while ((output = br.readLine()) != null) { jsonResponse.append(output); } JsonObject responseJson = (JsonObject) jsonParser.parse(jsonResponse.toString()); if (responseJson != null && responseJson.has("value")) { JsonArray vaulesArray = responseJson.get("value").getAsJsonArray(); if (vaulesArray.size() > 0) { String cloudGroupId = null; String onPremGroupId = null; for (int i=0;i<vaulesArray.size();i++) { JsonObject adObject = vaulesArray.get(i).getAsJsonObject(); if (adObject.has("onPremisesSyncEnabled")) { if (adObject.get("onPremisesSyncEnabled").isJsonNull()) { cloudGroupId = adObject.get("id").getAsString(); break; } else if (adObject.get("onPremisesSyncEnabled").getAsBoolean()) { onPremGroupId = adObject.get("id").getAsString(); } } } groupObjectId = (cloudGroupId!=null)?cloudGroupId:onPremGroupId; if (groupObjectId == null) { JsonObject adObject = vaulesArray.get(0).getAsJsonObject(); groupObjectId = adObject.get("id").getAsString(); } } } return groupObjectId; } catch (IOException e) { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)). put(LogMessage.ACTION, "getGroupObjectResponse"). put(LogMessage.MESSAGE, "Failed to parse group object api response"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)). build())); } return null; }
OIDCUtil { public String getGroupObjectResponse(String ssoToken, String groupName) { JsonParser jsonParser = new JsonParser(); HttpClient httpClient = httpUtils.getHttpClient(); String groupObjectId = null; if (httpClient == null) { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)). put(LogMessage.ACTION, "getGroupObjectResponse"). put(LogMessage.MESSAGE, "Failed to initialize httpClient"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)). build())); return null; } String filterSearch = "$filter=displayName%20eq%20'"+groupName+"'"; String api = ssoGroupsEndpoint + filterSearch; HttpGet getRequest = new HttpGet(api); getRequest.addHeader("accept", TVaultConstants.HTTP_CONTENT_TYPE_JSON); getRequest.addHeader("Authorization", "Bearer " + ssoToken); String output = ""; StringBuilder jsonResponse = new StringBuilder(); try { HttpResponse apiResponse = httpClient.execute(getRequest); if (apiResponse.getStatusLine().getStatusCode() != 200) { return null; } BufferedReader br = new BufferedReader(new InputStreamReader((apiResponse.getEntity().getContent()))); while ((output = br.readLine()) != null) { jsonResponse.append(output); } JsonObject responseJson = (JsonObject) jsonParser.parse(jsonResponse.toString()); if (responseJson != null && responseJson.has("value")) { JsonArray vaulesArray = responseJson.get("value").getAsJsonArray(); if (vaulesArray.size() > 0) { String cloudGroupId = null; String onPremGroupId = null; for (int i=0;i<vaulesArray.size();i++) { JsonObject adObject = vaulesArray.get(i).getAsJsonObject(); if (adObject.has("onPremisesSyncEnabled")) { if (adObject.get("onPremisesSyncEnabled").isJsonNull()) { cloudGroupId = adObject.get("id").getAsString(); break; } else if (adObject.get("onPremisesSyncEnabled").getAsBoolean()) { onPremGroupId = adObject.get("id").getAsString(); } } } groupObjectId = (cloudGroupId!=null)?cloudGroupId:onPremGroupId; if (groupObjectId == null) { JsonObject adObject = vaulesArray.get(0).getAsJsonObject(); groupObjectId = adObject.get("id").getAsString(); } } } return groupObjectId; } catch (IOException e) { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)). put(LogMessage.ACTION, "getGroupObjectResponse"). put(LogMessage.MESSAGE, "Failed to parse group object api response"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)). build())); } return null; } }
OIDCUtil { public String getGroupObjectResponse(String ssoToken, String groupName) { JsonParser jsonParser = new JsonParser(); HttpClient httpClient = httpUtils.getHttpClient(); String groupObjectId = null; if (httpClient == null) { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)). put(LogMessage.ACTION, "getGroupObjectResponse"). put(LogMessage.MESSAGE, "Failed to initialize httpClient"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)). build())); return null; } String filterSearch = "$filter=displayName%20eq%20'"+groupName+"'"; String api = ssoGroupsEndpoint + filterSearch; HttpGet getRequest = new HttpGet(api); getRequest.addHeader("accept", TVaultConstants.HTTP_CONTENT_TYPE_JSON); getRequest.addHeader("Authorization", "Bearer " + ssoToken); String output = ""; StringBuilder jsonResponse = new StringBuilder(); try { HttpResponse apiResponse = httpClient.execute(getRequest); if (apiResponse.getStatusLine().getStatusCode() != 200) { return null; } BufferedReader br = new BufferedReader(new InputStreamReader((apiResponse.getEntity().getContent()))); while ((output = br.readLine()) != null) { jsonResponse.append(output); } JsonObject responseJson = (JsonObject) jsonParser.parse(jsonResponse.toString()); if (responseJson != null && responseJson.has("value")) { JsonArray vaulesArray = responseJson.get("value").getAsJsonArray(); if (vaulesArray.size() > 0) { String cloudGroupId = null; String onPremGroupId = null; for (int i=0;i<vaulesArray.size();i++) { JsonObject adObject = vaulesArray.get(i).getAsJsonObject(); if (adObject.has("onPremisesSyncEnabled")) { if (adObject.get("onPremisesSyncEnabled").isJsonNull()) { cloudGroupId = adObject.get("id").getAsString(); break; } else if (adObject.get("onPremisesSyncEnabled").getAsBoolean()) { onPremGroupId = adObject.get("id").getAsString(); } } } groupObjectId = (cloudGroupId!=null)?cloudGroupId:onPremGroupId; if (groupObjectId == null) { JsonObject adObject = vaulesArray.get(0).getAsJsonObject(); groupObjectId = adObject.get("id").getAsString(); } } } return groupObjectId; } catch (IOException e) { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)). put(LogMessage.ACTION, "getGroupObjectResponse"). put(LogMessage.MESSAGE, "Failed to parse group object api response"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)). build())); } return null; } OIDCUtil(); }
OIDCUtil { public String getGroupObjectResponse(String ssoToken, String groupName) { JsonParser jsonParser = new JsonParser(); HttpClient httpClient = httpUtils.getHttpClient(); String groupObjectId = null; if (httpClient == null) { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)). put(LogMessage.ACTION, "getGroupObjectResponse"). put(LogMessage.MESSAGE, "Failed to initialize httpClient"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)). build())); return null; } String filterSearch = "$filter=displayName%20eq%20'"+groupName+"'"; String api = ssoGroupsEndpoint + filterSearch; HttpGet getRequest = new HttpGet(api); getRequest.addHeader("accept", TVaultConstants.HTTP_CONTENT_TYPE_JSON); getRequest.addHeader("Authorization", "Bearer " + ssoToken); String output = ""; StringBuilder jsonResponse = new StringBuilder(); try { HttpResponse apiResponse = httpClient.execute(getRequest); if (apiResponse.getStatusLine().getStatusCode() != 200) { return null; } BufferedReader br = new BufferedReader(new InputStreamReader((apiResponse.getEntity().getContent()))); while ((output = br.readLine()) != null) { jsonResponse.append(output); } JsonObject responseJson = (JsonObject) jsonParser.parse(jsonResponse.toString()); if (responseJson != null && responseJson.has("value")) { JsonArray vaulesArray = responseJson.get("value").getAsJsonArray(); if (vaulesArray.size() > 0) { String cloudGroupId = null; String onPremGroupId = null; for (int i=0;i<vaulesArray.size();i++) { JsonObject adObject = vaulesArray.get(i).getAsJsonObject(); if (adObject.has("onPremisesSyncEnabled")) { if (adObject.get("onPremisesSyncEnabled").isJsonNull()) { cloudGroupId = adObject.get("id").getAsString(); break; } else if (adObject.get("onPremisesSyncEnabled").getAsBoolean()) { onPremGroupId = adObject.get("id").getAsString(); } } } groupObjectId = (cloudGroupId!=null)?cloudGroupId:onPremGroupId; if (groupObjectId == null) { JsonObject adObject = vaulesArray.get(0).getAsJsonObject(); groupObjectId = adObject.get("id").getAsString(); } } } return groupObjectId; } catch (IOException e) { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)). put(LogMessage.ACTION, "getGroupObjectResponse"). put(LogMessage.MESSAGE, "Failed to parse group object api response"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)). build())); } return null; } 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 getGroupObjectResponse(String ssoToken, String groupName) { JsonParser jsonParser = new JsonParser(); HttpClient httpClient = httpUtils.getHttpClient(); String groupObjectId = null; if (httpClient == null) { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)). put(LogMessage.ACTION, "getGroupObjectResponse"). put(LogMessage.MESSAGE, "Failed to initialize httpClient"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)). build())); return null; } String filterSearch = "$filter=displayName%20eq%20'"+groupName+"'"; String api = ssoGroupsEndpoint + filterSearch; HttpGet getRequest = new HttpGet(api); getRequest.addHeader("accept", TVaultConstants.HTTP_CONTENT_TYPE_JSON); getRequest.addHeader("Authorization", "Bearer " + ssoToken); String output = ""; StringBuilder jsonResponse = new StringBuilder(); try { HttpResponse apiResponse = httpClient.execute(getRequest); if (apiResponse.getStatusLine().getStatusCode() != 200) { return null; } BufferedReader br = new BufferedReader(new InputStreamReader((apiResponse.getEntity().getContent()))); while ((output = br.readLine()) != null) { jsonResponse.append(output); } JsonObject responseJson = (JsonObject) jsonParser.parse(jsonResponse.toString()); if (responseJson != null && responseJson.has("value")) { JsonArray vaulesArray = responseJson.get("value").getAsJsonArray(); if (vaulesArray.size() > 0) { String cloudGroupId = null; String onPremGroupId = null; for (int i=0;i<vaulesArray.size();i++) { JsonObject adObject = vaulesArray.get(i).getAsJsonObject(); if (adObject.has("onPremisesSyncEnabled")) { if (adObject.get("onPremisesSyncEnabled").isJsonNull()) { cloudGroupId = adObject.get("id").getAsString(); break; } else if (adObject.get("onPremisesSyncEnabled").getAsBoolean()) { onPremGroupId = adObject.get("id").getAsString(); } } } groupObjectId = (cloudGroupId!=null)?cloudGroupId:onPremGroupId; if (groupObjectId == null) { JsonObject adObject = vaulesArray.get(0).getAsJsonObject(); groupObjectId = adObject.get("id").getAsString(); } } } return groupObjectId; } catch (IOException e) { log.error(JSONUtil.getJSON(ImmutableMap.<String, String>builder(). put(LogMessage.USER, ThreadLocalContext.getCurrentMap().get(LogMessage.USER)). put(LogMessage.ACTION, "getGroupObjectResponse"). put(LogMessage.MESSAGE, "Failed to parse group object api response"). put(LogMessage.APIURL, ThreadLocalContext.getCurrentMap().get(LogMessage.APIURL)). build())); } return null; } 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; }