Search in sources :

Example 1 with ConnectedAppsResult

use of org.wso2.carbon.idp.mgt.model.ConnectedAppsResult in project carbon-identity-framework by wso2.

the class IdPManagementDAO method getConnectedApplications.

/**
 * Get list of applications that are connected to the identity provider from DB.
 *
 * @param resourceId IDP resource ID.
 * @param limit      Limit parameter for pagination.
 * @param offset     Offset parameter for pagination.
 * @return ConnectedAppsResult.
 * @throws IdentityProviderManagementException
 */
public ConnectedAppsResult getConnectedApplications(String resourceId, int limit, int offset) throws IdentityProviderManagementException {
    ConnectedAppsResult connectedAppsResult = new ConnectedAppsResult();
    List<String> connectedApps = new ArrayList<>();
    try (Connection connection = IdentityDatabaseUtil.getDBConnection(false)) {
        try (PreparedStatement prepStmt = createConnectedAppsSqlStatement(connection, resourceId, limit, offset)) {
            try (ResultSet resultSet = prepStmt.executeQuery()) {
                while (resultSet.next()) {
                    connectedApps.add(resultSet.getString("UUID"));
                }
            }
        }
        String sqlQuery = IdPManagementConstants.SQLQueries.CONNECTED_APPS_TOTAL_COUNT_SQL;
        try (PreparedStatement prepStmt = connection.prepareStatement(sqlQuery)) {
            prepStmt.setString(1, resourceId);
            prepStmt.setString(2, resourceId);
            try (ResultSet resultSet = prepStmt.executeQuery()) {
                if (resultSet.next()) {
                    connectedAppsResult.setTotalAppCount(resultSet.getInt(1));
                }
            }
        }
    } catch (SQLException e) {
        log.error("Error occurred during retrieving connected applications of IDP: " + resourceId, e);
        throw IdPManagementUtil.handleServerException(IdPManagementConstants.ErrorMessage.ERROR_CODE_RETRIEVE_IDP_CONNECTED_APPS, resourceId);
    }
    connectedAppsResult.setApps(connectedApps);
    connectedAppsResult.setLimit(limit);
    connectedAppsResult.setOffSet(offset);
    return connectedAppsResult;
}
Also used : ConnectedAppsResult(org.wso2.carbon.idp.mgt.model.ConnectedAppsResult) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 2 with ConnectedAppsResult

use of org.wso2.carbon.idp.mgt.model.ConnectedAppsResult in project carbon-identity-framework by wso2.

the class ApplicationIdentityProviderMgtListener method doPostUpdateIdP.

@Override
public boolean doPostUpdateIdP(String oldIdPName, IdentityProvider identityProvider, String tenantDomain) throws IdentityProviderManagementException {
    try {
        IdentityProviderManager identityProviderManager = IdentityProviderManager.getInstance();
        ConnectedAppsResult connectedApplications;
        String updatedIdpId = identityProvider.getResourceId();
        ApplicationDAO applicationDAO = ApplicationMgtSystemConfig.getInstance().getApplicationDAO();
        int offset = 0;
        do {
            connectedApplications = identityProviderManager.getConnectedApplications(updatedIdpId, null, offset, tenantDomain);
            for (String appResourceId : connectedApplications.getApps()) {
                ServiceProvider serviceProvider = applicationDAO.getApplicationByResourceId(appResourceId, tenantDomain);
                applicationDAO.clearApplicationFromCache(serviceProvider, tenantDomain);
            }
            offset = connectedApplications.getOffSet() + connectedApplications.getLimit();
        } while (connectedApplications.getTotalAppCount() > offset);
    } catch (IdentityApplicationManagementException e) {
        throw new IdentityProviderManagementException("Error while running post IDP update tasks.", e);
    }
    return true;
}
Also used : ConnectedAppsResult(org.wso2.carbon.idp.mgt.model.ConnectedAppsResult) ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider) IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) IdentityProviderManager(org.wso2.carbon.idp.mgt.IdentityProviderManager) CacheBackedApplicationDAO(org.wso2.carbon.identity.application.mgt.dao.impl.CacheBackedApplicationDAO) ApplicationDAO(org.wso2.carbon.identity.application.mgt.dao.ApplicationDAO) IdentityProviderManagementException(org.wso2.carbon.idp.mgt.IdentityProviderManagementException)

Example 3 with ConnectedAppsResult

use of org.wso2.carbon.idp.mgt.model.ConnectedAppsResult in project identity-api-server by wso2.

the class ServerIdpManagementService method createConnectedAppsResponse.

private ConnectedApps createConnectedAppsResponse(String resourceId, ConnectedAppsResult connectedAppsResult) {
    ConnectedApps connectedAppsResponse = new ConnectedApps();
    if (connectedAppsResult == null) {
        return connectedAppsResponse;
    }
    List<ConnectedApp> connectedAppList = new ArrayList<>();
    if (CollectionUtils.isNotEmpty(connectedAppsResult.getApps())) {
        for (String app : connectedAppsResult.getApps()) {
            ConnectedApp listItem = new ConnectedApp();
            listItem.setAppId(app);
            listItem.setSelf(ContextLoader.buildURIForBody(String.format(V1_API_PATH_COMPONENT + "/applications/%s", app)).toString());
            connectedAppList.add(listItem);
        }
        connectedAppsResponse.setConnectedApps(connectedAppList);
        connectedAppsResponse.setCount(connectedAppList.size());
    } else {
        connectedAppsResponse.setCount(0);
    }
    connectedAppsResponse.setTotalResults(connectedAppsResult.getTotalAppCount());
    connectedAppsResponse.setStartIndex(connectedAppsResult.getOffSet() + 1);
    connectedAppsResponse.setLinks(createLinks(V1_API_PATH_COMPONENT + IDP_PATH_COMPONENT + Constants.PATH_SEPERATOR + resourceId + "/connected-apps", connectedAppsResult.getLimit(), connectedAppsResult.getOffSet(), connectedAppsResult.getTotalAppCount(), null));
    return connectedAppsResponse;
}
Also used : ConnectedApp(org.wso2.carbon.identity.api.server.idp.v1.model.ConnectedApp) ArrayList(java.util.ArrayList) ConnectedApps(org.wso2.carbon.identity.api.server.idp.v1.model.ConnectedApps)

Example 4 with ConnectedAppsResult

use of org.wso2.carbon.idp.mgt.model.ConnectedAppsResult in project carbon-identity-framework by wso2.

the class IdPManagementDAOTest method testGetConnectedApplications.

@Test(dataProvider = "getConnectedApplicationsData")
public void testGetConnectedApplications(String idPName, int tenantId, int limit, int offset, int count) throws Exception {
    mockStatic(IdentityDatabaseUtil.class);
    try (Connection connection = getConnection(DB_NAME)) {
        when(IdentityDatabaseUtil.getDBConnection(anyBoolean())).thenReturn(connection);
        when(IdentityDatabaseUtil.getDBConnection()).thenReturn(connection);
        when(IdentityDatabaseUtil.getDataSource()).thenReturn(dataSourceMap.get(DB_NAME));
        addTestIdps();
        IdentityProvider idp = idPManagementDAO.getIdPByName(connection, idPName, tenantId, TENANT_DOMAIN);
        String uuid = idp.getResourceId();
        ConnectedAppsResult result = idPManagementDAO.getConnectedApplications(uuid, limit, offset);
        assertEquals(result.getTotalAppCount(), count);
    }
}
Also used : ConnectedAppsResult(org.wso2.carbon.idp.mgt.model.ConnectedAppsResult) Connection(java.sql.Connection) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 5 with ConnectedAppsResult

use of org.wso2.carbon.idp.mgt.model.ConnectedAppsResult in project carbon-identity-framework by wso2.

the class ApplicationIdentityProviderMgtListener method doPreUpdateIdP.

@Override
public boolean doPreUpdateIdP(String oldIdPName, IdentityProvider identityProvider, String tenantDomain) throws IdentityProviderManagementException {
    try {
        IdentityServiceProviderCache.getInstance().clear(tenantDomain);
        IdentityProviderManager identityProviderManager = IdentityProviderManager.getInstance();
        ConnectedAppsResult connectedApplications;
        String idpId = identityProviderManager.getIdPByName(oldIdPName, tenantDomain).getResourceId();
        if (identityProvider.getResourceId() == null && idpId != null) {
            identityProvider.setResourceId(idpId);
        }
        int offset = 0;
        do {
            connectedApplications = identityProviderManager.getConnectedApplications(idpId, null, offset, tenantDomain);
            List<ServiceProvider> serviceProvidersList = new ArrayList<>();
            for (String appResourceId : connectedApplications.getApps()) {
                ServiceProvider serviceProvider = ApplicationMgtSystemConfig.getInstance().getApplicationDAO().getApplicationByResourceId(appResourceId, tenantDomain);
                serviceProvidersList.add(serviceProvider);
            }
            for (ServiceProvider serviceProvider : serviceProvidersList) {
                LocalAndOutboundAuthenticationConfig localAndOutboundAuthConfig = serviceProvider.getLocalAndOutBoundAuthenticationConfig();
                AuthenticationStep[] authSteps = localAndOutboundAuthConfig.getAuthenticationSteps();
                OutboundProvisioningConfig outboundProvisioningConfig = serviceProvider.getOutboundProvisioningConfig();
                IdentityProvider[] provisioningIdps = outboundProvisioningConfig.getProvisioningIdentityProviders();
                // Check whether the identity provider is referred in a service provider
                validateIdpDisable(identityProvider, authSteps, provisioningIdps);
                // Validating Applications with Federated Authenticators configured.
                updateApplicationWithFederatedAuthenticators(identityProvider, tenantDomain, serviceProvider, localAndOutboundAuthConfig, authSteps);
                // Validating Applications with Outbound Provisioning Connectors configured.
                updateApplicationWithProvisioningConnectors(identityProvider, provisioningIdps);
                // Clear application caches if IDP name is updated.
                if (!StringUtils.equals(oldIdPName, identityProvider.getIdentityProviderName())) {
                    CacheBackedApplicationDAO.clearAllAppCache(serviceProvider, tenantDomain);
                }
            }
            offset = connectedApplications.getOffSet() + connectedApplications.getLimit();
        } while (connectedApplications.getTotalAppCount() > offset);
    } catch (IdentityApplicationManagementException e) {
        throw new IdentityProviderManagementException("Error when updating default authenticator of service providers", e);
    }
    return true;
}
Also used : ConnectedAppsResult(org.wso2.carbon.idp.mgt.model.ConnectedAppsResult) IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) ArrayList(java.util.ArrayList) AuthenticationStep(org.wso2.carbon.identity.application.common.model.AuthenticationStep) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) OutboundProvisioningConfig(org.wso2.carbon.identity.application.common.model.OutboundProvisioningConfig) LocalAndOutboundAuthenticationConfig(org.wso2.carbon.identity.application.common.model.LocalAndOutboundAuthenticationConfig) ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider) IdentityProviderManager(org.wso2.carbon.idp.mgt.IdentityProviderManager) IdentityProviderManagementException(org.wso2.carbon.idp.mgt.IdentityProviderManagementException)

Aggregations

ConnectedAppsResult (org.wso2.carbon.idp.mgt.model.ConnectedAppsResult)4 ArrayList (java.util.ArrayList)3 Connection (java.sql.Connection)2 IdentityApplicationManagementException (org.wso2.carbon.identity.application.common.IdentityApplicationManagementException)2 IdentityProvider (org.wso2.carbon.identity.application.common.model.IdentityProvider)2 ServiceProvider (org.wso2.carbon.identity.application.common.model.ServiceProvider)2 IdentityProviderManagementException (org.wso2.carbon.idp.mgt.IdentityProviderManagementException)2 IdentityProviderManager (org.wso2.carbon.idp.mgt.IdentityProviderManager)2 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1 Test (org.testng.annotations.Test)1 ConnectedApp (org.wso2.carbon.identity.api.server.idp.v1.model.ConnectedApp)1 ConnectedApps (org.wso2.carbon.identity.api.server.idp.v1.model.ConnectedApps)1 AuthenticationStep (org.wso2.carbon.identity.application.common.model.AuthenticationStep)1 LocalAndOutboundAuthenticationConfig (org.wso2.carbon.identity.application.common.model.LocalAndOutboundAuthenticationConfig)1 OutboundProvisioningConfig (org.wso2.carbon.identity.application.common.model.OutboundProvisioningConfig)1 ApplicationDAO (org.wso2.carbon.identity.application.mgt.dao.ApplicationDAO)1 CacheBackedApplicationDAO (org.wso2.carbon.identity.application.mgt.dao.impl.CacheBackedApplicationDAO)1