mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Refactored permission module
This commit is contained in:
parent
a0187b905b
commit
e408d50037
@ -30,10 +30,11 @@ public class PermissionTree {
|
|||||||
|
|
||||||
private PermissionNode rootNode;
|
private PermissionNode rootNode;
|
||||||
private static final String DYNAMIC_PATH_NOTATION = "*";
|
private static final String DYNAMIC_PATH_NOTATION = "*";
|
||||||
|
private static final String ROOT = "/";
|
||||||
private static final Log log = LogFactory.getLog(PermissionTree.class);
|
private static final Log log = LogFactory.getLog(PermissionTree.class);
|
||||||
|
|
||||||
public PermissionTree() {
|
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.
|
* @param permission Permission object.
|
||||||
*/
|
*/
|
||||||
public void addPermission(Permission permission) {
|
public void addPermission(Permission permission) {
|
||||||
StringTokenizer st = new StringTokenizer(permission.getUrl(), "/");
|
StringTokenizer st = new StringTokenizer(permission.getUrl(), ROOT);
|
||||||
PermissionNode tempRoot = rootNode;
|
PermissionNode tempRoot = rootNode;
|
||||||
PermissionNode tempChild;
|
PermissionNode tempChild;
|
||||||
while (st.hasMoreTokens()) {
|
while (st.hasMoreTokens()) {
|
||||||
@ -84,7 +85,7 @@ public class PermissionTree {
|
|||||||
* no any permission that is stored with respected to the given request path.
|
* no any permission that is stored with respected to the given request path.
|
||||||
*/
|
*/
|
||||||
public Permission getPermission(String url, String httpMethod) {
|
public Permission getPermission(String url, String httpMethod) {
|
||||||
StringTokenizer st = new StringTokenizer(url, "/");
|
StringTokenizer st = new StringTokenizer(url, ROOT);
|
||||||
PermissionNode tempRoot = rootNode;
|
PermissionNode tempRoot = rootNode;
|
||||||
while (st.hasMoreTokens()) {
|
while (st.hasMoreTokens()) {
|
||||||
String currentToken = st.nextToken();
|
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.Permission;
|
||||||
import org.wso2.carbon.device.mgt.core.config.permission.PermissionManager;
|
import org.wso2.carbon.device.mgt.core.config.permission.PermissionManager;
|
||||||
import org.wso2.carbon.user.api.UserStoreException;
|
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 org.wso2.carbon.webapp.authenticator.framework.authenticator.WebappAuthenticator;
|
||||||
|
|
||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
@ -68,7 +69,8 @@ public class PermissionAuthorizer {
|
|||||||
boolean isUserAuthorized;
|
boolean isUserAuthorized;
|
||||||
try {
|
try {
|
||||||
isUserAuthorized = CarbonContext.getThreadLocalCarbonContext().getUserRealm().
|
isUserAuthorized = CarbonContext.getThreadLocalCarbonContext().getUserRealm().
|
||||||
getAuthorizationManager().isUserAuthorized(username, permissionString, "read");
|
getAuthorizationManager().isUserAuthorized(username, permissionString,
|
||||||
|
Constants.PermissionMethod.READ);
|
||||||
} catch (UserStoreException e) {
|
} catch (UserStoreException e) {
|
||||||
log.error("Error occurred while retrieving user store. " + e.getMessage());
|
log.error("Error occurred while retrieving user store. " + e.getMessage());
|
||||||
return WebappAuthenticator.Status.FAILURE;
|
return WebappAuthenticator.Status.FAILURE;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user