org.wso2.carbon.identity.core.util.IdentityDatabaseUtil Java Examples
The following examples show how to use
org.wso2.carbon.identity.core.util.IdentityDatabaseUtil.
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: UserIdentityMetadataStore.java From carbon-identity with Apache License 2.0 | 6 votes |
/** * Stores identity data set. * * @param metadataSet * @throws IdentityException */ public void storeMetadataSet(IdentityMetadataDO[] metadataSet) throws IdentityException { Connection connection = IdentityDatabaseUtil.getDBConnection(); PreparedStatement prepStmt = null; try { connection.setAutoCommit(false); prepStmt = connection.prepareStatement(SQLQuery.STORE_META_DATA); for (IdentityMetadataDO metadata : metadataSet) { prepStmt.setString(1, metadata.getUserName()); prepStmt.setInt(2, metadata.getTenantId()); prepStmt.setString(3, metadata.getMetadataType()); prepStmt.setString(4, metadata.getMetadata()); prepStmt.setString(5, Boolean.toString(metadata.isValid())); prepStmt.addBatch(); } prepStmt.executeBatch(); connection.commit(); } catch (SQLException e) { throw IdentityException.error("Error while storing user identity data", e); } finally { IdentityDatabaseUtil.closeStatement(prepStmt); IdentityDatabaseUtil.closeConnection(connection); } }
Example #2
Source File: UserSessionStore.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
/** * Remove the session information records of a given set of session IDs from the relevant tables. * * @param sessionIdList list of terminated session IDs */ public void removeTerminatedSessionRecords(List<String> sessionIdList) { String[] sessionsToRemove = sessionIdList.toArray(new String[0]); if (log.isDebugEnabled()) { log.debug("Removing meta information of the deleted sessions."); } try (Connection connection = IdentityDatabaseUtil.getDBConnection(false)) { deleteSessionDataFromTable(sessionsToRemove, connection, IDN_AUTH_USER_SESSION_MAPPING_TABLE, SQLQueries.SQL_DELETE_TERMINATED_SESSION_DATA); deleteSessionDataFromTable(sessionsToRemove, connection, IDN_AUTH_SESSION_APP_INFO_TABLE, SQLQueries.SQL_DELETE_IDN_AUTH_SESSION_APP_INFO); deleteSessionDataFromTable(sessionsToRemove, connection, IDN_AUTH_SESSION_META_DATA_TABLE, SQLQueries.SQL_DELETE_IDN_AUTH_SESSION_META_DATA); IdentityDatabaseUtil.commitTransaction(connection); } catch (SQLException e) { log.error("Error while removing the terminated session information from the database.", e); } }
Example #3
Source File: FunctionLibraryDAOImplTest.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
@Test(dataProvider = "listFunctionLibraryDataProvider") public void listFunctionLibraries(List<Object> functionLibraries, String tenantDomain) throws FunctionLibraryManagementException { try (Connection connection = DAOUtils.getConnection(DB_NAME)) { FunctionLibraryDAO functionLibraryDAO = new FunctionLibraryDAOImpl(); addFunctionLibraries(functionLibraryDAO, functionLibraries, tenantDomain); when(IdentityDatabaseUtil.getDBConnection(false)).thenReturn(connection); List<FunctionLibrary> functionLibrariesList = functionLibraryDAO.listFunctionLibraries(tenantDomain); assertTrue(functionLibrariesList != null && functionLibrariesList.size() != 0, "Failed to retrieve script libraries."); // Clean after test deleteFunctionLibraries(functionLibraryDAO, functionLibraries, tenantDomain); } catch (SQLException e) { log.error("SQLException"); } }
Example #4
Source File: IdPManagementDAO.java From carbon-identity with Apache License 2.0 | 6 votes |
/** * @param dbConnection * @param idpId * @param tenantId * @throws IdentityProviderManagementException * @throws SQLException */ private void deleteLocalIdPClaimValues(Connection dbConnection, int idpId, int tenantId) throws IdentityProviderManagementException, SQLException { PreparedStatement prepStmt = null; try { String sqlStmt = IdPManagementConstants.SQLQueries.DELETE_LOCAL_IDP_DEFAULT_CLAIM_VALUES_SQL; prepStmt = dbConnection.prepareStatement(sqlStmt); prepStmt.setInt(1, idpId); prepStmt.setInt(2, tenantId); prepStmt.executeUpdate(); } finally { IdentityDatabaseUtil.closeStatement(prepStmt); } }
Example #5
Source File: IdPManagementDAO.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
/** * @param idPName * @param tenantId * @param tenantDomain * @throws IdentityProviderManagementException */ public void deleteIdP(String idPName, int tenantId, String tenantDomain) throws IdentityProviderManagementException { Connection dbConnection = IdentityDatabaseUtil.getDBConnection(); try { IdentityProvider identityProvider = getIdPByName(dbConnection, idPName, tenantId, tenantDomain); if (identityProvider == null) { String msg = "Trying to delete non-existent Identity Provider: %s in tenantDomain: %s"; throw new IdentityProviderManagementException(String.format(msg, idPName, tenantDomain)); } deleteIdP(dbConnection, tenantId, idPName, null); IdentityDatabaseUtil.commitTransaction(dbConnection); } catch (SQLException e) { IdentityDatabaseUtil.rollbackTransaction(dbConnection); throw new IdentityProviderManagementException("Error occurred while deleting Identity Provider of tenant " + tenantDomain, e); } finally { IdentityDatabaseUtil.closeConnection(dbConnection); } }
Example #6
Source File: IdPManagementDAO.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
/** * @param conn * @param tenantId * @throws SQLException */ private void switchOffPrimary(Connection conn, int tenantId) throws SQLException { PreparedStatement prepStmt = null; // SP_IDP_PRIMARY String sqlStmt = IdPManagementConstants.SQLQueries.SWITCH_IDP_PRIMARY_SQL; try { prepStmt = conn.prepareStatement(sqlStmt); prepStmt.setString(1, "0"); prepStmt.setInt(2, tenantId); prepStmt.setString(3, "1"); prepStmt.executeUpdate(); } finally { IdentityDatabaseUtil.closeStatement(prepStmt); } }
Example #7
Source File: TokenMgtDAO.java From carbon-identity with Apache License 2.0 | 6 votes |
/** * * @param connection database connection * @param tokenId accesstoken * @param tokenState state of the token need to be updated. * @param tokenStateId token state id. * @param userStoreDomain user store domain. * @throws IdentityOAuth2Exception */ public void setAccessTokenState(Connection connection, String tokenId, String tokenState, String tokenStateId, String userStoreDomain) throws IdentityOAuth2Exception { PreparedStatement prepStmt = null; try { String sql = SQLQueries.UPDATE_TOKE_STATE; if (StringUtils.isNotBlank(userStoreDomain)) { sql = sql.replace(IDN_OAUTH2_ACCESS_TOKEN, IDN_OAUTH2_ACCESS_TOKEN + "_" + userStoreDomain); } prepStmt = connection.prepareStatement(sql); prepStmt.setString(1, tokenState); prepStmt.setString(2, tokenStateId); prepStmt.setString(3, tokenId); prepStmt.executeUpdate(); } catch (SQLException e) { throw new IdentityOAuth2Exception("Error while updating Access Token with ID : " + tokenId + " to Token State : " + tokenState, e); } finally { IdentityDatabaseUtil.closeStatement(prepStmt); } }
Example #8
Source File: WorkflowRequestDAO.java From carbon-identity with Apache License 2.0 | 6 votes |
/** * Get status of a request. * * @param uuid * @return * @throws InternalWorkflowException */ public String retrieveStatusOfWorkflow(String uuid) throws InternalWorkflowException { Connection connection = IdentityDatabaseUtil.getDBConnection(); PreparedStatement prepStmt = null; ResultSet resultSet = null; String query = SQLConstants.GET_WORKFLOW_REQUEST_QUERY; try { prepStmt = connection.prepareStatement(query); prepStmt.setString(1, uuid); resultSet = prepStmt.executeQuery(); if (resultSet.next()) { String status = resultSet.getString(SQLConstants.REQUEST_STATUS_COLUMN); return status; } } catch (SQLException e) { throw new InternalWorkflowException("Error when executing the sql query:" + query, e); } finally { IdentityDatabaseUtil.closeAllConnections(connection, resultSet, prepStmt); } return ""; }
Example #9
Source File: TokenMgtDAO.java From carbon-identity with Apache License 2.0 | 6 votes |
public String findScopeOfResource(String resourceUri) throws IdentityOAuth2Exception { Connection connection = IdentityDatabaseUtil.getDBConnection();; PreparedStatement ps = null; ResultSet rs = null; try { String sql = SQLQueries.RETRIEVE_IOS_SCOPE_KEY; ps = connection.prepareStatement(sql); ps.setString(1, resourceUri); rs = ps.executeQuery(); if (rs.next()) { return rs.getString("SCOPE_KEY"); } connection.commit(); return null; } catch (SQLException e) { String errorMsg = "Error getting scopes for resource - " + resourceUri + " : " + e.getMessage(); throw new IdentityOAuth2Exception(errorMsg, e); } finally { IdentityDatabaseUtil.closeAllConnections(connection, rs, ps); } }
Example #10
Source File: WorkflowDAO.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
/** * Adding a workflow * * @param workflow Workflow bean object * @param tenantId Tenant ID * @throws InternalWorkflowException */ public void addWorkflow(Workflow workflow, int tenantId) throws InternalWorkflowException { Connection connection = IdentityDatabaseUtil.getDBConnection(); PreparedStatement prepStmt = null; String query = SQLConstants.ADD_WORKFLOW_QUERY; try { prepStmt = connection.prepareStatement(query); prepStmt.setString(1, workflow.getWorkflowId()); prepStmt.setString(2, workflow.getWorkflowName()); prepStmt.setString(3, workflow.getWorkflowDescription()); prepStmt.setString(4, workflow.getTemplateId()); prepStmt.setString(5, workflow.getWorkflowImplId()); prepStmt.setInt(6, tenantId); prepStmt.executeUpdate(); IdentityDatabaseUtil.commitTransaction(connection); } catch (SQLException e) { IdentityDatabaseUtil.rollbackTransaction(connection); throw new InternalWorkflowException(errorMessage , e); } finally { IdentityDatabaseUtil.closeAllConnections(connection, null, prepStmt); } }
Example #11
Source File: WorkflowDAO.java From carbon-identity with Apache License 2.0 | 6 votes |
/** * Clear all the parameters that stored under workflow Id * * @param workflowId WorkflowId * @throws InternalWorkflowException */ public void removeWorkflowParams(String workflowId) throws InternalWorkflowException { Connection connection = IdentityDatabaseUtil.getDBConnection(); PreparedStatement prepStmt = null; String query = SQLConstants.DELETE_WORKFLOW_PARAMS_QUERY; try { prepStmt = connection.prepareStatement(query); prepStmt.setString(1, workflowId); prepStmt.executeUpdate(); connection.commit(); } catch (SQLException e) { throw new InternalWorkflowException(errorMessage, e); } finally { IdentityDatabaseUtil.closeAllConnections(connection, null, prepStmt); } }
Example #12
Source File: GroupDAO.java From carbon-identity with Apache License 2.0 | 6 votes |
/** * Lists the groups that are created from SCIM * * @return The set of groups that were created from SCIM * @throws IdentitySCIMException */ public Set<String> listSCIMGroups() throws IdentitySCIMException { Connection connection = IdentityDatabaseUtil.getDBConnection(); PreparedStatement prepStmt = null; ResultSet resultSet = null; Set<String> groups = new HashSet<>(); try { //retrieve groups from the DB prepStmt = connection.prepareStatement(SQLQueries.LIST_SCIM_GROUPS_SQL); prepStmt.setString(1, SCIMConstants.ID_URI); resultSet = prepStmt.executeQuery(); while (resultSet.next()) { String group = resultSet.getString(1); if (StringUtils.isNotEmpty(group)) { groups.add(group); } } } catch (SQLException e) { throw new IdentitySCIMException("Error when reading the SCIM Group information from persistence store.", e); } finally { IdentityDatabaseUtil.closeAllConnections(connection, resultSet, prepStmt); } return groups; }
Example #13
Source File: WorkflowRequestAssociationDAO.java From carbon-identity with Apache License 2.0 | 6 votes |
/** * Get list of states of workflows of a request * * @param requestId * @return * @throws InternalWorkflowException */ public List<String> getWorkflowStatesOfRequest(String requestId) throws InternalWorkflowException { List<String> states = new ArrayList<>(); Connection connection = IdentityDatabaseUtil.getDBConnection(); PreparedStatement prepStmt = null; String query = SQLConstants.GET_STATES_OF_REQUEST; ResultSet resultSet = null; try { prepStmt = connection.prepareStatement(query); prepStmt.setString(1, requestId); resultSet = prepStmt.executeQuery(); while (resultSet.next()) { states.add(resultSet.getString(SQLConstants.REQUEST_STATUS_COLUMN)); } connection.commit(); } catch (SQLException e) { throw new InternalWorkflowException("Error when executing the sql query:" + query, e); } finally { IdentityDatabaseUtil.closeAllConnections(connection, resultSet, prepStmt); } return states; }
Example #14
Source File: OpenIDRememberMeTokenDAO.java From carbon-identity with Apache License 2.0 | 6 votes |
/** * Check if the token already exist in the database. * * @param connection * @param rememberMe * @return * @throws SQLException */ private boolean isTokenExist(Connection connection, OpenIDRememberMeDO rememberMe) throws SQLException { PreparedStatement prepStmt = null; ResultSet results = null; boolean result = false; try { prepStmt = connection.prepareStatement(OpenIDSQLQueries.CHECK_REMEMBER_ME_TOKEN_EXIST); prepStmt.setString(1, rememberMe.getUserName()); prepStmt.setInt(2, IdentityTenantUtil.getTenantIdOfUser(rememberMe.getUserName())); results = prepStmt.executeQuery(); if (results.next()) { result = true; } } finally { IdentityDatabaseUtil.closeResultSet(results); IdentityDatabaseUtil.closeStatement(prepStmt); } return result; }
Example #15
Source File: WorkflowRequestAssociationDAO.java From carbon-identity with Apache License 2.0 | 6 votes |
/** * Adds new workflow-request relationship to database * * @param relationshipId * @param workflowId * @param requestId * @param status * @throws InternalWorkflowException */ public void addNewRelationship(String relationshipId, String workflowId, String requestId, String status, int tenantId) throws InternalWorkflowException { Connection connection = IdentityDatabaseUtil.getDBConnection(); PreparedStatement prepStmt = null; String query = SQLConstants.ADD_WORKFLOW_REQUEST_RELATIONSHIP; try { Timestamp createdDateStamp = new Timestamp(System.currentTimeMillis()); prepStmt = connection.prepareStatement(query); prepStmt.setString(1, relationshipId); prepStmt.setString(2, workflowId); prepStmt.setString(3, requestId); prepStmt.setTimestamp(4, createdDateStamp); prepStmt.setString(5, status); prepStmt.setInt(6, tenantId); prepStmt.execute(); connection.commit(); } catch (SQLException e) { throw new InternalWorkflowException("Error when executing the sql query:" + query, e); } finally { IdentityDatabaseUtil.closeAllConnections(connection, null, prepStmt); } }
Example #16
Source File: IdPManagementDAO.java From carbon-identity with Apache License 2.0 | 6 votes |
/** * @param conn * @param idPId * @param claims * @throws SQLException */ private void addIdPClaims(Connection conn, int idPId, int tenantId, Claim[] claims) throws SQLException { PreparedStatement prepStmt = null; if (claims == null || claims.length == 0) { return; } try { // SP_IDP_ID, SP_IDP_CLAIM String sqlStmt = IdPManagementConstants.SQLQueries.ADD_IDP_CLAIMS_SQL; prepStmt = conn.prepareStatement(sqlStmt); for (Claim claim : claims) { prepStmt.setInt(1, idPId); prepStmt.setInt(2, tenantId); prepStmt.setString(3, claim.getClaimUri()); prepStmt.addBatch(); prepStmt.clearParameters(); } prepStmt.executeBatch(); } finally { IdentityDatabaseUtil.closeStatement(prepStmt); } }
Example #17
Source File: JDBCUserRecoveryDataStore.java From carbon-identity with Apache License 2.0 | 6 votes |
/** * Stores identity data. * * @throws IdentityException */ @Override public void store(UserRecoveryDataDO recoveryDataDO) throws IdentityException { Connection connection = IdentityDatabaseUtil.getDBConnection(); PreparedStatement prepStmt = null; try { prepStmt = connection.prepareStatement(SQLQuery.STORE_META_DATA); prepStmt.setString(1, recoveryDataDO.getUserName()); prepStmt.setInt(2, recoveryDataDO.getTenantId()); prepStmt.setString(3, recoveryDataDO.getCode()); prepStmt.setString(4, recoveryDataDO.getSecret()); prepStmt.execute(); connection.setAutoCommit(false); connection.commit(); } catch (SQLException e) { throw IdentityException.error("Error while storing user identity data", e); } finally { IdentityDatabaseUtil.closeStatement(prepStmt); IdentityDatabaseUtil.closeConnection(connection); } }
Example #18
Source File: FunctionLibraryDAOImplTest.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
@Test(dataProvider = "updateFunctionLibraryDataProvider") public void updateFunctionLibrary(Object functionLibrary, String tenantDomain) throws SQLException, FunctionLibraryManagementException { try (Connection connection1 = DAOUtils.getConnection(DB_NAME); Connection connection2 = DAOUtils.getConnection(DB_NAME)) { FunctionLibraryDAO functionLibraryDAO = new FunctionLibraryDAOImpl(); addFunctionLibraries(functionLibraryDAO, Collections.singletonList(functionLibrary), tenantDomain); FunctionLibrary funLib = (FunctionLibrary) functionLibrary; String oldName = funLib.getFunctionLibraryName(); funLib.setFunctionLibraryName("updatedName"); when(IdentityDatabaseUtil.getDBConnection()).thenReturn(connection1); functionLibraryDAO.updateFunctionLibrary(oldName, funLib, tenantDomain); when(IdentityDatabaseUtil.getDBConnection(false)).thenReturn(connection2); assertNotNull(functionLibraryDAO.getFunctionLibrary(funLib.getFunctionLibraryName(), tenantDomain), "Failed to update script library."); // Clean after test deleteFunctionLibraries(functionLibraryDAO, Collections.singletonList(functionLibrary), tenantDomain); } }
Example #19
Source File: JDBCIdentityDataStore.java From carbon-identity with Apache License 2.0 | 6 votes |
private void addUserDataValue(String userName, int tenantId, String key, String value) throws SQLException { Connection connection = IdentityDatabaseUtil.getDBConnection(); PreparedStatement prepStmt = null; try { prepStmt = connection.prepareStatement(SQLQuery.STORE_USER_DATA); prepStmt.setInt(1, tenantId); prepStmt.setString(2, userName); prepStmt.setString(3, key); prepStmt.setString(4, value); prepStmt.execute(); connection.commit(); } finally { IdentityDatabaseUtil.closeStatement(prepStmt); IdentityDatabaseUtil.closeConnection(connection); } }
Example #20
Source File: IdPManagementDAO.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
/** * Get Identity properties map * * @param dbConnection database connection * @param idpId IDP Id * @return Identity provider properties */ private List<IdentityProviderProperty> getIdentityPropertiesByIdpId(Connection dbConnection, int idpId) throws SQLException { String sqlStmt = IdPManagementConstants.SQLQueries.GET_IDP_METADATA_BY_IDP_ID; PreparedStatement prepStmt = null; ResultSet rs = null; List<IdentityProviderProperty> idpProperties = new ArrayList<IdentityProviderProperty>(); try { prepStmt = dbConnection.prepareStatement(sqlStmt); prepStmt.setInt(1, idpId); rs = prepStmt.executeQuery(); while (rs.next()) { IdentityProviderProperty property = new IdentityProviderProperty(); property.setName(rs.getString("NAME")); property.setValue(rs.getString("VALUE")); property.setDisplayName(rs.getString("DISPLAY_NAME")); idpProperties.add(property); } } finally { IdentityDatabaseUtil.closeAllConnections(null, rs, prepStmt); } return idpProperties; }
Example #21
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 #22
Source File: IdPManagementDAO.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
/** * @param resourceId * @param tenantId * @param tenantDomain * @throws IdentityProviderManagementException */ public void deleteIdPByResourceId(String resourceId, int tenantId, String tenantDomain) throws IdentityProviderManagementException { Connection dbConnection = IdentityDatabaseUtil.getDBConnection(); try { IdentityProvider identityProvider = getIDPbyResourceId(dbConnection, resourceId, tenantId, tenantDomain); if (identityProvider == null) { String msg = "Trying to delete non-existent Identity Provider with resource ID: %s in tenantDomain: %s"; throw new IdentityProviderManagementException(String.format(msg, resourceId, tenantDomain)); } deleteIdP(dbConnection, tenantId, null, resourceId); IdentityDatabaseUtil.commitTransaction(dbConnection); } catch (SQLException e) { IdentityDatabaseUtil.rollbackTransaction(dbConnection); throw new IdentityProviderManagementException("Error occurred while deleting Identity Provider of tenant " + tenantDomain, e); } finally { IdentityDatabaseUtil.closeConnection(dbConnection); } }
Example #23
Source File: IdPManagementDAO.java From carbon-identity with Apache License 2.0 | 6 votes |
private void doAppointPrimary(Connection conn, int tenantId, String tenantDomain) throws SQLException, IdentityProviderManagementException { List<IdentityProvider> tenantIdPs = getIdPs(conn, tenantId, tenantDomain); if (!tenantIdPs.isEmpty()) { PreparedStatement prepStmt = null; try { String sqlStmt = IdPManagementConstants.SQLQueries.SWITCH_IDP_PRIMARY_ON_DELETE_SQL; prepStmt = conn.prepareStatement(sqlStmt); prepStmt.setString(1, IdPManagementConstants.IS_TRUE_VALUE); prepStmt.setInt(2, tenantId); prepStmt.setString(3, tenantIdPs.get(0).getIdentityProviderName()); prepStmt.setString(4, IdPManagementConstants.IS_FALSE_VALUE); prepStmt.executeUpdate(); } finally { IdentityDatabaseUtil.closeStatement(prepStmt); } } else { String msg = "No Identity Providers registered for tenant " + tenantDomain; log.warn(msg); } }
Example #24
Source File: GroupDAO.java From carbon-identity with Apache License 2.0 | 6 votes |
public void removeSCIMGroup(int tenantId, String roleName) throws IdentitySCIMException { Connection connection = IdentityDatabaseUtil.getDBConnection(); PreparedStatement prepStmt = null; try { prepStmt = connection.prepareStatement(SQLQueries.DELETE_GROUP_SQL); prepStmt.setInt(1, tenantId); prepStmt.setString(2, SCIMCommonUtils.getGroupNameWithDomain(roleName)); prepStmt.execute(); connection.commit(); } catch (SQLException e) { log.error("Error when executing the SQL : " + SQLQueries.DELETE_GROUP_SQL); throw new IdentitySCIMException("Error deleting the SCIM Group.", e); } finally { IdentityDatabaseUtil.closeAllConnections(connection, null, prepStmt); } }
Example #25
Source File: TokenMgtDAO.java From carbon-identity with Apache License 2.0 | 6 votes |
public void renameUserStoreDomainInAccessTokenTable(int tenantId, String currentUserStoreDomain, String newUserStoreDomain) throws IdentityOAuth2Exception { //we do not support access token partitioning here Connection connection = IdentityDatabaseUtil.getDBConnection(); PreparedStatement ps = null; try { String sqlQuery = SQLQueries.RENAME_USER_STORE_IN_ACCESS_TOKENS_TABLE; ps = connection.prepareStatement(sqlQuery); ps.setString(1, newUserStoreDomain.toUpperCase()); ps.setInt(2, tenantId); ps.setString(3, currentUserStoreDomain.toUpperCase()); int count = ps.executeUpdate(); if (log.isDebugEnabled()) { log.debug("Number of rows being updated : " + count); } connection.commit(); } catch (SQLException e) { IdentityDatabaseUtil.rollBack(connection); throw new IdentityOAuth2Exception("Error occurred while renaming user store : " + currentUserStoreDomain + " in tenant :" + tenantId, e); } finally { IdentityDatabaseUtil.closeAllConnections(connection, null, ps); } }
Example #26
Source File: IdPManagementDAO.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
/** * @param newProvisioningConnectorConfigs * @param dbConnection * @param idpId * @throws IdentityProviderManagementException * @throws SQLException */ private void updateProvisioningConnectorConfigs( ProvisioningConnectorConfig[] newProvisioningConnectorConfigs, Connection dbConnection, int idpId, int tenantId) throws IdentityProviderManagementException, SQLException { PreparedStatement prepStmt = null; ResultSet rs = null; try { deleteProvisioningConnectorConfigs(dbConnection, idpId); if (newProvisioningConnectorConfigs != null && newProvisioningConnectorConfigs.length > 0) { addProvisioningConnectorConfigs(newProvisioningConnectorConfigs, dbConnection, idpId, tenantId); } } finally { IdentityDatabaseUtil.closeAllConnections(null, rs, prepStmt); } }
Example #27
Source File: UserIdentityMetadataStore.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
/** * Stores identity data. * * @param metadata * @throws IdentityException */ public void storeMetadata(IdentityMetadataDO metadata) throws IdentityException { Connection connection = IdentityDatabaseUtil.getDBConnection(); PreparedStatement prepStmt = null; try { prepStmt = connection.prepareStatement(SQLQuery.STORE_META_DATA); prepStmt.setString(1, metadata.getUserName()); prepStmt.setInt(2, metadata.getTenantId()); prepStmt.setString(3, metadata.getMetadataType()); prepStmt.setString(4, metadata.getMetadata()); prepStmt.setString(5, Boolean.toString(metadata.isValid())); prepStmt.execute(); IdentityDatabaseUtil.commitTransaction(connection); } catch (SQLException e) { IdentityDatabaseUtil.rollbackTransaction(connection); throw IdentityException.error("Error while storing user identity data", e); } finally { IdentityDatabaseUtil.closeStatement(prepStmt); IdentityDatabaseUtil.closeConnection(connection); } }
Example #28
Source File: WorkflowRequestDAO.java From carbon-identity with Apache License 2.0 | 6 votes |
/** * update last updated time of a request * * @param requestId * @throws InternalWorkflowException */ public void updateLastUpdatedTimeOfRequest(String requestId) throws InternalWorkflowException { Connection connection = IdentityDatabaseUtil.getDBConnection(); PreparedStatement prepStmt = null; String query = SQLConstants.UPDATE_UPDATED_AT_OF_REQUEST; try { prepStmt = connection.prepareStatement(query); prepStmt.setTimestamp(1, new Timestamp(System.currentTimeMillis())); prepStmt.setString(2, requestId); prepStmt.execute(); connection.commit(); } catch (SQLException e) { throw new InternalWorkflowException("Error when executing the sql query:" + query, e); } finally { IdentityDatabaseUtil.closeAllConnections(connection, null, prepStmt); } }
Example #29
Source File: IdPManagementDAO.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
public void renameTenantRole(String newRoleName, String oldRoleName, int tenantId, String tenantDomain) throws IdentityProviderManagementException { Connection dbConnection = IdentityDatabaseUtil.getDBConnection(); PreparedStatement prepStmt = null; try { String sqlStmt = IdPManagementConstants.SQLQueries.RENAME_ROLE_LISTENER_SQL; prepStmt = dbConnection.prepareStatement(sqlStmt); prepStmt.setString(1, newRoleName); prepStmt.setInt(2, tenantId); prepStmt.setString(3, oldRoleName); prepStmt.executeUpdate(); IdentityDatabaseUtil.commitTransaction(dbConnection); } catch (SQLException e) { IdentityDatabaseUtil.rollbackTransaction(dbConnection); throw new IdentityProviderManagementException("Error occurred while renaming tenant role " + oldRoleName + " to " + newRoleName + " of tenant " + tenantDomain, e); } finally { IdentityDatabaseUtil.closeAllConnections(dbConnection, null, prepStmt); } }
Example #30
Source File: IdPManagementDAO.java From carbon-identity-framework with Apache License 2.0 | 6 votes |
/** * @param newClaimURI * @param oldClaimURI * @param tenantId * @param tenantDomain * @throws IdentityProviderManagementException */ public void renameClaimURI(String newClaimURI, String oldClaimURI, int tenantId, String tenantDomain) throws IdentityProviderManagementException { Connection dbConnection = IdentityDatabaseUtil.getDBConnection(); ; PreparedStatement prepStmt = null; try { String sqlStmt = IdPManagementConstants.SQLQueries.RENAME_CLAIM_SQL; prepStmt = dbConnection.prepareStatement(sqlStmt); prepStmt.setString(1, newClaimURI); prepStmt.setInt(2, tenantId); prepStmt.setString(3, oldClaimURI); prepStmt.executeUpdate(); IdentityDatabaseUtil.commitTransaction(dbConnection); } catch (SQLException e) { IdentityDatabaseUtil.rollbackTransaction(dbConnection); throw new IdentityProviderManagementException("Error occurred while renaming tenant role " + oldClaimURI + " to " + newClaimURI + " of tenant " + tenantDomain, e); } finally { IdentityDatabaseUtil.closeAllConnections(dbConnection, null, prepStmt); } }