From 5b3a8091ecae8e2525cfb21561461f6c7dc1c8c5 Mon Sep 17 00:00:00 2001 From: ayyoob Date: Thu, 12 Jan 2017 23:18:54 +0530 Subject: [PATCH] fixed Null pointer exception --- .../lifecycle/util/AnnotationProcessor.java | 6 +++++- .../config/permission/AnnotationProcessor.java | 15 +++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) 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 0e7aa9cb0ea..2c2f21f19c8 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 @@ -74,6 +74,7 @@ public class AnnotationProcessor { private static final String SWAGGER_ANNOTATIONS_PROPERTIES_VALUE = "value"; private static final String ANNOTATIONS_SCOPES = "scopes"; private static final String ANNOTATIONS_SCOPE = "scope"; + private static final String DEFAULT_SCOPE_NAME = "default admin scope"; private static final String DEFAULT_SCOPE_KEY = "perm:admin"; private static final String DEFAULT_SCOPE_PERMISSION = "/permision/device-mgt"; @@ -280,8 +281,11 @@ public class AnnotationProcessor { if (scope != null) { resource.setScope(scope); } else { - log.error("Scope is not defined for '" + makeContextURLReady(resourceRootContext) + + log.warn("Scope is not defined for '" + makeContextURLReady(resourceRootContext) + makeContextURLReady(subCtx) + "' endpoint, hence assigning the default scope"); + scope = new Scope(); + scope.setName(DEFAULT_SCOPE_NAME); + scope.setDescription(DEFAULT_SCOPE_NAME); scope.setKey(DEFAULT_SCOPE_KEY); scope.setRoles(DEFAULT_SCOPE_PERMISSION); resource.setScope(scope); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/permission/AnnotationProcessor.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/permission/AnnotationProcessor.java index ec4c9442439..1fae1c525e1 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/permission/AnnotationProcessor.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/permission/AnnotationProcessor.java @@ -71,7 +71,8 @@ public class AnnotationProcessor { private static final String SWAGGER_ANNOTATIONS_PROPERTIES_PERMISSIONS = "permissions"; private static final String ANNOTATIONS_SCOPES = "scopes"; private static final String ANNOTATIONS_SCOPE = "scope"; - + private static final String DEFAULT_PERM_NAME = "default"; + private static final String DEFAULT_PERM = "/device-mgt"; private static final String PERMISSION_PREFIX = "/permission/admin"; private StandardContext context; @@ -392,9 +393,15 @@ public class AnnotationProcessor { .getMethod(SWAGGER_ANNOTATIONS_PROPERTIES_VALUE, null), null); if (!scopeKey.isEmpty()) { scope = apiScopes.get(scopeKey); - permission.setName(scope.getName()); - //TODO: currently permission tree supports only adding one permission per API point. - permission.setPath(scope.getRoles().split(" ")[0]); + if (scope != null) { + permission.setName(scope.getName()); + //TODO: currently permission tree supports only adding one permission per API point. + permission.setPath(scope.getRoles().split(" ")[0]); + } else { + log.warn("No Scope mapping is done for scope key: " + scopeKey); + permission.setName(DEFAULT_PERM_NAME); + permission.setPath(DEFAULT_PERM); + } } } }