private static PermissionEntry[] getUserPermissions(UserRealm userRealm, String path)
throws UserStoreException {
Map <String, PermissionEntry> userPermissionMap = new HashMap <String, PermissionEntry>();
AuthorizationManager authorizer = userRealm.getAuthorizationManager();
RealmConfiguration realmConfig = userRealm.getRealmConfiguration();
String systemUserName = CarbonConstants.REGISTRY_SYSTEM_USERNAME;
String adminUserName = realmConfig.getAdminUserName();
String[] raUsers = authorizer.getExplicitlyAllowedUsersForResource(path, ActionConstants.GET);
for (String raUser : raUsers) {
if (raUser.equals(systemUserName) || raUser.equals(adminUserName)) {
continue;
}
if (userPermissionMap.containsKey(raUser)) {
PermissionEntry permission = userPermissionMap.get(raUser);
permission.setReadAllow(true);
} else {
PermissionEntry permission = new PermissionEntry();
permission.setUserName(raUser);
permission.setReadAllow(true);
userPermissionMap.put(raUser, permission);
}
}
String[] rdUsers = authorizer.getExplicitlyDeniedUsersForResource(path, ActionConstants.GET);
for (String rdUser : rdUsers) {
if (rdUser.equals(systemUserName) || rdUser.equals(adminUserName)) {
continue;
}
if (userPermissionMap.containsKey(rdUser)) {
PermissionEntry permission = userPermissionMap.get(rdUser);
permission.setReadDeny(true);
} else {
PermissionEntry permission = new PermissionEntry();
permission.setUserName(rdUser);
permission.setReadDeny(true);
userPermissionMap.put(rdUser, permission);
}
}
String[] waUsers = authorizer.getExplicitlyAllowedUsersForResource(path, ActionConstants.PUT);
for (String waUser : waUsers) {
if (waUser.equals(systemUserName) || waUser.equals(adminUserName)) {
continue;
}
if (userPermissionMap.containsKey(waUser)) {
PermissionEntry permission = userPermissionMap.get(waUser);
permission.setWriteAllow(true);
} else {
PermissionEntry permission = new PermissionEntry();
permission.setUserName(waUser);
permission.setWriteAllow(true);
userPermissionMap.put(waUser, permission);
}
}
String[] wdUsers = authorizer.getExplicitlyDeniedUsersForResource(path, ActionConstants.PUT);
for (String wdUser : wdUsers) {
if (wdUser.equals(systemUserName) || wdUser.equals(adminUserName)) {
continue;
}
if (userPermissionMap.containsKey(wdUser)) {
PermissionEntry permission = userPermissionMap.get(wdUser);
permission.setWriteDeny(true);
} else {
PermissionEntry permission = new PermissionEntry();
permission.setUserName(wdUser);
permission.setWriteDeny(true);
userPermissionMap.put(wdUser, permission);
}
}
String[] daUsers = authorizer.getExplicitlyAllowedUsersForResource(path, ActionConstants.DELETE);
for (String daUser : daUsers) {
if (daUser.equals(systemUserName) || daUser.equals(adminUserName)) {
continue;
}
if (userPermissionMap.containsKey(daUser)) {
PermissionEntry permission = userPermissionMap.get(daUser);
permission.setDeleteAllow(true);
} else {
PermissionEntry permission = new PermissionEntry();
permission.setUserName(daUser);
permission.setDeleteAllow(true);
userPermissionMap.put(daUser, permission);
}
}
String[] ddUsers = authorizer.getExplicitlyDeniedUsersForResource(path, ActionConstants.DELETE);
for (String ddUser : ddUsers) {
if (ddUser.equals(systemUserName) || ddUser.equals(adminUserName)) {
continue;
}
if (userPermissionMap.containsKey(ddUser)) {
PermissionEntry permission = userPermissionMap.get(ddUser);
permission.setDeleteDeny(true);
} else {
PermissionEntry permission = new PermissionEntry();
permission.setUserName(ddUser);
permission.setDeleteDeny(true);
userPermissionMap.put(ddUser, permission);
}
}
String[] aaUsers = authorizer.
getExplicitlyAllowedUsersForResource(path, AccessControlConstants.AUTHORIZE);
for (String aaUser : aaUsers) {
if (aaUser.equals(systemUserName) || aaUser.equals(adminUserName)) {
continue;
}
if (userPermissionMap.containsKey(aaUser)) {
PermissionEntry permission = userPermissionMap.get(aaUser);
permission.setAuthorizeAllow(true);
} else {
PermissionEntry permission = new PermissionEntry();
permission.setUserName(aaUser);
permission.setAuthorizeAllow(true);
userPermissionMap.put(aaUser, permission);
}
}
String[] adUsers = authorizer.
getExplicitlyDeniedUsersForResource(path, AccessControlConstants.AUTHORIZE);
for (String adUser : adUsers) {
if (adUser.equals(systemUserName) || adUser.equals(adminUserName)) {
continue;
}