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

Implement declarative auth design for upgrade service #216

Merged
merged 8 commits into from
Jun 11, 2021
Merged

Conversation

ldclakmal
Copy link
Member

@ldclakmal ldclakmal commented Jun 10, 2021

Purpose

This PR introduces the declarative auth design for WebSocket listener.

Design: https://docs.google.com/document/d/1dGw5uUP6kqZNTwMfQ_Ik-k0HTMKhX70XpEA3tys9_kk/edit?usp=sharing

Example:

import ballerina/websocket;

listener websocket:Listener securedEP = new(9090,
   secureSocket = {
       key: {
           certFile: "./resources/public.crt",
           keyFile: "./resources/private.key"
       }
   }
);

@websocket:ServiceConfig {
    auth: [
        {
            jwtValidatorConfig: {
                issuer: "wso2",
                audience: "ballerina",
                signatureConfig: {
                    certFile: "./resources/public.crt"
                },
                scopeKey: "scp"
            },
            scopes: ["admin"]
        }
    ]
}
service /foo on securedEP {
    resource function get bar() returns websocket:Service {
        return new WsService();
    }
}

service class WsService {
    *websocket:Service;
    remote function onTextMessage(websocket:Caller caller, string text) returns websocket:Error? {
        _ = check caller->writeTextMessage(text);
    }
}

Fixes ballerina-platform/ballerina-library#1405
Fixes ballerina-platform/ballerina-library#1230
Related to: ballerina-platform/ballerina-library#584

Checklist

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

@codecov
Copy link

codecov bot commented Jun 10, 2021

Codecov Report

Merging #216 (f8ecf1b) into main (abce8b1) will decrease coverage by 0.30%.
The diff coverage is 74.19%.

Impacted file tree graph

@@             Coverage Diff              @@
##               main     #216      +/-   ##
============================================
- Coverage     80.91%   80.60%   -0.31%     
- Complexity      346      349       +3     
============================================
  Files            43       44       +1     
  Lines          1991     2083      +92     
  Branches        271      311      +40     
============================================
+ Hits           1611     1679      +68     
- Misses          297      317      +20     
- Partials         83       87       +4     
Impacted Files Coverage Δ
websocket-ballerina/annotation.bal 100.00% <ø> (ø)
...et/websocket/server/OnUpgradeResourceCallback.java 62.79% <41.66%> (-8.18%) ⬇️
...org/ballerinalang/net/websocket/WebSocketUtil.java 73.52% <60.00%> (-0.41%) ⬇️
websocket-ballerina/auth_desugar.bal 78.68% <78.68%> (ø)
websocket-ballerina/auth_types.bal 87.50% <80.00%> (-12.50%) ⬇️
...allerinalang/net/websocket/WebSocketConstants.java 100.00% <100.00%> (ø)
...ang/net/websocket/WebSocketResourceDispatcher.java 82.63% <100.00%> (+0.09%) ⬆️

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 abce8b1...f8ecf1b. Read the comment docs.

@ldclakmal ldclakmal marked this pull request as ready for review June 10, 2021 07:11
Co-authored-by: Bhashinee <Bhashinee@users.noreply.github.com>
@ldclakmal ldclakmal merged commit 5075d34 into main Jun 11, 2021
@ldclakmal ldclakmal deleted the dev-chanakal branch June 11, 2021 06:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants