Skip to content

Commit

Permalink
Merge pull request #4926 from ThaminduR/add-authorized-api
Browse files Browse the repository at this point in the history
Implement authorizing API resource to an application
  • Loading branch information
ThaminduR authored Oct 11, 2023
2 parents 7c8dc56 + 76ab092 commit 3ee2fe4
Show file tree
Hide file tree
Showing 27 changed files with 1,569 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,140 @@
/*
* 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 apiIdentifier;
private String apiName;
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 getAPIIdentifier() {

return apiIdentifier;
}

public void setAPIIdentifier(String apiIdentifier) {

this.apiIdentifier = apiIdentifier;
}

public String getAPIName() {

return apiName;
}

public void setAPIName(String apiName) {

this.apiName = apiName;
}

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 String policyId;
private List<Scope> 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 @@ -125,6 +125,11 @@
<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>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.wso2.carbon.utils</groupId>
<artifactId>org.wso2.carbon.database.utils</artifactId>
Expand Down Expand Up @@ -236,6 +241,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,11 @@ 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";
public static final String MAIN_APP_ID = "MAIN_APP_ID";

private ApplicationTableColumns() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.apache.commons.lang.NotImplementedException;
import org.wso2.carbon.identity.application.common.IdentityApplicationManagementException;
import org.wso2.carbon.identity.application.common.IdentityApplicationManagementServerException;
import org.wso2.carbon.identity.application.common.model.ApplicationBasicInfo;
import org.wso2.carbon.identity.application.common.model.AuthenticationStep;
import org.wso2.carbon.identity.application.common.model.IdentityProvider;
Expand Down Expand Up @@ -492,5 +493,26 @@ public Set<String> getSystemApplications() {
return Collections.emptySet();
}

/**
* Get main application ID from the shared application ID.
*
* @param sharedAppId ID of the shared application.
* @return ID of the main application.
*/
public String getMainAppId(String sharedAppId) throws IdentityApplicationManagementServerException {

throw new NotImplementedException();
}

/**
* Get tenant ID of the application.
*
* @param appId ID of the application.
* @return Tenant ID.
*/
public int getTenantIdByApp(String appId) throws IdentityApplicationManagementServerException {

throw new NotImplementedException();
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -2650,6 +2650,18 @@ public Set<String> getSystemApplications() {
return systemApplications;
}

@Override
public String getMainAppId(String sharedAppId) throws IdentityApplicationManagementServerException {

return ApplicationMgtSystemConfig.getInstance().getApplicationDAO().getMainAppId(sharedAppId);
}

@Override
public int getTenantIdByApp(String appId) throws IdentityApplicationManagementServerException {

return ApplicationMgtSystemConfig.getInstance().getApplicationDAO().getTenantIdByApp(appId);
}

private void doPreUpdateChecks(String storedAppName, ServiceProvider updatedApp, String tenantDomain,
String username) throws IdentityApplicationManagementException {

Expand Down
Loading

0 comments on commit 3ee2fe4

Please sign in to comment.