From cb02c9da80b977c528f54666974f43c67bea3f82 Mon Sep 17 00:00:00 2001 From: harshanl Date: Mon, 16 Nov 2015 11:43:52 +0530 Subject: [PATCH] Fixed issues in DeviceAuthorization --- .../DeviceAccessAuthorizationServiceImpl.java | 11 +++++------ .../framework/WebappAuthenticationValve.java | 2 -- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/authorization/DeviceAccessAuthorizationServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/authorization/DeviceAccessAuthorizationServiceImpl.java index bed880e72c..47f1a8024e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/authorization/DeviceAccessAuthorizationServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/authorization/DeviceAccessAuthorizationServiceImpl.java @@ -20,7 +20,7 @@ package org.wso2.carbon.device.mgt.core.authorization; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.device.mgt.common.*; import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException; import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationService; @@ -31,7 +31,6 @@ import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; import org.wso2.carbon.device.mgt.core.permission.mgt.PermissionUtils; import org.wso2.carbon.user.api.UserRealm; import org.wso2.carbon.user.api.UserStoreException; -import org.wso2.carbon.utils.multitenancy.MultitenantUtils; import java.util.HashMap; import java.util.List; @@ -223,9 +222,9 @@ public class DeviceAccessAuthorizationServiceImpl implements DeviceAccessAuthori } private String getUserName() { - String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); - if (username != null && username.isEmpty()) { - String tenantDomain = MultitenantUtils.getTenantDomain(username); + String username = CarbonContext.getThreadLocalCarbonContext().getUsername(); + if (username != null && !username.isEmpty()) { + String tenantDomain = CarbonContext.getThreadLocalCarbonContext().getTenantDomain(); if (username.endsWith(tenantDomain)) { return username.substring(0, username.lastIndexOf("@")); } @@ -235,7 +234,7 @@ public class DeviceAccessAuthorizationServiceImpl implements DeviceAccessAuthori } private int getTenantId() { - return PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); + return CarbonContext.getThreadLocalCarbonContext().getTenantId(); } private boolean addAdminPermissionToRegistry() throws PermissionManagementException { diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticationValve.java b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticationValve.java index d2be75ca18..25ef416506 100644 --- a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticationValve.java +++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/WebappAuthenticationValve.java @@ -28,9 +28,7 @@ import org.wso2.carbon.tomcat.ext.valves.CompositeValve; import org.wso2.carbon.webapp.authenticator.framework.authenticator.WebappAuthenticator; import javax.servlet.http.HttpServletResponse; -import java.util.Arrays; import java.util.HashMap; -import java.util.List; import java.util.StringTokenizer; public class WebappAuthenticationValve extends CarbonTomcatValve {