How to Declare the Required Permissions for an API in the API Description (spring security)
- Consider adding the following configuration:
doc.method[@org.springframework.security.access.prepost.PreAuthorize]=groovy:```
def preAuthorize = it.ann("org.springframework.security.access.prepost.PreAuthorize")
if(tool.nullOrBlank(preAuthorize)){
return
}
def role = regex.getGroup1("hasRole\\('(.*?)'\\)",preAuthorize)
return "require role: $role"
```
@RestController
@RequestMapping(value = "mock")
public class MockCtrl {
@GetMapping("/string")
@PreAuthorize("hasRole('admin')")
public String mockString() {
return Result.success("mock string");
}
}