Java Code Examples for org.wso2.carbon.identity.application.common.util.IdentityApplicationManagementUtil#closeConnection()
The following examples show how to use
org.wso2.carbon.identity.application.common.util.IdentityApplicationManagementUtil#closeConnection() .
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 |
/** * Update an association key * * @param oldAssociationKey Old association key * @param newAssociationKey New association key * @throws UserAccountAssociationException */ public void updateUserAssociationKey(String oldAssociationKey, String newAssociationKey) throws UserAccountAssociationException { Connection dbConnection = IdentityDatabaseUtil.getDBConnection(); PreparedStatement preparedStatement = null; try { preparedStatement = dbConnection.prepareStatement(UserAccountAssociationConstants .SQLQueries.UPDATE_ASSOCIATION_KEY); preparedStatement.setString(1, newAssociationKey); preparedStatement.setString(2, oldAssociationKey); preparedStatement.executeUpdate(); if (!dbConnection.getAutoCommit()) { dbConnection.commit(); } } catch (SQLException e) { throw new UserAccountAssociationServerException(UserAccountAssociationConstants.ErrorMessages .CONN_UPDATE_DB_ERROR.getDescription(), e); } finally { IdentityApplicationManagementUtil.closeStatement(preparedStatement); IdentityApplicationManagementUtil.closeConnection(dbConnection); } }
Example 2
Source File: UserAccountAssociationDAO.java From carbon-identity with Apache License 2.0 | 6 votes |
/** * 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 3
Source File: UserProfileMgtDAO.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
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 4
Source File: UserProfileMgtDAO.java From carbon-identity with Apache License 2.0 | 6 votes |
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(); if (!dbConnection.getAutoCommit()) { dbConnection.commit(); } } catch (SQLException e) { 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 5
Source File: ProvisioningManagementDAO.java From carbon-identity-framework with Apache License 2.0 | 5 votes |
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 6
Source File: UserAccountAssociationDAO.java From carbon-identity with Apache License 2.0 | 5 votes |
/** * Checks if two user accounts can be popupated or not * * @param domainName1 user store domain of account 1 * @param tenantId1 tenant id of account 1 * @param userName1 username of account 1 * @param domainName2 user store domain of account 2 * @param tenantId2 tenant id of account 2 * @param userName2 username of account 2 * @return * @throws UserAccountAssociationException */ public boolean isValidUserAssociation(String domainName1, int tenantId1, String userName1, String domainName2, int tenantId2, String userName2) throws UserAccountAssociationException { Connection dbConnection = IdentityDatabaseUtil.getDBConnection(); PreparedStatement preparedStatement = null; ResultSet resultSet = null; boolean valid = false; try { preparedStatement = dbConnection.prepareStatement(UserAccountAssociationConstants .SQLQueries.IS_VALID_ASSOCIATION); preparedStatement.setInt(1, tenantId1); preparedStatement.setString(2, domainName1); preparedStatement.setString(3, userName1); preparedStatement.setInt(4, tenantId2); preparedStatement.setString(5, domainName2); preparedStatement.setString(6, userName2); resultSet = preparedStatement.executeQuery(); if (resultSet.next()) { valid = resultSet.getInt(1) > 0; } dbConnection.commit(); } catch (SQLException e) { throw new UserAccountAssociationServerException(UserAccountAssociationConstants.ErrorMessages .CHECK_ASSOCIATION_DB_ERROR.getDescription(), e); } finally { IdentityApplicationManagementUtil.closeResultSet(resultSet); IdentityApplicationManagementUtil.closeStatement(preparedStatement); IdentityApplicationManagementUtil.closeConnection(dbConnection); } return valid; }
Example 7
Source File: ApplicationDAOImpl.java From carbon-identity with Apache License 2.0 | 5 votes |
/** * 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 8
Source File: ApplicationDAOImpl.java From carbon-identity with Apache License 2.0 | 5 votes |
/** * Returns the application ID for a given application name * * @param applicationName * @param tenantID * @param connection * @return * @throws IdentityApplicationManagementException */ private int getApplicationIDByName(String applicationName, int tenantID, Connection connection) throws IdentityApplicationManagementException { int applicationId = 0; PreparedStatement getAppIDPrepStmt = null; ResultSet appidResult = null; try { getAppIDPrepStmt = connection .prepareStatement(ApplicationMgtDBQueries.LOAD_APP_ID_BY_APP_NAME); getAppIDPrepStmt.setString(1, applicationName); getAppIDPrepStmt.setInt(2, tenantID); appidResult = getAppIDPrepStmt.executeQuery(); if (!connection.getAutoCommit()) { connection.commit(); } if (appidResult.next()) { applicationId = appidResult.getInt(1); } } catch (SQLException e) { IdentityApplicationManagementUtil.closeConnection(connection); log.error("Error in storing the application", e); throw new IdentityApplicationManagementException("Error while storing application", e); } finally { IdentityApplicationManagementUtil.closeResultSet(appidResult); IdentityApplicationManagementUtil.closeStatement(getAppIDPrepStmt); } return applicationId; }
Example 9
Source File: UserAccountAssociationDAO.java From carbon-identity with Apache License 2.0 | 5 votes |
/** * 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 10
Source File: UserAccountAssociationDAO.java From carbon-identity with Apache License 2.0 | 5 votes |
/** * Delete all associations of a domain * * @param tenantId Tenant ID * @param domainName Domain name * @throws UserAccountAssociationException */ public void deleteAssociationsFromDomain(int tenantId, String domainName) throws UserAccountAssociationException { Connection dbConnection = IdentityDatabaseUtil.getDBConnection(); PreparedStatement preparedStatement = null; try { preparedStatement = dbConnection.prepareStatement(UserAccountAssociationConstants .SQLQueries.DELETE_USER_ASSOCIATION_FROM_DOMAIN); preparedStatement.setInt(1, tenantId); preparedStatement.setString(2, domainName); preparedStatement.executeUpdate(); if (!dbConnection.getAutoCommit()) { dbConnection.commit(); } } catch (SQLException e) { throw new UserAccountAssociationServerException(String.format(UserAccountAssociationConstants.ErrorMessages .ERROR_DELETE_ASSOC_FROM_DOMAIN_NAME .getDescription(), domainName, tenantId), e); } finally { IdentityApplicationManagementUtil.closeStatement(preparedStatement); IdentityApplicationManagementUtil.closeConnection(dbConnection); } }
Example 11
Source File: ProvisioningManagementDAO.java From carbon-identity with Apache License 2.0 | 5 votes |
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 12
Source File: ProvisioningManagementDAO.java From carbon-identity with Apache License 2.0 | 5 votes |
/** * @param dbConnection * @param idpName * @param tenantId * @return * @throws SQLException * @throws IdentityApplicationManagementException */ private int getIdentityProviderIdByName(Connection dbConnection, String idpName, int tenantId) throws SQLException, IdentityApplicationManagementException { boolean dbConnInitialized = true; PreparedStatement prepStmt = null; ResultSet rs = null; if (dbConnection == null) { dbConnection = IdentityDatabaseUtil.getDBConnection(); } else { dbConnInitialized = false; } try { String sqlStmt = IdPManagementConstants.SQLQueries.GET_IDP_ROW_ID_SQL; prepStmt = dbConnection.prepareStatement(sqlStmt); prepStmt.setInt(1, tenantId); prepStmt.setString(2, idpName); rs = prepStmt.executeQuery(); dbConnection.commit(); if (rs.next()) { return rs.getInt(1); } } finally { IdentityApplicationManagementUtil.closeStatement(prepStmt); IdentityApplicationManagementUtil.closeResultSet(rs); if (dbConnInitialized) { IdentityApplicationManagementUtil.closeConnection(dbConnection); } } return 0; }
Example 13
Source File: UserAccountAssociationDAO.java From carbon-identity with Apache License 2.0 | 5 votes |
/** * Delete account association * * @param domainName User store domain of user * @param tenantId Tenant ID of user * @param userName User name * @throws UserAccountAssociationException */ public void deleteUserAssociation(String domainName, int tenantId, String userName) throws UserAccountAssociationException { Connection dbConnection = IdentityDatabaseUtil.getDBConnection(); PreparedStatement preparedStatement = null; try { preparedStatement = dbConnection.prepareStatement(UserAccountAssociationConstants .SQLQueries.DELETE_CONNECTION); preparedStatement.setInt(1, tenantId); preparedStatement.setString(2, domainName); preparedStatement.setString(3, userName); preparedStatement.executeUpdate(); if (!dbConnection.getAutoCommit()) { dbConnection.commit(); } } catch (SQLException e) { throw new UserAccountAssociationServerException(UserAccountAssociationConstants.ErrorMessages .CONN_DELETE_DB_ERROR.getDescription(), e); } finally { IdentityApplicationManagementUtil.closeStatement(preparedStatement); IdentityApplicationManagementUtil.closeConnection(dbConnection); } }
Example 14
Source File: ApplicationDAOImpl.java From carbon-identity with Apache License 2.0 | 4 votes |
@Override public void updateApplication(ServiceProvider serviceProvider, String tenantDomain) throws IdentityApplicationManagementException { Connection connection = IdentityDatabaseUtil.getDBConnection(); int applicationId = serviceProvider.getApplicationID(); int tenantID = MultitenantConstants.INVALID_TENANT_ID; if (tenantDomain != null) { tenantID = IdentityTenantUtil.getTenantId(tenantDomain); } try { if (ApplicationManagementServiceComponent.getFileBasedSPs().containsKey( serviceProvider.getApplicationName())) { throw new IdentityApplicationManagementException( "Application with the same name laoded from the file system."); } // update basic information of the application. // you can change application name, description, isSasApp... updateBasicApplicationData(serviceProvider, connection); updateInboundProvisioningConfiguration(applicationId, serviceProvider.getInboundProvisioningConfig(), connection); // delete all in-bound authentication requests. deleteInboundAuthRequestConfiguration(serviceProvider.getApplicationID(), connection); // update all in-bound authentication requests. updateInboundAuthRequestConfiguration(serviceProvider.getApplicationID(), serviceProvider.getInboundAuthenticationConfig(), connection); // delete local and out-bound authentication configuration. deleteLocalAndOutboundAuthenticationConfiguration(applicationId, connection); // update local and out-bound authentication configuration. updateLocalAndOutboundAuthenticationConfiguration(serviceProvider.getApplicationID(), serviceProvider.getLocalAndOutBoundAuthenticationConfig(), connection); deleteRequestPathAuthenticators(applicationId, connection); updateRequestPathAuthenticators(applicationId, serviceProvider.getRequestPathAuthenticatorConfigs(), connection); deteClaimConfiguration(applicationId, connection); updateClaimConfiguration(serviceProvider.getApplicationID(), serviceProvider.getClaimConfig(), applicationId, connection); deleteOutboundProvisioningConfiguration(applicationId, connection); updateOutboundProvisioningConfiguration(applicationId, serviceProvider.getOutboundProvisioningConfig(), connection); deletePermissionAndRoleConfiguration(applicationId, connection); updatePermissionAndRoleConfiguration(serviceProvider.getApplicationID(), serviceProvider.getPermissionAndRoleConfig(), connection); deleteAssignedPermissions(connection, serviceProvider.getApplicationName(), serviceProvider.getPermissionAndRoleConfig().getPermissions()); if (serviceProvider.getSpProperties() != null) { updateServiceProviderProperties(connection, applicationId, Arrays.asList(serviceProvider.getSpProperties()), tenantID); } if (!connection.getAutoCommit()) { connection.commit(); } } catch (SQLException | UserStoreException e) { try { if (connection != null) { connection.rollback(); } } catch (SQLException e1) { throw new IdentityApplicationManagementException( "Failed to update service provider " + applicationId, e); } throw new IdentityApplicationManagementException("Failed to update service provider " + applicationId, e); } finally { IdentityApplicationManagementUtil.closeConnection(connection); } }
Example 15
Source File: ApplicationDAOImpl.java From carbon-identity with Apache License 2.0 | 4 votes |
@Override public ServiceProvider getApplication(String applicationName, String tenantDomain) throws IdentityApplicationManagementException { int applicationId = 0; int tenantID = MultitenantConstants.SUPER_TENANT_ID; if (tenantDomain != null) { try { tenantID = ApplicationManagementServiceComponentHolder.getInstance().getRealmService() .getTenantManager().getTenantId(tenantDomain); } catch (UserStoreException e1) { log.error("Error in reading application", e1); throw new IdentityApplicationManagementException("Error while reading application", e1); } } Connection connection = IdentityDatabaseUtil.getDBConnection(); try { // Load basic application data ServiceProvider serviceProvider = getBasicApplicationData(applicationName, connection, tenantID); if ((serviceProvider == null || serviceProvider.getApplicationName() == null) && ApplicationConstants.LOCAL_SP.equals(applicationName)) { ServiceProvider localServiceProvider = new ServiceProvider(); localServiceProvider.setApplicationName(applicationName); localServiceProvider.setDescription("Local Service Provider"); createApplication(localServiceProvider, tenantDomain); serviceProvider = getBasicApplicationData(applicationName, connection, tenantID); } if (serviceProvider == null) { return null; } applicationId = serviceProvider.getApplicationID(); serviceProvider.setInboundAuthenticationConfig(getInboundAuthenticationConfig( applicationId, connection, tenantID)); serviceProvider .setLocalAndOutBoundAuthenticationConfig(getLocalAndOutboundAuthenticationConfig( applicationId, connection, tenantID)); serviceProvider.setInboundProvisioningConfig(getInboundProvisioningConfiguration( applicationId, connection, tenantID)); serviceProvider.setOutboundProvisioningConfig(getOutboundProvisioningConfiguration( applicationId, connection, tenantID)); // Load Claim Mapping serviceProvider.setClaimConfig(getClaimConfiguration(applicationId, connection, tenantID)); // Load Role Mappings List<RoleMapping> roleMappings = getRoleMappingOfApplication(applicationId, connection, tenantID); PermissionsAndRoleConfig permissionAndRoleConfig = new PermissionsAndRoleConfig(); permissionAndRoleConfig.setRoleMappings(roleMappings .toArray(new RoleMapping[roleMappings.size()])); serviceProvider.setPermissionAndRoleConfig(permissionAndRoleConfig); RequestPathAuthenticatorConfig[] requestPathAuthenticators = getRequestPathAuthenticators( applicationId, connection, tenantID); serviceProvider.setRequestPathAuthenticatorConfigs(requestPathAuthenticators); List<ServiceProviderProperty> propertyList = getServicePropertiesBySpId(connection, applicationId); serviceProvider.setSpProperties(propertyList.toArray(new ServiceProviderProperty[propertyList.size()])); return serviceProvider; } catch (SQLException e) { throw new IdentityApplicationManagementException("Failed to update service provider " + applicationId, e); } finally { IdentityApplicationManagementUtil.closeConnection(connection); } }
Example 16
Source File: ApplicationDAOImpl.java From carbon-identity with Apache License 2.0 | 4 votes |
/** * Stores basic application information and meta-data such as the application name, creator and * tenant. * * @param serviceProvider * @throws IdentityApplicationManagementException */ @Override public int createApplication(ServiceProvider serviceProvider, String tenantDomain) throws IdentityApplicationManagementException { // get logged-in users tenant identifier. int tenantID = MultitenantConstants.INVALID_TENANT_ID; if (tenantDomain != null) { tenantID = IdentityTenantUtil.getTenantId(tenantDomain); } String qualifiedUsername = CarbonContext.getThreadLocalCarbonContext().getUsername(); if (ApplicationConstants.LOCAL_SP.equals(serviceProvider.getApplicationName())) { qualifiedUsername = CarbonConstants.REGISTRY_SYSTEM_USERNAME; } String username = UserCoreUtil.removeDomainFromName(qualifiedUsername); String userStoreDomain = IdentityUtil.extractDomainFromName(qualifiedUsername); String applicationName = serviceProvider.getApplicationName(); String description = serviceProvider.getDescription(); if (log.isDebugEnabled()) { log.debug("Creating Application " + applicationName + " for user " + qualifiedUsername); } Connection connection = IdentityDatabaseUtil.getDBConnection(); PreparedStatement storeAppPrepStmt = null; ResultSet results = null; try { String dbProductName = connection.getMetaData().getDatabaseProductName(); storeAppPrepStmt = connection.prepareStatement( ApplicationMgtDBQueries.STORE_BASIC_APPINFO, new String[]{ DBUtils.getConvertedAutoGeneratedColumnName(dbProductName, "ID")}); // TENANT_ID, APP_NAME, USER_STORE, USERNAME, DESCRIPTION, AUTH_TYPE storeAppPrepStmt.setInt(1, tenantID); storeAppPrepStmt.setString(2, applicationName); storeAppPrepStmt.setString(3, userStoreDomain); storeAppPrepStmt.setString(4, username); storeAppPrepStmt.setString(5, description); // by default authentication type would be default. // default authenticator is defined system-wide - in the configuration file. storeAppPrepStmt.setString(6, ApplicationConstants.AUTH_TYPE_DEFAULT); storeAppPrepStmt.execute(); results = storeAppPrepStmt.getGeneratedKeys(); if (!connection.getAutoCommit()) { connection.commit(); } int applicationId = 0; if (results.next()) { applicationId = results.getInt(1); } // some JDBC Drivers returns this in the result, some don't if (applicationId == 0) { if (log.isDebugEnabled()) { log.debug("JDBC Driver did not return the application id, executing Select operation"); } applicationId = getApplicationIDByName(applicationName, tenantID, connection); } if (serviceProvider.getSpProperties() != null) { addServiceProviderProperties(connection, applicationId, Arrays.asList(serviceProvider.getSpProperties()), tenantID); } if (log.isDebugEnabled()) { log.debug("Application Stored successfully with application id " + applicationId); } return applicationId; } catch (SQLException e) { try { if (connection != null) { connection.rollback(); } } catch (SQLException sql) { throw new IdentityApplicationManagementException( "Error while Creating Application", sql); } throw new IdentityApplicationManagementException("Error while Creating Application", e); } finally { IdentityApplicationManagementUtil.closeResultSet(results); IdentityApplicationManagementUtil.closeStatement(storeAppPrepStmt); IdentityApplicationManagementUtil.closeConnection(connection); } }
Example 17
Source File: ApplicationDAOImpl.java From carbon-identity with Apache License 2.0 | 4 votes |
/** * Get application Names for user * * @return * @throws IdentityApplicationManagementException */ public ApplicationBasicInfo[] getAllApplicationBasicInfo() throws IdentityApplicationManagementException { int tenantID = CarbonContext.getThreadLocalCarbonContext().getTenantId(); if (log.isDebugEnabled()) { log.debug("Reading all Applications of Tenant " + tenantID); } Connection connection = IdentityDatabaseUtil.getDBConnection(); PreparedStatement getAppNamesStmt = null; ResultSet appNameResultSet = null; ArrayList<ApplicationBasicInfo> appInfo = new ArrayList<ApplicationBasicInfo>(); try { getAppNamesStmt = connection .prepareStatement(ApplicationMgtDBQueries.LOAD_APP_NAMES_BY_TENANT); getAppNamesStmt.setInt(1, tenantID); appNameResultSet = getAppNamesStmt.executeQuery(); while (appNameResultSet.next()) { ApplicationBasicInfo basicInfo = new ApplicationBasicInfo(); if (ApplicationConstants.LOCAL_SP.equals(appNameResultSet.getString(1))) { continue; } basicInfo.setApplicationName(appNameResultSet.getString(1)); basicInfo.setDescription(appNameResultSet.getString(2)); appInfo.add(basicInfo); } connection.commit(); } catch (SQLException e) { throw new IdentityApplicationManagementException("Error while Reading all Applications"); } finally { IdentityApplicationManagementUtil.closeStatement(getAppNamesStmt); IdentityApplicationManagementUtil.closeResultSet(appNameResultSet); IdentityApplicationManagementUtil.closeConnection(connection); } return appInfo.toArray(new ApplicationBasicInfo[appInfo.size()]); }
Example 18
Source File: ProvisioningManagementDAO.java From carbon-identity with Apache License 2.0 | 4 votes |
/** * @param identityProviderName * @param connectorType * @param provisioningEntity * @param tenantId * @throws IdentityApplicationManagementException */ public ProvisionedIdentifier getProvisionedIdentifier(String identityProviderName, String connectorType, ProvisioningEntity provisioningEntity, int tenantId) throws IdentityApplicationManagementException { Connection dbConnection = IdentityDatabaseUtil.getDBConnection(); try { PreparedStatement prepStmt = null; // id of the identity provider int idpId = getIdentityProviderIdentifier(dbConnection, identityProviderName, tenantId); // id of the provisioning configuration int provisioningConfigId = getProvisioningConfigurationIdentifier(dbConnection, idpId, connectorType); // PROVISIONING_CONFIG_ID, ENTITY_TYPE, // ENTITY_LOCAL_USERSTORE, ENTITY_NAME, ENTITY_VALUE, // TENANT_ID String sqlStmt = IdentityProvisioningConstants.SQLQueries.GET_PROVISIONING_ENTITY_SQL; prepStmt = dbConnection.prepareStatement(sqlStmt); prepStmt.setInt(1, provisioningConfigId); prepStmt.setString(2, provisioningEntity.getEntityType().toString()); prepStmt.setString(3, IdentityUtil.extractDomainFromName(provisioningEntity.getEntityName())); prepStmt.setString(4, UserCoreUtil.removeDomainFromName(provisioningEntity.getEntityName())); prepStmt.setInt(5, tenantId); ResultSet rs = prepStmt.executeQuery(); dbConnection.commit(); if (rs.next()) { String entityId = rs.getString(1); ProvisionedIdentifier provisionedIdentifier = new ProvisionedIdentifier(); provisionedIdentifier.setIdentifier(entityId); return provisionedIdentifier; } else { return null; } } catch (SQLException e) { IdentityApplicationManagementUtil.rollBack(dbConnection); String msg = "Error occurred while adding Provisioning entity for tenant " + tenantId; throw new IdentityApplicationManagementException(msg, e); } finally { IdentityApplicationManagementUtil.closeConnection(dbConnection); } }
Example 19
Source File: ApplicationDAOImpl.java From carbon-identity with Apache License 2.0 | 4 votes |
public String getServiceProviderNameByClientId(String clientId, String clientType, String tenantDomain) throws IdentityApplicationManagementException { int tenantID = -123; if (tenantDomain != null) { try { tenantID = ApplicationManagementServiceComponentHolder.getInstance().getRealmService() .getTenantManager().getTenantId(tenantDomain); } catch (UserStoreException e1) { throw new IdentityApplicationManagementException("Error while reading application"); } } 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, clientType); storeAppPrepStmt.setInt(3, tenantID); storeAppPrepStmt.setInt(4, tenantID); appNameResult = storeAppPrepStmt.executeQuery(); if (appNameResult.next()) { applicationName = appNameResult.getString(1); } connection.commit(); } catch (SQLException e) { throw new IdentityApplicationManagementException("Error while reading application", e); } finally { IdentityApplicationManagementUtil.closeResultSet(appNameResult); IdentityApplicationManagementUtil.closeStatement(storeAppPrepStmt); IdentityApplicationManagementUtil.closeConnection(connection); } return applicationName; }
Example 20
Source File: ProvisioningManagementDAO.java From carbon-identity with Apache License 2.0 | 4 votes |
/** * @param identityProviderName * @param connectorType * @param provisioningEntity * @param tenantId * @throws IdentityApplicationManagementException */ public void addProvisioningEntity(String identityProviderName, String connectorType, ProvisioningEntity provisioningEntity, int tenantId) throws IdentityApplicationManagementException { Connection dbConnection = IdentityDatabaseUtil.getDBConnection(); try { PreparedStatement prepStmt = null; // id of the identity provider int idpId = getIdentityProviderIdentifier(dbConnection, identityProviderName, tenantId); // id of the provisioning configuration int provisioningConfigId = getProvisioningConfigurationIdentifier(dbConnection, idpId, connectorType); String localId = getLocalIdFromProvisioningEntity(provisioningEntity); // PROVISIONING_CONFIG_ID, ENTITY_TYPE, // ENTITY_LOCAL_USERSTORE, ENTITY_NAME, ENTITY_VALUE, // TENANT_ID String sqlStmt = IdentityProvisioningConstants.SQLQueries.ADD_PROVISIONING_ENTITY_SQL; prepStmt = dbConnection.prepareStatement(sqlStmt); prepStmt.setInt(1, provisioningConfigId); prepStmt.setString(2, provisioningEntity.getEntityType().toString()); prepStmt.setString(3, IdentityUtil.extractDomainFromName(provisioningEntity.getEntityName())); prepStmt.setString(4, UserCoreUtil.removeDomainFromName(provisioningEntity.getEntityName())); prepStmt.setString(5, provisioningEntity.getIdentifier().getIdentifier()); prepStmt.setInt(6, tenantId); prepStmt.setString(7, localId); prepStmt.execute(); dbConnection.commit(); } catch (SQLException e) { IdentityApplicationManagementUtil.rollBack(dbConnection); String msg = "Error occurred while adding Provisioning entity for tenant " + tenantId; throw new IdentityApplicationManagementException(msg, e); } finally { IdentityApplicationManagementUtil.closeConnection(dbConnection); } }