Search in sources :

Example 1 with IdentityApplicationManagementServerException

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;
}
Also used : NamedPreparedStatement(org.wso2.carbon.database.utils.jdbc.NamedPreparedStatement) IdentityApplicationManagementClientException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementClientException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) IdentityApplicationManagementServerException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementServerException) ApplicationBasicInfo(org.wso2.carbon.identity.application.common.model.ApplicationBasicInfo)

Example 2 with IdentityApplicationManagementServerException

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);
    }
}
Also used : ServiceProvider(org.wso2.carbon.identity.application.common.model.ServiceProvider) IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) IdentityApplicationManagementServerException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementServerException)

Example 3 with IdentityApplicationManagementServerException

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;
}
Also used : NamedPreparedStatement(org.wso2.carbon.database.utils.jdbc.NamedPreparedStatement) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) IdentityApplicationManagementServerException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementServerException)

Example 4 with IdentityApplicationManagementServerException

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);
}
Also used : NamedPreparedStatement(org.wso2.carbon.database.utils.jdbc.NamedPreparedStatement) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) IdentityApplicationManagementServerException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementServerException) ApplicationBasicInfo(org.wso2.carbon.identity.application.common.model.ApplicationBasicInfo)

Example 5 with IdentityApplicationManagementServerException

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);
}
Also used : ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse) Response(javax.ws.rs.core.Response) IdentityApplicationManagementClientException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementClientException) IdentityApplicationManagementServerException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementServerException) APIError(org.wso2.carbon.identity.api.server.common.error.APIError) ErrorResponse(org.wso2.carbon.identity.api.server.common.error.ErrorResponse)

Aggregations

IdentityApplicationManagementServerException (org.wso2.carbon.identity.application.common.IdentityApplicationManagementServerException)8 Connection (java.sql.Connection)4 ResultSet (java.sql.ResultSet)4 SQLException (java.sql.SQLException)4 NamedPreparedStatement (org.wso2.carbon.database.utils.jdbc.NamedPreparedStatement)4 IdentityApplicationManagementClientException (org.wso2.carbon.identity.application.common.IdentityApplicationManagementClientException)3 Response (javax.ws.rs.core.Response)2 APIError (org.wso2.carbon.identity.api.server.common.error.APIError)2 ErrorResponse (org.wso2.carbon.identity.api.server.common.error.ErrorResponse)2 IdentityApplicationManagementException (org.wso2.carbon.identity.application.common.IdentityApplicationManagementException)2 ApplicationBasicInfo (org.wso2.carbon.identity.application.common.model.ApplicationBasicInfo)2 ArrayList (java.util.ArrayList)1 ServiceProvider (org.wso2.carbon.identity.application.common.model.ServiceProvider)1