Skip to content

Commit 6b29c78

Browse files
committed
Split jwt/jwk example service
1 parent 8255c14 commit 6b29c78

File tree

2 files changed

+66
-30
lines changed

2 files changed

+66
-30
lines changed

test-suite/packages/test.auth.jwt/jwt_secured_service.bal

Lines changed: 63 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,7 @@ listener http:Listener jwtListenerEP = new(9090, config = {
1111
}
1212
});
1313

14-
listener http:Listener jwkListenerEP = new(9091, config = {
15-
secureSocket: {
16-
keyStore: {
17-
path: "resources/ballerinaKeystore.p12",
18-
password: "ballerina"
19-
}
20-
}
21-
});
22-
23-
service /orders on jwtListenerEP, jwkListenerEP {
14+
service /orders9090 on jwtListenerEP {
2415

2516
@http:ResourceConfig {
2617
auth: [
@@ -39,7 +30,67 @@ service /orders on jwtListenerEP, jwkListenerEP {
3930
}
4031
},
4132
scopes: ["view-order"]
42-
},
33+
}
34+
]
35+
}
36+
resource function get view() returns json {
37+
json inventory = {
38+
"items": [
39+
{
40+
"code": uuid:createType4AsString(),
41+
"qty" : checkpanic random:createIntInRange(1, 100)
42+
}
43+
]
44+
};
45+
return inventory;
46+
}
47+
48+
@http:ResourceConfig {
49+
auth: [
50+
{
51+
jwtValidatorConfig: {
52+
issuer: "wso2is",
53+
audience: "3VTwFk7u1i366wzmvpJ_LZlfAV4a",
54+
signatureConfig: {
55+
trustStoreConfig: {
56+
certAlias: "wso2carbon",
57+
trustStore: {
58+
path: "resources/wso2Truststore.p12",
59+
password: "wso2carbon"
60+
}
61+
}
62+
}
63+
},
64+
scopes: ["add-order"]
65+
}
66+
]
67+
}
68+
resource function get add() returns json {
69+
json inventory = {
70+
"items": [
71+
{
72+
"code": uuid:createType4AsString(),
73+
"qty" : checkpanic random:createIntInRange(1, 100)
74+
}
75+
]
76+
};
77+
return inventory;
78+
}
79+
}
80+
81+
listener http:Listener jwkListenerEP = new(9091, config = {
82+
secureSocket: {
83+
keyStore: {
84+
path: "resources/ballerinaKeystore.p12",
85+
password: "ballerina"
86+
}
87+
}
88+
});
89+
90+
service /orders9091 on jwkListenerEP {
91+
92+
@http:ResourceConfig {
93+
auth: [
4394
{
4495
jwtValidatorConfig: {
4596
issuer: "wso2is",
@@ -76,22 +127,6 @@ service /orders on jwtListenerEP, jwkListenerEP {
76127

77128
@http:ResourceConfig {
78129
auth: [
79-
{
80-
jwtValidatorConfig: {
81-
issuer: "wso2is",
82-
audience: "3VTwFk7u1i366wzmvpJ_LZlfAV4a",
83-
signatureConfig: {
84-
trustStoreConfig: {
85-
certAlias: "wso2carbon",
86-
trustStore: {
87-
path: "resources/wso2Truststore.p12",
88-
password: "wso2carbon"
89-
}
90-
}
91-
}
92-
},
93-
scopes: ["add-order"]
94-
},
95130
{
96131
jwtValidatorConfig: {
97132
issuer: "wso2is",
@@ -126,3 +161,4 @@ service /orders on jwtListenerEP, jwkListenerEP {
126161
return inventory;
127162
}
128163
}
164+

test-suite/scripts/test_jwt_auth.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,21 @@ for port in 9090 9091
2323
do
2424
echo -e "\nTest1: Authn Failure:"
2525
echo -e "\nInvoking Ballerina JWT service:"
26-
response=$(curl -k -i -H "AUTHORIZATION: Bearer InvalidToken" https://localhost:$port/orders/view)
26+
response=$(curl -k -i -H "AUTHORIZATION: Bearer InvalidToken" https://localhost:$port/orders$port/view)
2727
assertNotEmpty $response
2828
echo -e "\nBallerina service response: $response"
2929
assertAuthnFailure $response
3030

3131
echo -e "\nTest2: Authn Success - Authz Failure:"
3232
echo -e "\nInvoking Ballerina JWT service:"
33-
response=$(curl -k -i -H "AUTHORIZATION: Bearer $token" https://localhost:$port/orders/add)
33+
response=$(curl -k -i -H "AUTHORIZATION: Bearer $token" https://localhost:$port/orders$port/add)
3434
assertNotEmpty $response
3535
echo -e "\nBallerina service response: $response"
3636
assertAuthzFailure $response
3737

3838
echo -e "\nTest3: Authn Success - Authz Success:"
3939
echo -e "\nInvoking Ballerina JWT service:"
40-
response=$(curl -k -i -H "AUTHORIZATION: Bearer $token" https://localhost:$port/orders/view)
40+
response=$(curl -k -i -H "AUTHORIZATION: Bearer $token" https://localhost:$port/orders$port/view)
4141
assertNotEmpty $response
4242
echo -e "\nBallerina service response: $response"
4343
assertSuccess $response

0 commit comments

Comments
 (0)