use of org.wso2.carbon.identity.application.common.IdentityApplicationManagementServerException in project carbon-identity-framework by wso2.
the class ApplicationDAOImpl method getDiscoverableApplicationBasicInfoByResourceId.
@Override
public ApplicationBasicInfo getDiscoverableApplicationBasicInfoByResourceId(String resourceId, String tenantDomain) throws IdentityApplicationManagementException {
if (log.isDebugEnabled()) {
log.debug("Getting application basic information for resourceId: " + resourceId + " in tenantDomain: " + tenantDomain + " if discoverable.");
}
ApplicationBasicInfo applicationBasicInfo = null;
boolean isDiscoverable = false;
try (Connection connection = IdentityDatabaseUtil.getDBConnection(false)) {
try (NamedPreparedStatement statement = new NamedPreparedStatement(connection, LOAD_APP_BY_TENANT_AND_UUID)) {
statement.setInt(ApplicationTableColumns.TENANT_ID, IdentityTenantUtil.getTenantId(tenantDomain));
statement.setString(ApplicationTableColumns.UUID, resourceId);
try (ResultSet resultSet = statement.executeQuery()) {
while (resultSet.next()) {
applicationBasicInfo = buildApplicationBasicInfo(resultSet);
isDiscoverable = getBooleanValue(resultSet.getString(ApplicationTableColumns.IS_DISCOVERABLE));
}
}
}
} catch (SQLException e) {
throw new IdentityApplicationManagementServerException("Error while getting discoverable application " + "basic information for resourceId: " + resourceId + " in tenantDomain: " + tenantDomain, e);
}
if (applicationBasicInfo != null && !isDiscoverable) {
throw new IdentityApplicationManagementClientException(APPLICATION_NOT_DISCOVERABLE.getCode(), "Requested application resource " + resourceId + " is not discoverable.");
}
return applicationBasicInfo;
}
use of org.wso2.carbon.identity.application.common.IdentityApplicationManagementServerException in project carbon-identity-framework by wso2.
the class ApplicationDAOImpl method getApplicationByResourceId.
@Override
public ServiceProvider getApplicationByResourceId(String resourceId, String tenantDomain) throws IdentityApplicationManagementException {
try {
int appId = getAppIdUsingResourceId(resourceId, tenantDomain);
ServiceProvider application = getApplication(appId);
if (application == null) {
if (log.isDebugEnabled()) {
log.debug("Cannot find an application for resourceId:" + resourceId + ", tenantDomain:" + tenantDomain);
}
}
return application;
} catch (IdentityApplicationManagementException ex) {
throw new IdentityApplicationManagementServerException("Error while retrieving application with " + "resourceId: " + resourceId + " in tenantDomain: " + tenantDomain, ex);
}
}
use of org.wso2.carbon.identity.application.common.IdentityApplicationManagementServerException in project carbon-identity-framework by wso2.
the class ApplicationDAOImpl method isApplicationDiscoverable.
@Override
public boolean isApplicationDiscoverable(String resourceId, String tenantDomain) throws IdentityApplicationManagementException {
int count = 0;
try (Connection connection = IdentityDatabaseUtil.getDBConnection(false)) {
try (NamedPreparedStatement statement = new NamedPreparedStatement(connection, IS_APP_BY_TENANT_AND_UUID_DISCOVERABLE)) {
statement.setInt(ApplicationTableColumns.TENANT_ID, IdentityTenantUtil.getTenantId(tenantDomain));
statement.setString(ApplicationTableColumns.UUID, resourceId);
try (ResultSet resultSet = statement.executeQuery()) {
if (resultSet.next()) {
count = resultSet.getInt(1);
}
}
}
} catch (SQLException e) {
throw new IdentityApplicationManagementServerException("Error while getting discoverable application " + "basic information for resourceId: " + resourceId + " in tenantDomain: " + tenantDomain, e);
}
return count > 0;
}
use of org.wso2.carbon.identity.application.common.IdentityApplicationManagementServerException in project carbon-identity-framework by wso2.
the class ApplicationDAOImpl method getDiscoverableApplicationBasicInfo.
private List<ApplicationBasicInfo> getDiscoverableApplicationBasicInfo(int limit, int offset, String tenantDomain) throws IdentityApplicationManagementException {
List<ApplicationBasicInfo> applicationBasicInfoList = new ArrayList<>();
try (Connection connection = IdentityDatabaseUtil.getDBConnection(false)) {
String databaseVendorType = connection.getMetaData().getDatabaseProductName();
try (NamedPreparedStatement statement = new NamedPreparedStatement(connection, getDBVendorSpecificDiscoverableAppRetrievalQuery(databaseVendorType))) {
statement.setInt(ApplicationTableColumns.TENANT_ID, IdentityTenantUtil.getTenantId(tenantDomain));
statement.setInt(ApplicationConstants.OFFSET, offset);
statement.setInt(ApplicationConstants.LIMIT, limit);
statement.setInt(ApplicationConstants.ZERO_BASED_START_INDEX, offset);
statement.setInt(ApplicationConstants.ONE_BASED_START_INDEX, offset + 1);
statement.setInt(ApplicationConstants.END_INDEX, offset + limit);
try (ResultSet resultSet = statement.executeQuery()) {
while (resultSet.next()) {
applicationBasicInfoList.add(buildApplicationBasicInfo(resultSet));
}
}
}
} catch (SQLException e) {
throw new IdentityApplicationManagementServerException("Error while getting application basic information" + " for discoverable applications in tenantDomain: " + tenantDomain, e);
}
return Collections.unmodifiableList(applicationBasicInfoList);
}
use of org.wso2.carbon.identity.application.common.IdentityApplicationManagementServerException in project identity-api-server by wso2.
the class ServerAuthenticatorManagementService method handleApplicationMgtException.
/**
* Handle IdentityApplicationManagementException, extract error code, error description and status code to be sent
* in the response.
*
* @param e IdentityApplicationManagementException
* @param errorEnum Error information.
* @return APIError.
*/
private APIError handleApplicationMgtException(IdentityApplicationManagementException e, Constants.ErrorMessage errorEnum, String data) {
ErrorResponse errorResponse;
Response.Status status;
if (e instanceof IdentityApplicationManagementClientException) {
errorResponse = getErrorBuilder(errorEnum, data).build(log, e.getMessage());
if (e.getErrorCode() != null) {
String errorCode = e.getErrorCode();
errorCode = errorCode.contains(org.wso2.carbon.identity.api.server.common.Constants.ERROR_CODE_DELIMITER) ? errorCode : Constants.AUTHENTICATOR_ERROR_PREFIX + errorCode;
errorResponse.setCode(errorCode);
}
errorResponse.setDescription(e.getMessage());
status = Response.Status.BAD_REQUEST;
} else if (e instanceof IdentityApplicationManagementServerException) {
errorResponse = getErrorBuilder(errorEnum, data).build(log, e, errorEnum.getDescription());
if (e.getErrorCode() != null) {
String errorCode = e.getErrorCode();
errorCode = errorCode.contains(org.wso2.carbon.identity.api.server.common.Constants.ERROR_CODE_DELIMITER) ? errorCode : Constants.AUTHENTICATOR_ERROR_PREFIX + errorCode;
errorResponse.setCode(errorCode);
}
errorResponse.setDescription(e.getMessage());
status = Response.Status.INTERNAL_SERVER_ERROR;
} else {
errorResponse = getErrorBuilder(errorEnum, data).build(log, e, errorEnum.getDescription());
status = Response.Status.INTERNAL_SERVER_ERROR;
}
return new APIError(status, errorResponse);
}
Aggregations