Search in sources :

Example 6 with IdentityRuntimeException

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);
}
Also used : IdentityEventException(org.wso2.carbon.identity.event.IdentityEventException) MessageHandlerComparator(org.wso2.carbon.identity.core.handler.MessageHandlerComparator) IdentityRuntimeException(org.wso2.carbon.identity.base.IdentityRuntimeException) Reference(org.osgi.service.component.annotations.Reference)

Example 7 with IdentityRuntimeException

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();
    }
}
Also used : Registry(org.wso2.carbon.registry.core.Registry) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException)

Example 8 with IdentityRuntimeException

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();
    }
}
Also used : Resource(org.wso2.carbon.registry.core.Resource) Registry(org.wso2.carbon.registry.core.Registry) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException)

Example 9 with IdentityRuntimeException

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.");
        }
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) IdentityRuntimeException(org.wso2.carbon.identity.base.IdentityRuntimeException)

Example 10 with IdentityRuntimeException

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);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) FunctionLibrary(org.wso2.carbon.identity.functions.library.mgt.model.FunctionLibrary) PreparedStatement(java.sql.PreparedStatement) IOException(java.io.IOException) IdentityRuntimeException(org.wso2.carbon.identity.base.IdentityRuntimeException)

Aggregations

IdentityRuntimeException (org.wso2.carbon.identity.base.IdentityRuntimeException)17 Connection (java.sql.Connection)14 SQLException (java.sql.SQLException)14 PreparedStatement (java.sql.PreparedStatement)13 IOException (java.io.IOException)8 ResultSet (java.sql.ResultSet)5 SessionSerializerException (org.wso2.carbon.identity.application.authentication.framework.exception.SessionSerializerException)4 Registry (org.wso2.carbon.registry.core.Registry)4 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)4 IdentityApplicationManagementException (org.wso2.carbon.identity.application.common.IdentityApplicationManagementException)3 ArrayList (java.util.ArrayList)2 IdentityEventException (org.wso2.carbon.identity.event.IdentityEventException)2 IdentityEventMessageContext (org.wso2.carbon.identity.event.bean.IdentityEventMessageContext)2 Event (org.wso2.carbon.identity.event.event.Event)2 FunctionLibrary (org.wso2.carbon.identity.functions.library.mgt.model.FunctionLibrary)2 UserStoreException (org.wso2.carbon.user.api.UserStoreException)2 CertificateException (java.security.cert.CertificateException)1 X509Certificate (java.security.cert.X509Certificate)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1