Refactored permission module

revert-70aa11f8
milanperera 9 years ago
parent a0187b905b
commit e408d50037

@ -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();

@ -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;

Loading…
Cancel
Save