APIPublisherUtil { public static void setResourceAuthTypes(ServletContext servletContext, APIConfig apiConfig) { List<String> resourcesList = null; String nonSecuredResources = servletContext.getInitParameter(NON_SECURED_RESOURCES); if(null != nonSecuredResources){ resourcesList = Arrays.asList(nonSecuredResources.split(",")); } Set<ApiUriTemplate> templates = apiConfig.getUriTemplates(); if(null != resourcesList) { for (ApiUriTemplate template : templates) { String fullPaath = ""; if (!template.getUriTemplate().equals(AnnotationProcessor.WILD_CARD)) { fullPaath = apiConfig.getContext() + template.getUriTemplate(); } else{ fullPaath = apiConfig.getContext(); } for(String context : resourcesList) { if (context.trim().equals(fullPaath)) { template.setAuthType(AUTH_TYPE_NON_SECURED); } } } } apiConfig.setUriTemplates(templates); }  static String getServerBaseUrl(); static String getApiEndpointUrl(String context); static APIConfig buildApiConfig(ServletContext servletContext, APIResourceConfiguration apiDef); static String getSwaggerDefinition(APIConfig apiConfig); static void setResourceAuthTypes(ServletContext servletContext, APIConfig apiConfig); static final String API_VERSION_PARAM; }
@Test(description = "test method for setResourceAuthTypes") public void testSetResourceAuthTypes() throws UserStoreException { ServletContext servletContext = new MockServletContext(); APIResourceConfiguration apiDef = new APIResourceConfiguration(); List<APIResource> resources = new ArrayList<>(); apiDef.setResources(resources); APIConfig apiConfig = buildApiConfig(servletContext, apiDef); apiConfig.setContext("/*"); TestUtils util = new TestUtils(); util.setAPIURITemplates(apiConfig, "/*"); Assert.assertNotNull(apiConfig, "API configuration is null."); setResourceAuthTypes(servletContext, apiConfig); Set<ApiUriTemplate> templates = apiConfig.getUriTemplates(); Assert.assertEquals(templates.iterator().next().getAuthType(), AUTH_TYPE_NON_SECURED, "Resource " + "auth type is not properly set"); }