Skip to content
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 support to overwrite the scopes config by resource annotation #604

Merged
merged 2 commits into from
Aug 25, 2021

Conversation

ldclakmal
Copy link
Member

@ldclakmal ldclakmal commented Aug 25, 2021

Purpose

This PR add support to overwrite the auth.scopes config of service annotation by resource annotation.

Fixes ballerina-platform/ballerina-library#973

Examples

  1. scopes config defined at http:ServiceConfig annotation will be overwritten by the scopes config defined at http:ResourceConfig. That means, for the particular bar resource, the required scopes are "write" or "update".

    @http:ServiceConfig {
        auth: [
            {
                jwtValidatorConfig: {
                    issuer: "wso2",
                    audience: "ballerina",
                    signatureConfig: {
                        certFile: "./resources/public.crt"
                    },
                    scopeKey: "scp"
                },
                scopes: ["read"]
            }
        ]
    }
    service /foo on authListener {
    
        @http:ResourceConfig {
            auth: {
                scopes: ["write", "update"]
            }
        }
        resource function get bar() returns string {
            return "Hello World!";
        }
    }
  2. scopes config not defined at http:ServiceConfig annotation. So, it will be appended by the scopes config defined at http:ResourceConfig. That means, for the particular bar resource, the required scopes are "write" or "update".

    @http:ServiceConfig {
        auth: [
            {
                jwtValidatorConfig: {
                    issuer: "wso2",
                    audience: "ballerina",
                    signatureConfig: {
                        certFile: "./resources/public.crt"
                    },
                    scopeKey: "scp"
                }
            }
        ]
    }
    service /foo on authListener {
      
        @http:ResourceConfig {
            auth: {
                scopes: ["write", "update"]
            }
        }
        resource function get bar() returns string {
            return "Hello World!";
        }
    }

Checklist

  • Linked to an issue
  • Updated the changelog
  • Added tests

@codecov
Copy link

codecov bot commented Aug 25, 2021

Codecov Report

Merging #604 (91d1240) into master (fa8e854) will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #604      +/-   ##
============================================
+ Coverage     80.12%   80.13%   +0.01%     
  Complexity       67       67              
============================================
  Files           335      335              
  Lines         17089    17106      +17     
  Branches       3821     3827       +6     
============================================
+ Hits          13692    13708      +16     
- Misses         2659     2660       +1     
  Partials        738      738              
Impacted Files Coverage Δ
ballerina/http_annotation.bal 100.00% <ø> (ø)
ballerina/auth_desugar.bal 97.93% <100.00%> (+0.21%) ⬆️
ballerina/auth_types.bal 100.00% <100.00%> (ø)
...a/stdlib/http/transport/message/MessageFuture.java 91.30% <0.00%> (-4.35%) ⬇️
...lerina/stdlib/http/api/logging/HttpLogManager.java 90.66% <0.00%> (-1.99%) ⬇️
...nsport/contractimpl/DefaultHttpResponseFuture.java 73.37% <0.00%> (-1.30%) ⬇️
...dlib/http/transport/message/HttpCarbonMessage.java 94.53% <0.00%> (-0.55%) ⬇️
...tractimpl/sender/ConnectionAvailabilityFuture.java 75.60% <0.00%> (+1.21%) ⬆️
...transport/message/Http2InboundContentListener.java 53.84% <0.00%> (+2.56%) ⬆️
...impl/listener/http2/Http2ServerTimeoutHandler.java 80.82% <0.00%> (+2.73%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fa8e854...91d1240. Read the comment docs.

@ldclakmal ldclakmal marked this pull request as ready for review August 25, 2021 04:06
@ldclakmal ldclakmal merged commit 5023e99 into ballerina-platform:master Aug 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support to overwrite the auth.scopes config of service annotation by resource annotation
2 participants