-
Notifications
You must be signed in to change notification settings - Fork 129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add binder for annotated custom Principal
#1522
Conversation
A new `@User` annotation is added that can be used to bind a custom `Principal` object to a method argument for the currently active login.
Authentication
Principal
@sdelamo Note that I have not added documentation for this enhancement yet - wanted to see what you think of the idea first. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure about this. it will require to create a custom authentication response.
security/src/test/groovy/io/micronaut/security/authorization/AuthorizationSpec.groovy
Outdated
Show resolved
Hide resolved
@@ -95,7 +103,7 @@ class AuthorizationSpec extends EmbeddedServerSpecification { | |||
|
|||
void "Authentication Argument Binders binds Authentication if return type is Single"() { | |||
expect: | |||
embeddedServer.applicationContext.getBean(PrincipalArgumentBinder.class) | |||
embeddedServer.applicationContext.getBean(AuthenticationArgumentBinder.class) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seemed more appropriate since that is the binder that gets used when the method argument is Authentication
.
security/src/test/groovy/io/micronaut/security/authorization/AuthorizationSpec.groovy
Outdated
Show resolved
Hide resolved
security/src/test/groovy/io/micronaut/security/authorization/AuthorizationSpec.groovy
Outdated
Show resolved
Hide resolved
security/src/test/groovy/io/micronaut/security/authorization/AuthorizationSpec.groovy
Outdated
Show resolved
Hide resolved
security/src/test/groovy/io/micronaut/security/authorization/AuthorizationSpec.groovy
Outdated
Show resolved
Hide resolved
|
||
@Get("/single-server-authentication") | ||
@SingleResult | ||
Publisher<String> singleServerAuthentication(@User ServerAuthentication authentication) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all of these methods return Publisher
. we could just return String
. Returning Single
is unrelated with what is under test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. I wasn't sure if the original spec author was explicitly trying to make sure it worked with Publisher
for some non-obvious reason since it was explicitly being called out in the spec method descriptions.
I have created a PR with docs #1524 for the current behaviour. |
…uthorizationSpec.groovy Co-authored-by: Sergio del Amo <[email protected]>
…uthorizationSpec.groovy Co-authored-by: Sergio del Amo <[email protected]>
…uthorizationSpec.groovy Co-authored-by: Sergio del Amo <[email protected]>
…uthorizationSpec.groovy Co-authored-by: Sergio del Amo <[email protected]>
Kudos, SonarCloud Quality Gate passed! |
…uthorizationSpec.groovy Co-authored-by: Sergio del Amo <[email protected]>
Closing this for now. I am not sure about this feature. |
A new
@User
annotation is added that can be used to bind a customPrincipal
object to a method parameter for thecurrently active login.
This allows for users to provide their own custom authentication object and still be able to bind it to
@Controller
method parameters as long as the parameter is annotated with
@User
and matches the type of the authenticationstored in the request.
For example:
would work without requiring the user to supply their own
RequestArgumentBinder
This resolves #1430