Skip to content

Commit

Permalink
Merge pull request wso2#19076 from shanggeeth/master
Browse files Browse the repository at this point in the history
  • Loading branch information
shanggeeth committed Jan 22, 2024
2 parents 7ef5946 + ff7f75e commit 30394c6
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import org.testng.Assert;
Expand All @@ -72,6 +73,7 @@
import java.net.URI;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;

Expand All @@ -97,6 +99,7 @@ public class OrganizationManagementSuccessTest extends OrganizationManagementBas
private String switchedM2MToken;
private String b2bApplicationID;
private HttpClient client;
protected OAuth2RestClient restClient;

@Factory(dataProvider = "restAPIUserConfigProvider")
public OrganizationManagementSuccessTest(TestUserMode userMode) throws Exception {
Expand Down Expand Up @@ -147,29 +150,49 @@ public static Object[][] restAPIUserConfigProvider() {
}

@Test
public void enableSelfOrganizationOnboardService() throws IOException {
public void createApplicationForSelfOrganizationOnboardService() throws IOException, JSONException {

String endpointURL = "self-service/preferences";
String body = readResource("enable-self-organization-onboard-request-body.json");
String endpointURL = "applications";
String body = readResource("create-organization-self-service-app-request.body.json");

Response response = given().auth().preemptive().basic(authenticatingUserName, authenticatingCredential)
.contentType(ContentType.JSON)
.body(body)
.when()
.patch(endpointURL);
.body(body).when().post(endpointURL);
response.then()
.log().ifValidationFails()
.assertThat()
.statusCode(HttpStatus.SC_OK);
.log().ifValidationFails().assertThat().statusCode(HttpStatus.SC_CREATED);

Optional<ApplicationListItem> b2bSelfServiceApp = oAuth2RestClient.getAllApplications().getApplications().stream()
.filter(application -> application.getName().equals("B2B-Self-Service-Mgt-Application"))
.filter(application -> application.getName().equals("b2b-self-service-app"))
.findAny();
Assert.assertTrue(b2bSelfServiceApp.isPresent(), "B2B self organization onboard feature is not enabled properly");
Assert.assertTrue(b2bSelfServiceApp.isPresent(), "B2B self service application is not created");
selfServiceAppId = b2bSelfServiceApp.get().getId();

JSONObject jsonObject = new JSONObject(readResource("organization-self-service-apis.json"));

for (Iterator<String> apiNameIterator = jsonObject.keys(); apiNameIterator.hasNext(); ) {
String apiName = apiNameIterator.next();
Object requiredScopes = jsonObject.get(apiName);

Response aPIResource =
given().auth().preemptive().basic(authenticatingUserName, authenticatingCredential).when()
.queryParam("filter", "identifier eq " + apiName).get("api-resources");
aPIResource.then().log().ifValidationFails().assertThat().statusCode(HttpStatus.SC_OK);
String apiUUID = aPIResource.getBody().jsonPath().getString("apiResources[0].id");

JSONObject authorizedAPIRequestBody = new JSONObject();
authorizedAPIRequestBody.put("id", apiUUID);
authorizedAPIRequestBody.put("policyIdentifier", "RBAC");
authorizedAPIRequestBody.put("scopes", requiredScopes);

Response authorizedAPIResponse =
given().auth().preemptive().basic(authenticatingUserName, authenticatingCredential)
.contentType(ContentType.JSON).body(authorizedAPIRequestBody.toString()).when()
.post("applications/" + selfServiceAppId + "/authorized-apis");
authorizedAPIResponse.then().log().ifValidationFails().assertThat().statusCode(HttpStatus.SC_OK);
}
}

@Test(dependsOnMethods = "enableSelfOrganizationOnboardService")
@Test(dependsOnMethods = "createApplicationForSelfOrganizationOnboardService")
public void getM2MAccessToken() throws Exception {

OpenIDConnectConfiguration openIDConnectConfiguration = oAuth2RestClient.getOIDCInboundDetails(selfServiceAppId);
Expand Down Expand Up @@ -242,7 +265,7 @@ public void switchM2MToken() throws IOException, ParseException, InterruptedExce
Thread.sleep(5000);

List<NameValuePair> urlParameters = new ArrayList<>();
urlParameters.add(new BasicNameValuePair(OAuth2Constant.GRANT_TYPE_NAME, "organization_switch_cc"));
urlParameters.add(new BasicNameValuePair(OAuth2Constant.GRANT_TYPE_NAME, "organization_switch"));
urlParameters.add(new BasicNameValuePair("token", m2mToken));
urlParameters.add(new BasicNameValuePair("scope", "SYSTEM"));
urlParameters.add(new BasicNameValuePair("switching_organization", organizationID));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@
"name": "organization_switch",
"displayName": "Organization Switch"
},
{
"name": "organization_switch_cc",
"displayName": "organization_switch_cc"
},
{
"name": "urn:ietf:params:oauth:grant-type:jwt-bearer",
"displayName": "urn:ietf:params:oauth:grant-type:jwt-bearer"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "b2b-self-service-app",
"templateId": "custom-application-oidc",
"inboundProtocolConfiguration": {
"oidc": {
"grantTypes": [
"client_credentials",
"organization_switch"
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"/api/server/v1/organizations": [
"internal_organization_view",
"internal_organization_create"
],
"/scim2/Users": [
"internal_user_mgt_view",
"internal_user_mgt_create"
],
"/o/scim2/Users": [
"internal_org_user_mgt_create",
"internal_org_user_mgt_list"
],
"/o/scim2/Roles": [
"internal_org_role_mgt_view",
"internal_org_role_mgt_update"
],
"/o/api/server/v1/applications": [
"internal_org_application_mgt_view"
]
}
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2252,7 +2252,7 @@
<properties>

<!--Carbon Identity Framework Version-->
<carbon.identity.framework.version>5.26.14</carbon.identity.framework.version>
<carbon.identity.framework.version>5.26.15</carbon.identity.framework.version>
<carbon.identity.framework.version.range>[5.14.67, 6.0.0]</carbon.identity.framework.version.range>

<!--SAML Common Utils Version-->
Expand All @@ -2274,7 +2274,7 @@

<!-- Identity Inbound Versions -->
<identity.inbound.auth.saml.version>5.11.33</identity.inbound.auth.saml.version>
<identity.inbound.auth.oauth.version>6.12.7</identity.inbound.auth.oauth.version>
<identity.inbound.auth.oauth.version>6.12.8</identity.inbound.auth.oauth.version>
<identity.inbound.auth.openid.version>5.10.0</identity.inbound.auth.openid.version>
<identity.inbound.auth.sts.version>5.11.2</identity.inbound.auth.sts.version>
<identity.inbound.provisioning.scim.version>5.7.4</identity.inbound.provisioning.scim.version>
Expand Down Expand Up @@ -2354,7 +2354,7 @@
<identity.org.mgt.version>1.3.150</identity.org.mgt.version>
<identity.org.mgt.core.version>1.0.97</identity.org.mgt.core.version>
<identity.organization.login.version>1.1.25</identity.organization.login.version>
<identity.oauth2.grant.organizationswitch.version>1.1.20</identity.oauth2.grant.organizationswitch.version>
<identity.oauth2.grant.organizationswitch.version>1.1.21</identity.oauth2.grant.organizationswitch.version>

<!-- Hash Provider Versions-->
<hashprovider.pbkdf2.version>0.1.4</hashprovider.pbkdf2.version>
Expand Down

0 comments on commit 30394c6

Please sign in to comment.