Skip to content

Commit

Permalink
Add authorized API
Browse files Browse the repository at this point in the history
  • Loading branch information
ThaminduR committed Sep 21, 2023
1 parent dd43cde commit 56495fd
Show file tree
Hide file tree
Showing 15 changed files with 779 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,14 @@ void putScopes(String apiResourceId, List<Scope> currentScopes, List<Scope> scop
* @throws APIResourceMgtException If an error occurs while retrieving scopes.
*/
List<Scope> getScopesByTenantDomain(String tenantDomain, String filter) throws APIResourceMgtException;

/**
* Get scope by name.
*
* @param scopeName Scope name.
* @param tenantDomain Tenant domain.
* @return Scope.
* @throws APIResourceMgtException If an error occurs while retrieving scope.
*/
Scope getScopeByName(String scopeName, String tenantDomain) throws APIResourceMgtException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ public List<Scope> getScopesByTenantDomain(String tenantDomain, String filter) t
return CACHE_BACKED_DAO.getScopesByTenantId(tenantId, expressionNodes);
}

@Override
public Scope getScopeByName(String scopeName, String tenantDomain) throws APIResourceMgtException {

return CACHE_BACKED_DAO.getScopeByNameAndTenantId(scopeName, IdentityTenantUtil.getTenantId(tenantDomain));
}

/**
* Get the filter node as a list.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/*
* 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.carbon.identity.application.common.model;

import java.util.List;

/**
* Authorized API model class.
*/
public class AuthorizedAPI {

private String appId;
private String apiId;
private String policyId;
private List<Scope> scopes;

public AuthorizedAPI(String appId, String apiId, String policyId, List<Scope> scopes) {

this.appId = appId;
this.apiId = apiId;
this.policyId = policyId;
this.scopes = scopes;
}

public AuthorizedAPI() {

}

public String getAppId() {

return appId;
}

public String getApiId() {

return apiId;
}

public String getPolicyId() {

return policyId;
}

public List<Scope> getScopes() {

return scopes;
}

public void setScopes(List<Scope> scopes) {

this.scopes = scopes;
}

public void addScope(Scope scope) {

this.scopes.add(scope);
}

/**
* Builder class for {@link AuthorizedAPI}.
*/
public static class AuthorizedAPIBuilder {

private String appId;
private String apiId;
private boolean isUserBased;
private String policyId;
private List<Scope> scopes;

public AuthorizedAPIBuilder(String appId, String apiId, String policyId,
List<Scope> scopes) {

this.appId = appId;
this.apiId = apiId;
this.policyId = policyId;
this.scopes = scopes;
}

public AuthorizedAPIBuilder() {

}

public AuthorizedAPIBuilder appId(String appId) {

this.appId = appId;
return this;
}

public AuthorizedAPIBuilder apiId(String apiId) {

this.apiId = apiId;
return this;
}

public AuthorizedAPIBuilder policyId(String policyId) {

this.policyId = policyId;
return this;
}

public AuthorizedAPIBuilder scopes(List<Scope> scopes) {

this.scopes = scopes;
return this;
}

public AuthorizedAPI build() {

return new AuthorizedAPI(appId, apiId, policyId, scopes);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* 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.carbon.identity.application.common.model;

import java.util.List;

/**
* Authorized Scopes model class.
*/
public class AuthorizedScopes {

private String policyId;
private List<String> scopes;

public AuthorizedScopes(String policyId, List<String> scopes) {

this.policyId = policyId;
this.scopes = scopes;
}

public AuthorizedScopes() {

}

public String getPolicyId() {

return policyId;
}

public List<String> getScopes() {

return scopes;
}

public void setScopes(List<String> scopes) {

this.scopes = scopes;
}

/**
* Builder class for {@link AuthorizedScopes}.
*/
public static class AuthorizedScopesBuilder {

private String policyId;
private List<String> scopes;

public AuthorizedScopesBuilder policyId(String policyId) {

this.policyId = policyId;
return this;
}

public AuthorizedScopesBuilder scopes(List<String> scopes) {

this.scopes = scopes;
return this;
}

public AuthorizedScopes build() {

return new AuthorizedScopes(policyId, scopes);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@
<groupId>org.wso2.carbon.identity.framework</groupId>
<artifactId>org.wso2.carbon.identity.claim.metadata.mgt</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.identity.framework</groupId>
<artifactId>org.wso2.carbon.identity.api.resource.mgt</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon.utils</groupId>
<artifactId>org.wso2.carbon.database.utils</artifactId>
Expand Down Expand Up @@ -229,6 +233,7 @@
org.wso2.carbon.identity.central.log.mgt.*; version="${carbon.identity.package.import.version.range}",
org.wso2.carbon.identity.organization.management.service; version="${org.wso2.carbon.identity.organization.management.core.version.range}",
org.wso2.carbon.identity.organization.management.service.exception; version="${org.wso2.carbon.identity.organization.management.core.version.range}",
org.wso2.carbon.identity.api.resource.mgt.*; version="${carbon.identity.package.import.version.range}"
</Import-Package>
<Export-Package>
!org.wso2.carbon.identity.application.mgt.internal,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ public static class ApplicationTableColumns {
public static final String UUID = "UUID";
public static final String IMAGE_URL = "IMAGE_URL";
public static final String ACCESS_URL = "ACCESS_URL";
public static final String APP_ID = "APP_ID";
public static final String API_ID = "API_ID";
public static final String POLICY_ID = "POLICY_ID";
public static final String SCOPE_NAME = "SCOPE_NAME";

private ApplicationTableColumns() {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* 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.carbon.identity.application.mgt;

import org.wso2.carbon.identity.application.common.IdentityApplicationManagementException;
import org.wso2.carbon.identity.application.common.model.AuthorizedAPI;
import org.wso2.carbon.identity.application.common.model.AuthorizedScopes;

import java.util.List;

/**
* Authorized API management service.
*/
public interface AuthorizedAPIManagementService {

/**
* Authorize an API to the application.
*
* @param applicationId Application ID.
* @param authorizedAPI Authorized API.
* @param tenantDomain Tenant Domain.
* @throws IdentityApplicationManagementException if an error occurs while authorizing the API.
*/
public void addAuthorizedAPI(String applicationId, AuthorizedAPI authorizedAPI, String tenantDomain)
throws IdentityApplicationManagementException;

/**
* Delete authorized APIs from the application.
*
* @param appId Application ID.
* @param apiId API ID.
* @param tenantDomain Tenant Domain.
* @throws IdentityApplicationManagementException if an error occurs while deleting the authorized APIs.
*/
public void deleteAuthorizedAPIs(String appId, String apiId, String tenantDomain)
throws IdentityApplicationManagementException;

/**
* Get authorized APIs of the application.
*
* @param applicationId Application ID.
* @param tenantDomain Tenant Domain.
* @return List of authorized APIs.
* @throws IdentityApplicationManagementException if an error occurs while retrieving the authorized APIs.
*/
public List<AuthorizedAPI> getAuthorizedAPIs(String applicationId, String tenantDomain)
throws IdentityApplicationManagementException;

/**
* Patch authorized APIs of the application.
*
* @param appId Application ID.
* @param apiId API ID.
* @param addedScopes Added scopes.
* @param removedScopes Removed scopes.
* @param tenantDomain Tenant Domain.
* @throws IdentityApplicationManagementException if an error occurs while patching the authorized APIs.
*/
public void patchAuthorizedAPIs(String appId, String apiId, List<String> addedScopes,
List<String> removedScopes, String tenantDomain)
throws IdentityApplicationManagementException;

/**
* Get authorized scopes of the application.
*
* @param appId Application ID.
* @param tenantDomain Tenant Domain.
* @throws IdentityApplicationManagementException if an error occurs while retrieving the authorized scopes.
*/
public List<AuthorizedScopes> getAuthorizedScopes(String appId, String tenantDomain)
throws IdentityApplicationManagementException;
}
Loading

0 comments on commit 56495fd

Please sign in to comment.