Search in sources :

Example 91 with ApplicationDAO

use of org.wso2.carbon.identity.application.mgt.dao.ApplicationDAO in project carbon-identity-framework by wso2.

the class ApplicationManagementServiceImpl method getServiceProviderToLocalIdPClaimMapping.

/**
 * [sp-claim-uri,local-idp-claim-uri]
 *
 * @param serviceProviderName
 * @param tenantDomain
 * @return
 * @throws IdentityApplicationManagementException
 */
@Override
public Map<String, String> getServiceProviderToLocalIdPClaimMapping(String serviceProviderName, String tenantDomain) throws IdentityApplicationManagementException {
    ApplicationDAO appDAO = ApplicationMgtSystemConfig.getInstance().getApplicationDAO();
    Map<String, String> claimMap = appDAO.getServiceProviderToLocalIdPClaimMapping(serviceProviderName, tenantDomain);
    if (claimMap == null || claimMap.isEmpty() && ApplicationManagementServiceComponent.getFileBasedSPs().containsKey(serviceProviderName)) {
        return new FileBasedApplicationDAO().getServiceProviderToLocalIdPClaimMapping(serviceProviderName, tenantDomain);
    }
    return claimMap;
}
Also used : FileBasedApplicationDAO(org.wso2.carbon.identity.application.mgt.dao.impl.FileBasedApplicationDAO) PaginatableFilterableApplicationDAO(org.wso2.carbon.identity.application.mgt.dao.PaginatableFilterableApplicationDAO) ApplicationDAO(org.wso2.carbon.identity.application.mgt.dao.ApplicationDAO) FileBasedApplicationDAO(org.wso2.carbon.identity.application.mgt.dao.impl.FileBasedApplicationDAO)

Example 92 with ApplicationDAO

use of org.wso2.carbon.identity.application.mgt.dao.ApplicationDAO in project carbon-identity-framework by wso2.

the class ApplicationManagementServiceImpl method deleteApplicationByResourceId.

@Override
public void deleteApplicationByResourceId(String resourceId, String tenantDomain, String username) throws IdentityApplicationManagementException {
    // Invoking listeners.
    Collection<ApplicationResourceManagementListener> listeners = ApplicationMgtListenerServiceComponent.getApplicationResourceMgtListeners();
    for (ApplicationResourceManagementListener listener : listeners) {
        if (listener.isEnabled() && !listener.doPreDeleteApplicationByResourceId(resourceId, tenantDomain, username)) {
            throw buildServerException("Pre Delete application operation of listener: " + getName(listener) + " failed for application with resourceId: " + resourceId);
        }
    }
    ServiceProvider application;
    try {
        startTenantFlow(tenantDomain);
        ApplicationDAO appDAO = ApplicationMgtSystemConfig.getInstance().getApplicationDAO();
        application = appDAO.getApplicationByResourceId(resourceId, tenantDomain);
        if (application != null) {
            String applicationName = application.getApplicationName();
            doPreDeleteChecks(applicationName, tenantDomain, username);
            ApplicationMgtUtil.deleteAppRole(applicationName);
            ApplicationMgtUtil.deletePermissions(applicationName);
            // Delete the app information from SP_APP table.
            appDAO.deleteApplicationByResourceId(resourceId, tenantDomain);
        } else {
            if (log.isDebugEnabled()) {
                log.debug("Application cannot be found for resourceId: " + resourceId + " in tenantDomain: " + tenantDomain);
            }
            return;
        }
    } catch (Exception e) {
        log.error(String.format("Application: %s in tenant: %s might have partially deleted", resourceId, tenantDomain));
        throw e;
    } finally {
        endTenantFlow();
    }
    for (ApplicationResourceManagementListener listener : listeners) {
        if (listener.isEnabled() && !listener.doPostDeleteApplicationByResourceId(application, resourceId, tenantDomain, username)) {
            log.error("Post Delete application operation of listener: " + getName(listener) + " failed for " + "application with resourceId: " + resourceId);
            return;
        }
    }
    triggerAuditLogEvent(getInitiatorId(username, tenantDomain), getInitiatorId(username, tenantDomain), USER, CarbonConstants.LogEventConstants.EventCatalog.DELETE_APPLICATION.getEventId(), getAppId(application), getApplicationName(application), TARGET_APPLICATION, null);
}
Also used : ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider) ApplicationResourceManagementListener(org.wso2.carbon.identity.application.mgt.listener.ApplicationResourceManagementListener) PaginatableFilterableApplicationDAO(org.wso2.carbon.identity.application.mgt.dao.PaginatableFilterableApplicationDAO) ApplicationDAO(org.wso2.carbon.identity.application.mgt.dao.ApplicationDAO) FileBasedApplicationDAO(org.wso2.carbon.identity.application.mgt.dao.impl.FileBasedApplicationDAO) IdentityApplicationManagementClientException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementClientException) TransformerException(javax.xml.transform.TransformerException) RegistryException(org.wso2.carbon.registry.api.RegistryException) IOException(java.io.IOException) IdentityApplicationManagementValidationException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementValidationException) IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) JAXBException(javax.xml.bind.JAXBException) IdentityApplicationRegistrationFailureException(org.wso2.carbon.identity.application.common.IdentityApplicationRegistrationFailureException) SAXException(org.xml.sax.SAXException) DefaultAuthSeqMgtException(org.wso2.carbon.identity.application.mgt.defaultsequence.DefaultAuthSeqMgtException) UserStoreException(org.wso2.carbon.user.api.UserStoreException) IdentityApplicationManagementServerException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementServerException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 93 with ApplicationDAO

use of org.wso2.carbon.identity.application.mgt.dao.ApplicationDAO in project carbon-identity-framework by wso2.

the class ApplicationManagementServiceImpl method getApplicationBasicInfo.

@Override
public ApplicationBasicInfo[] getApplicationBasicInfo(String tenantDomain, String username, String filter) throws IdentityApplicationManagementException {
    ApplicationDAO appDAO = null;
    // invoking the listeners
    Collection<ApplicationMgtListener> listeners = getApplicationMgtListeners();
    for (ApplicationMgtListener listener : listeners) {
        if (listener.isEnable() && !listener.doPreGetApplicationBasicInfo(tenantDomain, username, filter)) {
            return new ApplicationBasicInfo[0];
        }
    }
    try {
        startTenantFlow(tenantDomain, username);
        appDAO = ApplicationMgtSystemConfig.getInstance().getApplicationDAO();
    } finally {
        endTenantFlow();
    }
    if (!(appDAO instanceof AbstractApplicationDAOImpl)) {
        log.error("Get application basic info service is not supported.");
        throw new IdentityApplicationManagementException("This service is not supported.");
    }
    // invoking the listeners
    for (ApplicationMgtListener listener : listeners) {
        if (listener.isEnable() && !listener.doPostGetApplicationBasicInfo(appDAO, tenantDomain, username, filter)) {
            return new ApplicationBasicInfo[0];
        }
    }
    return ((AbstractApplicationDAOImpl) appDAO).getApplicationBasicInfo(filter);
}
Also used : AbstractApplicationDAOImpl(org.wso2.carbon.identity.application.mgt.dao.impl.AbstractApplicationDAOImpl) IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) PaginatableFilterableApplicationDAO(org.wso2.carbon.identity.application.mgt.dao.PaginatableFilterableApplicationDAO) ApplicationDAO(org.wso2.carbon.identity.application.mgt.dao.ApplicationDAO) FileBasedApplicationDAO(org.wso2.carbon.identity.application.mgt.dao.impl.FileBasedApplicationDAO) AbstractApplicationMgtListener(org.wso2.carbon.identity.application.mgt.listener.AbstractApplicationMgtListener) ApplicationMgtListener(org.wso2.carbon.identity.application.mgt.listener.ApplicationMgtListener) ApplicationBasicInfo(org.wso2.carbon.identity.application.common.model.ApplicationBasicInfo)

Example 94 with ApplicationDAO

use of org.wso2.carbon.identity.application.mgt.dao.ApplicationDAO in project carbon-identity-framework by wso2.

the class ApplicationManagementServiceImpl method getApplicationExcludingFileBasedSPs.

@Override
public ServiceProvider getApplicationExcludingFileBasedSPs(String applicationName, String tenantDomain) throws IdentityApplicationManagementException {
    ServiceProvider serviceProvider;
    // invoking the listeners
    Collection<ApplicationMgtListener> listeners = getApplicationMgtListeners();
    for (ApplicationMgtListener listener : listeners) {
        if (listener.isEnable() && !listener.doPreGetApplicationExcludingFileBasedSPs(applicationName, tenantDomain)) {
            return null;
        }
    }
    try {
        startTenantFlow(tenantDomain);
        ApplicationDAO appDAO = ApplicationMgtSystemConfig.getInstance().getApplicationDAO();
        serviceProvider = appDAO.getApplication(applicationName, tenantDomain);
    } finally {
        endTenantFlow();
    }
    // invoking the listeners
    for (ApplicationMgtListener listener : listeners) {
        if (listener.isEnable() && !listener.doPostGetApplicationExcludingFileBasedSPs(serviceProvider, applicationName, tenantDomain)) {
            return null;
        }
    }
    return serviceProvider;
}
Also used : ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider) AbstractApplicationMgtListener(org.wso2.carbon.identity.application.mgt.listener.AbstractApplicationMgtListener) ApplicationMgtListener(org.wso2.carbon.identity.application.mgt.listener.ApplicationMgtListener) PaginatableFilterableApplicationDAO(org.wso2.carbon.identity.application.mgt.dao.PaginatableFilterableApplicationDAO) ApplicationDAO(org.wso2.carbon.identity.application.mgt.dao.ApplicationDAO) FileBasedApplicationDAO(org.wso2.carbon.identity.application.mgt.dao.impl.FileBasedApplicationDAO)

Example 95 with ApplicationDAO

use of org.wso2.carbon.identity.application.mgt.dao.ApplicationDAO in project carbon-identity-framework by wso2.

the class ApplicationMgtUtilTest method testIsUserAuthorized.

@Test(dataProvider = "userAuthorizeDataProvider")
public void testIsUserAuthorized(String applicationName, String userName, String allowRoleValidationProperty, String[] userRoles, int applicationId, Boolean expected) throws UserStoreException, IdentityApplicationManagementException {
    validateRole(allowRoleValidationProperty);
    mockStatic(ApplicationMgtSystemConfig.class);
    ApplicationDAO mockApplicationDAO = mock(ApplicationDAO.class);
    ApplicationMgtSystemConfig mockAppMgtSystemConfig = mock(ApplicationMgtSystemConfig.class);
    when(ApplicationMgtSystemConfig.getInstance()).thenReturn(mockAppMgtSystemConfig);
    when(mockAppMgtSystemConfig.getApplicationDAO()).thenReturn(mockApplicationDAO);
    when(mockApplicationDAO.getApplicationName(anyInt())).thenReturn(APPLICATION_NAME);
    mockUserStoreManager();
    when(mockUserStoreManager.getRoleListOfUser(userName)).thenReturn(userRoles);
    assertEquals(ApplicationMgtUtil.isUserAuthorized(applicationName, userName), expected);
    assertEquals(ApplicationMgtUtil.isUserAuthorized(applicationName, userName, applicationId), expected);
}
Also used : ApplicationDAO(org.wso2.carbon.identity.application.mgt.dao.ApplicationDAO) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

ApplicationDAO (org.wso2.carbon.apimgt.core.dao.ApplicationDAO)62 Test (org.testng.annotations.Test)59 Application (org.wso2.carbon.apimgt.core.models.Application)50 BeforeTest (org.testng.annotations.BeforeTest)33 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)32 ApplicationDAO (org.wso2.carbon.identity.application.mgt.dao.ApplicationDAO)31 PaginatableFilterableApplicationDAO (org.wso2.carbon.identity.application.mgt.dao.PaginatableFilterableApplicationDAO)25 FileBasedApplicationDAO (org.wso2.carbon.identity.application.mgt.dao.impl.FileBasedApplicationDAO)25 WorkflowDAO (org.wso2.carbon.apimgt.core.dao.WorkflowDAO)21 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)18 APISubscriptionDAO (org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO)18 PolicyDAO (org.wso2.carbon.apimgt.core.dao.PolicyDAO)15 ApplicationPolicy (org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy)15 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)13 SubscriptionPolicy (org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy)13 AbstractApplicationMgtListener (org.wso2.carbon.identity.application.mgt.listener.AbstractApplicationMgtListener)13 ApplicationMgtListener (org.wso2.carbon.identity.application.mgt.listener.ApplicationMgtListener)13 API (org.wso2.carbon.apimgt.core.models.API)12 ServiceProvider (org.wso2.carbon.identity.application.common.model.ServiceProvider)11 Policy (org.wso2.carbon.apimgt.core.models.policy.Policy)10