forked from bimberlabinternal/LabDevKitModules
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCustomPermissionsTable.java
More file actions
70 lines (61 loc) · 2.6 KB
/
CustomPermissionsTable.java
File metadata and controls
70 lines (61 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
* Copyright (c) 2014-2019 LabKey Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.labkey.api.ldk.table;
import org.jetbrains.annotations.NotNull;
import org.labkey.api.data.ContainerFilter;
import org.labkey.api.data.TableInfo;
import org.labkey.api.query.SimpleUserSchema;
import org.labkey.api.query.UserSchema;
import org.labkey.api.security.UserPrincipal;
import org.labkey.api.security.permissions.Permission;
import java.util.HashMap;
import java.util.Map;
/**
* The goal is to allow a table to specify an additional permission which is required at insert/update/delete.
* Table permissions are checked by calling hasPermission(), which tests for a specific Permission, such as InsertPermission, or UpdatePermission.
* You are able to map an addition permission to any of these, which the user must also have. Because InsertPermission and UpdatePermission are checked upstream anyway,
* the user must also have these permissions. This is just a way of enforcing more refined security, but not completely changing security.
*/
public class CustomPermissionsTable<SchemaType extends UserSchema> extends SimpleUserSchema.SimpleTable<SchemaType>
{
private final Map<Class<? extends Permission>, Class<? extends Permission>> _permMap = new HashMap<>();
public CustomPermissionsTable(SchemaType schema, TableInfo table, ContainerFilter cf)
{
super(schema, table, cf);
}
@Override
public CustomPermissionsTable<SchemaType> init()
{
return (CustomPermissionsTable<SchemaType>)super.init();
}
@Override
public boolean hasPermission(@NotNull UserPrincipal user, @NotNull Class<? extends Permission> perm)
{
if (!_userSchema.getContainer().hasPermission(user, perm))
{
return false;
}
if (_permMap.containsKey(perm))
{
return _userSchema.getContainer().hasPermission(user, _permMap.get(perm));
}
return true;
}
public void addPermissionMapping(Class<? extends Permission> perm1, Class<? extends Permission> perm2)
{
_permMap.put(perm1, perm2);
}
}