@@ -1992,58 +1992,39 @@ public void ecrireGenApiServiceImpl2(String classeLangueNom) throws Exception {
1992
1992
tl (4 , "try {" );
1993
1993
tl (5 , "HttpResponse<Buffer> authorizationDecision = authorizationDecisionResponse.result();" );
1994
1994
tl (5 , "JsonArray scopes = authorizationDecisionResponse.failed() ? new JsonArray() : authorizationDecision.bodyAsJsonArray().stream().findFirst().map(decision -> ((JsonObject)decision).getJsonArray(\" scopes\" )).orElse(new JsonArray());" );
1995
- if (StringUtils .equals (classeApiMethodeMethode , "GET" )) {
1996
- tl (5 , "{" );
1997
- } else {
1998
- if (classeRoleUtilisateur ) {
1999
- tl (5 , "scopes.add(\" GET\" );" );
2000
- tl (5 , "scopes.add(\" PATCH\" );" );
2001
- }
2002
- tl (5 , "if(authorizationDecisionResponse.failed() || !scopes.contains(\" " , classeApiMethodeMethode , "\" )) {" );
2003
- tl (6 , "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\" ));" );
2004
- tl (6 , "eventHandler.handle(Future.succeededFuture(" );
2005
- tl (7 , "new ServiceResponse(403, \" FORBIDDEN\" ," );
2006
- tl (8 , "Buffer.buffer().appendString(" );
2007
- tl (9 , "new JsonObject()" );
2008
- tl (10 , ".put(\" errorCode\" , \" 403\" )" );
2009
- tl (10 , ".put(\" errorMessage\" , msg)" );
2010
- tl (10 , ".encodePrettily()" );
2011
- tl (9 , "), MultiMap.caseInsensitiveMultiMap()" );
2012
- tl (7 , ")" );
2013
- tl (6 , "));" );
2014
- tl (5 , "} else {" );
2015
- }
2016
1995
if (classeRessourcesAutorisation .size () > 0 ) {
2017
- l ();
2018
- tl (6 , "if(!scopes.contains(\" " , classeApiMethodeMethode , "\" )) {" );
2019
- tl (7 , "//" );
2020
- tl (7 , "List<String> fqs = new ArrayList<>();" );
2021
- tl (7 , "List<String> groups = Optional.ofNullable(" , i18nGlobale .getString (I18n .var_requeteSite ), ".getGroups()).orElse(new ArrayList<>());" );
1996
+ tl (5 , "if(!scopes.contains(\" " , classeApiMethodeMethode , "\" )) {" );
1997
+ tl (6 , "//" );
1998
+ tl (6 , "List<String> fqs = new ArrayList<>();" );
1999
+ tl (6 , "List<String> groups = Optional.ofNullable(" , i18nGlobale .getString (I18n .var_requeteSite ), ".getGroups()).orElse(new ArrayList<>());" );
2022
2000
for (String classeRessourceAutorisation : classeRessourcesAutorisation ) {
2023
2001
2024
- tl (7 , "groups.stream().map(group -> {" );
2025
- tl (10 , "Matcher mPermission = Pattern.compile(\" ^/" , StringUtils .substringBefore (classeRessourceAutorisation , "-" ), "-(.*)-" , classeApiMethodeMethode , "$\" ).matcher(group);" );
2026
- tl (10 , "return mPermission.find() ? mPermission.group(1) : null;" );
2027
- tl (9 , "}).filter(v -> v != null).forEach(" , i18nGlobale .getString (I18n .var_valeur ), " -> {" );
2028
- tl (10 , "fqs.add(String.format(\" %s:%s\" , \" " , StringUtils .substringAfter (classeRessourceAutorisation , "-" ), "\" , " , i18nGlobale .getString (I18n .var_valeur ), "));" );
2029
- tl (9 , "});" );
2002
+ tl (6 , "groups.stream().map(group -> {" );
2003
+ tl (9 , "Matcher mPermission = Pattern.compile(\" ^/" , StringUtils .substringBefore (classeRessourceAutorisation , "-" ), "-(.*)-" , classeApiMethodeMethode , "$\" ).matcher(group);" );
2004
+ tl (9 , "return mPermission.find() ? mPermission.group(1) : null;" );
2005
+ tl (8 , "}).filter(v -> v != null).forEach(" , i18nGlobale .getString (I18n .var_valeur ), " -> {" );
2006
+ tl (9 , "fqs.add(String.format(\" %s:%s\" , \" " , StringUtils .substringAfter (classeRessourceAutorisation , "-" ), "\" , " , i18nGlobale .getString (I18n .var_valeur ), "));" );
2007
+ tl (8 , "});" );
2030
2008
}
2031
- tl (7 , "JsonObject authParams = " , i18nGlobale .getString (I18n .var_requeteSite ), ".get" , i18nGlobale .getString (I18n .var_RequeteService ), "().getParams();" );
2032
- tl (7 , "JsonObject authQuery = authParams.getJsonObject(\" query\" );" );
2033
- tl (7 , "if(authQuery == null) {" );
2034
- tl (8 , "authQuery = new JsonObject();" );
2035
- tl (8 , "authParams.put(\" query\" , authQuery);" );
2036
- tl (7 , "}" );
2037
- tl (7 , "JsonArray fq = authQuery.getJsonArray(\" fq\" );" );
2038
- tl (7 , "if(fq == null) {" );
2039
- tl (8 , "fq = new JsonArray();" );
2040
- tl (8 , "authQuery.put(\" fq\" , fq);" );
2041
- tl (7 , "}" );
2042
- tl (7 , "if(fqs.size() > 0) {" );
2043
- tl (8 , "fq.add(fqs.stream().collect(Collectors.joining(\" OR \" )));" );
2044
- tl (8 , "scopes.add(\" " , classeApiMethodeMethode , "\" );" );
2045
- tl (7 , "}" );
2009
+ tl (6 , "JsonObject authParams = " , i18nGlobale .getString (I18n .var_requeteSite ), ".get" , i18nGlobale .getString (I18n .var_RequeteService ), "().getParams();" );
2010
+ tl (6 , "JsonObject authQuery = authParams.getJsonObject(\" query\" );" );
2011
+ tl (6 , "if(authQuery == null) {" );
2012
+ tl (7 , "authQuery = new JsonObject();" );
2013
+ tl (7 , "authParams.put(\" query\" , authQuery);" );
2046
2014
tl (6 , "}" );
2015
+ tl (6 , "JsonArray fq = authQuery.getJsonArray(\" fq\" );" );
2016
+ tl (6 , "if(fq == null) {" );
2017
+ tl (7 , "fq = new JsonArray();" );
2018
+ tl (7 , "authQuery.put(\" fq\" , fq);" );
2019
+ tl (6 , "}" );
2020
+ tl (6 , "if(fqs.size() > 0) {" );
2021
+ tl (7 , "fq.add(fqs.stream().collect(Collectors.joining(\" OR \" )));" );
2022
+ tl (7 , "scopes.add(\" " , classeApiMethodeMethode , "\" );" );
2023
+ tl (6 , "}" );
2024
+ tl (5 , "}" );
2025
+ tl (5 , "{" );
2026
+ } else {
2027
+ tl (5 , "{" );
2047
2028
}
2048
2029
tl (6 , i18nGlobale .getString (I18n .var_requeteSite ), ".setScopes(scopes.stream().map(o -> o.toString()).collect(Collectors.toList()));" );
2049
2030
tl (6 , "List<String> scopes2 = " , i18nGlobale .getString (I18n .var_requeteSite ), ".getScopes();" );
@@ -2211,29 +2192,8 @@ public void ecrireGenApiServiceImpl2(String classeLangueNom) throws Exception {
2211
2192
tl (4 , "try {" );
2212
2193
tl (5 , "HttpResponse<Buffer> authorizationDecision = authorizationDecisionResponse.result();" );
2213
2194
tl (5 , "JsonArray scopes = authorizationDecisionResponse.failed() ? new JsonArray() : authorizationDecision.bodyAsJsonArray().stream().findFirst().map(decision -> ((JsonObject)decision).getJsonArray(\" scopes\" )).orElse(new JsonArray());" );
2214
- if (StringUtils .equals (classeApiMethodeMethode , "GET" )) {
2215
- tl (5 , "{" );
2216
- } else {
2217
- if (classeRoleUtilisateur ) {
2218
- tl (5 , "scopes.add(\" GET\" );" );
2219
- tl (5 , "scopes.add(\" PATCH\" );" );
2220
- }
2221
- tl (5 , "if(authorizationDecisionResponse.failed() " , classeRoleUtilisateur && StringUtils .equals (classeApiMethodeMethode , "PATCH" ) ? "&&" : "||" , " !scopes.contains(\" " , classeApiMethodeMethode , "\" )) {" );
2222
- tl (6 , "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\" ));" );
2223
- tl (6 , "eventHandler.handle(Future.succeededFuture(" );
2224
- tl (7 , "new ServiceResponse(403, \" FORBIDDEN\" ," );
2225
- tl (8 , "Buffer.buffer().appendString(" );
2226
- tl (9 , "new JsonObject()" );
2227
- tl (10 , ".put(\" errorCode\" , \" 403\" )" );
2228
- tl (10 , ".put(\" errorMessage\" , msg)" );
2229
- tl (10 , ".encodePrettily()" );
2230
- tl (9 , "), MultiMap.caseInsensitiveMultiMap()" );
2231
- tl (7 , ")" );
2232
- tl (6 , "));" );
2233
- tl (5 , "} else {" );
2234
- }
2235
2195
if (classeRessourcesAutorisation .size () > 0 ) {
2236
- l ( );
2196
+ tl ( 5 , "if(!scopes.contains( \" " , classeApiMethodeMethode , " \" )) {" );
2237
2197
tl (6 , "//" );
2238
2198
tl (6 , "List<String> fqs = new ArrayList<>();" );
2239
2199
tl (6 , "List<String> groups = Optional.ofNullable(" , i18nGlobale .getString (I18n .var_requeteSite ), ".getGroups()).orElse(new ArrayList<>());" );
@@ -2261,16 +2221,31 @@ public void ecrireGenApiServiceImpl2(String classeLangueNom) throws Exception {
2261
2221
tl (7 , "fq.add(fqs.stream().collect(Collectors.joining(\" OR \" )));" );
2262
2222
tl (7 , "scopes.add(\" " , classeApiMethodeMethode , "\" );" );
2263
2223
tl (6 , "}" );
2264
- l ();
2224
+ tl (5 , "}" );
2225
+ }
2226
+ if (StringUtils .equals (classeApiMethodeMethode , "GET" )) {
2227
+ tl (5 , "{" );
2228
+ } else {
2229
+ if (classeRoleUtilisateur ) {
2230
+ tl (5 , "scopes.add(\" GET\" );" );
2231
+ tl (5 , "scopes.add(\" PATCH\" );" );
2232
+ }
2233
+ tl (5 , "if(authorizationDecisionResponse.failed() && !scopes.contains(\" " , classeApiMethodeMethode , "\" )) {" );
2234
+ tl (6 , "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\" ));" );
2235
+ tl (6 , "eventHandler.handle(Future.succeededFuture(" );
2236
+ tl (7 , "new ServiceResponse(403, \" FORBIDDEN\" ," );
2237
+ tl (8 , "Buffer.buffer().appendString(" );
2238
+ tl (9 , "new JsonObject()" );
2239
+ tl (10 , ".put(\" errorCode\" , \" 403\" )" );
2240
+ tl (10 , ".put(\" errorMessage\" , msg)" );
2241
+ tl (10 , ".encodePrettily()" );
2242
+ tl (9 , "), MultiMap.caseInsensitiveMultiMap()" );
2243
+ tl (7 , ")" );
2244
+ tl (6 , "));" );
2245
+ tl (5 , "} else {" );
2265
2246
}
2266
2247
tl (6 , i18nGlobale .getString (I18n .var_requeteSite ), ".setScopes(scopes.stream().map(o -> o.toString()).collect(Collectors.toList()));" );
2267
2248
tl (6 , "List<String> scopes2 = " , i18nGlobale .getString (I18n .var_requeteSite ), ".getScopes();" );
2268
- // if(classeRoleSession || classeRoleUtilisateur || classeRoleChacun) {
2269
- // tl(6, "if(!scopes2.contains(\"POST\"))");
2270
- // tl(7, "scopes2.add(\"POST\");");
2271
- // tl(6, "if(!scopes2.contains(\"PATCH\"))");
2272
- // tl(7, "scopes2.add(\"PATCH\");");
2273
- // }
2274
2249
} else {
2275
2250
tl (3 , "authorizationProvider.getAuthorizations(" , i18nGlobale .getString (I18n .var_requeteSite ), ".get" , i18nGlobale .getString (I18n .var_Utilisateur ), "()).onFailure(ex -> {" );
2276
2251
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\" ));" );
0 commit comments