Changed auth type on API resources as configured in web.xml

4.x.x
Joseph Fonseka 8 years ago
parent 78c413c1ba
commit a5640f48b5

@ -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.APIResource;
import org.wso2.carbon.apimgt.webapp.publisher.config.APIResourceConfiguration; 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.config.WebappPublisherConfig;
import org.wso2.carbon.apimgt.webapp.publisher.lifecycle.util.AnnotationProcessor;
import org.wso2.carbon.base.MultitenantConstants; import org.wso2.carbon.base.MultitenantConstants;
import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.core.util.Utils; 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_SHARED_WITH_ALL_TENANTS = "isSharedWithAllTenants";
private static final String PARAM_PROVIDER_TENANT_DOMAIN = "providerTenantDomain"; 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 { public static API getAPI(APIConfig config) throws APIManagementException {
@ -313,4 +317,29 @@ public class APIPublisherUtil {
return apiConfig; return apiConfig;
} }
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<URITemplate> 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);
}
}
}
}
}
} }

@ -69,6 +69,7 @@ public class APIPublisherLifecycleListener implements LifecycleListener {
annotatedSwaggerAPIClasses); annotatedSwaggerAPIClasses);
for (APIResourceConfiguration apiDefinition : apiDefinitions) { for (APIResourceConfiguration apiDefinition : apiDefinitions) {
APIConfig apiConfig = APIPublisherUtil.buildApiConfig(servletContext, apiDefinition); APIConfig apiConfig = APIPublisherUtil.buildApiConfig(servletContext, apiDefinition);
APIPublisherUtil.setResourceAuthTypes(servletContext,apiConfig);
try { try {
int tenantId = APIPublisherDataHolder.getInstance().getTenantManager(). int tenantId = APIPublisherDataHolder.getInstance().getTenantManager().
getTenantId(apiConfig.getTenantDomain()); getTenantId(apiConfig.getTenantDomain());

@ -51,7 +51,7 @@ public class AnnotationProcessor {
private static final String PACKAGE_ORG_APACHE = "org.apache"; private static final String PACKAGE_ORG_APACHE = "org.apache";
private static final String PACKAGE_ORG_CODEHAUS = "org.codehaus"; private static final String PACKAGE_ORG_CODEHAUS = "org.codehaus";
private static final String PACKAGE_ORG_SPRINGFRAMEWORK = "org.springframework"; 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_INFO = "info";
private static final String SWAGGER_ANNOTATIONS_TAGS = "tags"; private static final String SWAGGER_ANNOTATIONS_TAGS = "tags";

Loading…
Cancel
Save