-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1182 from ldclakmal/fix-security-bbes
Fix BBEs of access control category
- Loading branch information
Showing
67 changed files
with
605 additions
and
791 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
51 changes: 19 additions & 32 deletions
51
examples/secured-client-with-basic-auth/secured_client_with_basic_auth.bal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,29 @@ | ||
import ballerina/auth; | ||
import ballerina/config; | ||
import ballerina/http; | ||
import ballerina/log; | ||
|
||
// Defines the Basic Auth client endpoint to call the backend services. | ||
// Basic Authentication is enabled by creating an | ||
// `auth:OutboundBasicAuthProvider` with the `username` and `password` | ||
// passed as a record. | ||
auth:OutboundBasicAuthProvider outboundBasicAuthProvider = new({ | ||
username: "tom", | ||
password: "1234" | ||
}); | ||
|
||
// Creates a Basic Auth handler with the created Basic Auth provider. | ||
http:BasicAuthHandler outboundBasicAuthHandler = | ||
new (outboundBasicAuthProvider); | ||
|
||
http:Client httpEndpoint = new("https://localhost:9090", { | ||
auth: { | ||
authHandler: outboundBasicAuthHandler | ||
}, | ||
secureSocket: { | ||
trustStore: { | ||
path: config:getAsString("b7a.home") + | ||
"/bre/security/ballerinaTruststore.p12", | ||
password: "ballerina" | ||
} | ||
// Defines the HTTP client to call the Basic auth secured APIs. | ||
// The client is enriched with the `Authorization: Basic <token>` header by | ||
// passing the `http:CredentialsConfig` for the `auth` configuration of the | ||
// client. | ||
http:Client securedEP = checkpanic new("https://localhost:9090", { | ||
auth: { | ||
username: "alice", | ||
password: "123" | ||
}, | ||
secureSocket: { | ||
trustStore: { | ||
path: "../resources/ballerinaTruststore.p12", | ||
password: "ballerina" | ||
} | ||
}); | ||
} | ||
}); | ||
|
||
public function main() { | ||
// Send a `GET` request to the specified endpoint. | ||
var response = httpEndpoint->get("/hello/sayHello"); | ||
var response = securedEP->get("/foo/bar"); | ||
if (response is http:Response) { | ||
var result = response.getTextPayload(); | ||
log:printInfo((result is error) ? | ||
"Failed to retrieve payload." : result); | ||
} else { | ||
log:printError("Failed to call the endpoint.", <error>response); | ||
log:print(response.statusCode.toString()); | ||
} else if (response is http:ClientError) { | ||
log:printError("Failed to call the endpoint.", err = response); | ||
} | ||
} |
16 changes: 6 additions & 10 deletions
16
examples/secured-client-with-basic-auth/secured_client_with_basic_auth.description
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,7 @@ | ||
// A client, which is secured with Basic authentication should be used to | ||
// connect to a service, which is secured with Basic authentication. | ||
// The `auth:OutboundBasicAuthProvider` is initialized with the `username` and | ||
// `password` and the `http:BasicAuthHandler` is initialized by providing | ||
// the created `auth:OutboundBasicAuthProvider`. An additional `auth` field is | ||
// added to the HTTP client endpoint initialization in order to secure the | ||
// simple HTTP client endpoint. | ||
// The `authHandler` field is defined inside the `auth` field with the value of | ||
// it being the reference of the created `http:BearerAuthHandler`.<br/><br/> | ||
// For more information on the underlying module, | ||
// A client, which is secured with Basic auth can be used to connect to | ||
// a secured service.<br/> | ||
// The client is enriched with the `Authorization: Basic <token>` header by | ||
// passing the `http:CredentialsConfig` for the `auth` configuration of the | ||
// client.<br/><br/> | ||
// For more information on the underlying module, | ||
// see the [Auth module](https://ballerina.io/swan-lake/learn/api-docs/ballerina/#/ballerina/auth/latest/auth/). |
2 changes: 1 addition & 1 deletion
2
examples/secured-client-with-basic-auth/secured_client_with_basic_auth.metatags
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
description: BBE on how to secure HTTP client with Basic Auth in Ballerina. | ||
description: BBE on how to secure HTTP client with Basic auth in Ballerina. | ||
keywords: ballerina, ballerina by example, http, auth, basic auth |
13 changes: 8 additions & 5 deletions
13
examples/secured-client-with-basic-auth/secured_client_with_basic_auth.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
# To test the client, first start a sample service secured with Basic Auth. | ||
# Then start the client by executing the below command by passing Ballerina home | ||
# path as a system property. | ||
bal run secured_client_with_basic_auth.bal --b7a.home=<ballerina_home_path> | ||
INFO [ballerina/log] - Hello, World!!! | ||
# Before testing this sample, first start a sample service secured with Basic Auth. | ||
# To run this sample, navigate to the directory that contains the `.bal` file, | ||
# and execute the `bal run` command below. | ||
# (You may need to change the keystore path. A sample keystore file is | ||
# available in the distribution. | ||
# The file path is <ballerina.home>/examples/resources/ballerinaKeystore.p12) | ||
bal run secured_client_with_basic_auth.bal | ||
time = 2021-01-20 20:04:13,261 level = INFO module = "" message = "200" |
24 changes: 0 additions & 24 deletions
24
examples/secured-client-with-basic-auth/tests/secured_client_with_basic_auth_test.bal
This file was deleted.
Oops, something went wrong.
28 changes: 28 additions & 0 deletions
28
examples/secured-client-with-bearer-token-auth/secured_client_with_bearer_token_auth.bal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import ballerina/http; | ||
import ballerina/log; | ||
|
||
// Defines the HTTP client to call the secured APIs. | ||
// The client is enriched with the `Authorization: Bearer <token>` header by | ||
// passing the `http:BearerTokenConfig` for the `auth` configuration of the | ||
// client. | ||
http:Client securedEP = checkpanic new("https://localhost:9090", { | ||
auth: { | ||
token: "JlbmMiOiJBMTI4Q0JDLUhTMjU2In" | ||
}, | ||
secureSocket: { | ||
trustStore: { | ||
path: "../resources/ballerinaTruststore.p12", | ||
password: "ballerina" | ||
} | ||
} | ||
}); | ||
|
||
public function main() { | ||
// Send a `GET` request to the specified endpoint. | ||
var response = securedEP->get("/foo/bar"); | ||
if (response is http:Response) { | ||
log:print(response.statusCode.toString()); | ||
} else if (response is http:ClientError) { | ||
log:printError("Failed to call the endpoint.", err = response); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...s/secured-client-with-bearer-token-auth/secured_client_with_bearer_token_auth.description
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// A client, which is secured with Bearer token auth can be used to connect to | ||
// a secured service.<br/> | ||
// The client is enriched with the `Authorization: Bearer <token>` header by | ||
// passing the `http:BearerTokenConfig` for the `auth` configuration of the | ||
// client. |
2 changes: 2 additions & 0 deletions
2
...ples/secured-client-with-bearer-token-auth/secured_client_with_bearer_token_auth.metatags
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
description: BBE on how to secure HTTP client with Bearer token auth in Ballerina. | ||
keywords: ballerina, ballerina by example, http, auth, jwt auth |
8 changes: 8 additions & 0 deletions
8
examples/secured-client-with-bearer-token-auth/secured_client_with_bearer_token_auth.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Before testing this sample, first start a secured sample service. | ||
# To run this sample, navigate to the directory that contains the `.bal` file, | ||
# and execute the `bal run` command below. | ||
# (You may need to change the keystore path. A sample keystore file is | ||
# available in the distribution. | ||
# The file path is <ballerina.home>/examples/resources/ballerinaKeystore.p12) | ||
bal run secured_client_with_bearer_token_auth.bal | ||
time = 2021-01-20 20:04:13,261 level = INFO module = "" message = "200" |
54 changes: 0 additions & 54 deletions
54
examples/secured-client-with-jwt-auth/secured_client_with_jwt_auth.bal
This file was deleted.
Oops, something went wrong.
16 changes: 0 additions & 16 deletions
16
examples/secured-client-with-jwt-auth/secured_client_with_jwt_auth.description
This file was deleted.
Oops, something went wrong.
2 changes: 0 additions & 2 deletions
2
examples/secured-client-with-jwt-auth/secured_client_with_jwt_auth.metatags
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
examples/secured-client-with-jwt-auth/secured_client_with_jwt_auth.out
This file was deleted.
Oops, something went wrong.
25 changes: 0 additions & 25 deletions
25
examples/secured-client-with-jwt-auth/tests/secured_client_with_jwt_auth_test.bal
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.