Skip to content

Commit b3d9d3d

Browse files
committed
Adding support for a super admin
1 parent 50f5f29 commit b3d9d3d

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

src/main/java/org/computate/vertx/config/ComputateConfigKeys.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,11 @@ public class ComputateConfigKeys {
188188
**/
189189
public static final String AUTH_ROLE_ADMIN = "AUTH_ROLE_ADMIN";
190190

191+
/**
192+
* JsonArray of super admin user roles.
193+
**/
194+
public static final String AUTH_ROLE_SUPER_ADMIN = "AUTH_ROLE_SUPER_ADMIN";
195+
191196
/**
192197
* Enable SSL Passthrough.
193198
**/
@@ -423,6 +428,11 @@ public class ComputateConfigKeys {
423428
**/
424429
public static final String ROLE_ADMIN = "ROLE_ADMIN";
425430

431+
/**
432+
* The OpenID Connect role for a super administrator.
433+
**/
434+
public static final String ROLE_SUPER_ADMIN = "ROLE_SUPER_ADMIN";
435+
426436
/**
427437
* The email address for the administrator of the site for the error reports.
428438
**/

src/main/java/org/computate/vertx/handlebars/AuthHelpers.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public Object apply(final Object a, final Options options) throws IOException {
2121
Long userKey = options.param(1, null);
2222
String expectedSessionId = options.param(2, null);
2323
String sessionId = options.param(3, null);
24-
List<String> userRoles = options.param(4, null);
24+
List<String> userRoles = Optional.ofNullable(options.param(4, null)).map(o -> o instanceof List ? (List<String>)o : Arrays.asList(o.toString())).orElse(Arrays.asList());
2525
List<String> requiredRoles = Optional.ofNullable(options.param(5, null)).map(o -> o instanceof List ? (List<String>)o : Arrays.asList(o.toString())).orElse(Arrays.asList());
2626

2727
Boolean result = userKey != null && expectedUserKeys.contains(userKey)
@@ -40,7 +40,7 @@ public Object apply(final Object a, final Options options) throws IOException {
4040
ifContainsAnyRoles {
4141
@Override
4242
public Object apply(final Object a, final Options options) throws IOException {
43-
List<String> userRoles = (List<String>)a;
43+
List<String> userRoles = Optional.ofNullable(a).map(o -> o instanceof List ? (List<String>)o : Arrays.asList(o.toString())).orElse(Arrays.asList());
4444
List<String> requiredRoles = Optional.ofNullable(options.param(0, null)).map(o -> o instanceof List ? (List<String>)o : Arrays.asList(o.toString())).orElse(Arrays.asList());
4545

4646
Boolean result = userRoles.stream().anyMatch(requiredRoles::contains);

src/main/java/org/computate/vertx/verticle/EmailVerticle.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ private Handler<Message<Object>> mailSender() {
6868
public void handle(Message<Object> event) {
6969

7070
try {
71-
JsonObject params = ((JsonObject)event.body()).getJsonObject("context").getJsonObject("params");
71+
JsonObject params = new JsonObject(event.body().toString()).getJsonObject("error").getJsonObject("params");
7272
JsonObject body = params.getJsonObject("body");
7373
JsonObject headers = params.getJsonObject("header");
7474
String mailTemplate = headers.getString(MAIL_HEADER_TEMPLATE);

0 commit comments

Comments
 (0)