|
|
@ -33,16 +33,17 @@ import java.util.StringTokenizer;
|
|
|
|
public class PermissionManager {
|
|
|
|
public class PermissionManager {
|
|
|
|
|
|
|
|
|
|
|
|
private static PermissionManager 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() {
|
|
|
|
public static PermissionManager getInstance() {
|
|
|
|
if (permissionManager == null) {
|
|
|
|
if (permissionManager == null) {
|
|
|
|
synchronized (PermissionManager.class) {
|
|
|
|
synchronized (PermissionManager.class) {
|
|
|
|
if (permissionManager == null) {
|
|
|
|
if (permissionManager == null) {
|
|
|
|
permissionManager = new PermissionManager();
|
|
|
|
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 {
|
|
|
|
public boolean addPermission(Permission permission) throws DeviceManagementException {
|
|
|
|
StringTokenizer st = new StringTokenizer(permission.getUrl(), "/");
|
|
|
|
permissionTree.addPermission(permission); // adding a permission to the tree
|
|
|
|
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
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
return PermissionUtils.putPermission(permission);
|
|
|
|
return PermissionUtils.putPermission(permission);
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
@ -81,7 +75,7 @@ public class PermissionManager {
|
|
|
|
Unmarshaller unmarshaller = cdmContext.createUnmarshaller();
|
|
|
|
Unmarshaller unmarshaller = cdmContext.createUnmarshaller();
|
|
|
|
PermissionConfiguration permissionConfiguration = (PermissionConfiguration)
|
|
|
|
PermissionConfiguration permissionConfiguration = (PermissionConfiguration)
|
|
|
|
unmarshaller.unmarshal(permissionStream);
|
|
|
|
unmarshaller.unmarshal(permissionStream);
|
|
|
|
if((permissionConfiguration != null) && (permissionConfiguration.getPermissions() != null)){
|
|
|
|
if (permissionConfiguration != null && permissionConfiguration.getPermissions() != null) {
|
|
|
|
this.addPermissions(permissionConfiguration.getPermissions());
|
|
|
|
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) {
|
|
|
|
public Permission getPermission(String url, String httpMethod) {
|
|
|
|
StringTokenizer st = new StringTokenizer(url, "/");
|
|
|
|
return permissionTree.getPermission(url, httpMethod);
|
|
|
|
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);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|