diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherUtil.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherUtil.java index a4afb01808b..8ae3c531c19 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherUtil.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherUtil.java @@ -28,6 +28,7 @@ import org.wso2.carbon.apimgt.impl.utils.APIUtil; import org.wso2.carbon.apimgt.webapp.publisher.config.APIResource; import org.wso2.carbon.apimgt.webapp.publisher.config.APIResourceConfiguration; import org.wso2.carbon.apimgt.webapp.publisher.config.WebappPublisherConfig; +import org.wso2.carbon.apimgt.webapp.publisher.lifecycle.util.AnnotationProcessor; import org.wso2.carbon.base.MultitenantConstants; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.core.util.Utils; @@ -51,6 +52,9 @@ public class APIPublisherUtil { private static final String PARAM_SHARED_WITH_ALL_TENANTS = "isSharedWithAllTenants"; private static final String PARAM_PROVIDER_TENANT_DOMAIN = "providerTenantDomain"; + private static final String NON_SECURED_RESOURCES = "nonSecuredEndPoints"; + private static final String AUTH_TYPE_NON_SECURED = "None"; + public static API getAPI(APIConfig config) throws APIManagementException { @@ -313,4 +317,29 @@ public class APIPublisherUtil { return apiConfig; } + + public static void setResourceAuthTypes(ServletContext servletContext, APIConfig apiConfig) { + List resourcesList = null; + String nonSecuredResources = servletContext.getInitParameter(NON_SECURED_RESOURCES); + if(null != nonSecuredResources){ + resourcesList = Arrays.asList(nonSecuredResources.split(",")); + } + Set templates = apiConfig.getUriTemplates(); + if(null != resourcesList) { + for (URITemplate template : templates) { + String fullPaath = ""; + if( template.getUriTemplate() != 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); + } + } + } + } + } } diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/listener/APIPublisherLifecycleListener.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/listener/APIPublisherLifecycleListener.java index f9a28ee41d4..adf73f0d17b 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/listener/APIPublisherLifecycleListener.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/listener/APIPublisherLifecycleListener.java @@ -69,6 +69,7 @@ public class APIPublisherLifecycleListener implements LifecycleListener { annotatedSwaggerAPIClasses); for (APIResourceConfiguration apiDefinition : apiDefinitions) { APIConfig apiConfig = APIPublisherUtil.buildApiConfig(servletContext, apiDefinition); + APIPublisherUtil.setResourceAuthTypes(servletContext,apiConfig); try { int tenantId = APIPublisherDataHolder.getInstance().getTenantManager(). getTenantId(apiConfig.getTenantDomain()); diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/util/AnnotationProcessor.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/util/AnnotationProcessor.java index b820a4426fc..c967039259a 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/util/AnnotationProcessor.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/util/AnnotationProcessor.java @@ -51,7 +51,7 @@ public class AnnotationProcessor { private static final String PACKAGE_ORG_APACHE = "org.apache"; private static final String PACKAGE_ORG_CODEHAUS = "org.codehaus"; private static final String PACKAGE_ORG_SPRINGFRAMEWORK = "org.springframework"; - private static final String WILD_CARD = "/*"; + public static final String WILD_CARD = "/*"; private static final String SWAGGER_ANNOTATIONS_INFO = "info"; private static final String SWAGGER_ANNOTATIONS_TAGS = "tags";