@@ -0,0 +1,2712 @@
+/*%0A * Copyright (c) 2020 WSO2 Inc. (http://www.wso2.org) All Rights Reserved.%0A *%0A * WSO2 Inc. licenses this file to you under the Apache License,%0A * Version 2.0 (the %22License%22); you may not use this file except%0A * in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *   http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing,%0A * software distributed under the License is distributed on an%0A * %22AS IS%22 BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY%0A * KIND, either express or implied.  See the License for the%0A * specific language governing permissions and limitations%0A * under the License.%0A */%0Apackage org.wso2.carbon.apimgt.impl.observers;%0A%0Aimport org.apache.axis2.context.ConfigurationContext;%0Aimport org.apache.commons.logging.Log;%0Aimport org.apache.commons.logging.LogFactory;%0Aimport org.wso2.carbon.apimgt.api.APIManagementException;%0Aimport org.wso2.carbon.apimgt.api.model.OAuthApplicationInfo;%0Aimport org.wso2.carbon.apimgt.impl.dao.KMApplicationDAO;%0Aimport org.wso2.carbon.apimgt.impl.factory.KeyManagerHolder;%0Aimport org.wso2.carbon.context.PrivilegedCarbonContext;%0Aimport org.wso2.carbon.utils.AbstractAxis2ConfigurationContextObserver;%0A%0A/**%0A * This task provisions the OAuth application for the keymanager management operations needed by any tenant.%0A */%0Apublic class KMConfigDeployer extends AbstractAxis2ConfigurationContextObserver %7B%0A%0A    private static final Log log = LogFactory.getLog(KMConfigDeployer.class);%0A%0A    @Override%0A    public void createdConfigurationContext(ConfigurationContext configContext) %7B%0A%0A        String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();%0A        int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();%0A        try %7B%0A            //check whether an application is already registered for the tenant%0A            OAuthApplicationInfo oAuthApplicationInfo =%0A                    KMApplicationDAO.getInstance().getApplicationForTenant(tenantId);%0A            if (oAuthApplicationInfo == null) %7B // if not registered%0A                oAuthApplicationInfo =%0A                        KeyManagerHolder.getKeyManagerInstance().registerKeyManagerMgtApplication(tenantDomain);%0A                // add the application info to the AM database%0A                KMApplicationDAO.getInstance().AddApplication(oAuthApplicationInfo.getClientId(),%0A                        oAuthApplicationInfo.getClientSecret(), tenantId);%0A            %7D%0A        %7D catch (APIManagementException e) %7B%0A            log.error(%22Failed to register key manager management application for tenant: %22 + tenantDomain%0A                    + e.getMessage());%0A        %7D%0A    %7D%0A%7D%0A

Add KMConfigDeployer to provision OAuth app when each tenant is loading.