use of org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException in project carbon-identity-framework by wso2.
the class UserSessionStore method updateFederatedAuthSessionInfo.
/**
* Update session details of a given session context key to map the current session context key with
* the federated IdP's session ID.
*
* @param sessionContextKey Session Context Key.
* @param authHistory History of the authentication flow.
* @throws UserSessionException Error while storing session details.
*/
public void updateFederatedAuthSessionInfo(String sessionContextKey, AuthHistory authHistory) throws UserSessionException {
JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate();
try {
jdbcTemplate.executeUpdate(SQLQueries.SQL_UPDATE_FEDERATED_AUTH_SESSION_INFO, preparedStatement -> {
preparedStatement.setString(1, sessionContextKey);
preparedStatement.setString(2, authHistory.getIdpSessionIndex());
});
} catch (DataAccessException e) {
throw new UserSessionException("Error while updating " + sessionContextKey + " of session:" + authHistory.getIdpSessionIndex() + " in table " + IDN_AUTH_SESSION_META_DATA_TABLE + ".", e);
}
}
use of org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException in project carbon-identity-framework by wso2.
the class UserSessionStore method getAppId.
/**
* Method to get app id from SP_APP table.
*
* @param applicationName application Name
* @param appTenantID app tenant id
* @return the application id
* @throws UserSessionException if an error occurs when retrieving app id
*
* @deprecated Since the UserSessionStore should not invoke the application management table.
*/
@Deprecated
public int getAppId(String applicationName, int appTenantID) throws UserSessionException {
Integer appId;
JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate(JdbcUtils.Database.SESSION);
try {
appId = jdbcTemplate.fetchSingleRecord(SQLQueries.SQL_SELECT_APP_ID_OF_APP, ((resultSet, rowNumber) -> resultSet.getInt(1)), preparedStatement -> {
preparedStatement.setString(1, applicationName);
preparedStatement.setInt(2, appTenantID);
});
} catch (DataAccessException e) {
throw new UserSessionException("Error while retrieving the app id of " + applicationName + ", " + "tenant id" + appTenantID + ".", e);
}
return appId == null ? 0 : appId;
}
use of org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException in project carbon-identity-framework by wso2.
the class ConfigurationDAOImpl method getTenantResourceById.
/**
* {@inheritDoc}
*/
@Override
public Resource getTenantResourceById(int tenantId, String resourceId) throws ConfigurationManagementException {
JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate();
List<ConfigurationRawDataCollector> configurationRawDataCollectors;
try {
String queryWithCreatedTime = GET_RESOURCE_BY_ID_MYSQL;
String queryWithOutCreatedTime = GET_RESOURCE_BY_ID_MYSQL_WITHOUT_CREATED_TIME;
if (isOracleDB() || isMSSqlDB()) {
queryWithCreatedTime = GET_RESOURCE_BY_ID_MSSQL_OR_ORACLE;
}
StringBuilder sb = new StringBuilder();
sb.append(useCreatedTimeField() ? queryWithCreatedTime : queryWithOutCreatedTime);
sb.append(" AND R.TENANT_ID = ?");
configurationRawDataCollectors = jdbcTemplate.executeQuery(sb.toString(), (resultSet, rowNumber) -> {
ConfigurationRawDataCollector.ConfigurationRawDataCollectorBuilder configurationRawDataCollectorBuilder = new ConfigurationRawDataCollector.ConfigurationRawDataCollectorBuilder().setResourceId(resultSet.getString(DB_SCHEMA_COLUMN_NAME_ID)).setTenantId(resultSet.getInt(DB_SCHEMA_COLUMN_NAME_TENANT_ID)).setResourceName(resultSet.getString(DB_SCHEMA_COLUMN_NAME_NAME)).setLastModified(resultSet.getTimestamp(DB_SCHEMA_COLUMN_NAME_LAST_MODIFIED, calendar)).setResourceTypeName(resultSet.getString(DB_SCHEMA_COLUMN_NAME_RESOURCE_TYPE)).setResourceTypeDescription(resultSet.getString(DB_SCHEMA_COLUMN_NAME_DESCRIPTTION)).setAttributeKey(resultSet.getString(DB_SCHEMA_COLUMN_NAME_ATTRIBUTE_KEY)).setAttributeValue(resultSet.getString(DB_SCHEMA_COLUMN_NAME_ATTRIBUTE_VALUE)).setAttributeId(resultSet.getString(DB_SCHEMA_COLUMN_NAME_ATTRIBUTE_ID)).setFileId(resultSet.getString(DB_SCHEMA_COLUMN_NAME_FILE_ID)).setHasFile(resultSet.getBoolean(DB_SCHEMA_COLUMN_NAME_HAS_FILE)).setHasAttribute(resultSet.getBoolean(DB_SCHEMA_COLUMN_NAME_HAS_ATTRIBUTE));
if (useCreatedTimeField()) {
configurationRawDataCollectorBuilder.setCreatedTime(resultSet.getTimestamp(DB_SCHEMA_COLUMN_NAME_CREATED_TIME, calendar));
}
return configurationRawDataCollectorBuilder.build();
}, preparedStatement -> {
preparedStatement.setString(1, resourceId);
preparedStatement.setInt(2, tenantId);
});
/*
Database call can contain duplicate data for some columns. Need to filter them in order to build the
resource.
*/
return configurationRawDataCollectors == null || configurationRawDataCollectors.size() == 0 ? null : buildResourceFromRawData(configurationRawDataCollectors);
} catch (DataAccessException e) {
throw handleServerException(ERROR_CODE_GET_RESOURCE, "id = " + resourceId, e);
}
}
use of org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException in project carbon-identity-framework by wso2.
the class ConfigurationDAOImpl method updateMetadataForH2.
private void updateMetadataForH2(Resource resource, String resourceTypeId, boolean isAttributeExists, Timestamp currentTime, boolean useCreatedTime) throws TransactionException, ConfigurationManagementServerException {
JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate();
if (isResourceExists(resource, resourceTypeId)) {
jdbcTemplate.withTransaction(template -> template.executeInsert(UPDATE_RESOURCE_H2, preparedStatement -> {
int initialParameterIndex = 1;
preparedStatement.setInt(initialParameterIndex, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
preparedStatement.setString(++initialParameterIndex, resource.getResourceName());
preparedStatement.setTimestamp(++initialParameterIndex, currentTime, calendar);
/*
Resource files are uploaded using a separate endpoint. Therefore resource creation
does not create files. It is allowed to create a resource without files or attributes
in order to allow file uploadafter resource creation.
*/
preparedStatement.setBoolean(++initialParameterIndex, false);
preparedStatement.setBoolean(++initialParameterIndex, isAttributeExists);
preparedStatement.setString(++initialParameterIndex, resourceTypeId);
preparedStatement.setString(++initialParameterIndex, resource.getResourceId());
}, resource, false));
} else {
try {
boolean isOracleOrMsssql = isOracleDB() || isMSSqlDB();
jdbcTemplate.withTransaction(template -> template.executeInsert(useCreatedTime ? INSERT_RESOURCE_SQL : INSERT_RESOURCE_SQL_WITHOUT_CREATED_TIME, preparedStatement -> {
int initialParameterIndex = 1;
preparedStatement.setString(initialParameterIndex, resource.getResourceId());
preparedStatement.setInt(++initialParameterIndex, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
preparedStatement.setString(++initialParameterIndex, resource.getResourceName());
if (useCreatedTime) {
preparedStatement.setTimestamp(++initialParameterIndex, currentTime, calendar);
}
preparedStatement.setTimestamp(++initialParameterIndex, currentTime, calendar);
if (isOracleOrMsssql) {
preparedStatement.setInt(++initialParameterIndex, 0);
preparedStatement.setInt(++initialParameterIndex, isAttributeExists ? 1 : 0);
} else {
preparedStatement.setBoolean(++initialParameterIndex, false);
preparedStatement.setBoolean(++initialParameterIndex, isAttributeExists);
}
preparedStatement.setString(++initialParameterIndex, resourceTypeId);
}, resource, false));
} catch (DataAccessException e) {
throw handleServerException(ERROR_CODE_CHECK_DB_METADATA, e.getMessage(), e);
}
}
}
use of org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException in project carbon-identity-framework by wso2.
the class ConfigurationDAOImpl method getFilesByResourceType.
@Override
public List<ResourceFile> getFilesByResourceType(String resourceTypeId, int tenantId) throws ConfigurationManagementServerException {
JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate();
try {
return jdbcTemplate.executeQuery(GET_FILES_BY_RESOURCE_TYPE_ID_SQL, ((resultSet, rowNumber) -> {
String resourceFileId = resultSet.getString(DB_SCHEMA_COLUMN_NAME_ID);
String resourceFileName = resultSet.getString(DB_SCHEMA_COLUMN_NAME_FILE_NAME);
String resourceName = resultSet.getString(DB_SCHEMA_COLUMN_NAME_RESOURCE_NAME);
String resourceTypeName = resultSet.getString(DB_SCHEMA_COLUMN_NAME_RESOURCE_TYPE_NAME);
return new ResourceFile(resourceFileId, getFilePath(resourceFileId, resourceTypeName, resourceName), resourceFileName);
}), preparedStatement -> {
preparedStatement.setString(1, resourceTypeId);
preparedStatement.setInt(2, tenantId);
});
} catch (DataAccessException e) {
throw handleServerException(ERROR_CODE_GET_FILES_BY_TYPE, resourceTypeId, e);
}
}
Aggregations