Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ThaminduR committed Sep 27, 2023
1 parent 86fb29c commit 2b9d51e
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ private ApplicationManagementConstants() {
public static final String ISSUER = "issuer";
public static final String RBAC = "RBAC";
public static final String NO_POLICY = "No Policy";

public static final String NON_EXISTING_USER_CODE = "30007 - ";

/**
Expand Down Expand Up @@ -116,7 +117,7 @@ public enum ErrorMessage {
"API resource with id: %s is not authorized for the application with id: %s."),
INVALID_POLICY_VALUE("60511", "Invalid policy id value provided.",
"Invalid policy id value. It should be 'RBAC' or 'No Policy'."),
INVALID_POLICY_TYPE_FOR_API_RESOURCE("60511", "Invalid policy type provided for the API " +
INVALID_POLICY_TYPE_FOR_API_RESOURCE("60512", "Invalid policy type provided for the API " +
"resource.", "API resource with id: %s doesn't allow the provided policy type: %s."),

// Server Errors.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Copyright (c) 2021, WSO2 Inc. (http://www.wso2.com).
* Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 Inc. licenses this file to you under the Apache License,
* 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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Copyright (c) 2021, WSO2 Inc. (http://www.wso2.com).
* Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 Inc. licenses this file to you under the Apache License,
* 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
Expand All @@ -19,10 +19,38 @@
package org.wso2.carbon.identity.api.server.application.management.v1;

import org.apache.cxf.jaxrs.ext.search.SearchContext;
import org.wso2.carbon.identity.api.server.application.management.v1.*;
import org.wso2.carbon.identity.api.server.application.management.v1.*;
import org.apache.cxf.jaxrs.ext.multipart.Attachment;
import org.apache.cxf.jaxrs.ext.multipart.Multipart;

import java.io.InputStream;

import java.util.List;
import org.wso2.carbon.identity.api.server.application.management.v1.AdaptiveAuthTemplates;
import org.wso2.carbon.identity.api.server.application.management.v1.ApplicationListResponse;
import org.wso2.carbon.identity.api.server.application.management.v1.ApplicationModel;
import org.wso2.carbon.identity.api.server.application.management.v1.ApplicationOwner;
import org.wso2.carbon.identity.api.server.application.management.v1.ApplicationPatchModel;
import org.wso2.carbon.identity.api.server.application.management.v1.ApplicationResponseModel;
import org.wso2.carbon.identity.api.server.application.management.v1.ApplicationTemplateModel;
import org.wso2.carbon.identity.api.server.application.management.v1.ApplicationTemplatesList;
import org.wso2.carbon.identity.api.server.application.management.v1.AuthProtocolMetadata;
import org.wso2.carbon.identity.api.server.application.management.v1.ConfiguredAuthenticatorsModal;
import org.wso2.carbon.identity.api.server.application.management.v1.CustomInboundProtocolConfiguration;
import org.wso2.carbon.identity.api.server.application.management.v1.CustomInboundProtocolMetaData;
import org.wso2.carbon.identity.api.server.application.management.v1.Error;
import java.io.File;
import org.wso2.carbon.identity.api.server.application.management.v1.InboundProtocolListItem;
import org.wso2.carbon.identity.api.server.application.management.v1.OIDCMetaData;
import org.wso2.carbon.identity.api.server.application.management.v1.OpenIDConnectConfiguration;
import org.wso2.carbon.identity.api.server.application.management.v1.PassiveStsConfiguration;
import org.wso2.carbon.identity.api.server.application.management.v1.ProvisioningConfiguration;
import org.wso2.carbon.identity.api.server.application.management.v1.ResidentApplication;
import org.wso2.carbon.identity.api.server.application.management.v1.SAML2Configuration;
import org.wso2.carbon.identity.api.server.application.management.v1.SAML2ServiceProvider;
import org.wso2.carbon.identity.api.server.application.management.v1.SAMLMetaData;
import org.wso2.carbon.identity.api.server.application.management.v1.WSTrustConfiguration;
import org.wso2.carbon.identity.api.server.application.management.v1.WSTrustMetaData;
import javax.ws.rs.core.Response;


Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Copyright (c) 2021, WSO2 Inc. (http://www.wso2.com).
* Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 Inc. licenses this file to you under the Apache License,
* 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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Copyright (c) 2021, WSO2 Inc. (http://www.wso2.com).
* Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 Inc. licenses this file to you under the Apache License,
* 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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Copyright (c) 2021, WSO2 Inc. (http://www.wso2.com).
* Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 Inc. licenses this file to you under the Apache License,
* 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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Copyright (c) 2021, WSO2 Inc. (http://www.wso2.com).
* Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 Inc. licenses this file to you under the Apache License,
* 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ public class ServerApplicationManagementService {
private static final String[] VALID_MEDIA_TYPES_XML = {"application/xml", "text/xml"};
private static final String[] VALID_MEDIA_TYPES_YAML = {"application/yaml", "text/yaml", "application/x-yaml"};
private static final String[] VALID_MEDIA_TYPES_JSON = {"application/json", "text/json"};
private static final Class<?>[] INBOUND_CONFIG_PROTOCOLS = new Class<?>[]{ServiceProvider.class,
SAMLSSOServiceProviderDTO.class, OAuthAppDO.class};
private static final Class<?>[] INBOUND_CONFIG_PROTOCOLS = new Class<?>[] {ServiceProvider.class,
SAMLSSOServiceProviderDTO.class, OAuthAppDO.class};

static {
SUPPORTED_FILTER_ATTRIBUTES.add(NAME);
Expand Down Expand Up @@ -791,7 +791,7 @@ public String createApplication(ApplicationModel applicationModel, String templa
// Update owner for B2B Self Service applications.
if (application.isB2BSelfServiceApp()) {
String systemUserID = org.wso2.carbon.identity.organization.management.service.util.Utils
.getB2BSelfServiceSystemUser(tenantDomain);
.getB2BSelfServiceSystemUser(tenantDomain);
if (StringUtils.isNotEmpty(systemUserID)) {
ApplicationOwner systemOwner = new ApplicationOwner();
systemOwner.id(systemUserID);
Expand Down Expand Up @@ -1308,6 +1308,12 @@ public void changeApplicationOwner(String applicationId, ApplicationOwner applic
updateServiceProvider(applicationId, appToUpdate);
}

/**
* Authorize an API resource to the application.
*
* @param applicationId Application ID.
* @param authorizedAPICreationModel API Authorization creation model.
*/
public void addAuthorizedAPI(String applicationId, AuthorizedAPICreationModel authorizedAPICreationModel) {

try {
Expand Down Expand Up @@ -1355,31 +1361,12 @@ public void addAuthorizedAPI(String applicationId, AuthorizedAPICreationModel au
}
}

public String validatePolicy(String policyId) {

if (policyId == null || policyId.isEmpty()) {
// No input provided, use the default policy identifier.
return ApplicationManagementConstants.RBAC;
} else if (policyId.equalsIgnoreCase(ApplicationManagementConstants.RBAC)
|| policyId.equalsIgnoreCase(ApplicationManagementConstants.NO_POLICY)) {
return policyId.toUpperCase(Locale.ENGLISH);
} else {
throw buildClientError(ErrorMessage.INVALID_POLICY_VALUE);
}
}

private void validateAPIResourceScopes(APIResource apiResource, List<String> scopes)
throws APIResourceMgtException {

List<Scope> apiResourceScopes = apiResource.getScopes();
for (String scopeName : scopes) {
if (apiResourceScopes.stream().noneMatch(scope -> scope.getName().equals(scopeName))) {
throw buildClientError(ErrorMessage.SCOPES_NOT_FOUND, apiResource.getId(),
CarbonContext.getThreadLocalCarbonContext().getTenantDomain());
}
}
}

/**
* Delete an API authorization from the application.
*
* @param applicationId Application ID.
* @param apiId API resource ID.
*/
public void deleteAuthorizedAPI(String applicationId, String apiId) {

try {
Expand All @@ -1392,6 +1379,12 @@ public void deleteAuthorizedAPI(String applicationId, String apiId) {
}
}

/**
* Update the API authorization of the application for an API resource.
* @param applicationId Application ID.
* @param apiId API resource ID.
* @param authorizedAPIPatchModel
*/
public void updateAuthorizedAPI(String applicationId, String apiId,
AuthorizedAPIPatchModel authorizedAPIPatchModel) {

Expand Down Expand Up @@ -1454,6 +1447,31 @@ public List<AuthorizedAPIResponse> getAuthorizedAPIs(String applicationId) {
}
}

private String validatePolicy(String policyId) {

if (policyId == null || policyId.isEmpty()) {
// No input provided, use the default policy identifier.
return ApplicationManagementConstants.RBAC;
} else if (policyId.equalsIgnoreCase(ApplicationManagementConstants.RBAC)
|| policyId.equalsIgnoreCase(ApplicationManagementConstants.NO_POLICY)) {
return policyId.toUpperCase(Locale.ENGLISH);
} else {
throw buildClientError(ErrorMessage.INVALID_POLICY_VALUE);
}
}

private void validateAPIResourceScopes(APIResource apiResource, List<String> scopes)
throws APIResourceMgtException {

List<Scope> apiResourceScopes = apiResource.getScopes();
for (String scopeName : scopes) {
if (apiResourceScopes.stream().noneMatch(scope -> scope.getName().equals(scopeName))) {
throw buildClientError(ErrorMessage.SCOPES_NOT_FOUND, apiResource.getId(),
CarbonContext.getThreadLocalCarbonContext().getTenantDomain());
}
}
}

private List<AuthorizedScope> createAuthorizedScope(List<Scope> scope) {

return scope.stream().map(s -> new AuthorizedScope()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
class="org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementServiceHolder">
<property name="apiResourceManager" ref="apiResourceManagerServiceFactoryBean"/>
</bean>

<bean id="applicationManagementServiceFactoryBean"
class="org.wso2.carbon.identity.api.server.application.management.common.factory.ApplicationManagementOSGiServiceFactory"/>
<bean id="oauthAdminServiceFactoryBean"
Expand Down

0 comments on commit 2b9d51e

Please sign in to comment.