Java Code Examples for org.wso2.carbon.identity.application.common.util.IdentityApplicationManagementUtil#closeStatement()

The following examples show how to use org.wso2.carbon.identity.application.common.util.IdentityApplicationManagementUtil#closeStatement() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UserAccountAssociationDAO.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
/**
 * Delete all associations of a tenant
 *
 * @param tenantId  tenant ID
 * @throws UserAccountAssociationException
 */
public void deleteUserAssociationsFromTenantId(int tenantId) throws UserAccountAssociationException {

    Connection dbConnection = IdentityDatabaseUtil.getDBConnection();
    PreparedStatement preparedStatement = null;

    try {
        preparedStatement = dbConnection.prepareStatement(UserAccountAssociationConstants
                .SQLQueries.DELETE_CONNECTION_FROM_TENANT_ID);

        preparedStatement.setInt(1, tenantId);
        preparedStatement.executeUpdate();

        if (!dbConnection.getAutoCommit()) {
            dbConnection.commit();
        }
    } catch (SQLException e) {
        throw new UserAccountAssociationServerException(UserAccountAssociationConstants.ErrorMessages
                .ASSOCIATIONS_DELETE_DB_ERROR.getDescription(), e);
    } finally {
        IdentityApplicationManagementUtil.closeStatement(preparedStatement);
        IdentityApplicationManagementUtil.closeConnection(dbConnection);
    }
}
 
Example 2
Source File: ApplicationDAOImpl.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
/**
 * @param applicationID
 * @param connection
 * @throws IdentityApplicationManagementException
 */
public void deletePermissionAndRoleConfiguration(int applicationID, Connection connection)
        throws SQLException {

    int tenantID = CarbonContext.getThreadLocalCarbonContext().getTenantId();

    if (log.isDebugEnabled()) {
        log.debug("Deleting Role Mapping of Application " + applicationID);
    }

    PreparedStatement deleteRoleMappingPrepStmt = null;
    try {
        deleteRoleMappingPrepStmt = connection
                .prepareStatement(ApplicationMgtDBQueries.REMOVE_ROLE_MAPPINGS_FROM_APPMGT_ROLE_MAPPING);
        deleteRoleMappingPrepStmt.setInt(1, applicationID);
        deleteRoleMappingPrepStmt.setInt(2, tenantID);
        deleteRoleMappingPrepStmt.execute();
    } finally {
        IdentityApplicationManagementUtil.closeStatement(deleteRoleMappingPrepStmt);
    }
}
 
Example 3
Source File: ApplicationDAOImpl.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
/**
 * @param applicationId
 * @param connection
 * @throws SQLException
 */
private void deleteOutboundProvisioningConfiguration(int applicationId, Connection connection)
        throws SQLException {

    if (log.isDebugEnabled()) {
        log.debug("Deleting Steps of Application " + applicationId);
    }

    PreparedStatement deleteOutboundProConfigPrepStmt = null;
    int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();

    try {
        deleteOutboundProConfigPrepStmt = connection
                .prepareStatement(ApplicationMgtDBQueries.REMOVE_PRO_CONNECTORS);
        deleteOutboundProConfigPrepStmt.setInt(1, applicationId);
        deleteOutboundProConfigPrepStmt.setInt(2, tenantId);
        deleteOutboundProConfigPrepStmt.execute();

    } finally {
        IdentityApplicationManagementUtil.closeStatement(deleteOutboundProConfigPrepStmt);
    }
}
 
Example 4
Source File: ApplicationDAOImpl.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
/**
 * @param applicationId
 * @param inBoundProvisioningConfig
 * @param connection
 * @throws SQLException
 */
private void updateInboundProvisioningConfiguration(int applicationId,
                                                    InboundProvisioningConfig inBoundProvisioningConfig, Connection connection)
        throws SQLException {

    int tenantID = CarbonContext.getThreadLocalCarbonContext().getTenantId();
    PreparedStatement inboundProConfigPrepStmt = null;

    try {
        inboundProConfigPrepStmt = connection
                .prepareStatement(ApplicationMgtDBQueries.UPDATE_BASIC_APPINFO_WITH_PRO_PROPERTIES);

        // PROVISIONING_USERSTORE_DOMAIN=?
        inboundProConfigPrepStmt.setString(1, inBoundProvisioningConfig.getProvisioningUserStore());
        inboundProConfigPrepStmt.setString(2, inBoundProvisioningConfig.isDumbMode() ? "1" : "0");
        inboundProConfigPrepStmt.setInt(3, tenantID);
        inboundProConfigPrepStmt.setInt(4, applicationId);
        inboundProConfigPrepStmt.execute();

    } finally {
        IdentityApplicationManagementUtil.closeStatement(inboundProConfigPrepStmt);
    }
}
 
Example 5
Source File: ApplicationDAOImpl.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
/**
 * @param conn
 * @param tenantId
 * @param authenticatorId
 * @return
 * @throws SQLException
 */
private Map<String, String> getAuthenticatorInfo(Connection conn, int tenantId,
                                                 int authenticatorId) throws SQLException {
    PreparedStatement prepStmt = null;
    ResultSet rs = null;
    String sqlStmt = ApplicationMgtDBQueries.LOAD_IDP_AND_AUTHENTICATOR_NAMES;
    Map<String, String> returnData = new HashMap<String, String>();
    try {
        prepStmt = conn.prepareStatement(sqlStmt);
        prepStmt.setInt(1, authenticatorId);
        prepStmt.setInt(2, tenantId);
        prepStmt.setInt(3, tenantId);
        prepStmt.setInt(4, MultitenantConstants.SUPER_TENANT_ID);
        prepStmt.setInt(5, MultitenantConstants.SUPER_TENANT_ID);
        rs = prepStmt.executeQuery();
        while (rs.next()) {
            returnData.put(ApplicationConstants.IDP_NAME, rs.getString(1));
            returnData.put(ApplicationConstants.IDP_AUTHENTICATOR_NAME, rs.getString(2));
            returnData
                    .put(ApplicationConstants.IDP_AUTHENTICATOR_DISPLAY_NAME, rs.getString(3));
        }
    } finally {
        IdentityApplicationManagementUtil.closeStatement(prepStmt);
    }
    return returnData;
}
 
Example 6
Source File: UserProfileMgtDAO.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
public void deleteAssociationsFromDomain(int tenantId, String domainName) throws
                                                                          UserProfileException {

    Connection dbConnection = IdentityDatabaseUtil.getDBConnection();
    PreparedStatement preparedStatement = null;

    try {
        preparedStatement = dbConnection.prepareStatement(Constants.SQLQueries.DELETE_ASSOCIATED_ID_FROM_DOMAIN);
        preparedStatement.setInt(1, tenantId);
        preparedStatement.setString(2, domainName);
        preparedStatement.executeUpdate();
        IdentityDatabaseUtil.commitTransaction(dbConnection);

    } catch (SQLException e) {
        IdentityDatabaseUtil.rollbackTransaction(dbConnection);
        throw new UserProfileException(String.format("Database error occurred while deleting associated ids with " +
                                                     "domain '%s'", domainName), e);
    } finally {
        IdentityApplicationManagementUtil.closeStatement(preparedStatement);
        IdentityApplicationManagementUtil.closeConnection(dbConnection);
    }
}
 
Example 7
Source File: UserProfileMgtDAO.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
public void updateDomainNameOfAssociations(int tenantId, String currentDomainName, String newDomainName) throws
        UserProfileException {

    Connection dbConnection = IdentityDatabaseUtil.getDBConnection();
    PreparedStatement preparedStatement = null;

    try {
        preparedStatement = dbConnection.prepareStatement(Constants.SQLQueries.UPDATE_USER_DOMAIN_NAME);

        preparedStatement.setString(1, newDomainName);
        preparedStatement.setString(2, currentDomainName);
        preparedStatement.setInt(3, tenantId);
        preparedStatement.executeUpdate();
        IdentityDatabaseUtil.commitTransaction(dbConnection);
    } catch (SQLException e) {
        IdentityDatabaseUtil.rollbackTransaction(dbConnection);
        throw new UserProfileException(String.format("Database error occurred while updating user domain of " +
                                                     "associated ids with domain '%s'", currentDomainName), e);
    } finally {
        IdentityApplicationManagementUtil.closeStatement(preparedStatement);
        IdentityApplicationManagementUtil.closeConnection(dbConnection);
    }
}
 
Example 8
Source File: ApplicationDAOImpl.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * Reads back the basic application data
 *
 * @param applicationID
 * @param connection
 * @return
 * @throws IdentityApplicationManagementException
 */
private String getApplicationName(int applicationID, Connection connection) throws SQLException {

    int tenantID = CarbonContext.getThreadLocalCarbonContext().getTenantId();

    if (log.isDebugEnabled()) {
        log.debug("Loading Application Name for ID: " + applicationID);
    }

    PreparedStatement loadBasicAppInfoStmt = null;
    ResultSet appNameResultSet = null;
    String applicationName = null;

    try {
        loadBasicAppInfoStmt = connection
                .prepareStatement(ApplicationMgtDBQueries.LOAD_APP_NAME_BY_APP_ID);
        loadBasicAppInfoStmt.setInt(1, applicationID);
        loadBasicAppInfoStmt.setInt(2, tenantID);
        appNameResultSet = loadBasicAppInfoStmt.executeQuery();

        if (appNameResultSet.next()) {
            applicationName = appNameResultSet.getString(1);
        }

        if (log.isDebugEnabled()) {
            log.debug("ApplicationName : " + applicationName);
        }
        return applicationName;

    } finally {
        IdentityApplicationManagementUtil.closeResultSet(appNameResultSet);
        IdentityApplicationManagementUtil.closeStatement(loadBasicAppInfoStmt);
    }
}
 
Example 9
Source File: ApplicationDAOImpl.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * @param applicationid
 * @param connection
 * @return
 * @throws SQLException
 */
private String getAuthenticationType(int applicationid, Connection connection)
        throws SQLException {

    int tenantID = CarbonContext.getThreadLocalCarbonContext().getTenantId();

    PreparedStatement authTypeStmt = null;
    ResultSet authTypeResultSet = null;
    try {
        authTypeStmt = connection
                .prepareStatement(ApplicationMgtDBQueries.LOAD_AUTH_TYPE_BY_APP_ID);
        authTypeStmt.setInt(1, applicationid);
        authTypeStmt.setInt(2, tenantID);
        authTypeResultSet = authTypeStmt.executeQuery();

        if (authTypeResultSet.next()) {
            return authTypeResultSet.getString(1);
        }

        return ApplicationConstants.AUTH_TYPE_DEFAULT;

    } finally {
        IdentityApplicationManagementUtil.closeResultSet(authTypeResultSet);
        IdentityApplicationManagementUtil.closeStatement(authTypeStmt);
    }

}
 
Example 10
Source File: ProvisioningManagementDAO.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
public List<String> getSPNamesOfProvisioningConnectorsByIDP(String idPName, int tenantId)
        throws IdentityApplicationManagementException {
    Connection dbConnection = IdentityDatabaseUtil.getDBConnection(false);
    PreparedStatement prepStmt = null;
    ResultSet rs = null;
    List<String> spNames = new ArrayList<String>();
    try {
        String sqlStmt = IdentityProvisioningConstants.SQLQueries.GET_SP_NAMES_OF_PROVISIONING_CONNECTORS_BY_IDP;
        prepStmt = dbConnection.prepareStatement(sqlStmt);
        prepStmt.setString(1, idPName);
        prepStmt.setInt(2, tenantId);
        rs = prepStmt.executeQuery();

        while (rs.next()) {
            spNames.add(rs.getString(1));
        }
    } catch (SQLException e) {
        String msg = "Error occurred while retrieving SP names of provisioning connectors by IDP name";
        throw new IdentityApplicationManagementException(msg, e);
    } finally {
        if (prepStmt != null) {
            IdentityApplicationManagementUtil.closeStatement(prepStmt);
        }
        if (rs != null) {
            IdentityApplicationManagementUtil.closeResultSet(rs);
        }
        IdentityApplicationManagementUtil.closeConnection(dbConnection);
    }
    return spNames;
}
 
Example 11
Source File: ProvisioningManagementDAO.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * @param conn
 * @param tenantId
 * @param idPName
 * @throws SQLException
 */
private void deleteIdP(Connection conn, int tenantId, String idPName) throws SQLException {

    PreparedStatement prepStmt = null;
    String sqlStmt = IdPManagementConstants.SQLQueries.DELETE_IDP_SQL;

    try {
        prepStmt = conn.prepareStatement(sqlStmt);
        prepStmt.setInt(1, tenantId);
        prepStmt.setString(2, idPName);
        prepStmt.executeUpdate();
    } finally {
        IdentityApplicationManagementUtil.closeStatement(prepStmt);
    }
}
 
Example 12
Source File: ProvisioningManagementDAO.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
public List<String> getSPNamesOfProvisioningConnectorsByIDP(String idPName, int tenantId)
        throws IdentityApplicationManagementException {
    Connection dbConnection = IdentityDatabaseUtil.getDBConnection();
    PreparedStatement prepStmt = null;
    ResultSet rs = null;
    List<String> spNames = new ArrayList<String>();
    try {
        String sqlStmt = IdentityProvisioningConstants.SQLQueries.GET_SP_NAMES_OF_PROVISIONING_CONNECTORS_BY_IDP;
        prepStmt = dbConnection.prepareStatement(sqlStmt);
        prepStmt.setString(1, idPName);
        prepStmt.setInt(2, tenantId);
        rs = prepStmt.executeQuery();

        while (rs.next()) {
            spNames.add(rs.getString(1));
        }
    } catch (SQLException e) {
        String msg = "Error occurred while retrieving SP names of provisioning connectors by IDP name";
        throw new IdentityApplicationManagementException(msg, e);
    } finally {
        if (prepStmt != null) {
            IdentityApplicationManagementUtil.closeStatement(prepStmt);
        }
        if (rs != null) {
            IdentityApplicationManagementUtil.closeResultSet(rs);
        }
        IdentityApplicationManagementUtil.closeConnection(dbConnection);
    }
    return spNames;
}
 
Example 13
Source File: ApplicationDAOImpl.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * @param applicationID
 * @param permissionsAndRoleConfiguration
 * @param connection
 * @throws SQLException
 */
private void updatePermissionAndRoleConfiguration(int applicationID,
                                                  PermissionsAndRoleConfig permissionsAndRoleConfiguration, Connection connection)
        throws SQLException {

    if (permissionsAndRoleConfiguration == null
            || permissionsAndRoleConfiguration.getRoleMappings() == null
            || permissionsAndRoleConfiguration.getRoleMappings().length == 0) {
        return;
    }

    RoleMapping[] roleMappings = permissionsAndRoleConfiguration.getRoleMappings();
    int tenantID = CarbonContext.getThreadLocalCarbonContext().getTenantId();

    PreparedStatement storeRoleMapPrepStmt = null;
    try {
        storeRoleMapPrepStmt = connection
                .prepareStatement(ApplicationMgtDBQueries.STORE_ROLE_MAPPING);
        for (RoleMapping roleMapping : roleMappings) {
            // TENANT_ID, IDP_ROLE, SP_ROLE, APP_ID
            storeRoleMapPrepStmt.setInt(1, tenantID);
            storeRoleMapPrepStmt.setString(2, roleMapping.getLocalRole().getLocalRoleName());
            storeRoleMapPrepStmt.setString(3, roleMapping.getRemoteRole());
            storeRoleMapPrepStmt.setInt(4, applicationID);
            storeRoleMapPrepStmt.addBatch();

            if (log.isDebugEnabled()) {
                log.debug("Storing Claim Mapping. IDPRole: " + roleMapping.getLocalRole()
                        + " SPRole: " + roleMapping.getRemoteRole());
            }
        }

        storeRoleMapPrepStmt.executeBatch();
    } finally {
        IdentityApplicationManagementUtil.closeStatement(storeRoleMapPrepStmt);
    }
}
 
Example 14
Source File: ApplicationDAOImpl.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * @param applicationId
 * @param connection
 * @return
 * @throws SQLException
 */
private InboundProvisioningConfig getInboundProvisioningConfiguration(int applicationId,
                                                                      Connection connection, int tenantID) throws SQLException {

    PreparedStatement inboundProConfigPrepStmt = null;
    InboundProvisioningConfig inBoundProvisioningConfig = new InboundProvisioningConfig();
    ResultSet resultSet = null;

    try {

        inboundProConfigPrepStmt = connection
                .prepareStatement(ApplicationMgtDBQueries.LOAD_PRO_PROPERTIES_BY_APP_ID);
        // PROVISIONING_USERSTORE_DOMAIN
        inboundProConfigPrepStmt.setInt(1, tenantID);
        inboundProConfigPrepStmt.setInt(2, applicationId);
        resultSet = inboundProConfigPrepStmt.executeQuery();

        while (resultSet.next()) {
            inBoundProvisioningConfig.setProvisioningUserStore(resultSet.getString(1));
            inBoundProvisioningConfig.setDumbMode("1".equals(resultSet.getString(2)));
        }

    } finally {
        IdentityApplicationManagementUtil.closeStatement(inboundProConfigPrepStmt);
    }
    return inBoundProvisioningConfig;
}
 
Example 15
Source File: ApplicationDAOImpl.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * Deletes the application from IDN_APPMGT_APP table. Cascade deletes with foreign key
 * constraints should delete the corresponding entries from the tables
 *
 * @param appName
 * @throws IdentityApplicationManagementException
 */
public void deleteApplication(String appName) throws IdentityApplicationManagementException {

    int tenantID = CarbonContext.getThreadLocalCarbonContext().getTenantId();
    Connection connection = IdentityDatabaseUtil.getDBConnection();

    if (log.isDebugEnabled()) {
        log.debug("Deleting Application " + appName);
    }

    // Now, delete the application
    PreparedStatement deleteClientPrepStmt = null;
    try {
        // First, delete all the clients of the application
        int applicationID = getApplicationIDByName(appName, tenantID, connection);
        InboundAuthenticationConfig clients = getInboundAuthenticationConfig(applicationID,
                connection, tenantID);
        for (InboundAuthenticationRequestConfig client : clients
                .getInboundAuthenticationRequestConfigs()) {
            deleteClient(client.getInboundAuthKey(), client.getInboundAuthType());
        }

        deleteClientPrepStmt = connection
                .prepareStatement(ApplicationMgtDBQueries.REMOVE_APP_FROM_APPMGT_APP);
        deleteClientPrepStmt.setString(1, appName);
        deleteClientPrepStmt.setInt(2, tenantID);
        deleteClientPrepStmt.execute();

        if (!connection.getAutoCommit()) {
            connection.commit();
        }

    } catch (SQLException e) {
        throw new IdentityApplicationManagementException("Error deleting application", e);
    } finally {
        IdentityApplicationManagementUtil.closeStatement(deleteClientPrepStmt);
        IdentityApplicationManagementUtil.closeConnection(connection);
    }
}
 
Example 16
Source File: UserAccountAssociationDAO.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieve association key of a user
 *
 * @param domainName  User store domain of user
 * @param tenantId  Tenant ID of user
 * @param userName  User name
 * @return
 * @throws UserAccountAssociationException
 */
public String getAssociationKeyOfUser(String domainName, int tenantId,
                                      String userName) throws UserAccountAssociationException {

    Connection dbConnection = IdentityDatabaseUtil.getDBConnection();
    PreparedStatement preparedStatement = null;
    ResultSet resultSet = null;
    String associationKey = null;

    try {
        preparedStatement = dbConnection.prepareStatement(UserAccountAssociationConstants
                .SQLQueries.GET_ASSOCIATION_KEY_OF_USER);

        preparedStatement.setInt(1, tenantId);
        preparedStatement.setString(2, domainName);
        preparedStatement.setString(3, userName);
        resultSet = preparedStatement.executeQuery();

        if (resultSet.next()) {
            associationKey = resultSet.getString(1);
        }
        dbConnection.commit();
    } catch (SQLException e) {
        throw new UserAccountAssociationServerException(UserAccountAssociationConstants.ErrorMessages
                .ERROR_WHILE_RETRIEVING_ASSOC_KEY.getDescription
                        (), e);
    } finally {
        IdentityApplicationManagementUtil.closeResultSet(resultSet);
        IdentityApplicationManagementUtil.closeStatement(preparedStatement);
        IdentityApplicationManagementUtil.closeConnection(dbConnection);
    }
    return associationKey;
}
 
Example 17
Source File: UserAccountAssociationDAO.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * Update domain name of association
 *
 * @param tenantId  Tenant ID
 * @param currentDomainName  Old domain name
 * @param newDomainName  New domain name
 * @throws UserAccountAssociationException
 */
public void updateDomainNameOfAssociations(int tenantId, String currentDomainName, String newDomainName) throws
        UserAccountAssociationException {

    Connection dbConnection = IdentityDatabaseUtil.getDBConnection();
    PreparedStatement preparedStatement = null;

    try {
        preparedStatement = dbConnection.prepareStatement(UserAccountAssociationConstants
                .SQLQueries.UPDATE_USER_DOMAIN_NAME);

        preparedStatement.setString(1, newDomainName);
        preparedStatement.setString(2, currentDomainName);
        preparedStatement.setInt(3, tenantId);
        preparedStatement.executeUpdate();

        if (!dbConnection.getAutoCommit()) {
            dbConnection.commit();
        }
    } catch (SQLException e) {
        throw new UserAccountAssociationServerException(String.format(UserAccountAssociationConstants.ErrorMessages
                        .ERROR_UPDATE_DOMAIN_NAME.getDescription(),
                currentDomainName, tenantId), e);
    } finally {
        IdentityApplicationManagementUtil.closeStatement(preparedStatement);
        IdentityApplicationManagementUtil.closeConnection(dbConnection);
    }
}
 
Example 18
Source File: ApplicationDAOImpl.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
/**
 * @param applicationId
 * @param outBoundProvisioningConfig
 * @param connection
 * @throws SQLException
 */
private void updateOutboundProvisioningConfiguration(int applicationId,
                                                     OutboundProvisioningConfig outBoundProvisioningConfig, Connection connection)
        throws SQLException {

    int tenantID = CarbonContext.getThreadLocalCarbonContext().getTenantId();
    PreparedStatement outboundProConfigPrepStmt = null;

    IdentityProvider[] proProviders = outBoundProvisioningConfig
            .getProvisioningIdentityProviders();

    try {
        if (outBoundProvisioningConfig == null || proProviders == null
                || proProviders.length == 0) {
            // no in-bound authentication requests defined.
            return;
        }

        outboundProConfigPrepStmt = connection
                .prepareStatement(ApplicationMgtDBQueries.STORE_PRO_CONNECTORS);
        // TENANT_ID, IDP_NAME, CONNECTOR_NAME, APP_ID

        for (IdentityProvider proProvider : proProviders) {
            if (proProvider != null) {
                ProvisioningConnectorConfig proConnector = proProvider
                        .getDefaultProvisioningConnectorConfig();
                if (proConnector == null) {
                    continue;
                }

                String jitEnabled = "0";

                if (proProvider.getJustInTimeProvisioningConfig() != null
                        && proProvider.getJustInTimeProvisioningConfig()
                        .isProvisioningEnabled()) {
                    jitEnabled = "1";
                }

                String blocking = "0";

                if (proProvider.getDefaultProvisioningConnectorConfig() != null
                        && proProvider.getDefaultProvisioningConnectorConfig().isBlocking()) {
                    blocking = "1";
                }

                outboundProConfigPrepStmt.setInt(1, tenantID);
                outboundProConfigPrepStmt.setString(2, proProvider.getIdentityProviderName());
                outboundProConfigPrepStmt.setString(3, proConnector.getName());
                outboundProConfigPrepStmt.setInt(4, applicationId);
                outboundProConfigPrepStmt.setString(5, jitEnabled);
                outboundProConfigPrepStmt.setString(6, blocking);
                outboundProConfigPrepStmt.addBatch();

            }
        }

        outboundProConfigPrepStmt.executeBatch();

    } finally {
        IdentityApplicationManagementUtil.closeStatement(outboundProConfigPrepStmt);
    }
}
 
Example 19
Source File: ApplicationDAOImpl.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
/**
 * This method will be heavily used by the Authentication Framework. The framework would ask for
 * application data with the given client key and secrete
 *
 * @param clientId
 * @param type
 * @param tenantDomain
 * @return
 * @throws IdentityApplicationManagementException
 */
public ServiceProvider getApplicationData(String clientId, String type, String tenantDomain)
        throws IdentityApplicationManagementException {

    if (log.isDebugEnabled()) {
        log.debug("Loading Application Data of Client " + clientId);
    }

    int tenantID = -123;

    try {
        tenantID = ApplicationManagementServiceComponentHolder.getInstance().getRealmService()
                .getTenantManager().getTenantId(tenantDomain);
    } catch (UserStoreException e1) {
        log.error("Error while reading application", e1);
        throw new IdentityApplicationManagementException("Error while reading application", e1);
    }

    String applicationName = null;

    // Reading application name from the database
    Connection connection = IdentityDatabaseUtil.getDBConnection();
    PreparedStatement storeAppPrepStmt = null;
    ResultSet appNameResult = null;
    try {
        storeAppPrepStmt = connection
                .prepareStatement(ApplicationMgtDBQueries.LOAD_APPLICATION_NAME_BY_CLIENT_ID_AND_TYPE);
        storeAppPrepStmt.setString(1, clientId);
        storeAppPrepStmt.setString(2, type);
        storeAppPrepStmt.setInt(3, tenantID);
        appNameResult = storeAppPrepStmt.executeQuery();
        connection.commit();
        if (appNameResult.next()) {
            applicationName = appNameResult.getString(1);
        }

    } catch (SQLException e) {
        throw new IdentityApplicationManagementException("Error while reading application", e);
    } finally {
        IdentityApplicationManagementUtil.closeResultSet(appNameResult);
        IdentityApplicationManagementUtil.closeStatement(storeAppPrepStmt);
        IdentityApplicationManagementUtil.closeConnection(connection);
    }

    return getApplication(applicationName, tenantDomain);
}
 
Example 20
Source File: ApplicationDAOImpl.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
/**
 * Deletes the Application with application ID
 *
 * @param applicationID
 * @param connection
 * @throws IdentityApplicationManagementException
 */
public void deleteApplication(int applicationID, Connection connection)
        throws IdentityApplicationManagementException {

    int tenantID = CarbonContext.getThreadLocalCarbonContext().getTenantId();

    if (log.isDebugEnabled()) {
        log.debug("Deleting Application " + applicationID);
    }

    // Now, delete the application
    PreparedStatement deleteClientPrepStmt = null;
    try {

        // delete clients
        InboundAuthenticationConfig clients = getInboundAuthenticationConfig(applicationID,
                connection, tenantID);
        for (InboundAuthenticationRequestConfig client : clients
                .getInboundAuthenticationRequestConfigs()) {
            deleteClient(client.getInboundAuthKey(), client.getInboundAuthType());
        }

        String applicationName = getApplicationName(applicationID, connection);
        // delete roles
        ApplicationMgtUtil.deleteAppRole(applicationName);

        deleteClientPrepStmt = connection
                .prepareStatement(ApplicationMgtDBQueries.REMOVE_APP_FROM_APPMGT_APP_WITH_ID);
        deleteClientPrepStmt.setInt(1, applicationID);
        deleteClientPrepStmt.setInt(2, tenantID);
        deleteClientPrepStmt.execute();

        if (!connection.getAutoCommit()) {
            connection.commit();
        }

    } catch (SQLException e) {
        log.error(e.getMessage(), e);
        throw new IdentityApplicationManagementException("Error deleting application");

    } finally {
        IdentityApplicationManagementUtil.closeStatement(deleteClientPrepStmt);
    }

}