如何解析 java 中的 /getusereffectivepermissions 共享点响应?
How to parse /getusereffectivepermissions sharepoint response in java?
我有这样的共享点请求:
/_api/web/getFolderByServerRelativeUrl('<folder-rel-url>')/ListItemAllFields/getusereffectivepermissions(@u)?@u='<account>'
回复如下:
<d:GetUserEffectivePermissions m:type="SP.BasePermissions">
<d:High m:type="Edm.Int64">176</d:High>
<d:Low m:type="Edm.Int64">138612833</d:Low>
</d:GetUserEffectivePermissions>
没看懂什么意思
我找到了几个如何解析它的代码示例,但是这段代码是用 javascript 编写的,并使用了特殊的 Object(SP.BasePermissions
)
function parseBasePermissions(value)
{
let permissions = new SP.BasePermissions();
permissions.initPropertiesFromJson(value);
let result = {};
for(var levelName in SP.PermissionKind.prototype) {
if (SP.PermissionKind.hasOwnProperty(levelName)) {
var permLevel = SP.PermissionKind.parse(levelName);
if(permissions.has(permLevel))
result[levelName] = true;
else
result[levelName] = false;
}
}
return result;
}
如何正确解析?我想知道用户是否可以读取该文件夹
关于:
I don't understand what does it mean.
SP.ListItem.getUserEffectivePermissions
method returns
A bitwise combination of enumeration values that specifies a set of
permissions.
该示例演示了如何解析 SP.BasePermissions
值并确定用户是否已被授予读取项目的权限:
BasePermissions permissions = new BasePermissions(138612833L,176L);
String[] roles = permissions.parse();
if(Arrays.asList(roles).contains("ViewListItems"))
System.out.println("User has permissions to read items");
其中 PermissionKind
和 BasePermissions
类 在某种程度上等同于 SharePoint Client SDK BasePermissions
and PermissionKind
类:
import java.util.ArrayList;
import java.util.List;
public class BasePermissions {
private final long low;
private final long high;
public BasePermissions(long low, long high) {
this.low = low;
this.high = high;
}
public String[] parse() {
List<String> result = new ArrayList<>();
for (PermissionKind value : PermissionKind.values()) {
if(has(value)){
result.add(value.toString());
}
}
return result.toArray(new String[0]);
}
public Boolean has(PermissionKind perm)
{
switch (perm)
{
case EmptyMask:
return true;
case FullMask:
if ((this.high & 32767) == 32767)
return this.low == 65535;
return false;
default:
long n = perm.getValue() - 1;
long val = 1;
if (n >= 0 && n < 32)
return 0 != (this.low & (val << n));
if (n >= 32 && n < 64)
return 0 != (this.high & (val << n - 32));
return false;
}
}
}
和
public enum PermissionKind {
EmptyMask(0),
ViewListItems(1),
AddListItems(2),
EditListItems(3),
DeleteListItems(4),
ApproveItems(5),
OpenItems(6),
ViewVersions(7),
DeleteVersions(8),
CancelCheckout(9),
ManagePersonalViews(10),
ManageLists(12),
ViewFormPages(13),
AnonymousSearchAccessList(14),
Open(17),
ViewPages(18),
AddAndCustomizePages(19),
ApplyThemeAndBorder(20),
ApplyStyleSheets(21),
ViewUsageData(22),
CreateSSCSite(23),
ManageSubwebs(24),
CreateGroups(25),
ManagePermissions(26),
BrowseDirectories(27),
BrowseUserInfo(28),
AddDelPrivateWebParts(29),
UpdatePersonalWebParts(30),
ManageWeb(31),
AnonymousSearchAccessWebLists(32),
UseClientIntegration(37),
UseRemoteAPIs(38),
ManageAlerts(39),
CreateAlerts(40),
EditMyUserInfo(41),
EnumeratePermissions(63),
FullMask(65);
PermissionKind(long value) {
this.value = value;
}
public long getValue() { return value; }
private final long value;
}
我有这样的共享点请求:
/_api/web/getFolderByServerRelativeUrl('<folder-rel-url>')/ListItemAllFields/getusereffectivepermissions(@u)?@u='<account>'
回复如下:
<d:GetUserEffectivePermissions m:type="SP.BasePermissions">
<d:High m:type="Edm.Int64">176</d:High>
<d:Low m:type="Edm.Int64">138612833</d:Low>
</d:GetUserEffectivePermissions>
没看懂什么意思
我找到了几个如何解析它的代码示例,但是这段代码是用 javascript 编写的,并使用了特殊的 Object(SP.BasePermissions
)
function parseBasePermissions(value)
{
let permissions = new SP.BasePermissions();
permissions.initPropertiesFromJson(value);
let result = {};
for(var levelName in SP.PermissionKind.prototype) {
if (SP.PermissionKind.hasOwnProperty(levelName)) {
var permLevel = SP.PermissionKind.parse(levelName);
if(permissions.has(permLevel))
result[levelName] = true;
else
result[levelName] = false;
}
}
return result;
}
如何正确解析?我想知道用户是否可以读取该文件夹
关于:
I don't understand what does it mean.
SP.ListItem.getUserEffectivePermissions
method returns
A bitwise combination of enumeration values that specifies a set of permissions.
该示例演示了如何解析 SP.BasePermissions
值并确定用户是否已被授予读取项目的权限:
BasePermissions permissions = new BasePermissions(138612833L,176L);
String[] roles = permissions.parse();
if(Arrays.asList(roles).contains("ViewListItems"))
System.out.println("User has permissions to read items");
其中 PermissionKind
和 BasePermissions
类 在某种程度上等同于 SharePoint Client SDK BasePermissions
and PermissionKind
类:
import java.util.ArrayList;
import java.util.List;
public class BasePermissions {
private final long low;
private final long high;
public BasePermissions(long low, long high) {
this.low = low;
this.high = high;
}
public String[] parse() {
List<String> result = new ArrayList<>();
for (PermissionKind value : PermissionKind.values()) {
if(has(value)){
result.add(value.toString());
}
}
return result.toArray(new String[0]);
}
public Boolean has(PermissionKind perm)
{
switch (perm)
{
case EmptyMask:
return true;
case FullMask:
if ((this.high & 32767) == 32767)
return this.low == 65535;
return false;
default:
long n = perm.getValue() - 1;
long val = 1;
if (n >= 0 && n < 32)
return 0 != (this.low & (val << n));
if (n >= 32 && n < 64)
return 0 != (this.high & (val << n - 32));
return false;
}
}
}
和
public enum PermissionKind {
EmptyMask(0),
ViewListItems(1),
AddListItems(2),
EditListItems(3),
DeleteListItems(4),
ApproveItems(5),
OpenItems(6),
ViewVersions(7),
DeleteVersions(8),
CancelCheckout(9),
ManagePersonalViews(10),
ManageLists(12),
ViewFormPages(13),
AnonymousSearchAccessList(14),
Open(17),
ViewPages(18),
AddAndCustomizePages(19),
ApplyThemeAndBorder(20),
ApplyStyleSheets(21),
ViewUsageData(22),
CreateSSCSite(23),
ManageSubwebs(24),
CreateGroups(25),
ManagePermissions(26),
BrowseDirectories(27),
BrowseUserInfo(28),
AddDelPrivateWebParts(29),
UpdatePersonalWebParts(30),
ManageWeb(31),
AnonymousSearchAccessWebLists(32),
UseClientIntegration(37),
UseRemoteAPIs(38),
ManageAlerts(39),
CreateAlerts(40),
EditMyUserInfo(41),
EnumeratePermissions(63),
FullMask(65);
PermissionKind(long value) {
this.value = value;
}
public long getValue() { return value; }
private final long value;
}