use of org.wso2.carbon.identity.application.mgt.dao.ApplicationDAO in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testDeleteSubscriptionException.
@Test(description = "Exception when deleting subscription", expectedExceptions = APIManagementException.class)
public void testDeleteSubscriptionException() throws APIManagementException {
ApplicationDAO applicationDAO = Mockito.mock(ApplicationDAO.class);
APISubscriptionDAO apiSubscriptionDAO = Mockito.mock(APISubscriptionDAO.class);
APIStore apiStore = getApiStoreImpl(applicationDAO, apiSubscriptionDAO);
Mockito.doThrow(new APIMgtDAOException("Error occurred while deleting api subscription " + UUID, new SQLException())).when(apiSubscriptionDAO).deleteAPISubscription(UUID);
apiStore.deleteAPISubscription(UUID);
}
use of org.wso2.carbon.identity.application.mgt.dao.ApplicationDAO in project carbon-apimgt by wso2.
the class AbstractAPIManagerTestCase method testGetLastUpdatedTimeOfApplication.
@Test(description = "Getting last updated time of Application")
public void testGetLastUpdatedTimeOfApplication() throws APIManagementException {
ApplicationDAO applicationDAO = mock(ApplicationDAO.class);
AbstractAPIManager apiStore = getAPIStoreImpl(applicationDAO);
when(applicationDAO.getLastUpdatedTimeOfApplication(UUID)).thenReturn(LAST_UPDATED_TIME);
apiStore.getLastUpdatedTimeOfApplication(UUID);
verify(applicationDAO, times(1)).getLastUpdatedTimeOfApplication(UUID);
}
use of org.wso2.carbon.identity.application.mgt.dao.ApplicationDAO in project carbon-apimgt by wso2.
the class AbstractAPIManagerTestCase method testGetApplicationByUuid.
@Test(description = "Retrieve an application by uuid")
public void testGetApplicationByUuid() throws APIManagementException {
ApplicationDAO applicationDAO = mock(ApplicationDAO.class);
AbstractAPIManager apiStore = getAPIStoreImpl(applicationDAO);
Application applicationFromDAO = new Application(APP_NAME, USER_NAME);
when(applicationDAO.getApplication(UUID)).thenReturn(applicationFromDAO);
Application application = apiStore.getApplication(UUID, USER_NAME);
Assert.assertNotNull(application);
verify(applicationDAO, times(1)).getApplication(UUID);
}
use of org.wso2.carbon.identity.application.mgt.dao.ApplicationDAO in project carbon-identity-framework by wso2.
the class ApplicationManagementServiceImpl method updateApplicationByResourceId.
@Override
public void updateApplicationByResourceId(String resourceId, ServiceProvider updatedApp, String tenantDomain, String username) throws IdentityApplicationManagementException {
validateApplicationConfigurations(updatedApp, tenantDomain, username);
updatedApp.setApplicationResourceId(resourceId);
setDisplayNamesOfLocalAuthenticators(updatedApp, tenantDomain);
Collection<ApplicationResourceManagementListener> listeners = ApplicationMgtListenerServiceComponent.getApplicationResourceMgtListeners();
for (ApplicationResourceManagementListener listener : listeners) {
if (listener.isEnabled() && !listener.doPreUpdateApplicationByResourceId(updatedApp, resourceId, tenantDomain, username)) {
throw buildServerException("Pre Update application operation of listener: " + getName(listener) + " failed for application with resourceId: " + resourceId);
}
}
try {
startTenantFlow(tenantDomain);
ApplicationBasicInfo storedAppInfo = getApplicationBasicInfo(resourceId, tenantDomain);
if (storedAppInfo == null) {
String msg = "Cannot find an application for " + "resourceId: " + resourceId + " in tenantDomain: " + tenantDomain;
throw buildClientException(APPLICATION_NOT_FOUND, msg);
}
String updatedAppName = updatedApp.getApplicationName();
String storedAppName = storedAppInfo.getApplicationName();
doPreUpdateChecks(storedAppName, updatedApp, tenantDomain, username);
ApplicationDAO appDAO = ApplicationMgtSystemConfig.getInstance().getApplicationDAO();
appDAO.updateApplicationByResourceId(resourceId, tenantDomain, updatedApp);
if (isOwnerUpdateRequest(storedAppInfo.getAppOwner(), updatedApp.getOwner())) {
// User existence check is already done in appDAO.updateApplicationByResourceId() method.
assignApplicationRole(updatedApp.getApplicationName(), updatedApp.getOwner().getUserName());
}
updateApplicationPermissions(updatedApp, updatedAppName, storedAppName);
} catch (RegistryException e) {
String message = "Error while updating application with resourceId: " + resourceId + " in tenantDomain: " + tenantDomain;
throw buildServerException(message, e);
} finally {
endTenantFlow();
}
for (ApplicationResourceManagementListener listener : listeners) {
if (listener.isEnabled() && !listener.doPostUpdateApplicationByResourceId(updatedApp, resourceId, tenantDomain, username)) {
log.error("Post Update application operation of listener: " + getName(listener) + " failed for " + "application with resourceId: " + resourceId);
return;
}
}
triggerAuditLogEvent(getInitiatorId(username, tenantDomain), getInitiatorId(username, tenantDomain), USER, CarbonConstants.LogEventConstants.EventCatalog.UPDATE_APPLICATION.getEventId(), getAppId(updatedApp), getApplicationName(updatedApp), TARGET_APPLICATION, buildSPData(updatedApp));
}
use of org.wso2.carbon.identity.application.mgt.dao.ApplicationDAO in project carbon-identity-framework by wso2.
the class ApplicationManagementServiceImpl method doPreAddApplicationChecks.
private void doPreAddApplicationChecks(ServiceProvider serviceProvider, String tenantDomain, String username) throws IdentityApplicationManagementException {
String appName = serviceProvider.getApplicationName();
if (StringUtils.isBlank(appName)) {
// check for required attributes.
throw buildClientException(INVALID_REQUEST, "Application name cannot be empty.");
}
ApplicationDAO appDAO = ApplicationMgtSystemConfig.getInstance().getApplicationDAO();
if (appDAO.isApplicationExists(appName, tenantDomain)) {
String msg = "An application with name: '" + appName + "' already exists in tenantDomain: " + tenantDomain;
throw new IdentityApplicationRegistrationFailureException(APPLICATION_ALREADY_EXISTS.getCode(), msg);
}
if (ApplicationManagementServiceComponent.getFileBasedSPs().containsKey(appName)) {
String msg = "Application with name: '" + appName + "' already loaded from the file system.";
throw buildClientException(APPLICATION_ALREADY_EXISTS, msg);
}
if (!isRegexValidated(appName)) {
String message = "The Application name: '" + appName + "' is not valid! It is not adhering to the regex: " + ApplicationMgtUtil.getSPValidatorRegex();
throw buildClientException(INVALID_REQUEST, message);
}
addUserIdAsDefaultSubject(serviceProvider);
validateApplicationConfigurations(serviceProvider, tenantDomain, username);
}
Aggregations