|
|
|
@ -33,16 +33,17 @@ import java.util.StringTokenizer;
|
|
|
|
|
public class PermissionManager {
|
|
|
|
|
|
|
|
|
|
private static PermissionManager permissionManager;
|
|
|
|
|
private static PermissionHolder rootNode;
|
|
|
|
|
private static PermissionTree permissionTree; // holds the permissions at runtime.
|
|
|
|
|
|
|
|
|
|
private PermissionManager(){};
|
|
|
|
|
private PermissionManager() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static PermissionManager getInstance() {
|
|
|
|
|
if (permissionManager == null) {
|
|
|
|
|
synchronized (PermissionManager.class) {
|
|
|
|
|
if (permissionManager == null) {
|
|
|
|
|
permissionManager = new PermissionManager();
|
|
|
|
|
rootNode = new PermissionHolder("/"); // initializing the root node.
|
|
|
|
|
permissionTree = new PermissionTree();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -50,14 +51,7 @@ public class PermissionManager {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean addPermission(Permission permission) throws DeviceManagementException {
|
|
|
|
|
StringTokenizer st = new StringTokenizer(permission.getUrl(), "/");
|
|
|
|
|
PermissionHolder tempRoot = rootNode;
|
|
|
|
|
PermissionHolder tempChild;
|
|
|
|
|
while(st.hasMoreTokens()) {
|
|
|
|
|
tempChild = new PermissionHolder(st.nextToken());
|
|
|
|
|
tempRoot = addPermissionNode(tempRoot, tempChild);
|
|
|
|
|
}
|
|
|
|
|
tempRoot.addPermission(permission.getMethod(), permission); //setting permission to the vertex
|
|
|
|
|
permissionTree.addPermission(permission); // adding a permission to the tree
|
|
|
|
|
try {
|
|
|
|
|
return PermissionUtils.putPermission(permission);
|
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
@ -81,7 +75,7 @@ public class PermissionManager {
|
|
|
|
|
Unmarshaller unmarshaller = cdmContext.createUnmarshaller();
|
|
|
|
|
PermissionConfiguration permissionConfiguration = (PermissionConfiguration)
|
|
|
|
|
unmarshaller.unmarshal(permissionStream);
|
|
|
|
|
if((permissionConfiguration != null) && (permissionConfiguration.getPermissions() != null)){
|
|
|
|
|
if (permissionConfiguration != null && permissionConfiguration.getPermissions() != null) {
|
|
|
|
|
this.addPermissions(permissionConfiguration.getPermissions());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -90,38 +84,7 @@ public class PermissionManager {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private PermissionHolder addPermissionNode(PermissionHolder parent, PermissionHolder child) {
|
|
|
|
|
PermissionHolder existChild = parent.getChild(child.getPathName());
|
|
|
|
|
if (existChild == null) {
|
|
|
|
|
parent.addChild(child);
|
|
|
|
|
return child;
|
|
|
|
|
}
|
|
|
|
|
return existChild;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Permission getPermission(String url, String httpMethod) {
|
|
|
|
|
StringTokenizer st = new StringTokenizer(url, "/");
|
|
|
|
|
PermissionHolder tempRoot = rootNode;
|
|
|
|
|
PermissionHolder previousRoot;
|
|
|
|
|
while (st.hasMoreTokens()) {
|
|
|
|
|
String currentToken = st.nextToken();
|
|
|
|
|
previousRoot = tempRoot;
|
|
|
|
|
tempRoot = tempRoot.getChild(currentToken);
|
|
|
|
|
if (tempRoot == null) {
|
|
|
|
|
tempRoot = previousRoot;
|
|
|
|
|
int leftTokens = st.countTokens();
|
|
|
|
|
for (int i = 0; i <= leftTokens; i++) {
|
|
|
|
|
if (tempRoot == null) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
tempRoot = tempRoot.getChild("*");
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (tempRoot == null) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return tempRoot.getPermission(httpMethod);
|
|
|
|
|
return permissionTree.getPermission(url, httpMethod);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|