OpenAPITools / OpenAPITools/openapi-generator
[REQ] [Java] [Spring] Security info without SecurityContextHolder
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Is your feature request related to a problem? Please describe.
No. This suggests is about include a modern alternative to get security info in Controllers, not replace SecurityContextHolder, but include a possibility to use this modern approach.
Describe the solution you'd like
Instead of use SecurityContextHolder to get security info in protected endpoints is include a one new param in methods:
@PostMapping("/orders")
public ResponseEntity<PedidoDTO> createOrder(@RequestBody final OrdrerRequest request, final Principal principal) { // using Principal from Java
final var username = principal.getName();
// ...
}
or for custom impl
@PostMapping("/orders")
public ResponseEntity<PedidoDTO> createOrder(@RequestBody final OrderRequest request,@Authentication final Principal CustomPrincipal principal) { // custom impl with annotation
Long userId = principal.getId();
// ...
}
the suggest is provide this alternative if want. This approach is helpfull for create unit tests for controller
Describe alternatives you've considered
could be created a config to enable this, something like
<InjectPrincipalInController>true</InjectPrincipalInController>//default false
for define custom principal:
<CustomPrincipalToUse>FULL_QUALIFIED_NAME_IN_CLASS</CustomPrincipalToUse>
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No files or tests are identified. Start by locating the Spring controller generation entry point and review how controller parameters are currently represented; define the scope for Java Principal support, custom principal annotations, configuration, and tests before implementation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100