Skip to content

Commit

Permalink
Add integration tests for B2B feature
Browse files Browse the repository at this point in the history
  • Loading branch information
chamilaadhi committed Feb 26, 2025
1 parent b66b58f commit 0998de9
Show file tree
Hide file tree
Showing 29 changed files with 3,464 additions and 30 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
/*
* WSO2 API Manager - Admin
* This document specifies a **RESTful API** for WSO2 **API Manager** - **Admin Portal**. Please see [full OpenAPI Specification](https://raw.githubusercontent.com/wso2/carbon-apimgt/v6.7.206/components/apimgt/org.wso2.carbon.apimgt.rest.api.admin.v1/src/main/resources/admin-api.yaml) of the API which is written using [OAS 3.0](http://swagger.io/) specification. # Authentication Our REST APIs are protected using OAuth2 and access control is achieved through scopes. Before you start invoking the the API you need to obtain an access token with the required scopes. This guide will walk you through the steps that you will need to follow to obtain an access token. First you need to obtain the consumer key/secret key pair by calling the dynamic client registration (DCR) endpoint. You can add your preferred grant types in the payload. A sample payload is shown below. ``` { \"callbackUrl\":\"www.google.lk\", \"clientName\":\"rest_api_admin\", \"owner\":\"admin\", \"grantType\":\"client_credentials password refresh_token\", \"saasApp\":true } ``` Create a file (payload.json) with the above sample payload, and use the cURL shown bellow to invoke the DCR endpoint. Authorization header of this should contain the base64 encoded admin username and password. **Format of the request** ``` curl -X POST -H \"Authorization: Basic Base64(admin_username:admin_password)\" -H \"Content-Type: application/json\" \\ -d @payload.json https://<host>:<servlet_port>/client-registration/v0.17/register ``` **Sample request** ``` curl -X POST -H \"Authorization: Basic YWRtaW46YWRtaW4=\" -H \"Content-Type: application/json\" \\ -d @payload.json https://localhost:9443/client-registration/v0.17/register ``` Following is a sample response after invoking the above curl. ``` { \"clientId\": \"fOCi4vNJ59PpHucC2CAYfYuADdMa\", \"clientName\": \"rest_api_admin\", \"callBackURL\": \"www.google.lk\", \"clientSecret\": \"a4FwHlq0iCIKVs2MPIIDnepZnYMa\", \"isSaasApplication\": true, \"appOwner\": \"admin\", \"jsonString\": \"{\\\"grant_types\\\":\\\"client_credentials password refresh_token\\\",\\\"redirect_uris\\\":\\\"www.google.lk\\\",\\\"client_name\\\":\\\"rest_api_admin\\\"}\", \"jsonAppAttribute\": \"{}\", \"tokenType\": null } ``` Next you must use the above client id and secret to obtain the access token. We will be using the password grant type for this, you can use any grant type you desire. You also need to add the proper **scope** when getting the access token. All possible scopes for Admin REST API can be viewed in **OAuth2 Security** section of this document and scope for each resource is given in **authorizations** section of resource documentation. Following is the format of the request if you are using the password grant type. ``` curl -k -d \"grant_type=password&username=<admin_username>&password=<admin_passowrd>&scope=<scopes seperated by space>\" \\ -H \"Authorization: Basic base64(cliet_id:client_secret)\" \\ https://<host>:<gateway_port>/token ``` **Sample request** ``` curl https://localhost:8243/token -k \\ -H \"Authorization: Basic Zk9DaTR2Tko1OVBwSHVjQzJDQVlmWXVBRGRNYTphNEZ3SGxxMGlDSUtWczJNUElJRG5lcFpuWU1h\" \\ -d \"grant_type=password&username=admin&password=admin&scope=apim:admin apim:tier_view\" ``` Shown below is a sample response to the above request. ``` { \"access_token\": \"e79bda48-3406-3178-acce-f6e4dbdcbb12\", \"refresh_token\": \"a757795d-e69f-38b8-bd85-9aded677a97c\", \"scope\": \"apim:admin apim:tier_view\", \"token_type\": \"Bearer\", \"expires_in\": 3600 } ``` Now you have a valid access token, which you can use to invoke an API. Navigate through the API descriptions to find the required API, obtain an access token as described above and invoke the API with the authentication header. If you use a different authentication mechanism, this process may change. # Try out in Postman If you want to try-out the embedded postman collection with \"Run in Postman\" option, please follow the guidelines listed below. * All of the OAuth2 secured endpoints have been configured with an Authorization Bearer header with a parameterized access token. Before invoking any REST API resource make sure you run the `Register DCR Application` and `Generate Access Token` requests to fetch an access token with all required scopes. * Make sure you have an API Manager instance up and running. * Update the `basepath` parameter to match the hostname and port of the APIM instance. [![Run in Postman](https://run.pstmn.io/button.svg)](https://app.getpostman.com/run-collection/f5ac2ca9fb22afef6ed6)
*
* The version of the OpenAPI document: v4
* Contact: architecture@wso2.com
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/


package org.wso2.am.integration.clients.admin.api;

import org.wso2.am.integration.clients.admin.ApiCallback;
import org.wso2.am.integration.clients.admin.ApiClient;
import org.wso2.am.integration.clients.admin.ApiException;
import org.wso2.am.integration.clients.admin.ApiResponse;
import org.wso2.am.integration.clients.admin.Configuration;
import org.wso2.am.integration.clients.admin.Pair;
import org.wso2.am.integration.clients.admin.ProgressRequestBody;
import org.wso2.am.integration.clients.admin.ProgressResponseBody;

import com.google.gson.reflect.TypeToken;

import java.io.IOException;


import org.wso2.am.integration.clients.admin.api.dto.ErrorDTO;
import org.wso2.am.integration.clients.admin.api.dto.OrganizationInfoDTO;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class UsersApi {
private ApiClient localVarApiClient;

public UsersApi() {
this(Configuration.getDefaultApiClient());
}

public UsersApi(ApiClient apiClient) {
this.localVarApiClient = apiClient;
}

public ApiClient getApiClient() {
return localVarApiClient;
}

public void setApiClient(ApiClient apiClient) {
this.localVarApiClient = apiClient;
}

/**
* Build call for organizationInformation
* @param _callback Callback for upload/download progress
* @return Call to execute
* @throws ApiException If fail to serialize the request body object
* @http.response.details
<table summary="Response Details" border="1">
<tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
<tr><td> 200 </td><td> OK. Key Manager list returned </td><td> - </td></tr>
<tr><td> 400 </td><td> Bad Request. Invalid request or validation error. </td><td> - </td></tr>
</table>
*/
public okhttp3.Call organizationInformationCall(final ApiCallback _callback) throws ApiException {
Object localVarPostBody = null;

// create path and map variables
String localVarPath = "/me/organization-information";

List<Pair> localVarQueryParams = new ArrayList<Pair>();
List<Pair> localVarCollectionQueryParams = new ArrayList<Pair>();
Map<String, String> localVarHeaderParams = new HashMap<String, String>();
Map<String, String> localVarCookieParams = new HashMap<String, String>();
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
final String[] localVarAccepts = {
"application/json"
};
final String localVarAccept = localVarApiClient.selectHeaderAccept(localVarAccepts);
if (localVarAccept != null) {
localVarHeaderParams.put("Accept", localVarAccept);
}

final String[] localVarContentTypes = {

};
final String localVarContentType = localVarApiClient.selectHeaderContentType(localVarContentTypes);
localVarHeaderParams.put("Content-Type", localVarContentType);

String[] localVarAuthNames = new String[] { "OAuth2Security" };
return localVarApiClient.buildCall(localVarPath, "GET", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarCookieParams, localVarFormParams, localVarAuthNames, _callback);
}

@SuppressWarnings("rawtypes")
private okhttp3.Call organizationInformationValidateBeforeCall(final ApiCallback _callback) throws ApiException {


okhttp3.Call localVarCall = organizationInformationCall(_callback);
return localVarCall;

}

/**
* Get the Organization information of the user
* Using this operation, logged-in user can get their organization information.
* @return OrganizationInfoDTO
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
* @http.response.details
<table summary="Response Details" border="1">
<tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
<tr><td> 200 </td><td> OK. Key Manager list returned </td><td> - </td></tr>
<tr><td> 400 </td><td> Bad Request. Invalid request or validation error. </td><td> - </td></tr>
</table>
*/
public OrganizationInfoDTO organizationInformation() throws ApiException {
ApiResponse<OrganizationInfoDTO> localVarResp = organizationInformationWithHttpInfo();
return localVarResp.getData();
}

/**
* Get the Organization information of the user
* Using this operation, logged-in user can get their organization information.
* @return ApiResponse&lt;OrganizationInfoDTO&gt;
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
* @http.response.details
<table summary="Response Details" border="1">
<tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
<tr><td> 200 </td><td> OK. Key Manager list returned </td><td> - </td></tr>
<tr><td> 400 </td><td> Bad Request. Invalid request or validation error. </td><td> - </td></tr>
</table>
*/
public ApiResponse<OrganizationInfoDTO> organizationInformationWithHttpInfo() throws ApiException {
okhttp3.Call localVarCall = organizationInformationValidateBeforeCall(null);
Type localVarReturnType = new TypeToken<OrganizationInfoDTO>(){}.getType();
return localVarApiClient.execute(localVarCall, localVarReturnType);
}

/**
* Get the Organization information of the user (asynchronously)
* Using this operation, logged-in user can get their organization information.
* @param _callback The callback to be executed when the API call finishes
* @return The request call
* @throws ApiException If fail to process the API call, e.g. serializing the request body object
* @http.response.details
<table summary="Response Details" border="1">
<tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
<tr><td> 200 </td><td> OK. Key Manager list returned </td><td> - </td></tr>
<tr><td> 400 </td><td> Bad Request. Invalid request or validation error. </td><td> - </td></tr>
</table>
*/
public okhttp3.Call organizationInformationAsync(final ApiCallback<OrganizationInfoDTO> _callback) throws ApiException {

okhttp3.Call localVarCall = organizationInformationValidateBeforeCall(_callback);
Type localVarReturnType = new TypeToken<OrganizationInfoDTO>(){}.getType();
localVarApiClient.executeAsync(localVarCall, localVarReturnType, _callback);
return localVarCall;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@ public TokenTypeEnum read(final JsonReader jsonReader) throws IOException {
@SerializedName(SERIALIZED_NAME_TOKEN_TYPE)
private TokenTypeEnum tokenType = TokenTypeEnum.DIRECT;

public static final String SERIALIZED_NAME_ALLOWED_ORGANIZATIONS = "allowedOrganizations";
@SerializedName(SERIALIZED_NAME_ALLOWED_ORGANIZATIONS)
private List<String> allowedOrganizations = null;


public KeyManagerDTO id(String id) {

Expand Down Expand Up @@ -974,6 +978,29 @@ public void setTokenType(TokenTypeEnum tokenType) {
}


public KeyManagerDTO allowedOrganizations(List<String> allowedOrganizations) {

this.allowedOrganizations = allowedOrganizations;
return this;
}

/**
* Get allowedOrganizations
* @return allowedOrganizations
**/
@javax.annotation.Nullable
@ApiModelProperty(value = "")

public List<String> getAllowedOrganizations() {
return allowedOrganizations;
}


public void setAllowedOrganizations(List<String> allowedOrganizations) {
this.allowedOrganizations = allowedOrganizations;
}


@Override
public boolean equals(Object o) {
if (this == o) {
Expand Down Expand Up @@ -1015,12 +1042,13 @@ public boolean equals(Object o) {
Objects.equals(this.enabled, keyManager.enabled) &&
Objects.equals(this.additionalProperties, keyManager.additionalProperties) &&
Objects.equals(this.permissions, keyManager.permissions) &&
Objects.equals(this.tokenType, keyManager.tokenType);
Objects.equals(this.tokenType, keyManager.tokenType) &&
Objects.equals(this.allowedOrganizations, keyManager.allowedOrganizations);
}

@Override
public int hashCode() {
return Objects.hash(id, name, displayName, type, description, wellKnownEndpoint, introspectionEndpoint, clientRegistrationEndpoint, tokenEndpoint, displayTokenEndpoint, revokeEndpoint, displayRevokeEndpoint, userInfoEndpoint, authorizeEndpoint, certificates, issuer, alias, scopeManagementEndpoint, availableGrantTypes, enableTokenGeneration, enableTokenEncryption, enableTokenHashing, enableMapOAuthConsumerApps, enableOAuthAppCreation, enableSelfValidationJWT, claimMapping, consumerKeyClaim, scopesClaim, tokenValidation, enabled, additionalProperties, permissions, tokenType);
return Objects.hash(id, name, displayName, type, description, wellKnownEndpoint, introspectionEndpoint, clientRegistrationEndpoint, tokenEndpoint, displayTokenEndpoint, revokeEndpoint, displayRevokeEndpoint, userInfoEndpoint, authorizeEndpoint, certificates, issuer, alias, scopeManagementEndpoint, availableGrantTypes, enableTokenGeneration, enableTokenEncryption, enableTokenHashing, enableMapOAuthConsumerApps, enableOAuthAppCreation, enableSelfValidationJWT, claimMapping, consumerKeyClaim, scopesClaim, tokenValidation, enabled, additionalProperties, permissions, tokenType, allowedOrganizations);
}


Expand Down Expand Up @@ -1061,6 +1089,7 @@ public String toString() {
sb.append(" additionalProperties: ").append(toIndentedString(additionalProperties)).append("\n");
sb.append(" permissions: ").append(toIndentedString(permissions)).append("\n");
sb.append(" tokenType: ").append(toIndentedString(tokenType)).append("\n");
sb.append(" allowedOrganizations: ").append(toIndentedString(allowedOrganizations)).append("\n");
sb.append("}");
return sb.toString();
}
Expand Down
Loading

0 comments on commit 0998de9

Please sign in to comment.