Skip to content

Commit

Permalink
Allowing for read-only role based access control
Browse files Browse the repository at this point in the history
  • Loading branch information
computate committed Aug 16, 2023
1 parent 12082f3 commit aa48f0c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/main/java/org/computate/frFR/java/EcrireApiClasse.java
Original file line number Diff line number Diff line change
Expand Up @@ -2557,7 +2557,10 @@ public void ecrireGenApiServiceImpl2(String classeLangueNom) throws Exception {
tl(5, ")");
tl(4, "));");
tl(3, "}).onSuccess(b -> {");
tl(4, "if(!Optional.ofNullable(config.getString(ConfigKeys.", classeLangueConfig.getString(ConfigCles.var_AUTH_ROLE_REQUIS), " + \"_", classeNomSimple, "\")).map(v -> RoleBasedAuthorization.create(v).match(", classeLangueConfig.getString(ConfigCles.var_requeteSite), ".get", classeLangueConfig.getString(ConfigCles.var_Utilisateur), "())).orElse(false)) {");
tl(4, "if(");
tl(6, "!Optional.ofNullable(config.getString(ConfigKeys.", classeLangueConfig.getString(ConfigCles.var_AUTH_ROLE_REQUIS), " + \"_", classeNomSimple, "\")).map(v -> RoleBasedAuthorization.create(v).match(", classeLangueConfig.getString(ConfigCles.var_requeteSite), ".get", classeLangueConfig.getString(ConfigCles.var_Utilisateur), "())).orElse(false)");
tl(6, "&& !Optional.ofNullable(config.getString(ConfigKeys.", classeLangueConfig.getString(ConfigCles.var_AUTH_ROLE_LIRE_REQUIS), " + \"_", classeNomSimple, "\")).map(v -> RoleBasedAuthorization.create(v).match(", classeLangueConfig.getString(ConfigCles.var_requeteSite), ".get", classeLangueConfig.getString(ConfigCles.var_Utilisateur), "())).orElse(false)");
tl(6, ") {");
tl(5, "String msg = String.format(\"401 UNAUTHORIZED user %s to %s %s\", siteRequest.getUser().attributes().getJsonObject(\"accessToken\").getString(\"preferred_username\"), serviceRequest.getExtra().getString(\"method\"), serviceRequest.getExtra().getString(\"uri\"));");
tl(5, "eventHandler.handle(Future.succeededFuture(");
tl(6, "new ServiceResponse(401, \"UNAUTHORIZED\",");
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/org/computate/frFR/java/EcrirePageClasse.java
Original file line number Diff line number Diff line change
Expand Up @@ -1284,15 +1284,22 @@ else if("LocalTime".equals(entiteNomSimple)) {
if(classePageSuperNomSimple != null)
tl(1, "@Override");
tl(1, "protected void _", langueConfig.getString(ConfigCles.var_roleRequis), "(List<String> l) {");
tl(2, "l.add(", langueConfig.getString(ConfigCles.var_requeteSite), "_.getConfig().getString(", classePartsConfigCles.nomSimple(langueNom), ".", langueConfig.getString(ConfigCles.var_AUTH_ROLE_REQUIS), " + \"_", classeApiClasseNomSimple, "\"));");
tl(2, "Optional.ofNullable(", langueConfig.getString(ConfigCles.var_requeteSite), "_.getConfig().getString(", classePartsConfigCles.nomSimple(langueNom), ".", langueConfig.getString(ConfigCles.var_AUTH_ROLE_REQUIS), " + \"_", classeApiClasseNomSimple, "\")).ifPresent(v -> {");
tl(3, "l.add(v);");
tl(2, "});");
tl(1, "}");
}
if(classeRoleLiresTrouves) {
l();
if(classePageSuperNomSimple != null)
tl(1, "@Override");
tl(1, "protected void _", langueConfig.getString(ConfigCles.var_rolePourLires), "(List<String> l) {");
tl(2, "l.add(", langueConfig.getString(ConfigCles.var_requeteSite), "_.getConfig().getString(", classePartsConfigCles.nomSimple(langueNom), ".", langueConfig.getString(ConfigCles.var_AUTH_ROLE_LIRE_REQUIS), " + \"_", classeApiClasseNomSimple, "\"));");
tl(2, "Optional.ofNullable(", langueConfig.getString(ConfigCles.var_requeteSite), "_.getConfig().getString(", classePartsConfigCles.nomSimple(langueNom), ".", langueConfig.getString(ConfigCles.var_AUTH_ROLE_LIRE_REQUIS), " + \"_", classeApiClasseNomSimple, "\")).ifPresent(v -> {");
tl(3, "l.add(v);");
tl(2, "});");
tl(2, "Optional.ofNullable(", langueConfig.getString(ConfigCles.var_requeteSite), "_.getConfig().getString(", classePartsConfigCles.nomSimple(langueNom), ".", langueConfig.getString(ConfigCles.var_AUTH_ROLE_REQUIS), " + \"_", classeApiClasseNomSimple, "\")).ifPresent(v -> {");
tl(3, "l.add(v);");
tl(2, "});");
tl(1, "}");
}

Expand Down

0 comments on commit aa48f0c

Please sign in to comment.