-
Notifications
You must be signed in to change notification settings - Fork 755
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
Refactor inbound authentication with custom provider and handlers #15056
Refactor inbound authentication with custom provider and handlers #15056
Conversation
…ina-lang into refactor-inbound-auth # Conflicts: # tests/ballerina-integration-test/src/test/resources/auth/authservices/13_authn_with_expired_certificate.bal
bc8655b
to
b10bcc2
Compare
...rina-integration-test/src/test/resources/auth/authservices/17_authn_with_custom_handlers.bal
Outdated
Show resolved
Hide resolved
...rina-integration-test/src/test/resources/auth/authservices/17_authn_with_custom_handlers.bal
Outdated
Show resolved
Hide resolved
@@ -0,0 +1,26 @@ | |||
// Copyright (c) 2018 WSO2 Inc. (http://www.wso2.org) All Rights Reserved. |
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.
Is this a new file? Incorrect year
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.
Earlier this file was auth_store_provider.bal
. In this PR I have renamed it and updated.
stdlib/http/src/test/resources/test-src/auth/basic-authn-handler-test.bal
Show resolved
Hide resolved
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.
Reviewed changes affected to Language server
Purpose
This PR provides the capability of custom authentication providers and handlers engagement for inbound authentication. Currently, the user cannot attach a custom provider and handler because the authentication filter related logic is tightly coupled with the pre-provided handlers by Ballerina.
Fixes #14823
Fixes #15175
Approach
ballerina/auth
module provides an abstract object namedAuthProvider
, which authenticate the provided credentials and return the status of authentication astrue
orfalse
.ConfigAuthStoreProvider
,JWTAuthProvider
andLdapAuthStoreProvider
are implementations of theAuthProvider
for different use cases.runtime:Principal.scopes
, since it is used at the authorization phase.auth
package ofballerina/http
module has the authentication filter, authorization filter, and authentication handlers.ballerina/http
module provides an abstract object namedAuthnHandler
, which handle the authentication of the provided http request and return the status of authentication astrue
orfalse
.BasicAuthnHandler
andJwtAuthnHandler
are implementations of theAuthnHandler
for different use cases.If a user wants to engage a custom authentication logic, it is needed to write a custom provider and handler as follows. Or else already implemented handlers and providers can be used.
Custom Provider
Custom Handler
Samples
Sample 1 - Basic authn handler example
This is a sample program which handles authentication with authorization with Basic auth.
Sample 2 - JWT authn handler example
This is a sample program which handles authentication with authorization with JWT.
Sample 3 - Basic authn handler with config overwrite example
Here, listener config will be overwritten by service level config and then service level config will be overwritten by resource level config.
Sample 4 - Custom authn handler example
This is a sample program which handles authentication with authorization with a custom header.
sample.bal
custom_authn_handler.bal
custom_auth_store_provider.bal
Invoke the service with following
curl
command.$ curl -kv https://localhost:9090/hello/sayHello -H "Authorization: Custom YWJjOjEyMw=="
Testing
Check List