use of org.wso2.carbon.identity.base.IdentityRuntimeException in project carbon-identity-framework by wso2.
the class IdentityEventServiceComponent method registerEventHandler.
@Reference(name = "event.handler", service = org.wso2.carbon.identity.event.handler.AbstractEventHandler.class, cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC, unbind = "unRegisterEventHandler")
protected void registerEventHandler(AbstractEventHandler eventHandler) {
String handlerName = eventHandler.getName();
try {
eventHandler.init(IdentityEventConfigBuilder.getInstance().getModuleConfigurations(handlerName));
} catch (IdentityEventException | IdentityRuntimeException e) {
log.warn("Properties for " + handlerName + " is not configured. This event handler will not be activated");
}
eventHandlerList.add(eventHandler);
MessageHandlerComparator messageHandlerComparator = new MessageHandlerComparator(null);
Collections.sort(eventHandlerList, messageHandlerComparator);
}
use of org.wso2.carbon.identity.base.IdentityRuntimeException in project carbon-identity-framework by wso2.
the class RegistryResourceMgtServiceImpl method addIdentityResource.
@Override
public void addIdentityResource(Resource identityResource, String path, String tenantDomain) throws IdentityRuntimeException {
startTenantFlow(tenantDomain);
try {
Registry registry = getRegistryForTenant(tenantDomain);
if (registry.get(path) != null) {
// resource already exists at the path so we throw an exception
String errorMsg = String.format(ERROR_ADD_RESOURCE, tenantDomain, path);
throw IdentityRuntimeException.error(errorMsg);
}
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 getIdentityResource.
@Override
public Resource getIdentityResource(String path, String tenantDomain) throws IdentityRuntimeException {
startTenantFlow(tenantDomain);
try {
Registry registry = getRegistryForTenant(tenantDomain);
Resource resource = null;
if (registry.resourceExists(path)) {
resource = registry.get(path);
}
return resource;
} catch (RegistryException e) {
String errorMsg = String.format(ERROR_GET_RESOURCE, path, tenantDomain);
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 IdentityDBInitializer method createIdentityDatabase.
void createIdentityDatabase() {
if (!isDatabaseStructureCreated()) {
Connection conn = null;
try {
conn = dataSource.getConnection();
conn.setAutoCommit(false);
statement = conn.createStatement();
executeSQLScript();
conn.commit();
log.debug("Identity tables are created successfully.");
} catch (SQLException e) {
try {
conn.rollback();
} catch (SQLException e1) {
throw new IdentityRuntimeException("SQL transaction rollback connection error occurred while create database tables" + " for Identity meta-data store.", e1);
}
String msg = "Failed to create database tables for Identity meta-data store. " + e.getMessage();
throw IdentityRuntimeException.error(msg, e);
} finally {
if (statement != null) {
try {
statement.close();
} catch (SQLException e) {
log.error("Failed to close statement.", e);
}
}
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
log.error("Failed to close database connection.", e);
}
}
}
} else {
if (log.isDebugEnabled()) {
log.debug("Identity Database already exists. Not creating a new database.");
}
}
}
use of org.wso2.carbon.identity.base.IdentityRuntimeException in project carbon-identity-framework by wso2.
the class FunctionLibraryDAOImpl method getFunctionLibrary.
/**
* Retrieve a function library from the given name.
*
* @param functionLibraryName Function library name
* @param tenantDomain Tenant domain
* @return Function library
* @throws FunctionLibraryManagementException
*/
public FunctionLibrary getFunctionLibrary(String functionLibraryName, String tenantDomain) throws FunctionLibraryManagementException {
// get logged-in users tenant identifier.
int tenantID = MultitenantConstants.INVALID_TENANT_ID;
if (tenantDomain != null) {
tenantID = IdentityTenantUtil.getTenantId(tenantDomain);
}
try (Connection connection = IdentityDatabaseUtil.getDBConnection(false)) {
try (PreparedStatement getFunctionLibStmt = connection.prepareStatement(FunctionLibMgtDBQueries.LOAD_FUNCTIONLIB_FROM_TENANTID_AND_NAME)) {
getFunctionLibStmt.setInt(1, tenantID);
getFunctionLibStmt.setString(2, functionLibraryName);
try (ResultSet resultSet = getFunctionLibStmt.executeQuery()) {
if (resultSet.next()) {
FunctionLibrary functionlib = new FunctionLibrary();
functionlib.setFunctionLibraryName(resultSet.getString("NAME"));
functionlib.setDescription(resultSet.getString("DESCRIPTION"));
functionlib.setFunctionLibraryScript(IOUtils.toString(resultSet.getBinaryStream("DATA")));
return functionlib;
} else {
return null;
}
}
} catch (IOException e) {
throw FunctionLibraryExceptionManagementUtil.handleServerException(FunctionLibraryManagementConstants.ErrorMessage.ERROR_CODE_RETRIEVE_SCRIPT_LIBRARY, functionLibraryName, e);
}
} catch (SQLException e) {
throw FunctionLibraryExceptionManagementUtil.handleServerException(FunctionLibraryManagementConstants.ErrorMessage.ERROR_CODE_RETRIEVE_SCRIPT_LIBRARY, functionLibraryName, e);
} catch (IdentityRuntimeException e) {
throw FunctionLibraryExceptionManagementUtil.handleServerException(FunctionLibraryManagementConstants.ErrorMessage.ERROR_CODE_DATABASE_CONNECTION, e);
}
}
Aggregations