Migrate #oauth2 method security expressions to Spring Security authorities

Proprietary

Rewrites the #oauth2.hasScope('x') and #oauth2.hasAnyScope('x', 'y') expressions of the end-of-life org.springframework.security.oauth:spring-security-oauth2 project to the hasAuthority('SCOPE_x') and hasAnyAuthority('SCOPE_x', 'SCOPE_y') that replace them, in the @PreAuthorize, @PostAuthorize, @PreFilter, @PostFilter and @Secured annotations and in access(String) calls on the HTTP security DSL. Only those two methods are rewritten, and only where the expression is a string literal on one of those elements, so that the annotation's own type is what identifies the string as Spring Security's. Everything around the call is left alone: and, or, hasRole(..) and hasAuthority(..) all mean the same thing after the migration, so a composite expression needs only its #oauth2 part replaced. The remaining #oauth2 methods are marked for a manual migration rather than approximated, because a wrong authorization expression fails silently rather than loudly. Note that SCOPE_ is the prefix JwtGrantedAuthoritiesConverter uses by default: an application that calls setAuthorityPrefix with something else, or that maps authorities with a converter of its own, needs the new prefix applied by hand.

io.moderne.java.spring.security.oauth.MigrateOAuth2SecurityExpressions
mod run . --recipe=io.moderne.java.spring.security.oauth.MigrateOAuth2SecurityExpressions

Install it once from Recipe actions, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.