66import com .gewia .common .spring .auth .AuthScope ;
77import com .gewia .common .spring .auth .Authentication ;
88import com .gewia .common .util .Pair ;
9+ import java .util .ArrayList ;
910import java .util .List ;
1011import javax .servlet .http .HttpServletRequest ;
1112import javax .servlet .http .HttpServletResponse ;
@@ -25,13 +26,18 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons
2526
2627 HandlerMethod method = (HandlerMethod ) handler ;
2728
29+ AuthScope [] authScopes ;
2830 Authentication auth = method .getMethodAnnotation (Authentication .class );
29- if (auth == null ) {
30- response .setStatus (HttpStatus .OK .value ());
31- return true ;
31+ AuthScope methodAuthScope = method .getMethodAnnotation (AuthScope .class );
32+ if (auth != null ) authScopes = auth .value ();
33+ else {
34+ if (methodAuthScope == null ) {
35+ response .setStatus (HttpStatus .OK .value ());
36+ return true ;
37+ }
38+ authScopes = new AuthScope []{methodAuthScope };
3239 }
3340
34- AuthScope [] authScopes = auth .value ();
3541
3642 String jwt = request .getHeader ("Authorization" );
3743 if (jwt == null || jwt .isBlank ()) return false ;
@@ -41,7 +47,16 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons
4147 if (result .getRight () != JwtUtil .VerificationResult .SUCCESS ) return false ;
4248
4349 Claim claim = result .getLeft ().getClaim ("scopes" );
44- List <String > userScopes = claim .asList (String .class );
50+ List <String > userScopes = new ArrayList <>();
51+ for (String userScope : claim .asList (String .class )) {
52+ String [] splitUserScope = userScope .split ("\\ +" );
53+ if (splitUserScope .length < 2 ) userScopes .add (userScope );
54+ else {
55+ for (int i = 1 ; i < splitUserScope .length ; i ++)
56+ userScopes .add (splitUserScope [0 ] + "." + splitUserScope [i ]);
57+ }
58+ }
59+
4560 for (AuthScope authScope : authScopes ) {
4661 String scope = authScope .scope ();
4762 if (scope .isBlank ()) scope = authScope .value ();
0 commit comments