Skip to content

Commit d339e79

Browse files
committed
feat(Security): Wire in new authorisation
Initial pass to configure the authorisation at runtime Jira: MSG-158
1 parent 90b81ac commit d339e79

23 files changed

+210
-920
lines changed

PROTOCOLS.md

Lines changed: 0 additions & 174 deletions
This file was deleted.

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@
145145
<!-- Second level dependencies -->
146146
<maps.storage.version>2.5.2-SNAPSHOT</maps.storage.version>
147147
<maps.device.version>3.0.1-SNAPSHOT</maps.device.version>
148-
<maps.auth.version>2.0.2-SNAPSHOT</maps.auth.version>
148+
<maps.auth.version>3.0.0-SNAPSHOT</maps.auth.version>
149149

150150

151151
</properties>

src/main/java/io/mapsmessaging/auth/AuthManager.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
import io.mapsmessaging.security.access.Group;
3535
import io.mapsmessaging.security.access.Identity;
3636
import io.mapsmessaging.security.access.mapping.GroupIdMap;
37+
import io.mapsmessaging.security.authorisation.Permission;
38+
import io.mapsmessaging.security.authorisation.ProtectedResource;
3739
import io.mapsmessaging.security.identity.IdentityLookupFactory;
3840
import io.mapsmessaging.security.identity.principals.UniqueIdentifierPrincipal;
3941
import io.mapsmessaging.utilities.Agent;
@@ -169,6 +171,29 @@ public SessionPrivileges getQuota(UUID userId) {
169171
return null;
170172
}
171173

174+
175+
public boolean canAccess(Identity identity, Permission permission, ProtectedResource resource) {
176+
return authenticationStorage.canAccess(identity, permission, resource);
177+
}
178+
179+
public void grant(Identity identity, Permission permission, ProtectedResource resource) {
180+
authenticationStorage.grant(identity, permission, resource);
181+
}
182+
183+
public void grant(Group group, Permission permission, ProtectedResource resource) {
184+
authenticationStorage.grant(group, permission, resource);
185+
}
186+
187+
public void revoke(Identity identity, Permission permission, ProtectedResource resource) {
188+
authenticationStorage.revoke(identity, permission, resource);
189+
}
190+
191+
public void revoke(Group group, Permission permission, ProtectedResource resource) {
192+
authenticationStorage.revoke(group, permission, resource);
193+
}
194+
195+
196+
172197
private AuthManager() {
173198
logger = LoggerFactory.getLogger(AuthManager.class);
174199
config = ConfigurationManager.getInstance().getConfiguration(AuthManagerConfig.class);
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
*
3+
* Copyright [ 2020 - 2024 ] Matthew Buckton
4+
* Copyright [ 2024 - 2025 ] MapsMessaging B.V.
5+
*
6+
* Licensed under the Apache License, Version 2.0 with the Commons Clause
7+
* (the "License"); you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at:
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
* https://commonsclause.com/
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
package io.mapsmessaging.auth;
21+
22+
23+
import io.mapsmessaging.security.authorisation.Permission;
24+
import lombok.Getter;
25+
26+
@Getter
27+
public enum ServerPermissions implements Permission {
28+
29+
READ("read", "Allows Read access to the resource", 0),
30+
WRITE("write", "Allows Write access to the resource", 1),
31+
DELETE("delete", "Allows Delete access to the resource", 2),
32+
CREATE("create", "Allows Create access to the resource", 3),
33+
SUBSCRIBE("subscribe", "Allows Subscription access to the topic", 4),
34+
PUBLISH("publish", "Allows Publish access to the topic", 5),
35+
PUBLISH_RETAINED("retain", "Allows Retain access to the topic", 6),
36+
CONNECT("connect", "allows user to connect", 7),
37+
MANAGE("manage", "allows user to manage resource", 8)
38+
;
39+
40+
private final String name;
41+
private final String description;
42+
private final long mask;
43+
44+
ServerPermissions(final String name, final String description, final long mask) {
45+
this.name = name;
46+
this.description = description;
47+
this.mask = 1L <<mask;
48+
}
49+
50+
public static String generateOpenFgaModel() {
51+
StringBuilder stringBuilder = new StringBuilder();
52+
53+
stringBuilder.append("model\n");
54+
stringBuilder.append(" schema 1.1\n");
55+
stringBuilder.append("\n");
56+
stringBuilder.append("type user\n");
57+
stringBuilder.append("\n");
58+
stringBuilder.append("type group\n");
59+
stringBuilder.append(" relations\n");
60+
stringBuilder.append(" define member: [user]\n");
61+
stringBuilder.append("\n");
62+
stringBuilder.append("type resource\n");
63+
stringBuilder.append(" relations\n");
64+
65+
for (ServerPermissions serverPermission : ServerPermissions.values()) {
66+
String permissionName = serverPermission.getName();
67+
stringBuilder
68+
.append(" define ")
69+
.append(permissionName)
70+
.append(": [user, group#member]\n");
71+
}
72+
73+
return stringBuilder.toString();
74+
}
75+
76+
public static void main(String[] args) {
77+
System.err.println(generateOpenFgaModel());
78+
}
79+
}

0 commit comments

Comments
 (0)