diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2ServiceAbstractIntegrationTest.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2ServiceAbstractIntegrationTest.java index 17730e54dc5..c9f98c6b889 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2ServiceAbstractIntegrationTest.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/OAuth2ServiceAbstractIntegrationTest.java @@ -51,6 +51,8 @@ import org.wso2.identity.integration.common.clients.oauth.OauthAdminClient; import org.wso2.identity.integration.common.clients.usermgt.remote.RemoteUserStoreManagerServiceClient; import org.wso2.identity.integration.common.utils.ISIntegrationTest; +import org.wso2.identity.integration.test.rest.api.server.api.resource.v1.model.APIResourceListItem; +import org.wso2.identity.integration.test.rest.api.server.api.resource.v1.model.ScopeGetModel; import org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.*; import org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.ClaimConfiguration.DialectEnum; import org.wso2.identity.integration.test.restclients.OAuth2RestClient; @@ -898,4 +900,37 @@ public String getPublicCertificate(CloseableHttpClient client, String endPoint) JSONObject json = (JSONObject) parser.parse(EntityUtils.toString(response.getEntity())); return ((JSONArray) ((JSONObject)((JSONArray) json.get("keys")).get(0)).get("x5c")).get(0).toString(); } + + /** + * Authorize list of SYSTEM APIs to an application. + * + * @param applicationId Application id. + * @param apiIdentifiers API identifiers to authorize. + * @throws Exception Error occured while authorizing APIs. + */ + public void authorizeSystemAPIs(String applicationId, List apiIdentifiers) throws Exception { + + apiIdentifiers.stream().forEach(apiIdentifier -> { + try { + List filteredAPIResource = + restClient.getAPIResourcesWithFiltering("type+eq+SYSTEM+and+identifier+eq+" + apiIdentifier); + if (filteredAPIResource == null) { + return; + } + String apiId = filteredAPIResource.get(0).getId(); + // Get API scopes. + List apiResourceScopes = restClient.getAPIResourceScopes(apiId); + AuthorizedAPICreationModel authorizedAPICreationModel = new AuthorizedAPICreationModel(); + authorizedAPICreationModel.setId(apiId); + authorizedAPICreationModel.setPolicyIdentifier("RBAC"); + apiResourceScopes.forEach(scope -> { + authorizedAPICreationModel.addScopesItem(scope.getName()); + }); + restClient.addAPIAuthorizationToApplication(applicationId, authorizedAPICreationModel); + } catch (Exception e) { + throw new RuntimeException("Error while authorizing system API " + apiIdentifier + " to application " + + applicationId, e); + } + }); + } } diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/SystemScopePermissionValidationTestCase.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/SystemScopePermissionValidationTestCase.java index 3b155d7da8a..b96f73969d4 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/SystemScopePermissionValidationTestCase.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/oauth2/SystemScopePermissionValidationTestCase.java @@ -40,6 +40,9 @@ import org.testng.annotations.DataProvider; import org.testng.annotations.Factory; import org.testng.annotations.Test; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; import org.wso2.carbon.automation.engine.context.AutomationContext; import org.wso2.carbon.automation.engine.context.TestUserMode; import org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.ApplicationResponseModel; @@ -47,12 +50,20 @@ import org.wso2.identity.integration.test.utils.DataExtractUtil; import org.wso2.identity.integration.test.utils.OAuth2Constant; +import java.io.ByteArrayInputStream; import java.net.URI; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; + import static org.wso2.identity.integration.test.utils.DataExtractUtil.KeyValue; public class SystemScopePermissionValidationTestCase extends OAuth2ServiceAbstractIntegrationTest { @@ -68,6 +79,8 @@ public class SystemScopePermissionValidationTestCase extends OAuth2ServiceAbstra private final TestUserMode testUserMode; private static final String SYSTEM_SCOPE = "SYSTEM"; + private static final String ENABLE_LEGACY_AUTHZ_RUNTIME_CONFIG = "EnableLegacyAuthzRuntime"; + private static boolean isLegacyRuntimeEnabled; private String applicationId; @DataProvider(name = "configProvider") @@ -94,6 +107,7 @@ public void testInit() throws Exception { setSystemproperties(); client = HttpClientBuilder.create().build(); + isLegacyRuntimeEnabled = isLegacyAuthzRuntimeEnabled(); } @AfterClass(alwaysRun = true) @@ -119,6 +133,12 @@ public void testRegisterApplication() throws Exception { consumerSecret = oidcConfig.getClientSecret(); Assert.assertNotNull(consumerSecret, "Application creation failed."); + + if (!isLegacyRuntimeEnabled) { + // Authorize few system APIs. + authorizeSystemAPIs(applicationId, + new ArrayList<>(Arrays.asList("/api/server/v1/tenants", "/scim2/Users"))); + } } @Test(groups = "wso2.is", description = "Send authorize user request and get access token", dependsOnMethods = "testRegisterApplication") @@ -180,8 +200,10 @@ public void getTokenAndValidate() throws Exception { AccessTokenResponse tokenResponse = AccessTokenResponse.parse(tokenHTTPResp); Assert.assertNotNull(tokenResponse, "Access token response is null."); accessToken = tokenResponse.getTokens().getAccessToken().getValue(); - String scope = getScopesFromIntrospectionResponse(); - doTheScopeValidationBasedOnTheTestUserMode(scope, false); + if (isLegacyRuntimeEnabled) { + String scope = getScopesFromIntrospectionResponse(); + doTheScopeValidationBasedOnTheTestUserMode(scope, false); + } } finally { client.close(); } @@ -200,15 +222,17 @@ private String getScopesFromIntrospectionResponse() throws Exception { private void doTheScopeValidationBasedOnTheTestUserMode(String scope, boolean isClientCredentialsGrant) { if (testUserMode == TestUserMode.SUPER_TENANT_ADMIN) { - Assert.assertTrue(scope.contains("internal_server_admin"), "Scope should contain " + - "`internal_server_admin` scope"); + if (isLegacyRuntimeEnabled) { + Assert.assertTrue(scope.contains("internal_server_admin"), "Scope should contain " + + "`internal_server_admin` scope"); + } Assert.assertTrue(scope.contains("internal_modify_tenants"), "Scope should contain " + "`internal_modify_tenants` scope"); } else if (testUserMode == TestUserMode.TENANT_ADMIN) { Assert.assertFalse(scope.contains("internal_server_admin"), "Scope should not contain " + "`internal_server_admin` scope"); Assert.assertFalse(scope.contains("internal_modify_tenants"), "Scope should not contain " + - "`internal_modify_tenants` scope"); + "`internal_modify_tenants` scope"); } else { // Normal user. if (isClientCredentialsGrant) { @@ -221,7 +245,33 @@ private void doTheScopeValidationBasedOnTheTestUserMode(String scope, boolean is Assert.assertFalse(scope.contains("internal_server_admin"), "Scope should not contain " + "`internal_server_admin` scope"); Assert.assertFalse(scope.contains("internal_modify_tenants"), "Scope should not contain " + - "`internal_modify_tenants` scope"); + "`internal_modify_tenants` scope"); + } + } + + private static boolean isLegacyAuthzRuntimeEnabled() throws Exception { + + String carbonHome = System.getProperty("carbon.home"); + String carbonXMLFilePath = carbonHome + "/repository/conf/carbon.xml"; + Path filePath = Paths.get(carbonXMLFilePath); + String xmlContent = new String(Files.readAllBytes(filePath)); + + // Parse the XML content + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + DocumentBuilder builder = factory.newDocumentBuilder(); + Document document = builder.parse(new ByteArrayInputStream(xmlContent.getBytes())); + + // Get the root element + Element root = document.getDocumentElement(); + + // Find the element with the EnableLegacyAuthzRuntime tag. + NodeList nodeList = root.getElementsByTagName(ENABLE_LEGACY_AUTHZ_RUNTIME_CONFIG); + + if (nodeList.getLength() > 0) { + // Get the value of EnableLegacyAuthzRuntime + String enableLegacyAuthzRuntimeValue = nodeList.item(0).getTextContent(); + return Boolean.parseBoolean(enableLegacyAuthzRuntimeValue); } + return true; } } diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/api/resource/v1/model/APIResourceListItem.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/api/resource/v1/model/APIResourceListItem.java new file mode 100644 index 00000000000..e705486d81f --- /dev/null +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/api/resource/v1/model/APIResourceListItem.java @@ -0,0 +1,238 @@ +/* + * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.identity.integration.test.rest.api.server.api.resource.v1.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +import javax.validation.Valid; +import javax.validation.constraints.NotNull; + +public class APIResourceListItem { + + private String id; + private String name; + private String identifier; + private String type; + private Boolean requiresAuthorization; + private List properties = null; + + private String self; + + /** + **/ + public APIResourceListItem id(String id) { + + this.id = id; + return this; + } + + @ApiModelProperty(example = "gh43-jk34-vb34-df67", required = true, value = "") + @JsonProperty("id") + @Valid + @NotNull(message = "Property id cannot be null.") + + public String getId() { + return id; + } + public void setId(String id) { + this.id = id; + } + + /** + **/ + public APIResourceListItem name(String name) { + + this.name = name; + return this; + } + + @ApiModelProperty(example = "Greetings API", required = true, value = "") + @JsonProperty("name") + @Valid + @NotNull(message = "Property name cannot be null.") + + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + + /** + **/ + public APIResourceListItem identifier(String identifier) { + + this.identifier = identifier; + return this; + } + + @ApiModelProperty(example = "greetings_api", required = true, value = "") + @JsonProperty("identifier") + @Valid + @NotNull(message = "Property identifier cannot be null.") + + public String getIdentifier() { + return identifier; + } + public void setIdentifier(String identifier) { + this.identifier = identifier; + } + + /** + **/ + public APIResourceListItem type(String type) { + + this.type = type; + return this; + } + + @ApiModelProperty(example = "SYSTEM", value = "") + @JsonProperty("type") + @Valid + public String getType() { + return type; + } + public void setType(String type) { + this.type = type; + } + + /** + **/ + public APIResourceListItem requiresAuthorization(Boolean requiresAuthorization) { + + this.requiresAuthorization = requiresAuthorization; + return this; + } + + @ApiModelProperty(example = "true", value = "") + @JsonProperty("requiresAuthorization") + @Valid + public Boolean getRequiresAuthorization() { + return requiresAuthorization; + } + public void setRequiresAuthorization(Boolean requiresAuthorization) { + this.requiresAuthorization = requiresAuthorization; + } + + /** + **/ + public APIResourceListItem properties(List properties) { + + this.properties = properties; + return this; + } + + @ApiModelProperty(value = "") + @JsonProperty("properties") + @Valid + public List getProperties() { + return properties; + } + public void setProperties(List properties) { + this.properties = properties; + } + + public APIResourceListItem addPropertiesItem(Property propertiesItem) { + if (this.properties == null) { + this.properties = new ArrayList(); + } + this.properties.add(propertiesItem); + return this; + } + + /** + **/ + public APIResourceListItem self(String self) { + + this.self = self; + return this; + } + + @ApiModelProperty(example = "/t/carbon.super/api/server/v1/api-resources/eDUwOUNlcnRpZmljYXRlQXV0aGVudGljYXRvcg", required = true, value = "") + @JsonProperty("self") + @Valid + @NotNull(message = "Property self cannot be null.") + + public String getSelf() { + return self; + } + public void setSelf(String self) { + this.self = self; + } + + + + @Override + public boolean equals(java.lang.Object o) { + + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + APIResourceListItem apIResourceListItem = (APIResourceListItem) o; + return Objects.equals(this.id, apIResourceListItem.id) && + Objects.equals(this.name, apIResourceListItem.name) && + Objects.equals(this.identifier, apIResourceListItem.identifier) && + Objects.equals(this.type, apIResourceListItem.type) && + Objects.equals(this.requiresAuthorization, apIResourceListItem.requiresAuthorization) && + Objects.equals(this.properties, apIResourceListItem.properties) && + Objects.equals(this.self, apIResourceListItem.self); + } + + @Override + public int hashCode() { + return Objects.hash(id, name, identifier, type, requiresAuthorization, properties, self); + } + + @Override + public String toString() { + + StringBuilder sb = new StringBuilder(); + sb.append("class APIResourceListItem {\n"); + + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append(" identifier: ").append(toIndentedString(identifier)).append("\n"); + sb.append(" type: ").append(toIndentedString(type)).append("\n"); + sb.append(" requiresAuthorization: ").append(toIndentedString(requiresAuthorization)).append("\n"); + sb.append(" properties: ").append(toIndentedString(properties)).append("\n"); + sb.append(" self: ").append(toIndentedString(self)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(java.lang.Object o) { + + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n"); + } +} diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/api/resource/v1/model/APIResourceListResponse.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/api/resource/v1/model/APIResourceListResponse.java new file mode 100644 index 00000000000..af50cbbf0f5 --- /dev/null +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/api/resource/v1/model/APIResourceListResponse.java @@ -0,0 +1,154 @@ +/* + * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.identity.integration.test.rest.api.server.api.resource.v1.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +import javax.validation.Valid; +import javax.validation.constraints.NotNull; + +public class APIResourceListResponse { + + private Integer totalResults; + private List links = new ArrayList(); + + private List apiResources = null; + + + /** + **/ + public APIResourceListResponse totalResults(Integer totalResults) { + + this.totalResults = totalResults; + return this; + } + + @ApiModelProperty(example = "1", value = "") + @JsonProperty("totalResults") + @Valid + public Integer getTotalResults() { + return totalResults; + } + public void setTotalResults(Integer totalResults) { + this.totalResults = totalResults; + } + + /** + **/ + public APIResourceListResponse links(List links) { + + this.links = links; + return this; + } + + @ApiModelProperty(required = true, value = "") + @JsonProperty("links") + @Valid + @NotNull(message = "Property links cannot be null.") + + public List getLinks() { + return links; + } + public void setLinks(List links) { + this.links = links; + } + + public APIResourceListResponse addLinksItem(PaginationLink linksItem) { + this.links.add(linksItem); + return this; + } + + /** + **/ + public APIResourceListResponse apiResources(List apiResources) { + + this.apiResources = apiResources; + return this; + } + + @ApiModelProperty(value = "") + @JsonProperty("apiResources") + @Valid + public List getApiResources() { + return apiResources; + } + public void setApiResources(List apiResources) { + this.apiResources = apiResources; + } + + public APIResourceListResponse addApiResourcesItem(APIResourceListItem apiResourcesItem) { + if (this.apiResources == null) { + this.apiResources = new ArrayList(); + } + this.apiResources.add(apiResourcesItem); + return this; + } + + + + @Override + public boolean equals(java.lang.Object o) { + + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + APIResourceListResponse apIResourceListResponse = (APIResourceListResponse) o; + return Objects.equals(this.totalResults, apIResourceListResponse.totalResults) && + Objects.equals(this.links, apIResourceListResponse.links) && + Objects.equals(this.apiResources, apIResourceListResponse.apiResources); + } + + @Override + public int hashCode() { + return Objects.hash(totalResults, links, apiResources); + } + + @Override + public String toString() { + + StringBuilder sb = new StringBuilder(); + sb.append("class APIResourceListResponse {\n"); + + sb.append(" totalResults: ").append(toIndentedString(totalResults)).append("\n"); + sb.append(" links: ").append(toIndentedString(links)).append("\n"); + sb.append(" apiResources: ").append(toIndentedString(apiResources)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(java.lang.Object o) { + + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n"); + } +} diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/api/resource/v1/model/APIResourceResponse.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/api/resource/v1/model/APIResourceResponse.java new file mode 100644 index 00000000000..df05962caba --- /dev/null +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/api/resource/v1/model/APIResourceResponse.java @@ -0,0 +1,319 @@ +/* + * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.identity.integration.test.rest.api.server.api.resource.v1.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +import javax.validation.Valid; +import javax.validation.constraints.NotNull; + +public class APIResourceResponse { + + private String id; + private String name; + private String description; + private String identifier; + private String type; + private Boolean requiresAuthorization; + private List scopes = null; + + private List subscribedApplications = null; + + private List properties = null; + + private String self; + + /** + **/ + public APIResourceResponse id(String id) { + + this.id = id; + return this; + } + + @ApiModelProperty(example = "gh43-jk34-vb34-df67", required = true, value = "") + @JsonProperty("id") + @Valid + @NotNull(message = "Property id cannot be null.") + + public String getId() { + return id; + } + public void setId(String id) { + this.id = id; + } + + /** + **/ + public APIResourceResponse name(String name) { + + this.name = name; + return this; + } + + @ApiModelProperty(example = "Greetings API", required = true, value = "") + @JsonProperty("name") + @Valid + @NotNull(message = "Property name cannot be null.") + + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + + /** + **/ + public APIResourceResponse description(String description) { + + this.description = description; + return this; + } + + @ApiModelProperty(example = "Greeting API representation", value = "") + @JsonProperty("description") + @Valid + public String getDescription() { + return description; + } + public void setDescription(String description) { + this.description = description; + } + + /** + **/ + public APIResourceResponse identifier(String identifier) { + + this.identifier = identifier; + return this; + } + + @ApiModelProperty(example = "greetings_api", required = true, value = "") + @JsonProperty("identifier") + @Valid + @NotNull(message = "Property identifier cannot be null.") + + public String getIdentifier() { + return identifier; + } + public void setIdentifier(String identifier) { + this.identifier = identifier; + } + + /** + **/ + public APIResourceResponse type(String type) { + + this.type = type; + return this; + } + + @ApiModelProperty(example = "SYSTEM", value = "") + @JsonProperty("type") + @Valid + public String getType() { + return type; + } + public void setType(String type) { + this.type = type; + } + + /** + **/ + public APIResourceResponse requiresAuthorization(Boolean requiresAuthorization) { + + this.requiresAuthorization = requiresAuthorization; + return this; + } + + @ApiModelProperty(example = "true", value = "") + @JsonProperty("requiresAuthorization") + @Valid + public Boolean getRequiresAuthorization() { + return requiresAuthorization; + } + public void setRequiresAuthorization(Boolean requiresAuthorization) { + this.requiresAuthorization = requiresAuthorization; + } + + /** + **/ + public APIResourceResponse scopes(List scopes) { + + this.scopes = scopes; + return this; + } + + @ApiModelProperty(value = "") + @JsonProperty("scopes") + @Valid + public List getScopes() { + return scopes; + } + public void setScopes(List scopes) { + this.scopes = scopes; + } + + public APIResourceResponse addScopesItem(ScopeGetModel scopesItem) { + if (this.scopes == null) { + this.scopes = new ArrayList(); + } + this.scopes.add(scopesItem); + return this; + } + + /** + **/ + public APIResourceResponse subscribedApplications(List subscribedApplications) { + + this.subscribedApplications = subscribedApplications; + return this; + } + + @ApiModelProperty(value = "") + @JsonProperty("subscribedApplications") + @Valid + public List getSubscribedApplications() { + return subscribedApplications; + } + public void setSubscribedApplications(List subscribedApplications) { + this.subscribedApplications = subscribedApplications; + } + + public APIResourceResponse addSubscribedApplicationsItem(SubscribedApplicationGetModel subscribedApplicationsItem) { + if (this.subscribedApplications == null) { + this.subscribedApplications = new ArrayList(); + } + this.subscribedApplications.add(subscribedApplicationsItem); + return this; + } + + /** + **/ + public APIResourceResponse properties(List properties) { + + this.properties = properties; + return this; + } + + @ApiModelProperty(value = "") + @JsonProperty("properties") + @Valid + public List getProperties() { + return properties; + } + public void setProperties(List properties) { + this.properties = properties; + } + + public APIResourceResponse addPropertiesItem(Property propertiesItem) { + if (this.properties == null) { + this.properties = new ArrayList(); + } + this.properties.add(propertiesItem); + return this; + } + + /** + **/ + public APIResourceResponse self(String self) { + + this.self = self; + return this; + } + + @ApiModelProperty(example = "/t/carbon.super/api/server/v1/api-resources/eDUwOUNlcnRpZmljYXRlQXV0aGVudGljYXRvcg", required = true, value = "") + @JsonProperty("self") + @Valid + @NotNull(message = "Property self cannot be null.") + + public String getSelf() { + return self; + } + public void setSelf(String self) { + this.self = self; + } + + + + @Override + public boolean equals(java.lang.Object o) { + + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + APIResourceResponse apIResourceResponse = (APIResourceResponse) o; + return Objects.equals(this.id, apIResourceResponse.id) && + Objects.equals(this.name, apIResourceResponse.name) && + Objects.equals(this.description, apIResourceResponse.description) && + Objects.equals(this.identifier, apIResourceResponse.identifier) && + Objects.equals(this.type, apIResourceResponse.type) && + Objects.equals(this.requiresAuthorization, apIResourceResponse.requiresAuthorization) && + Objects.equals(this.scopes, apIResourceResponse.scopes) && + Objects.equals(this.subscribedApplications, apIResourceResponse.subscribedApplications) && + Objects.equals(this.properties, apIResourceResponse.properties) && + Objects.equals(this.self, apIResourceResponse.self); + } + + @Override + public int hashCode() { + return Objects.hash(id, name, description, identifier, type, requiresAuthorization, scopes, subscribedApplications, properties, self); + } + + @Override + public String toString() { + + StringBuilder sb = new StringBuilder(); + sb.append("class APIResourceResponse {\n"); + + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append(" description: ").append(toIndentedString(description)).append("\n"); + sb.append(" identifier: ").append(toIndentedString(identifier)).append("\n"); + sb.append(" type: ").append(toIndentedString(type)).append("\n"); + sb.append(" requiresAuthorization: ").append(toIndentedString(requiresAuthorization)).append("\n"); + sb.append(" scopes: ").append(toIndentedString(scopes)).append("\n"); + sb.append(" subscribedApplications: ").append(toIndentedString(subscribedApplications)).append("\n"); + sb.append(" properties: ").append(toIndentedString(properties)).append("\n"); + sb.append(" self: ").append(toIndentedString(self)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(java.lang.Object o) { + + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n"); + } +} diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/api/resource/v1/model/PaginationLink.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/api/resource/v1/model/PaginationLink.java new file mode 100644 index 00000000000..e6b066c666a --- /dev/null +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/api/resource/v1/model/PaginationLink.java @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.identity.integration.test.rest.api.server.api.resource.v1.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; + +import java.util.Objects; + +import javax.validation.Valid; + +public class PaginationLink { + + private String rel; + private String href; + + /** + **/ + public PaginationLink rel(String rel) { + + this.rel = rel; + return this; + } + + @ApiModelProperty(example = "before", value = "") + @JsonProperty("rel") + @Valid + public String getRel() { + return rel; + } + public void setRel(String rel) { + this.rel = rel; + } + + /** + **/ + public PaginationLink href(String href) { + + this.href = href; + return this; + } + + @ApiModelProperty(example = "/o/orgName/api-resources?after=NDoy", value = "") + @JsonProperty("href") + @Valid + public String getHref() { + return href; + } + public void setHref(String href) { + this.href = href; + } + + + + @Override + public boolean equals(java.lang.Object o) { + + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + PaginationLink paginationLink = (PaginationLink) o; + return Objects.equals(this.rel, paginationLink.rel) && + Objects.equals(this.href, paginationLink.href); + } + + @Override + public int hashCode() { + return Objects.hash(rel, href); + } + + @Override + public String toString() { + + StringBuilder sb = new StringBuilder(); + sb.append("class PaginationLink {\n"); + + sb.append(" rel: ").append(toIndentedString(rel)).append("\n"); + sb.append(" href: ").append(toIndentedString(href)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(java.lang.Object o) { + + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n"); + } +} diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/api/resource/v1/model/Property.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/api/resource/v1/model/Property.java new file mode 100644 index 00000000000..cb3f6cca22d --- /dev/null +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/api/resource/v1/model/Property.java @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.identity.integration.test.rest.api.server.api.resource.v1.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; + +import java.util.Objects; + +import javax.validation.Valid; +import javax.validation.constraints.NotNull; + +public class Property { + + private String name; + private String value; + + /** + * + **/ + public Property name(String name) { + + this.name = name; + return this; + } + + @ApiModelProperty(example = "label", required = true, value = "") + @JsonProperty("name") + @Valid + @NotNull(message = "Property name cannot be null.") + + public String getName() { + + return name; + } + + public void setName(String name) { + + this.name = name; + } + + /** + * + **/ + public Property value(String value) { + + this.value = value; + return this; + } + + @ApiModelProperty(example = "Internal", required = true, value = "") + @JsonProperty("value") + @Valid + @NotNull(message = "Property value cannot be null.") + + public String getValue() { + + return value; + } + + public void setValue(String value) { + + this.value = value; + } + + @Override + public boolean equals(java.lang.Object o) { + + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Property property = (Property) o; + return Objects.equals(this.name, property.name) && + Objects.equals(this.value, property.value); + } + + @Override + public int hashCode() { + + return Objects.hash(name, value); + } + + @Override + public String toString() { + + StringBuilder sb = new StringBuilder(); + sb.append("class Property {\n"); + + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append(" value: ").append(toIndentedString(value)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(java.lang.Object o) { + + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n"); + } +} diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/api/resource/v1/model/ScopeGetModel.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/api/resource/v1/model/ScopeGetModel.java new file mode 100644 index 00000000000..a9606f3e79f --- /dev/null +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/api/resource/v1/model/ScopeGetModel.java @@ -0,0 +1,177 @@ +/* + * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.identity.integration.test.rest.api.server.api.resource.v1.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; + +import java.util.Objects; + +import javax.validation.Valid; +import javax.validation.constraints.NotNull; + +public class ScopeGetModel { + + private String id; + private String displayName; + private String name; + private String description; + + /** + * + **/ + public ScopeGetModel id(String id) { + + this.id = id; + return this; + } + + @ApiModelProperty(example = "sf23-fg34-fy53-hj23", required = true, value = "") + @JsonProperty("id") + @Valid + @NotNull(message = "Property id cannot be null.") + + public String getId() { + + return id; + } + + public void setId(String id) { + + this.id = id; + } + + /** + * + **/ + public ScopeGetModel displayName(String displayName) { + + this.displayName = displayName; + return this; + } + + @ApiModelProperty(example = "Write", required = true, value = "") + @JsonProperty("displayName") + @Valid + @NotNull(message = "Property displayName cannot be null.") + + public String getDisplayName() { + + return displayName; + } + + public void setDisplayName(String displayName) { + + this.displayName = displayName; + } + + /** + * + **/ + public ScopeGetModel name(String name) { + + this.name = name; + return this; + } + + @ApiModelProperty(example = "greetings:write", required = true, value = "") + @JsonProperty("name") + @Valid + @NotNull(message = "Property name cannot be null.") + + public String getName() { + + return name; + } + + public void setName(String name) { + + this.name = name; + } + + /** + * + **/ + public ScopeGetModel description(String description) { + + this.description = description; + return this; + } + + @ApiModelProperty(example = "Allow writing greetings", value = "") + @JsonProperty("description") + @Valid + public String getDescription() { + + return description; + } + + public void setDescription(String description) { + + this.description = description; + } + + @Override + public boolean equals(java.lang.Object o) { + + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + ScopeGetModel scopeGetModel = (ScopeGetModel) o; + return Objects.equals(this.id, scopeGetModel.id) && + Objects.equals(this.displayName, scopeGetModel.displayName) && + Objects.equals(this.name, scopeGetModel.name) && + Objects.equals(this.description, scopeGetModel.description); + } + + @Override + public int hashCode() { + + return Objects.hash(id, displayName, name, description); + } + + @Override + public String toString() { + + StringBuilder sb = new StringBuilder(); + sb.append("class ScopeGetModel {\n"); + + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" displayName: ").append(toIndentedString(displayName)).append("\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append(" description: ").append(toIndentedString(description)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(java.lang.Object o) { + + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n"); + } +} diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/api/resource/v1/model/SubscribedApplicationGetModel.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/api/resource/v1/model/SubscribedApplicationGetModel.java new file mode 100644 index 00000000000..c6531bd1c99 --- /dev/null +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/api/resource/v1/model/SubscribedApplicationGetModel.java @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.identity.integration.test.rest.api.server.api.resource.v1.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; + +import java.util.Objects; + +import javax.validation.Valid; + +public class SubscribedApplicationGetModel { + + private String name; + private String id; + + /** + * + **/ + public SubscribedApplicationGetModel name(String name) { + + this.name = name; + return this; + } + + @ApiModelProperty(example = "Application1", value = "") + @JsonProperty("name") + @Valid + public String getName() { + + return name; + } + + public void setName(String name) { + + this.name = name; + } + + /** + * + **/ + public SubscribedApplicationGetModel id(String id) { + + this.id = id; + return this; + } + + @ApiModelProperty(example = "23fd-23gd-54vv-sdhf", value = "") + @JsonProperty("id") + @Valid + public String getId() { + + return id; + } + + public void setId(String id) { + + this.id = id; + } + + @Override + public boolean equals(java.lang.Object o) { + + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + SubscribedApplicationGetModel subscribedApplicationGetModel = (SubscribedApplicationGetModel) o; + return Objects.equals(this.name, subscribedApplicationGetModel.name) && + Objects.equals(this.id, subscribedApplicationGetModel.id); + } + + @Override + public int hashCode() { + + return Objects.hash(name, id); + } + + @Override + public String toString() { + + StringBuilder sb = new StringBuilder(); + sb.append("class SubscribedApplicationGetModel {\n"); + + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(java.lang.Object o) { + + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n"); + } +} diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/application/management/v1/model/AuthorizedAPICreationModel.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/application/management/v1/model/AuthorizedAPICreationModel.java new file mode 100644 index 00000000000..8dc99f871ae --- /dev/null +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/application/management/v1/model/AuthorizedAPICreationModel.java @@ -0,0 +1,145 @@ +/* + * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.identity.integration.test.rest.api.server.application.management.v1.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +import javax.validation.Valid; + +public class AuthorizedAPICreationModel { + + private String id; + private String policyIdentifier; + private List scopes = null; + + + /** + **/ + public AuthorizedAPICreationModel id(String id) { + + this.id = id; + return this; + } + + @ApiModelProperty(example = "012df-232gf-545fg-dff23", value = "") + @JsonProperty("id") + @Valid + public String getId() { + return id; + } + public void setId(String id) { + this.id = id; + } + + /** + **/ + public AuthorizedAPICreationModel policyIdentifier(String policyIdentifier) { + + this.policyIdentifier = policyIdentifier; + return this; + } + + @ApiModelProperty(example = "RBAC", value = "") + @JsonProperty("policyIdentifier") + @Valid + public String getPolicyIdentifier() { + return policyIdentifier; + } + public void setPolicyIdentifier(String policyIdentifier) { + this.policyIdentifier = policyIdentifier; + } + + /** + **/ + public AuthorizedAPICreationModel scopes(List scopes) { + + this.scopes = scopes; + return this; + } + + @ApiModelProperty(value = "") + @JsonProperty("scopes") + @Valid + public List getScopes() { + return scopes; + } + public void setScopes(List scopes) { + this.scopes = scopes; + } + + public AuthorizedAPICreationModel addScopesItem(String scopesItem) { + if (this.scopes == null) { + this.scopes = new ArrayList<>(); + } + this.scopes.add(scopesItem); + return this; + } + + + + @Override + public boolean equals(java.lang.Object o) { + + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + AuthorizedAPICreationModel authorizedAPICreationModel = (AuthorizedAPICreationModel) o; + return Objects.equals(this.id, authorizedAPICreationModel.id) && + Objects.equals(this.policyIdentifier, authorizedAPICreationModel.policyIdentifier) && + Objects.equals(this.scopes, authorizedAPICreationModel.scopes); + } + + @Override + public int hashCode() { + return Objects.hash(id, policyIdentifier, scopes); + } + + @Override + public String toString() { + + StringBuilder sb = new StringBuilder(); + sb.append("class AuthorizedAPICreationModel {\n"); + + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" policyIdentifier: ").append(toIndentedString(policyIdentifier)).append("\n"); + sb.append(" scopes: ").append(toIndentedString(scopes)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(java.lang.Object o) { + + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n"); + } +} diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/application/management/v1/model/AuthorizedAPIResponse.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/application/management/v1/model/AuthorizedAPIResponse.java new file mode 100644 index 00000000000..6f8b239209f --- /dev/null +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/application/management/v1/model/AuthorizedAPIResponse.java @@ -0,0 +1,185 @@ +/* + * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.identity.integration.test.rest.api.server.application.management.v1.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +import javax.validation.Valid; + +public class AuthorizedAPIResponse { + + private String id; + private String identifier; + private String displayName; + private String policyId; + private List authorizedScopes = null; + + + /** + **/ + public AuthorizedAPIResponse id(String id) { + + this.id = id; + return this; + } + + @ApiModelProperty(example = "012df-232gf-545fg-dff23", value = "") + @JsonProperty("id") + @Valid + public String getId() { + return id; + } + public void setId(String id) { + this.id = id; + } + + /** + **/ + public AuthorizedAPIResponse identifier(String identifier) { + + this.identifier = identifier; + return this; + } + + @ApiModelProperty(example = "https://greetings.io/v1/greet", value = "") + @JsonProperty("identifier") + @Valid + public String getIdentifier() { + return identifier; + } + public void setIdentifier(String identifier) { + this.identifier = identifier; + } + + /** + **/ + public AuthorizedAPIResponse displayName(String displayName) { + + this.displayName = displayName; + return this; + } + + @ApiModelProperty(example = "Greetings API", value = "") + @JsonProperty("displayName") + @Valid + public String getDisplayName() { + return displayName; + } + public void setDisplayName(String displayName) { + this.displayName = displayName; + } + + /** + **/ + public AuthorizedAPIResponse policyId(String policyId) { + + this.policyId = policyId; + return this; + } + + @ApiModelProperty(example = "RBAC", value = "") + @JsonProperty("policyId") + @Valid + public String getPolicyId() { + return policyId; + } + public void setPolicyId(String policyId) { + this.policyId = policyId; + } + + /** + **/ + public AuthorizedAPIResponse authorizedScopes(List authorizedScopes) { + + this.authorizedScopes = authorizedScopes; + return this; + } + + @ApiModelProperty(value = "") + @JsonProperty("authorizedScopes") + @Valid + public List getAuthorizedScopes() { + return authorizedScopes; + } + public void setAuthorizedScopes(List authorizedScopes) { + this.authorizedScopes = authorizedScopes; + } + + public AuthorizedAPIResponse addAuthorizedScopesItem(AuthorizedScope authorizedScopesItem) { + if (this.authorizedScopes == null) { + this.authorizedScopes = new ArrayList<>(); + } + this.authorizedScopes.add(authorizedScopesItem); + return this; + } + + @Override + public boolean equals(java.lang.Object o) { + + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + AuthorizedAPIResponse authorizedAPIResponse = (AuthorizedAPIResponse) o; + return Objects.equals(this.id, authorizedAPIResponse.id) && + Objects.equals(this.identifier, authorizedAPIResponse.identifier) && + Objects.equals(this.displayName, authorizedAPIResponse.displayName) && + Objects.equals(this.policyId, authorizedAPIResponse.policyId) && + Objects.equals(this.authorizedScopes, authorizedAPIResponse.authorizedScopes); + } + + @Override + public int hashCode() { + return Objects.hash(id, identifier, displayName, policyId, authorizedScopes); + } + + @Override + public String toString() { + + StringBuilder sb = new StringBuilder(); + sb.append("class AuthorizedAPIResponse {\n"); + + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" identifier: ").append(toIndentedString(identifier)).append("\n"); + sb.append(" displayName: ").append(toIndentedString(displayName)).append("\n"); + sb.append(" policyId: ").append(toIndentedString(policyId)).append("\n"); + sb.append(" authorizedScopes: ").append(toIndentedString(authorizedScopes)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(java.lang.Object o) { + + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n"); + } +} diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/application/management/v1/model/AuthorizedScope.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/application/management/v1/model/AuthorizedScope.java new file mode 100644 index 00000000000..3a8b205370e --- /dev/null +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/rest/api/server/application/management/v1/model/AuthorizedScope.java @@ -0,0 +1,134 @@ +/* + * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.identity.integration.test.rest.api.server.application.management.v1.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModelProperty; + +import java.util.Objects; + +import javax.validation.Valid; + +public class AuthorizedScope { + + private String id; + private String name; + private String displayName; + + /** + **/ + public AuthorizedScope id(String id) { + + this.id = id; + return this; + } + + @ApiModelProperty(example = "012df-232gf-545fg-dff23", value = "") + @JsonProperty("id") + @Valid + public String getId() { + return id; + } + public void setId(String id) { + this.id = id; + } + + /** + **/ + public AuthorizedScope name(String name) { + + this.name = name; + return this; + } + + @ApiModelProperty(example = "bookings:read", value = "") + @JsonProperty("name") + @Valid + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + + /** + **/ + public AuthorizedScope displayName(String displayName) { + + this.displayName = displayName; + return this; + } + + @ApiModelProperty(example = "Read Bookings", value = "") + @JsonProperty("displayName") + @Valid + public String getDisplayName() { + return displayName; + } + public void setDisplayName(String displayName) { + this.displayName = displayName; + } + + + + @Override + public boolean equals(java.lang.Object o) { + + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + AuthorizedScope authorizedScope = (AuthorizedScope) o; + return Objects.equals(this.id, authorizedScope.id) && + Objects.equals(this.name, authorizedScope.name) && + Objects.equals(this.displayName, authorizedScope.displayName); + } + + @Override + public int hashCode() { + return Objects.hash(id, name, displayName); + } + + @Override + public String toString() { + + StringBuilder sb = new StringBuilder(); + sb.append("class AuthorizedScope {\n"); + + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append(" displayName: ").append(toIndentedString(displayName)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(java.lang.Object o) { + + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n"); + } +} diff --git a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/OAuth2RestClient.java b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/OAuth2RestClient.java index 00e8978e71b..ffc56f401ac 100644 --- a/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/OAuth2RestClient.java +++ b/modules/integration/tests-integration/tests-backend/src/test/java/org/wso2/identity/integration/test/restclients/OAuth2RestClient.java @@ -29,13 +29,17 @@ import org.json.JSONException; import org.testng.Assert; import org.wso2.carbon.automation.engine.context.beans.Tenant; -import org.wso2.carbon.utils.StringUtils; import org.wso2.carbon.utils.multitenancy.MultitenantConstants; +import org.wso2.identity.integration.test.rest.api.server.api.resource.v1.model.APIResourceListItem; +import org.wso2.identity.integration.test.rest.api.server.api.resource.v1.model.APIResourceListResponse; +import org.wso2.identity.integration.test.rest.api.server.api.resource.v1.model.APIResourceResponse; +import org.wso2.identity.integration.test.rest.api.server.api.resource.v1.model.ScopeGetModel; import org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.ApplicationListItem; import org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.ApplicationListResponse; import org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.ApplicationModel; import org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.ApplicationPatchModel; import org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.ApplicationResponseModel; +import org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.AuthorizedAPICreationModel; import org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.OpenIDConnectConfiguration; import org.wso2.identity.integration.test.rest.api.server.application.management.v1.model.SAML2ServiceProvider; import org.wso2.identity.integration.test.utils.OAuth2Constant; @@ -48,8 +52,11 @@ public class OAuth2RestClient extends RestBaseClient { private static final String API_SERVER_BASE_PATH = "api/server/v1"; private static final String APPLICATION_MANAGEMENT_PATH = "/applications"; + private static final String API_RESOURCE_MANAGEMENT_PATH = "/api-resources"; private static final String INBOUND_PROTOCOLS_BASE_PATH = "/inbound-protocols"; + private static final String AUTHORIZED_API_BASE_PATH = "/authorized-apis"; private final String applicationManagementApiBasePath; + private final String apiResourceManagementApiBasePath; private final String username; private final String password; @@ -59,6 +66,7 @@ public OAuth2RestClient(String backendUrl, Tenant tenantInfo) { String tenantDomain = tenantInfo.getContextUser().getUserDomain(); applicationManagementApiBasePath = getApplicationsPath(backendUrl, tenantDomain); + apiResourceManagementApiBasePath = getAPIResourcesPath(backendUrl, tenantDomain); } /** @@ -250,6 +258,16 @@ private String getApplicationsPath(String serverUrl, String tenantDomain) { } } + private String getAPIResourcesPath(String serverUrl, String tenantDomain) { + + if (tenantDomain.equals(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) { + return serverUrl + API_SERVER_BASE_PATH + API_RESOURCE_MANAGEMENT_PATH; + } else { + return serverUrl + TENANT_PATH + tenantDomain + PATH_SEPARATOR + API_SERVER_BASE_PATH + + API_RESOURCE_MANAGEMENT_PATH; + } + } + private Header[] getHeaders() { Header[] headerList = new Header[3]; headerList[0] = new BasicHeader(USER_AGENT_ATTRIBUTE, OAuth2Constant.USER_AGENT); @@ -260,6 +278,62 @@ private Header[] getHeaders() { return headerList; } + /** + * Add API authorization to an application + * + * @param appId Application id. + * @param authorizedAPICreationModel AuthorizedAPICreationModel object with api authorization details. + * @return Status code of the response. + * @throws Exception Error when getting the response. + */ + public int addAPIAuthorizationToApplication(String appId, AuthorizedAPICreationModel authorizedAPICreationModel) + throws IOException { + + String jsonRequestBody = toJSONString(authorizedAPICreationModel); + String endPointUrl = applicationManagementApiBasePath + PATH_SEPARATOR + appId + AUTHORIZED_API_BASE_PATH; + + try (CloseableHttpResponse response = getResponseOfHttpPost(endPointUrl, jsonRequestBody, getHeaders())) { + return response.getStatusLine().getStatusCode(); + } + } + + /** + * Get API resources by filtering. + * + * @param apiResourceFilter API resource filter. + * @return List of API resources. + * @throws IOException Error when getting the filtered API resource. + */ + public List getAPIResourcesWithFiltering(String apiResourceFilter) throws IOException { + + String endPointUrl = apiResourceManagementApiBasePath + "?filter=" + apiResourceFilter; + try (CloseableHttpResponse response = getResponseOfHttpGet(endPointUrl, getHeaders())) { + String responseBody = EntityUtils.toString(response.getEntity()); + ObjectMapper jsonWriter = new ObjectMapper(new JsonFactory()); + APIResourceListResponse apiResourceListResponse = + jsonWriter.readValue(responseBody, APIResourceListResponse.class); + return apiResourceListResponse.getApiResources(); + } + } + + /** + * Get API resource scopes. + * + * @param apiIdentifier API identifier. + * @return List of API resource scopes. + * @throws IOException Error when getting the scopes. + */ + public List getAPIResourceScopes(String apiIdentifier) throws IOException { + + String endPointUrl = apiResourceManagementApiBasePath + PATH_SEPARATOR + apiIdentifier; + try (CloseableHttpResponse response = getResponseOfHttpGet(endPointUrl, getHeaders())) { + String responseBody = EntityUtils.toString(response.getEntity()); + ObjectMapper jsonWriter = new ObjectMapper(new JsonFactory()); + APIResourceResponse apiResourceResponse = jsonWriter.readValue(responseBody, APIResourceResponse.class); + return apiResourceResponse.getScopes(); + } + } + /** * Close the HTTP client */