@@ -1915,40 +1915,55 @@ public void ecrireGenApiServiceImpl2(String classeLangueNom) throws Exception {
19151915 tl (4 , "try {" );
19161916 tl (5 , "HttpResponse<Buffer> authorizationDecision = authorizationDecisionResponse.result();" );
19171917 tl (5 , "JsonArray scopes = authorizationDecisionResponse.failed() ? new JsonArray() : authorizationDecision.bodyAsJsonArray().stream().findFirst().map(decision -> ((JsonObject)decision).getJsonArray(\" scopes\" )).orElse(new JsonArray());" );
1918+ if (StringUtils .equals (classeApiMethodeMethode , "GET" )) {
1919+ tl (5 , "{" );
1920+ } else {
1921+ tl (5 , "if(authorizationDecisionResponse.failed()) {" );
1922+ 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\" ));" );
1923+ tl (6 , "eventHandler.handle(Future.succeededFuture(" );
1924+ tl (7 , "new ServiceResponse(403, \" FORBIDDEN\" ," );
1925+ tl (8 , "Buffer.buffer().appendString(" );
1926+ tl (9 , "new JsonObject()" );
1927+ tl (10 , ".put(\" errorCode\" , \" 403\" )" );
1928+ tl (10 , ".put(\" errorMessage\" , msg)" );
1929+ tl (10 , ".encodePrettily()" );
1930+ tl (9 , "), MultiMap.caseInsensitiveMultiMap()" );
1931+ tl (7 , ")" );
1932+ tl (6 , "));" );
1933+ tl (5 , "} else {" );
1934+ }
19181935 if (classeRessourcesAutorisation .size () > 0 ) {
19191936 l ();
1920- tl (5 , "if(!scopes.contains(\" " , classeApiMethodeMethode , "\" )) {" );
1921- tl (6 , "//" );
1922- tl (6 , "List<String> fqs = new ArrayList<>();" );
1923- tl (6 , "List<String> groups = Optional.ofNullable(" , i18nGlobale .getString (I18n .var_requeteSite ), ".getGroups()).orElse(new ArrayList<>());" );
1937+ tl (6 , "if(!scopes.contains(\" " , classeApiMethodeMethode , "\" )) {" );
1938+ tl (7 , "//" );
1939+ tl (7 , "List<String> fqs = new ArrayList<>();" );
1940+ tl (7 , "List<String> groups = Optional.ofNullable(" , i18nGlobale .getString (I18n .var_requeteSite ), ".getGroups()).orElse(new ArrayList<>());" );
19241941 for (String classeRessourceAutorisation : classeRessourcesAutorisation ) {
19251942
1926- tl (6 , "groups.stream().map(group -> {" );
1927- tl (9 , "Matcher mPermission = Pattern.compile(\" ^/" , StringUtils .substringBefore (classeRessourceAutorisation , "-" ), "-(.*)-" , classeApiMethodeMethode , "$\" ).matcher(group);" );
1928- tl (9 , "return mPermission.find() ? mPermission.group(1) : null;" );
1929- tl (8 , "}).filter(v -> v != null).forEach(" , i18nGlobale .getString (I18n .var_valeur ), " -> {" );
1930- tl (9 , "fqs.add(String.format(\" %s:%s\" , \" " , StringUtils .substringAfter (classeRessourceAutorisation , "-" ), "\" , " , i18nGlobale .getString (I18n .var_valeur ), "));" );
1931- tl (8 , "});" );
1943+ tl (7 , "groups.stream().map(group -> {" );
1944+ tl (10 , "Matcher mPermission = Pattern.compile(\" ^/" , StringUtils .substringBefore (classeRessourceAutorisation , "-" ), "-(.*)-" , classeApiMethodeMethode , "$\" ).matcher(group);" );
1945+ tl (10 , "return mPermission.find() ? mPermission.group(1) : null;" );
1946+ tl (9 , "}).filter(v -> v != null).forEach(" , i18nGlobale .getString (I18n .var_valeur ), " -> {" );
1947+ tl (10 , "fqs.add(String.format(\" %s:%s\" , \" " , StringUtils .substringAfter (classeRessourceAutorisation , "-" ), "\" , " , i18nGlobale .getString (I18n .var_valeur ), "));" );
1948+ tl (9 , "});" );
19321949 }
1933- tl (6 , "JsonObject params = " , i18nGlobale .getString (I18n .var_requeteSite ), ".get" , i18nGlobale .getString (I18n .var_RequeteService ), "().getParams();" );
1934- tl (6 , "JsonObject query = params.getJsonObject(\" query\" );" );
1935- tl (6 , "if(query == null) {" );
1936- tl (7 , "query = new JsonObject();" );
1937- tl (7 , "params.put(\" query\" , query);" );
1938- tl (6 , "}" );
1939- tl (6 , "JsonArray fq = query.getJsonArray(\" fq\" );" );
1940- tl (6 , "if(fq == null) {" );
1941- tl (7 , "fq = new JsonArray();" );
1942- tl (7 , "query.put(\" fq\" , fq);" );
1943- tl (6 , "}" );
1944- tl (6 , "if(fqs.size() > 0) {" );
1945- tl (7 , "fq.add(fqs.stream().collect(Collectors.joining(\" OR \" )));" );
1946- tl (7 , "scopes.add(\" " , classeApiMethodeMethode , "\" );" );
1950+ tl (7 , "JsonObject params = " , i18nGlobale .getString (I18n .var_requeteSite ), ".get" , i18nGlobale .getString (I18n .var_RequeteService ), "().getParams();" );
1951+ tl (7 , "JsonObject query = params.getJsonObject(\" query\" );" );
1952+ tl (7 , "if(query == null) {" );
1953+ tl (8 , "query = new JsonObject();" );
1954+ tl (8 , "params.put(\" query\" , query);" );
1955+ tl (7 , "}" );
1956+ tl (7 , "JsonArray fq = query.getJsonArray(\" fq\" );" );
1957+ tl (7 , "if(fq == null) {" );
1958+ tl (8 , "fq = new JsonArray();" );
1959+ tl (8 , "query.put(\" fq\" , fq);" );
1960+ tl (7 , "}" );
1961+ tl (7 , "if(fqs.size() > 0) {" );
1962+ tl (8 , "fq.add(fqs.stream().collect(Collectors.joining(\" OR \" )));" );
1963+ tl (8 , "scopes.add(\" " , classeApiMethodeMethode , "\" );" );
1964+ tl (7 , "}" );
19471965 tl (6 , "}" );
1948- tl (5 , "}" );
1949- l ();
19501966 }
1951- tl (5 , "{" );
19521967 tl (6 , i18nGlobale .getString (I18n .var_requeteSite ), ".setScopes(scopes.stream().map(o -> o.toString()).collect(Collectors.toList()));" );
19531968 tl (6 , "List<String> scopes2 = " , i18nGlobale .getString (I18n .var_requeteSite ), ".getScopes();" );
19541969 if (classeRoleSession || classeRoleUtilisateur || classeRoleChacun ) {
@@ -2079,7 +2094,7 @@ public void ecrireGenApiServiceImpl2(String classeLangueNom) throws Exception {
20792094 tl (2 , i18nGlobale .getString (I18n .var_utilisateur ), "(" , i18nGlobale .getString (I18n .var_requeteService ), ", " , classePartsRequeteSite .nomSimple (classeLangueNom ), ".class, " , classePartsUtilisateurSite .nomSimple (classeLangueNom ), ".class, " , classePartsUtilisateurSite .nomSimple (classeLangueNom ), ".get" , i18nGlobale .getString (I18n .var_ClasseApiAddresse ), "(), \" post" , classePartsUtilisateurSite .nomSimple (classeLangueNom ), "Future\" , \" patch" , classePartsUtilisateurSite .nomSimple (classeLangueNom ), "Future\" , " , i18nGlobale .getString (I18n .var_classe ), i18nGlobale .getString (I18n .var_PublicLire ), ").onSuccess(" , i18nGlobale .getString (I18n .var_requeteSite ), " -> {" );
20802095 if (
20812096 classeAuth
2082- && BooleanUtils .isNotTrue (classePublicLire )
2097+ && BooleanUtils .isNotTrue (classePublicLire ) || ! StringUtils . equals ( classeApiMethodeMethode , "GET" )
20832098 ) {
20842099 if (authPolitiqueGranulee ) {
20852100 tl (3 , "String " , classeVarId , " = " , i18nGlobale .getString (I18n .var_requeteSite ), ".get" , i18nGlobale .getString (I18n .var_RequeteService ), "().getParams().getJsonObject(\" path\" ).getString(\" " , classeVarId , "\" );" );
@@ -2112,9 +2127,25 @@ public void ecrireGenApiServiceImpl2(String classeLangueNom) throws Exception {
21122127 tl (4 , "try {" );
21132128 tl (5 , "HttpResponse<Buffer> authorizationDecision = authorizationDecisionResponse.result();" );
21142129 tl (5 , "JsonArray scopes = authorizationDecisionResponse.failed() ? new JsonArray() : authorizationDecision.bodyAsJsonArray().stream().findFirst().map(decision -> ((JsonObject)decision).getJsonArray(\" scopes\" )).orElse(new JsonArray());" );
2130+ if (StringUtils .equals (classeApiMethodeMethode , "GET" )) {
2131+ tl (5 , "{" );
2132+ } else {
2133+ tl (5 , "if(authorizationDecisionResponse.failed()) {" );
2134+ 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\" ));" );
2135+ tl (6 , "eventHandler.handle(Future.succeededFuture(" );
2136+ tl (7 , "new ServiceResponse(403, \" FORBIDDEN\" ," );
2137+ tl (8 , "Buffer.buffer().appendString(" );
2138+ tl (9 , "new JsonObject()" );
2139+ tl (10 , ".put(\" errorCode\" , \" 403\" )" );
2140+ tl (10 , ".put(\" errorMessage\" , msg)" );
2141+ tl (10 , ".encodePrettily()" );
2142+ tl (9 , "), MultiMap.caseInsensitiveMultiMap()" );
2143+ tl (7 , ")" );
2144+ tl (6 , "));" );
2145+ tl (5 , "} else {" );
2146+ }
21152147 if (classeRessourcesAutorisation .size () > 0 ) {
21162148 l ();
2117- tl (5 , "if(!scopes.contains(\" " , classeApiMethodeMethode , "\" )) {" );
21182149 tl (6 , "//" );
21192150 tl (6 , "List<String> fqs = new ArrayList<>();" );
21202151 tl (6 , "List<String> groups = Optional.ofNullable(" , i18nGlobale .getString (I18n .var_requeteSite ), ".getGroups()).orElse(new ArrayList<>());" );
@@ -2142,10 +2173,8 @@ public void ecrireGenApiServiceImpl2(String classeLangueNom) throws Exception {
21422173 tl (7 , "fq.add(fqs.stream().collect(Collectors.joining(\" OR \" )));" );
21432174 tl (7 , "scopes.add(\" " , classeApiMethodeMethode , "\" );" );
21442175 tl (6 , "}" );
2145- tl (5 , "}" );
21462176 l ();
21472177 }
2148- tl (5 , "{" );
21492178 tl (6 , i18nGlobale .getString (I18n .var_requeteSite ), ".setScopes(scopes.stream().map(o -> o.toString()).collect(Collectors.toList()));" );
21502179 tl (6 , "List<String> scopes2 = " , i18nGlobale .getString (I18n .var_requeteSite ), ".getScopes();" );
21512180 if (classeRoleSession || classeRoleUtilisateur || classeRoleChacun ) {
@@ -2401,7 +2430,7 @@ else if(classeApiMethode.equals(i18nGlobale.getString(I18n.var_PUTFusion)) || cl
24012430
24022431 if (
24032432 classeAuth
2404- && BooleanUtils .isNotTrue (classePublicLire )
2433+ && BooleanUtils .isNotTrue (classePublicLire ) || ! StringUtils . equals ( classeApiMethodeMethode , "GET" )
24052434 ) {
24062435 if (authPolitiqueGranulee ) {
24072436 tl (5 , "}" );
0 commit comments