From e408d500379c5ec629cbae4a8a2375aadc2f9d11 Mon Sep 17 00:00:00 2001 From: milanperera Date: Fri, 2 Oct 2015 17:07:57 +0530 Subject: [PATCH] Refactored permission module --- .../device/mgt/core/config/permission/PermissionTree.java | 7 ++++--- .../framework/authorizer/PermissionAuthorizer.java | 4 +++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/permission/PermissionTree.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/permission/PermissionTree.java index 4017ae059b4..d74ae1505c5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/permission/PermissionTree.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/permission/PermissionTree.java @@ -30,10 +30,11 @@ public class PermissionTree { private PermissionNode rootNode; private static final String DYNAMIC_PATH_NOTATION = "*"; + private static final String ROOT = "/"; private static final Log log = LogFactory.getLog(PermissionTree.class); public PermissionTree() { - rootNode = new PermissionNode("/"); // initializing the root node. + rootNode = new PermissionNode(ROOT); // initializing the root node. } /** @@ -44,7 +45,7 @@ public class PermissionTree { * @param permission Permission object. */ public void addPermission(Permission permission) { - StringTokenizer st = new StringTokenizer(permission.getUrl(), "/"); + StringTokenizer st = new StringTokenizer(permission.getUrl(), ROOT); PermissionNode tempRoot = rootNode; PermissionNode tempChild; while (st.hasMoreTokens()) { @@ -84,7 +85,7 @@ public class PermissionTree { * no any permission that is stored with respected to the given request path. */ public Permission getPermission(String url, String httpMethod) { - StringTokenizer st = new StringTokenizer(url, "/"); + StringTokenizer st = new StringTokenizer(url, ROOT); PermissionNode tempRoot = rootNode; while (st.hasMoreTokens()) { String currentToken = st.nextToken(); diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authorizer/PermissionAuthorizer.java b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authorizer/PermissionAuthorizer.java index 530f5ea5ec2..469b085e20c 100644 --- a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authorizer/PermissionAuthorizer.java +++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authorizer/PermissionAuthorizer.java @@ -26,6 +26,7 @@ import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.device.mgt.core.config.permission.Permission; import org.wso2.carbon.device.mgt.core.config.permission.PermissionManager; import org.wso2.carbon.user.api.UserStoreException; +import org.wso2.carbon.webapp.authenticator.framework.Constants; import org.wso2.carbon.webapp.authenticator.framework.authenticator.WebappAuthenticator; import java.util.StringTokenizer; @@ -68,7 +69,8 @@ public class PermissionAuthorizer { boolean isUserAuthorized; try { isUserAuthorized = CarbonContext.getThreadLocalCarbonContext().getUserRealm(). - getAuthorizationManager().isUserAuthorized(username, permissionString, "read"); + getAuthorizationManager().isUserAuthorized(username, permissionString, + Constants.PermissionMethod.READ); } catch (UserStoreException e) { log.error("Error occurred while retrieving user store. " + e.getMessage()); return WebappAuthenticator.Status.FAILURE;