use of org.wso2.carbon.identity.base.IdentityRuntimeException in project carbon-identity-framework by wso2.
the class FunctionLibraryDAOImpl method deleteFunctionLibrary.
/**
* Delete an existing function library.
*
* @param functionLibraryName Function library name
* @param tenantDomain Tenant domain
* @throws FunctionLibraryManagementException
*/
public void deleteFunctionLibrary(String functionLibraryName, String tenantDomain) throws FunctionLibraryManagementException {
int tenantID = MultitenantConstants.INVALID_TENANT_ID;
if (tenantDomain != null) {
tenantID = IdentityTenantUtil.getTenantId(tenantDomain);
}
try (Connection connection = IdentityDatabaseUtil.getDBConnection()) {
try (PreparedStatement deleteFunctionLibStmt = connection.prepareStatement(FunctionLibMgtDBQueries.REMOVE_FUNCTIONLIB)) {
deleteFunctionLibStmt.setInt(1, tenantID);
deleteFunctionLibStmt.setString(2, functionLibraryName);
deleteFunctionLibStmt.executeUpdate();
IdentityDatabaseUtil.commitTransaction(connection);
if (log.isDebugEnabled()) {
log.debug("Removed the script library " + functionLibraryName + " successfully.");
}
} catch (SQLException e1) {
IdentityDatabaseUtil.rollbackTransaction(connection);
throw FunctionLibraryExceptionManagementUtil.handleServerException(FunctionLibraryManagementConstants.ErrorMessage.ERROR_CODE_PROCESSING_CONTENT_STREAM_SCRIPT_LIBRARY, functionLibraryName, e1);
}
} catch (SQLException e) {
throw FunctionLibraryExceptionManagementUtil.handleServerException(FunctionLibraryManagementConstants.ErrorMessage.ERROR_CODE_PROCESSING_CONTENT_STREAM_SCRIPT_LIBRARY, functionLibraryName, e);
} catch (IdentityRuntimeException e) {
throw FunctionLibraryExceptionManagementUtil.handleServerException(FunctionLibraryManagementConstants.ErrorMessage.ERROR_CODE_DATABASE_CONNECTION, e);
}
}
use of org.wso2.carbon.identity.base.IdentityRuntimeException in project carbon-identity-framework by wso2.
the class DatabaseCertificateRetriever method getCertificate.
/**
* @param certificateId Database identifier of the certificate.
* @param tenant Tenant where the certificate belongs to. But in this implementation the passed tenant is
* not considered since the database id is already there.
* @return The certificate for the given database identifier.
* @throws CertificateRetrievingException
*/
@Override
public X509Certificate getCertificate(String certificateId, Tenant tenant) throws CertificateRetrievingException {
Connection connection;
try {
connection = IdentityDatabaseUtil.getDBConnection(false);
} catch (IdentityRuntimeException e) {
throw new CertificateRetrievingException("Couldn't get a database connection.", e);
}
PreparedStatement statementToGetApplicationCertificate = null;
ResultSet queryResults = null;
try {
statementToGetApplicationCertificate = connection.prepareStatement(QUERY_TO_GET_APPLICATION_CERTIFICATE);
statementToGetApplicationCertificate.setInt(1, Integer.parseInt(certificateId));
queryResults = statementToGetApplicationCertificate.executeQuery();
String certificateContent = null;
while (queryResults.next()) {
certificateContent = getBlobValue(queryResults.getBinaryStream(1));
}
if (StringUtils.isNotBlank(certificateContent)) {
return (X509Certificate) IdentityUtil.convertPEMEncodedContentToCertificate(certificateContent);
}
} catch (SQLException e) {
String errorMessage = String.format("An error occurred while retrieving the certificate content from " + "the database for the ID '%s'", certificateId);
throw new CertificateRetrievingException(errorMessage, e);
} catch (CertificateException e) {
String errorMessage = String.format("An error occurred while build a certificate using the certificate " + "content from the database for the ID '%s'", certificateId);
throw new CertificateRetrievingException(errorMessage, e);
} catch (IOException e) {
String errorMessage = String.format("An error occurred while reading the certificate blob from the " + "database for the ID '%s'", certificateId);
throw new CertificateRetrievingException(errorMessage, e);
} finally {
IdentityDatabaseUtil.closeAllConnections(connection, queryResults, statementToGetApplicationCertificate);
}
return null;
}
use of org.wso2.carbon.identity.base.IdentityRuntimeException in project carbon-identity-framework by wso2.
the class RegistryResourceMgtServiceImpl method putIdentityResource.
@Override
public void putIdentityResource(Resource identityResource, String path, String tenantDomain) throws IdentityRuntimeException {
startTenantFlow(tenantDomain);
try {
Registry registry = getRegistryForTenant(tenantDomain);
registry.put(path, identityResource);
if (log.isDebugEnabled()) {
log.debug(String.format(MSG_RESOURCE_PERSIST, path, tenantDomain));
}
} catch (RegistryException e) {
String errorMsg = String.format(ERROR_PERSIST_RESOURCE, tenantDomain, path);
throw IdentityRuntimeException.error(errorMsg, e);
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
}
use of org.wso2.carbon.identity.base.IdentityRuntimeException in project carbon-identity-framework by wso2.
the class RegistryResourceMgtServiceImpl method deleteIdentityResource.
@Override
public void deleteIdentityResource(String path, String tenantDomain) throws IdentityRuntimeException {
startTenantFlow(tenantDomain);
try {
Registry registry = getRegistryForTenant(tenantDomain);
if (registry.resourceExists(path)) {
registry.delete(path);
} else {
String errorMsg = String.format(ERROR_NO_RESOURCE_FOUND, path, tenantDomain);
log.error(errorMsg);
throw IdentityRuntimeException.error(errorMsg);
}
} catch (RegistryException e) {
String errorMsg = String.format(ERROR_DELETE_RESOURCE, tenantDomain, path);
throw IdentityRuntimeException.error(errorMsg, e);
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
}
use of org.wso2.carbon.identity.base.IdentityRuntimeException in project carbon-identity-framework by wso2.
the class IdentityTenantUtil method getTenantIdOfUser.
/**
* Get the tenant id of the given user.
*
* @param username Username
* @return Tenant Id of domain user belongs to.
* @throws IdentityRuntimeException Error when getting the tenant Id from tenant domain
*/
public static int getTenantIdOfUser(String username) throws IdentityRuntimeException {
int tenantId = MultitenantConstants.INVALID_TENANT_ID;
String domainName = MultitenantUtils.getTenantDomain(username);
if (domainName != null) {
try {
TenantManager tenantManager = IdentityTenantUtil.getRealmService().getTenantManager();
tenantId = tenantManager.getTenantId(domainName);
} catch (UserStoreException e) {
String errorMsg = "Error when getting the tenant id from the tenant domain : " + domainName;
throw IdentityRuntimeException.error(errorMsg, e);
}
}
if (tenantId == MultitenantConstants.INVALID_TENANT_ID) {
throw IdentityRuntimeException.error("Invalid tenant domain of user " + username);
} else {
return tenantId;
}
}
Aggregations