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;
}
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;
}
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;
}
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);
}
}
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;
}
Aggregations