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

Reorganize and cleanup auth stdlib #13808

Merged
merged 28 commits into from
Feb 25, 2019

Conversation

ayomawdb
Copy link
Member

@ayomawdb ayomawdb commented Feb 22, 2019

Purpose

Resolve following auth stdlib related improvements and feature additions.

In addition, this PR reorganize the client and server endpoint auth configurations, to make it easier to understand. Previously, configuration for all the authentication mechanisms were put in record, which confused uses on which configurations to use for each authentication mechanism. Now the client auth configuration has been separated as follows:

# AuthConfig record can be used to configure the authentication mechanism used by the HTTP endpoint.
#
# + scheme - Authentication scheme
# + basicAuthConfig - Configuration for BasicAuth scheme
# + oAuth2AuthConfig - Configuration for OAuth2 scheme
# + jwtAuthConfig - Configuration for JWT scheme. If inbound authentication is JWT, sends the same JWT with client
#                   invocation, unless reissuing is configured using InferredJwtIssuerConfig.
public type AuthConfig record {
    OutboundAuthScheme scheme;
    BasicAuthConfig basicAuthConfig?;
    OAuth2AuthConfig oAuth2AuthConfig?;
    JwtAuthConfig jwtAuthConfig?;
    !...;
};

In addition, improve the crypto and encoding stdlib to provide operations that are required for internal workings of auth stdlib. This limits to:

  • Adding RSA signature verification support
  • Adding Base64Url encoding and decoding support

Update 1

AuthConfig was changed to use union for configuration.

# AuthConfig record can be used to configure the authentication mechanism used by the HTTP endpoint.
#
# + scheme - Authentication scheme
# + config - Configuration related to the selected authenticator.
public type AuthConfig record {
    OutboundAuthScheme scheme;
    BasicAuthConfig|OAuth2AuthConfig|JwtAuthConfig config?;
    !...;
};

@ayomawdb ayomawdb marked this pull request as ready for review February 22, 2019 09:23
@davebaol
Copy link

In addition, this PR reorganize the client and server endpoint auth configurations, to make it easier to understand. Previously, configuration for all the authentication mechanisms were put in record, which confused uses on which configurations to use for each authentication mechanism. Now the client auth configuration has been separated as follows:

# AuthConfig record can be used to configure the authentication mechanism used by the HTTP endpoint.
#
# + scheme - Authentication scheme
# + basicAuthConfig - Configuration for BasicAuth scheme
# + oAuth2AuthConfig - Configuration for OAuth2 scheme
# + jwtAuthConfig - Configuration for JWT scheme. If inbound authentication is JWT, sends the same JWT with client
#                   invocation, unless reissuing is configured using InferredJwtIssuerConfig.
public type AuthConfig record {
    OutboundAuthScheme scheme;
    BasicAuthConfig basicAuthConfig?;
    OAuth2AuthConfig oAuth2AuthConfig?;
    JwtAuthConfig jwtAuthConfig?;
    !...;
};

I see your point and this is certainly easier to understand, but I would have expected something like that

public type AuthConfig record {
    OutboundAuthScheme scheme;
    BasicAuthConfig|OAuth2AuthConfig|JwtAuthConfig config;
    !...;
};

Why do you prefer 3 optional fields in place of a union?

@ayomawdb
Copy link
Member Author

@davebaol Thank you for the feedback. Yes you have a valid point here and I do not have any strong point to defend using separate optional config records.

There were some implementation complications related to record ambiguity that prevented using an union initially. We are working on reorganizing and improving OAuth2 related logic, targeting March end. Initial idea was to do this with OAuth2 related changes.

However, I agreed with you that will change will look very neat and clean with a single union for configuration. I had some time to further look at record ambiguity problem, and I have now used union for configuration, as you have suggested. Updated PR description accordingly.

@davebaol thanks again for the valuable input!

@codecov-io
Copy link

Codecov Report

Merging #13808 into master will decrease coverage by 0.61%.
The diff coverage is 74.14%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master   #13808      +/-   ##
============================================
- Coverage     65.14%   64.52%   -0.62%     
  Complexity      426      426              
============================================
  Files          2116     2150      +34     
  Lines         94178    95356    +1178     
  Branches      12492    12699     +207     
============================================
+ Hits          61349    61531     +182     
- Misses        27844    28817     +973     
- Partials       4985     5008      +23
Impacted Files Coverage Δ Complexity Δ
...rinalang/stdlib/encoding/nativeimpl/EncodeHex.java 100% <ø> (ø) 0 <0> (ø) ⬇️
...alang/stdlib/encoding/nativeimpl/DecodeBase64.java 100% <ø> (ø) 0 <0> (ø) ⬇️
...rinalang/stdlib/encoding/nativeimpl/DecodeHex.java 100% <ø> (ø) 0 <0> (ø) ⬇️
...alang/stdlib/encoding/nativeimpl/EncodeBase64.java 100% <ø> (ø) 0 <0> (ø) ⬇️
...ava/org/ballerinalang/stdlib/crypto/Constants.java 0% <ø> (ø) 0 <0> (ø) ⬇️
.../stdlib/encoding/nativeimpl/ByteArrayToString.java 77.77% <ø> (ø) 0 <0> (ø) ⬇️
...lib/runtime/nativeimpl/InvocationContextUtils.java 88.57% <100%> (ø) 0 <0> (ø) ⬇️
...ng/stdlib/encoding/nativeimpl/EncodeBase64Url.java 100% <100%> (ø) 0 <0> (?)
...ang/stdlib/crypto/nativeimpl/DecodePrivateKey.java 58.13% <100%> (+0.99%) 0 <0> (ø) ⬇️
...a/org/ballerinalang/stdlib/crypto/CryptoUtils.java 66.16% <29.62%> (-9.31%) 0 <0> (ø)
... and 75 more

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 105430c...5c581d9. Read the comment docs.

@ayomawdb ayomawdb merged commit ba6e2eb into ballerina-platform:master Feb 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team/StandardLibs All Ballerina standard libraries Type/Improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants