Skip to content

Commit fa7b8a4

Browse files
committed
Fixing fine-grained auth for VarId field
1 parent cfb1023 commit fa7b8a4

File tree

1 file changed

+41
-33
lines changed

1 file changed

+41
-33
lines changed

src/main/java/org/computate/frFR/java/EcrireApiClasse.java

Lines changed: 41 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1930,38 +1930,40 @@ public void ecrireGenApiServiceImpl2(String classeLangueNom) throws Exception {
19301930
) {
19311931
if(authPolitiqueGranulee) {
19321932
tl(3, "String ", classeVarId, " = ", i18nGlobale.getString(I18n.var_requeteSite), ".get", i18nGlobale.getString(I18n.var_RequeteService), "().getParams().getJsonObject(\"path\").getString(\"", classeVarId, "\");");
1933+
tl(3, "MultiMap form = MultiMap.caseInsensitiveMultiMap();");
1934+
tl(3, "form.add(\"grant_type\", \"urn:ietf:params:oauth:grant-type:uma-ticket\");");
1935+
tl(3, "form.add(\"audience\", config.getString(ComputateConfigKeys.AUTH_CLIENT));");
1936+
tl(3, "form.add(\"response_mode\", \"permissions\");");
1937+
tl(3, "form.add(\"permission\", String.format(\"%s#%s\", ", classeNomSimple, ".", i18nGlobale.getString(I18n.var_CLASSE_NOM_SIMPLE), ", config.getString(ComputateConfigKeys.", i18nGlobale.getString(I18n.var_AUTH_PORTEE_ADMIN), ")));");
1938+
tl(3, "form.add(\"permission\", String.format(\"%s#%s\", ", classeNomSimple, ".", i18nGlobale.getString(I18n.var_CLASSE_NOM_SIMPLE), ", config.getString(ComputateConfigKeys.", i18nGlobale.getString(I18n.var_AUTH_PORTEE_SUPER_ADMIN), ")));");
1939+
tl(3, "form.add(\"permission\", String.format(\"%s#%s\", ", classeNomSimple, ".", i18nGlobale.getString(I18n.var_CLASSE_NOM_SIMPLE), ", \"GET\"));");
1940+
tl(3, "form.add(\"permission\", String.format(\"%s#%s\", ", classeNomSimple, ".", i18nGlobale.getString(I18n.var_CLASSE_NOM_SIMPLE), ", \"POST\"));");
1941+
tl(3, "form.add(\"permission\", String.format(\"%s#%s\", ", classeNomSimple, ".", i18nGlobale.getString(I18n.var_CLASSE_NOM_SIMPLE), ", \"DELETE\"));");
1942+
tl(3, "form.add(\"permission\", String.format(\"%s#%s\", ", classeNomSimple, ".", i18nGlobale.getString(I18n.var_CLASSE_NOM_SIMPLE), ", \"PATCH\"));");
1943+
tl(3, "form.add(\"permission\", String.format(\"%s#%s\", ", classeNomSimple, ".", i18nGlobale.getString(I18n.var_CLASSE_NOM_SIMPLE), ", \"PUT\"));");
1944+
tl(3, "if(", classeVarId, " != null)");
1945+
tl(4, "form.add(\"permission\", String.format(\"%s-%s#%s\", ", classeNomSimple, ".", i18nGlobale.getString(I18n.var_CLASSE_NOM_SIMPLE), ", ", classeVarId, ", \"", classeApiMethodeMethode, "\"));");
19331946
tl(3, "webClient.post(");
19341947
tl(5, "config.getInteger(ComputateConfigKeys.AUTH_PORT)");
19351948
tl(5, ", config.getString(ComputateConfigKeys.AUTH_HOST_NAME)");
19361949
tl(5, ", config.getString(ComputateConfigKeys.AUTH_TOKEN_URI)");
19371950
tl(5, ")");
19381951
tl(5, ".ssl(config.getBoolean(ComputateConfigKeys.AUTH_SSL))");
19391952
tl(5, ".putHeader(\"Authorization\", String.format(\"Bearer %s\", siteRequest.getUser().principal().getString(\"access_token\")))");
1940-
tl(5, ".expect(ResponsePredicate.status(200))");
1941-
tl(5, ".sendForm(MultiMap.caseInsensitiveMultiMap()");
1942-
tl(7, ".add(\"grant_type\", \"urn:ietf:params:oauth:grant-type:uma-ticket\")");
1943-
tl(7, ".add(\"audience\", config.getString(ComputateConfigKeys.AUTH_CLIENT))");
1944-
tl(7, ".add(\"response_mode\", \"permissions\")");
1945-
tl(7, ".add(\"permission\", String.format(\"%s-%s#%s\", ", classeNomSimple, ".", i18nGlobale.getString(I18n.var_CLASSE_NOM_SIMPLE), ", ", classeVarId, ", \"", classeApiMethodeMethode, "\"))");
1946-
tl(7, ".add(\"permission\", String.format(\"%s#%s\", ", classeNomSimple, ".", i18nGlobale.getString(I18n.var_CLASSE_NOM_SIMPLE), ", config.getString(ComputateConfigKeys.", i18nGlobale.getString(I18n.var_AUTH_PORTEE_ADMIN), ")))");
1947-
tl(7, ".add(\"permission\", String.format(\"%s#%s\", ", classeNomSimple, ".", i18nGlobale.getString(I18n.var_CLASSE_NOM_SIMPLE), ", config.getString(ComputateConfigKeys.", i18nGlobale.getString(I18n.var_AUTH_PORTEE_SUPER_ADMIN), ")))");
1948-
tl(7, ".add(\"permission\", String.format(\"%s#%s\", ", classeNomSimple, ".", i18nGlobale.getString(I18n.var_CLASSE_NOM_SIMPLE), ", \"GET\"))");
1949-
tl(7, ".add(\"permission\", String.format(\"%s#%s\", ", classeNomSimple, ".", i18nGlobale.getString(I18n.var_CLASSE_NOM_SIMPLE), ", \"POST\"))");
1950-
tl(7, ".add(\"permission\", String.format(\"%s#%s\", ", classeNomSimple, ".", i18nGlobale.getString(I18n.var_CLASSE_NOM_SIMPLE), ", \"DELETE\"))");
1951-
tl(7, ".add(\"permission\", String.format(\"%s#%s\", ", classeNomSimple, ".", i18nGlobale.getString(I18n.var_CLASSE_NOM_SIMPLE), ", \"PATCH\"))");
1952-
tl(7, ".add(\"permission\", String.format(\"%s#%s\", ", classeNomSimple, ".", i18nGlobale.getString(I18n.var_CLASSE_NOM_SIMPLE), ", \"PUT\"))");
1953+
tl(5, ".sendForm(form)");
1954+
tl(5, ".expecting(HttpResponseExpectation.SC_OK)");
19531955
if(classeApiMethode.contains(i18nGlobale.getString(I18n.var_PageEdition))
19541956
|| classeApiMethode.contains(i18nGlobale.getString(I18n.var_PageAffichage))
19551957
|| classeApiMethode.contains(i18nGlobale.getString(I18n.var_PageUtilisateur))
19561958
) {
1957-
tl(3, ").onComplete(authorizationDecisionResult -> {");
1959+
tl(3, ".onComplete(authorizationDecisionResult -> {");
19581960
tl(4, "HttpResponse<Buffer> authorizationDecision = authorizationDecisionResult.result();");
19591961
tl(4, "try {");
19601962
tl(5, "JsonArray scopes = Optional.ofNullable(authorizationDecision).map(decision -> decision.bodyAsJsonArray().stream().findFirst().map(d -> ((JsonObject)d).getJsonArray(\"scopes\")).orElse(new JsonArray())).orElse(new JsonArray());");
19611963
tl(5, "if(scopes != null) {");
19621964
tl(6, i18nGlobale.getString(I18n.var_requeteSite), ".setScopes(scopes.stream().map(o -> o.toString()).collect(Collectors.toList()));");
19631965
} else {
1964-
tl(3, ").onFailure(ex -> {");
1966+
tl(3, ".onFailure(ex -> {");
19651967
tl(4, "String msg = String.format(\"403 FORBIDDEN user %s to %s %s\", siteRequest.getUser().attributes().getJsonObject(\"accessToken\").getString(\"preferred_username\"), serviceRequest.getExtra().getString(\"method\"), serviceRequest.getExtra().getString(\"uri\"));");
19661968
tl(4, "eventHandler.handle(Future.succeededFuture(");
19671969
tl(5, "new ServiceResponse(403, \"FORBIDDEN\",");
@@ -2145,27 +2147,29 @@ public void ecrireGenApiServiceImpl2(String classeLangueNom) throws Exception {
21452147
) {
21462148
if(authPolitiqueGranulee) {
21472149
tl(3, "String ", classeVarId, " = ", i18nGlobale.getString(I18n.var_requeteSite), ".get", i18nGlobale.getString(I18n.var_RequeteService), "().getParams().getJsonObject(\"path\").getString(\"", classeVarId, "\");");
2150+
tl(3, "MultiMap form = MultiMap.caseInsensitiveMultiMap();");
2151+
tl(3, "form.add(\"grant_type\", \"urn:ietf:params:oauth:grant-type:uma-ticket\");");
2152+
tl(3, "form.add(\"audience\", config.getString(ComputateConfigKeys.AUTH_CLIENT));");
2153+
tl(3, "form.add(\"response_mode\", \"permissions\");");
2154+
tl(3, "form.add(\"permission\", String.format(\"%s#%s\", ", classeNomSimple, ".", i18nGlobale.getString(I18n.var_CLASSE_NOM_SIMPLE), ", config.getString(ComputateConfigKeys.", i18nGlobale.getString(I18n.var_AUTH_PORTEE_ADMIN), ")));");
2155+
tl(3, "form.add(\"permission\", String.format(\"%s#%s\", ", classeNomSimple, ".", i18nGlobale.getString(I18n.var_CLASSE_NOM_SIMPLE), ", config.getString(ComputateConfigKeys.", i18nGlobale.getString(I18n.var_AUTH_PORTEE_SUPER_ADMIN), ")));");
2156+
tl(3, "form.add(\"permission\", String.format(\"%s#%s\", ", classeNomSimple, ".", i18nGlobale.getString(I18n.var_CLASSE_NOM_SIMPLE), ", \"GET\"));");
2157+
tl(3, "form.add(\"permission\", String.format(\"%s#%s\", ", classeNomSimple, ".", i18nGlobale.getString(I18n.var_CLASSE_NOM_SIMPLE), ", \"POST\"));");
2158+
tl(3, "form.add(\"permission\", String.format(\"%s#%s\", ", classeNomSimple, ".", i18nGlobale.getString(I18n.var_CLASSE_NOM_SIMPLE), ", \"DELETE\"));");
2159+
tl(3, "form.add(\"permission\", String.format(\"%s#%s\", ", classeNomSimple, ".", i18nGlobale.getString(I18n.var_CLASSE_NOM_SIMPLE), ", \"PATCH\"));");
2160+
tl(3, "form.add(\"permission\", String.format(\"%s#%s\", ", classeNomSimple, ".", i18nGlobale.getString(I18n.var_CLASSE_NOM_SIMPLE), ", \"PUT\"));");
2161+
tl(3, "if(", classeVarId, " != null)");
2162+
tl(4, "form.add(\"permission\", String.format(\"%s-%s#%s\", ", classeNomSimple, ".", i18nGlobale.getString(I18n.var_CLASSE_NOM_SIMPLE), ", ", classeVarId, ", \"", classeApiMethodeMethode, "\"));");
21482163
tl(3, "webClient.post(");
21492164
tl(5, "config.getInteger(ComputateConfigKeys.AUTH_PORT)");
21502165
tl(5, ", config.getString(ComputateConfigKeys.AUTH_HOST_NAME)");
21512166
tl(5, ", config.getString(ComputateConfigKeys.AUTH_TOKEN_URI)");
21522167
tl(5, ")");
21532168
tl(5, ".ssl(config.getBoolean(ComputateConfigKeys.AUTH_SSL))");
21542169
tl(5, ".putHeader(\"Authorization\", String.format(\"Bearer %s\", siteRequest.getUser().principal().getString(\"access_token\")))");
2155-
tl(5, ".expect(ResponsePredicate.status(200))");
2156-
tl(5, ".sendForm(MultiMap.caseInsensitiveMultiMap()");
2157-
tl(7, ".add(\"grant_type\", \"urn:ietf:params:oauth:grant-type:uma-ticket\")");
2158-
tl(7, ".add(\"audience\", config.getString(ComputateConfigKeys.AUTH_CLIENT))");
2159-
tl(7, ".add(\"response_mode\", \"permissions\")");
2160-
tl(7, ".add(\"permission\", String.format(\"%s-%s#%s\", ", classeNomSimple, ".", i18nGlobale.getString(I18n.var_CLASSE_NOM_SIMPLE), ", ", classeVarId, ", \"", classeApiMethodeMethode, "\"))");
2161-
tl(7, ".add(\"permission\", String.format(\"%s#%s\", ", classeNomSimple, ".", i18nGlobale.getString(I18n.var_CLASSE_NOM_SIMPLE), ", \"GET\"))");
2162-
tl(7, ".add(\"permission\", String.format(\"%s#%s\", ", classeNomSimple, ".", i18nGlobale.getString(I18n.var_CLASSE_NOM_SIMPLE), ", config.getString(ComputateConfigKeys.", i18nGlobale.getString(I18n.var_AUTH_PORTEE_ADMIN), ")))");
2163-
tl(7, ".add(\"permission\", String.format(\"%s#%s\", ", classeNomSimple, ".", i18nGlobale.getString(I18n.var_CLASSE_NOM_SIMPLE), ", config.getString(ComputateConfigKeys.", i18nGlobale.getString(I18n.var_AUTH_PORTEE_SUPER_ADMIN), ")))");
2164-
tl(7, ".add(\"permission\", String.format(\"%s#%s\", ", classeNomSimple, ".", i18nGlobale.getString(I18n.var_CLASSE_NOM_SIMPLE), ", \"POST\"))");
2165-
tl(7, ".add(\"permission\", String.format(\"%s#%s\", ", classeNomSimple, ".", i18nGlobale.getString(I18n.var_CLASSE_NOM_SIMPLE), ", \"DELETE\"))");
2166-
tl(7, ".add(\"permission\", String.format(\"%s#%s\", ", classeNomSimple, ".", i18nGlobale.getString(I18n.var_CLASSE_NOM_SIMPLE), ", \"PATCH\"))");
2167-
tl(7, ".add(\"permission\", String.format(\"%s#%s\", ", classeNomSimple, ".", i18nGlobale.getString(I18n.var_CLASSE_NOM_SIMPLE), ", \"PUT\"))");
2168-
tl(3, ").onFailure(ex -> {");
2170+
tl(5, ".sendForm(form)");
2171+
tl(5, ".expecting(HttpResponseExpectation.SC_OK)");
2172+
tl(3, ".onFailure(ex -> {");
21692173
tl(4, "String msg = String.format(\"403 FORBIDDEN user %s to %s %s\", siteRequest.getUser().attributes().getJsonObject(\"accessToken\").getString(\"preferred_username\"), serviceRequest.getExtra().getString(\"method\"), serviceRequest.getExtra().getString(\"uri\"));");
21702174
tl(4, "eventHandler.handle(Future.succeededFuture(");
21712175
tl(5, "new ServiceResponse(403, \"FORBIDDEN\",");
@@ -4652,8 +4656,12 @@ public void ecrireGenApiServiceImpl3(String classeLangueNom) throws Exception {
46524656
tl(5, ".expecting(HttpResponseExpectation.SC_NO_CONTENT).onSuccess(b -> {");
46534657
tl(4, "promise.complete();");
46544658
tl(3, "}).onFailure(ex -> {");
4655-
tl(4, "LOG.error(String.format(\"cbDeleteEntity failed. \"), ex);");
4656-
tl(4, "promise.fail(ex);");
4659+
tl(4, "if(\"Response status code 404 is not equal to 204\".equals(ex.getMessage())) {");
4660+
tl(5, "promise.complete();");
4661+
tl(4, "} else {");
4662+
tl(5, "LOG.error(String.format(\"cbDeleteEntity failed. \"), ex);");
4663+
tl(5, "promise.fail(ex);");
4664+
tl(4, "}");
46574665
tl(3, "});");
46584666
tl(2, "} catch(Throwable ex) {");
46594667
tl(3, "LOG.error(String.format(\"cbDeleteEntity failed. \"), ex);");
@@ -4744,7 +4752,7 @@ public void ecrireGenApiServiceImpl3(String classeLangueNom) throws Exception {
47444752
tl(4, "else if(softCommit == null)");
47454753
tl(5, "softCommit = false;");
47464754
tl(3, "String solrRequestUri = String.format(\"/solr/%s/update%s%s%s\", solrCollection, \"?overwrite=true&wt=json\", softCommit ? \"&softCommit=true\" : \"\", commitWithin != null ? (\"&commitWithin=\" + commitWithin) : \"\");");
4747-
tl(3, i18nGlobale.getString(I18n.var_clientWeb), ".post(solrPort, solrHostName, solrRequestUri).ssl(solrSsl).authentication(new UsernamePasswordCredentials(solrUsername, solrPassword)).putHeader(\"Content-Type\", \"application/json\").expect(ResponsePredicate.SC_OK).sendBuffer(json.toBuffer()).onSuccess(b -> {");
4755+
tl(3, i18nGlobale.getString(I18n.var_clientWeb), ".post(solrPort, solrHostName, solrRequestUri).ssl(solrSsl).authentication(new UsernamePasswordCredentials(solrUsername, solrPassword)).putHeader(\"Content-Type\", \"application/json\").sendBuffer(json.toBuffer()).expecting(HttpResponseExpectation.SC_OK).onSuccess(b -> {");
47484756
tl(4, "promise.complete(o);");
47494757
tl(3, "}).onFailure(ex -> {");
47504758
tl(4, "LOG.error(String.format(\"", i18nGlobale.getString(I18n.var_indexer), classeNomSimple, " ", i18nGlobale.getString(I18n.str_a_échoué), ". \"), new RuntimeException(ex));");
@@ -4789,7 +4797,7 @@ public void ecrireGenApiServiceImpl3(String classeLangueNom) throws Exception {
47894797
tl(5, "else if(softCommit == null)");
47904798
tl(6, "softCommit = false;");
47914799
tl(4, "String solrRequestUri = String.format(\"/solr/%s/update%s%s%s\", solrCollection, \"?overwrite=true&wt=json\", softCommit ? \"&softCommit=true\" : \"\", commitWithin != null ? (\"&commitWithin=\" + commitWithin) : \"\");");
4792-
tl(4, i18nGlobale.getString(I18n.var_clientWeb), ".post(solrPort, solrHostName, solrRequestUri).ssl(solrSsl).authentication(new UsernamePasswordCredentials(solrUsername, solrPassword)).putHeader(\"Content-Type\", \"application/json\").expect(ResponsePredicate.SC_OK).sendBuffer(json.toBuffer()).onSuccess(b -> {");
4800+
tl(4, i18nGlobale.getString(I18n.var_clientWeb), ".post(solrPort, solrHostName, solrRequestUri).ssl(solrSsl).authentication(new UsernamePasswordCredentials(solrUsername, solrPassword)).putHeader(\"Content-Type\", \"application/json\").sendBuffer(json.toBuffer()).expecting(HttpResponseExpectation.SC_OK).onSuccess(b -> {");
47934801
tl(5, "promise.complete(o);");
47944802
tl(4, "}).onFailure(ex -> {");
47954803
tl(5, "LOG.error(String.format(\"", i18nGlobale.getString(I18n.var_desindexer), classeNomSimple, " ", i18nGlobale.getString(I18n.str_a_échoué), ". \"), new RuntimeException(ex));");

0 commit comments

Comments
 (0)