diff --git a/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/dao/impl/ApplicationDAOImpl.java b/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/dao/impl/ApplicationDAOImpl.java index a090874f93..70ba103373 100644 --- a/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/dao/impl/ApplicationDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/dao/impl/ApplicationDAOImpl.java @@ -2038,6 +2038,7 @@ public ApplicationBasicInfo[] getAllApplicationBasicInfo() } } } + connection.commit(); } catch (SQLException | IdentityException e) { throw new IdentityApplicationManagementException("Error while Reading all Applications"); } finally { @@ -2412,6 +2413,7 @@ public String getServiceProviderNameByClientId(String clientId, String clientTyp if (appNameResult.next()) { applicationName = appNameResult.getString(1); } + connection.commit(); } catch (SQLException | IdentityException e) { throw new IdentityApplicationManagementException("Error while reading application"); } finally { @@ -2470,7 +2472,7 @@ private Map getClaimMapping(String serviceProviderName, String t claimMapping.put(resultSet.getString(2), resultSet.getString(1)); } } - + connection.commit(); } catch (IdentityException e) { throw new IdentityApplicationManagementException("Error while reading claim mappings.", e); } finally { @@ -2537,12 +2539,12 @@ public List getAllRequestedClaimsByServiceProvider(String serviceProvide getClaimPreStmt.setString(1, CharacterEncoder.getSafeText(serviceProviderName)); getClaimPreStmt.setInt(2, tenantID); resultSet = getClaimPreStmt.executeQuery(); - while (resultSet.next()) { if ("1".equalsIgnoreCase(resultSet.getString(3))) { reqClaimUris.add(resultSet.getString(1)); } } + connection.commit(); } catch (SQLException | IdentityException e) { throw new IdentityApplicationManagementException( "Error while retrieving requested claims", e); diff --git a/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/dao/impl/OAuthApplicationDAOImpl.java b/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/dao/impl/OAuthApplicationDAOImpl.java index b8a7c36ffd..a11f0e911c 100644 --- a/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/dao/impl/OAuthApplicationDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/dao/impl/OAuthApplicationDAOImpl.java @@ -49,7 +49,6 @@ public void removeOAuthApplication(String clientIdentifier) throws IdentityAppli prepStmt.setString(1, clientIdentifier); prepStmt.execute(); connection.commit(); - } catch (IdentityException e) { String errorMsg = "Error when getting an Identity Persistence Store instance."; log.error(errorMsg, e); diff --git a/components/identity-mgt/org.wso2.carbon.identity.mgt/src/main/java/org/wso2/carbon/identity/mgt/store/JDBCIdentityDataStore.java b/components/identity-mgt/org.wso2.carbon.identity.mgt/src/main/java/org/wso2/carbon/identity/mgt/store/JDBCIdentityDataStore.java index 29918d3873..8ab1e728c5 100644 --- a/components/identity-mgt/org.wso2.carbon.identity.mgt/src/main/java/org/wso2/carbon/identity/mgt/store/JDBCIdentityDataStore.java +++ b/components/identity-mgt/org.wso2.carbon.identity.mgt/src/main/java/org/wso2/carbon/identity/mgt/store/JDBCIdentityDataStore.java @@ -100,10 +100,7 @@ private boolean isExistingUserDataValue(String userName, int tenantId, String ke return true; } connection.commit(); - } catch (SQLException e) { - log.error("Error while retrieving user identity data in database", e); - throw new IdentityException("Error while retrieving user identity data in database", e); - } catch (IdentityException e) { + } catch (SQLException | IdentityException e) { log.error("Error while retrieving user identity data in database", e); throw new IdentityException("Error while retrieving user identity data in database", e); } finally { @@ -128,10 +125,7 @@ private void addUserDataValue(String userName, int tenantId, String key, String prepStmt.setString(4, value); prepStmt.execute(); connection.commit(); - } catch (SQLException e) { - log.error("Error while persisting user identity data in database", e); - throw new IdentityException("Error while persisting user identity data in database", e); - } catch (IdentityException e) { + } catch (SQLException | IdentityException e) { log.error("Error while persisting user identity data in database", e); throw new IdentityException("Error while persisting user identity data in database", e); } finally { @@ -155,10 +149,7 @@ private void updateUserDataValue(String userName, int tenantId, String key, Stri prepStmt.setString(4, key); prepStmt.executeUpdate(); connection.commit(); - } catch (SQLException e) { - log.error("Error while persisting user identity data in database", e); - throw new IdentityException("Error while persisting user identity data in database", e); - } catch (IdentityException e) { + } catch (SQLException | IdentityException e) { log.error("Error while persisting user identity data in database", e); throw new IdentityException("Error while persisting user identity data in database", e); } finally { @@ -203,12 +194,9 @@ public UserIdentityClaimsDO load(String userName, UserStoreManager userStoreMana } dto = new UserIdentityClaimsDO(userName, data); dto.setTenantId(tenantId); + connection.commit(); return dto; - } catch (SQLException e) { - log.error("Error while reading user identity data", e); - } catch (UserStoreException e) { - log.error("Error while reading user identity data", e); - } catch (IdentityException e) { + } catch (SQLException | IdentityException | UserStoreException e) { log.error("Error while reading user identity data", e); } finally { IdentityDatabaseUtil.closeResultSet(results); diff --git a/components/identity-mgt/org.wso2.carbon.identity.mgt/src/main/java/org/wso2/carbon/identity/mgt/store/JDBCUserRecoveryDataStore.java b/components/identity-mgt/org.wso2.carbon.identity.mgt/src/main/java/org/wso2/carbon/identity/mgt/store/JDBCUserRecoveryDataStore.java index f803022567..aeb780e68a 100644 --- a/components/identity-mgt/org.wso2.carbon.identity.mgt/src/main/java/org/wso2/carbon/identity/mgt/store/JDBCUserRecoveryDataStore.java +++ b/components/identity-mgt/org.wso2.carbon.identity.mgt/src/main/java/org/wso2/carbon/identity/mgt/store/JDBCUserRecoveryDataStore.java @@ -56,7 +56,6 @@ public void invalidate(UserRecoveryDataDO recoveryDataDO) throws IdentityExcepti prepStmt.setInt(2, recoveryDataDO.getTenantId()); prepStmt.setString(3, recoveryDataDO.getCode()); prepStmt.execute(); - connection.setAutoCommit(false); connection.commit(); } catch (SQLException e) { throw new IdentityException("Error while storing user identity data", e); @@ -79,7 +78,6 @@ public void invalidate(String userId, int tenant) throws IdentityException { prepStmt = connection.prepareStatement(SQLQuery.INVALIDATE_METADATA); prepStmt.setString(1, userId); prepStmt.setInt(2, tenant); - connection.setAutoCommit(false); connection.commit(); } catch (SQLException e) { throw new IdentityException("Error while invalidating user identity data", e); @@ -179,6 +177,7 @@ public UserRecoveryDataDO[] load(String userName, int tenantId) throws IdentityE results.getString(3), results.getString(4))); } UserRecoveryDataDO[] resultMetadata = new UserRecoveryDataDO[metada.size()]; + connection.commit(); return metada.toArray(resultMetadata); } catch (SQLException e) { throw new IdentityException("Error while reading user identity data", e); diff --git a/components/identity-mgt/org.wso2.carbon.identity.mgt/src/main/java/org/wso2/carbon/identity/mgt/store/UserIdentityMetadataStore.java b/components/identity-mgt/org.wso2.carbon.identity.mgt/src/main/java/org/wso2/carbon/identity/mgt/store/UserIdentityMetadataStore.java index 2c810b0940..892f4495f7 100644 --- a/components/identity-mgt/org.wso2.carbon.identity.mgt/src/main/java/org/wso2/carbon/identity/mgt/store/UserIdentityMetadataStore.java +++ b/components/identity-mgt/org.wso2.carbon.identity.mgt/src/main/java/org/wso2/carbon/identity/mgt/store/UserIdentityMetadataStore.java @@ -112,7 +112,6 @@ public void storeMetadata(IdentityMetadataDO metadata) throws IdentityException prepStmt.setString(4, metadata.getMetadata()); prepStmt.setString(5, Boolean.toString(metadata.isValid())); prepStmt.execute(); - connection.setAutoCommit(false); connection.commit(); } catch (SQLException e) { throw new IdentityException("Error while storing user identity data", e); @@ -177,7 +176,7 @@ public IdentityMetadataDO loadMetadata(String userName, int tenantId, String met prepStmt.setString(3, metadataType); prepStmt.setString(4, metadata); results = prepStmt.executeQuery(); - + connection.commit(); if (results.next()) { return new IdentityMetadataDO(results.getString(1), results.getInt(2), results.getString(3), results.getString(4), @@ -220,6 +219,7 @@ public IdentityMetadataDO[] loadMetadata(String userName, int tenantId) Boolean.parseBoolean(results.getString(5)))); } IdentityMetadataDO[] resultMetadata = new IdentityMetadataDO[metada.size()]; + connection.commit(); return metada.toArray(resultMetadata); } catch (SQLException e) { throw new IdentityException("Error while reading user identity data", e); @@ -256,6 +256,7 @@ public IdentityMetadataDO[] loadMetadata(String userName, int tenantId, String m Boolean.parseBoolean(results.getString(5)))); } IdentityMetadataDO[] resultMetadata = new IdentityMetadataDO[metada.size()]; + connection.commit(); return metada.toArray(resultMetadata); } catch (SQLException e) { throw new IdentityException("Error while reading user identity data", e); diff --git a/components/idp-mgt/org.wso2.carbon.idp.mgt/src/main/java/org/wso2/carbon/idp/mgt/dao/IdPManagementDAO.java b/components/idp-mgt/org.wso2.carbon.idp.mgt/src/main/java/org/wso2/carbon/idp/mgt/dao/IdPManagementDAO.java index e77606d324..5fd29349cc 100644 --- a/components/idp-mgt/org.wso2.carbon.idp.mgt/src/main/java/org/wso2/carbon/idp/mgt/dao/IdPManagementDAO.java +++ b/components/idp-mgt/org.wso2.carbon.idp.mgt/src/main/java/org/wso2/carbon/idp/mgt/dao/IdPManagementDAO.java @@ -124,6 +124,7 @@ public List getIdPs(Connection dbConnection, int tenantId, Str idps.add(identityProvider); } } + dbConnection.commit(); return idps; } catch (SQLException | IdentityException e) { log.error(e.getMessage(), e); @@ -1020,6 +1021,7 @@ public IdentityProvider getIdPByName(Connection dbConnection, String idPName, in dbConnection, idPName, idpId, tenantId)); } + dbConnection.commit(); return federatedIdp; } catch (SQLException | IdentityException e) { IdentityApplicationManagementUtil.rollBack(dbConnection); @@ -1169,6 +1171,7 @@ public IdentityProvider getIdPByAuthenticatorPropertyValue(Connection dbConnecti dbConnection, idPName, idpId, tenantId)); } + dbConnection.commit(); return federatedIdp; } catch (SQLException | IdentityException e) { IdentityApplicationManagementUtil.rollBack(dbConnection); @@ -1213,6 +1216,7 @@ public IdentityProvider getIdPByRealmId(String realmId, int tenantId, String ten IdentityApplicationManagementUtil.closeStatement(prepStmt); IdentityApplicationManagementUtil.closeResultSet(rs); + dbConnection.commit(); return getIdPByName(dbConnection, idPName, tenantId, tenantDomain); } catch (SQLException | IdentityException e) { throw new IdentityApplicationManagementException( @@ -1602,6 +1606,7 @@ public boolean isIdpReferredBySP(String idPName, int tenantId) isReffered = rsProvIdp.getInt(1) > 0; } } + dbConnection.commit(); } catch (SQLException | IdentityException e) { log.error(e.getMessage(), e); String msg = "Error occurred while searching for IDP references in SP "; @@ -1681,6 +1686,7 @@ public IdentityProvider getPrimaryIdP(Connection dbConnection, int tenantId, Str prepStmt.setInt(1, tenantId); prepStmt.setString(2, "1"); ResultSet rs = prepStmt.executeQuery(); + dbConnection.commit(); if (rs.next()) { IdentityProvider identityProviderDO = new IdentityProvider(); identityProviderDO.setIdentityProviderName(rs.getString(1)); @@ -2384,6 +2390,7 @@ private int getIdentityProviderIdByName(Connection dbConnection, String idpName, prepStmt.setInt(2, MultitenantConstants.SUPER_TENANT_ID); prepStmt.setString(3, CharacterEncoder.getSafeText(idpName)); rs = prepStmt.executeQuery(); + dbConnection.commit(); if (rs.next()) { return rs.getInt(1); } @@ -2489,6 +2496,7 @@ public boolean isSimilarIdPEntityIdsAvailble(String idPEntityId, int tenantId) if (rs.next()) { isAvailable = rs.getInt(1) > 0; } + dbConnection.commit(); } catch (SQLException | IdentityException e) { log.error(e.getMessage(), e); String msg = "Error occurred while searching for similar IdP EntityIds"; diff --git a/components/oauth/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth/dao/OAuthAppDAO.java b/components/oauth/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth/dao/OAuthAppDAO.java index b299b7c1a8..6fe95f2eeb 100644 --- a/components/oauth/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth/dao/OAuthAppDAO.java +++ b/components/oauth/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth/dao/OAuthAppDAO.java @@ -167,6 +167,7 @@ public OAuthAppDO[] getOAuthConsumerAppsOfUser(String username, int tenantId) th } } oauthAppsOfUser = oauthApps.toArray(new OAuthAppDO[oauthApps.size()]); + connection.commit(); } catch (IdentityException e) { throw new IdentityOAuthAdminException("Error when getting an Identity Persistence Store instance.", e); } catch (SQLException e) { @@ -223,6 +224,7 @@ public OAuthAppDO getAppInformation(String consumerKey) throws InvalidOAuthClien throw new InvalidOAuthClientException("Cannot find an application associated with the given consumer key : " + consumerKey); } + connection.commit(); } catch (IdentityException e) { throw new IdentityOAuth2Exception("Error while retrieving database connection" ,e); } catch (SQLException e) { @@ -280,6 +282,7 @@ public OAuthAppDO getAppInformationByAppName(String appName) throws InvalidOAuth log.debug(message); throw new InvalidOAuthClientException(message); } + connection.commit(); } catch (IdentityException e) { throw new IdentityOAuth2Exception("Error while retrieving database connection", e); } catch (SQLException e) { @@ -357,6 +360,7 @@ private boolean isDuplicateApplication(String username, int tenantId, OAuthAppDO if (rSet.next()) { isDuplicateApp = true; } + connection.commit(); } catch (IdentityException e) { throw new IdentityOAuthAdminException("Error when getting an Identity Persistence Store instance.", e); } catch (SQLException e) { @@ -383,6 +387,7 @@ private boolean isDuplicateConsumer(String consumerKey) throws IdentityOAuthAdmi if (rSet.next()) { isDuplicateConsumer = true; } + connection.commit(); } catch (IdentityException e) { throw new IdentityOAuthAdminException("Error when getting an Identity Persistence Store instance.", e); } catch (SQLException e) { diff --git a/components/oauth/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth/dao/OAuthConsumerDAO.java b/components/oauth/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth/dao/OAuthConsumerDAO.java index b34b848325..e88a72ca53 100644 --- a/components/oauth/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth/dao/OAuthConsumerDAO.java +++ b/components/oauth/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth/dao/OAuthConsumerDAO.java @@ -75,6 +75,7 @@ public String getOAuthConsumerSecret(String consumerKey) throws IdentityOAuthAdm } else { log.debug("Invalid Consumer Key : " + consumerKey); } + connection.commit(); } catch (IdentityException e) { String errorMsg = "Error when getting an Identity Persistence Store instance."; log.error(errorMsg, e); @@ -117,6 +118,7 @@ public String getAuthenticatedUsername(String clientId, String clientSecret) thr } else { log.debug("Invalid client id : " + clientId + ", and consumer secret : " + clientSecret); } + connection.commit(); } catch (IdentityException e) { String errorMsg = "Error when getting an Identity Persistence Store instance."; log.error(errorMsg, e); @@ -160,6 +162,7 @@ public String getOAuthTokenSecret(String token, Boolean isAccessToken) throws Id prepStmt = connection.prepareStatement(sqlStmt); prepStmt.setString(1, token); resultSet = prepStmt.executeQuery(); + connection.commit(); if (resultSet.next()) { tokenSecret = resultSet.getString(1); @@ -298,7 +301,7 @@ public Parameters getRequestToken(String oauthToken) throws IdentityOAuthAdminEx log.error("Invalid request token : " + oauthToken); throw new IdentityException("Invalid request token. No such token issued."); } - + connection.commit(); } catch (IdentityException e) { String errorMsg = "Error when getting an Identity Persistence Store instance."; log.error(errorMsg, e); @@ -381,6 +384,7 @@ public String validateAccessToken(String consumerKey, String oauthToken, String } else { throw new IdentityException("Invalid access token. No such token issued."); } + connection.commit(); } catch (IdentityException e) { String errorMsg = "Error when getting an Identity Persistence Store instance."; log.error(errorMsg, e); @@ -415,6 +419,7 @@ private String getCallbackURLOfApp(String consumerKey) throws IdentityOAuthAdmin if (resultSet.next()) { callbackURL = resultSet.getString(1); } + connection.commit(); } catch (IdentityException e) { String errorMsg = "Error when getting an Identity Persistence Store instance."; log.error(errorMsg, e); @@ -445,6 +450,7 @@ private String getCallbackURLOfReqToken(String oauthToken) throws IdentityOAuthA if (resultSet.next()) { callbackURL = resultSet.getString(1); } + connection.commit(); } catch (IdentityException e) { String errorMsg = "Error when getting an Identity Persistence Store instance."; log.error(errorMsg, e); diff --git a/components/oauth/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth2/dao/TokenMgtDAO.java b/components/oauth/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth2/dao/TokenMgtDAO.java index be4347609f..8b58d51cc9 100644 --- a/components/oauth/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth2/dao/TokenMgtDAO.java +++ b/components/oauth/org.wso2.carbon.identity.oauth/src/main/java/org/wso2/carbon/identity/oauth2/dao/TokenMgtDAO.java @@ -301,7 +301,8 @@ public AccessTokenDO retrieveLatestAccessToken(String consumerKey, String userNa prepStmt.setString(3, scope); } resultSet = prepStmt.executeQuery(); - + connection.commit(); + if (resultSet.next()) { boolean returnToken = false; String tokenState = resultSet.getString(7); @@ -360,7 +361,7 @@ public Set retrieveAccessTokens(String consumerKey, String userNa Set accessTokenDOs = new HashSet(); - Connection connection = null; + Connection connection; try { connection = JDBCPersistenceManager.getInstance().getDBConnection(); } catch (IdentityException e) { @@ -404,6 +405,7 @@ public Set retrieveAccessTokens(String consumerKey, String userNa accessTokenDOs.add(dataDO); } + connection.commit(); } catch (IdentityException e) { String errorMsg = "Error when getting an Identity Persistence Store instance"; throw new IdentityOAuth2Exception(errorMsg, e); @@ -446,7 +448,7 @@ public AuthzCodeDO validateAuthorizationCode(String consumerKey, String authoriz OAuth2Util.buildScopeArray(scopeString), issuedTime, validityPeriod, callbackUrl); } - + connection.commit(); } catch (IdentityException e) { String errorMsg = "Error when getting an Identity Persistence Store instance."; log.error(errorMsg, e); @@ -576,7 +578,7 @@ public RefreshTokenValidationDataDO validateRefreshToken(String consumerKey, Str ("UTC")))); validationDataDO.setValidityPeriodInMillis(resultSet.getLong(6)); } - + connection.commit(); } catch (IdentityException e) { String errorMsg = "Error when getting an Identity Persistence Store instance."; log.error(errorMsg, e); @@ -683,7 +685,7 @@ public AccessTokenDO retrieveAccessToken(String accessTokenIdentifier, boolean i dataDO.setAccessToken(accessTokenIdentifier); dataDO.setRefreshToken(refreshToken); } - + connection.commit(); } catch (IdentityException e) { String errorMsg = "Error when getting an Identity Persistence Store instance"; throw new IdentityOAuth2Exception(errorMsg, e); @@ -862,6 +864,7 @@ public String findScopeOfResource(String resourceUri) throws IdentityOAuth2Excep if (rs.next()) { return rs.getString("SCOPE_KEY"); } + connection.commit(); return null; } catch (IdentityException e) { String errorMsg = "Error when getting an Identity Persistence Store instance."; diff --git a/components/openid/org.wso2.carbon.identity.provider/src/main/java/org/wso2/carbon/identity/provider/openid/dao/OpenIDAssociationDAO.java b/components/openid/org.wso2.carbon.identity.provider/src/main/java/org/wso2/carbon/identity/provider/openid/dao/OpenIDAssociationDAO.java index 55bd081018..19bf8791b4 100644 --- a/components/openid/org.wso2.carbon.identity.provider/src/main/java/org/wso2/carbon/identity/provider/openid/dao/OpenIDAssociationDAO.java +++ b/components/openid/org.wso2.carbon.identity.provider/src/main/java/org/wso2/carbon/identity/provider/openid/dao/OpenIDAssociationDAO.java @@ -80,11 +80,8 @@ public synchronized void storeAssociation(Association association) { } else { log.debug("Association " + association.getHandle() + " already exist in the databse."); } - - } catch (SQLException e) { - log.error("Failed to store the association " + association.getHandle() + - ". Error while accessing the database. ", e); - } catch (IdentityException e) { + connection.commit(); + } catch (SQLException | IdentityException e) { log.error("Failed to store the association " + association.getHandle() + ". Error while accessing the database. ", e); } finally { @@ -115,11 +112,10 @@ public synchronized Association loadAssociation(String handle) { log.debug("Loading association " + handle); return buildAssociationObject(results); } - - } catch (SQLException e) { - log.error("Failed to load the association " + handle + ". Error while accessing the database. ", e); - } catch (IdentityException e) { - log.error("Failed to load the association " + handle + ". Error while accessing the database. ", e); + connection.commit(); + } catch (SQLException | IdentityException e) { + log.error("Failed to load the association " + handle + + ". Error while accessing the database. ", e); } finally { IdentityDatabaseUtil.closeAllConnections(connection, results, prepStmt); } diff --git a/components/openid/org.wso2.carbon.identity.provider/src/main/java/org/wso2/carbon/identity/provider/openid/dao/OpenIDRememberMeTokenDAO.java b/components/openid/org.wso2.carbon.identity.provider/src/main/java/org/wso2/carbon/identity/provider/openid/dao/OpenIDRememberMeTokenDAO.java index bd3d549123..e20e2cc716 100644 --- a/components/openid/org.wso2.carbon.identity.provider/src/main/java/org/wso2/carbon/identity/provider/openid/dao/OpenIDRememberMeTokenDAO.java +++ b/components/openid/org.wso2.carbon.identity.provider/src/main/java/org/wso2/carbon/identity/provider/openid/dao/OpenIDRememberMeTokenDAO.java @@ -72,13 +72,9 @@ public void updateTokenData(OpenIDRememberMeDO rememberMe) throws IdentityProvid log.debug("RememberMe token of " + rememberMe.getUserName() + " successfully stored in the database."); } - } catch (SQLException e) { - log.error("Unable to update the token for " + rememberMe.getUserName() + - " Error while accessing the database", e); - throw new IdentityProviderException("Error while accessing the database"); - } catch (IdentityException e) { + } catch (SQLException | IdentityException e) { log.error("Unable to update the token for " + rememberMe.getUserName() + - " Error while accessing the database", e); + " Error while accessing the database", e); throw new IdentityProviderException("Error while accessing the database"); } finally { IdentityDatabaseUtil.closeStatement(prepStmt); @@ -103,8 +99,10 @@ public OpenIDRememberMeDO getTokenData(OpenIDRememberMeDO rememberMe) throws Ide prepStmt.setString(1, rememberMe.getUserName()); prepStmt.setInt(2, IdentityUtil.getTenantIdOFUser(rememberMe.getUserName())); - return buildRememberMeDO(prepStmt.executeQuery(), rememberMe.getUserName()); - + OpenIDRememberMeDO openIDRememberMeDO = buildRememberMeDO(prepStmt.executeQuery() + , rememberMe.getUserName()); + connection.commit(); + return openIDRememberMeDO; } catch (SQLException | IdentityException e) { log.error("Unable to load RememberMe token for " + rememberMe.getUserName() + " Error while accessing the database", e); diff --git a/components/openid/org.wso2.carbon.identity.provider/src/main/java/org/wso2/carbon/identity/provider/openid/dao/OpenIDUserRPDAO.java b/components/openid/org.wso2.carbon.identity.provider/src/main/java/org/wso2/carbon/identity/provider/openid/dao/OpenIDUserRPDAO.java index af546d59b8..5148604d4f 100644 --- a/components/openid/org.wso2.carbon.identity.provider/src/main/java/org/wso2/carbon/identity/provider/openid/dao/OpenIDUserRPDAO.java +++ b/components/openid/org.wso2.carbon.identity.provider/src/main/java/org/wso2/carbon/identity/provider/openid/dao/OpenIDUserRPDAO.java @@ -201,7 +201,9 @@ public OpenIDUserRPDO getOpenIDUserRP(String userName, String rpUrl) throws Iden prepStmt.setString(1, userName); prepStmt.setInt(2, IdentityUtil.getTenantIdOFUser(userName)); prepStmt.setString(3, rpUrl); - return buildUserRPDO(prepStmt.executeQuery(), userName); + OpenIDUserRPDO openIDUserRPDO = buildUserRPDO(prepStmt.executeQuery(), userName); + connection.commit(); + return openIDUserRPDO; } else { log.debug("RP: " + rpUrl + " of user: " + userName + " not found in the database"); } @@ -246,7 +248,7 @@ public OpenIDUserRPDO[] getAllOpenIDUserRP() throws IdentityException { rpDOs = new OpenIDUserRPDO[rpdos.size()]; rpDOs = rpdos.toArray(rpDOs); - + connection.commit(); } catch (SQLException e) { log.error("Error while accessing the database to load RPs.", e); } finally { diff --git a/components/provisioning/org.wso2.carbon.identity.provisioning/src/main/java/org/wso2/carbon/identity/provisioning/dao/ProvisioningManagementDAO.java b/components/provisioning/org.wso2.carbon.identity.provisioning/src/main/java/org/wso2/carbon/identity/provisioning/dao/ProvisioningManagementDAO.java index fe91c047d0..218650b810 100644 --- a/components/provisioning/org.wso2.carbon.identity.provisioning/src/main/java/org/wso2/carbon/identity/provisioning/dao/ProvisioningManagementDAO.java +++ b/components/provisioning/org.wso2.carbon.identity.provisioning/src/main/java/org/wso2/carbon/identity/provisioning/dao/ProvisioningManagementDAO.java @@ -177,6 +177,7 @@ public ProvisionedIdentifier getProvisionedIdentifier(String identityProviderNam ResultSet rs = prepStmt.executeQuery(); + dbConnection.commit(); if (rs.next()) { String entityId = rs.getString(1); ProvisionedIdentifier provisionedIdentifier = new ProvisionedIdentifier(); @@ -364,6 +365,7 @@ private int getIdentityProviderIdByName(Connection dbConnection, String idpName, prepStmt.setInt(1, tenantId); prepStmt.setString(2, idpName); rs = prepStmt.executeQuery(); + dbConnection.commit(); if (rs.next()) { return rs.getInt(1); } diff --git a/components/scim/org.wso2.carbon.identity.scim.common/src/main/java/org/wso2/carbon/identity/scim/common/config/SCIMProviderDAO.java b/components/scim/org.wso2.carbon.identity.scim.common/src/main/java/org/wso2/carbon/identity/scim/common/config/SCIMProviderDAO.java index d272504601..9c28d1ff0c 100644 --- a/components/scim/org.wso2.carbon.identity.scim.common/src/main/java/org/wso2/carbon/identity/scim/common/config/SCIMProviderDAO.java +++ b/components/scim/org.wso2.carbon.identity.scim.common/src/main/java/org/wso2/carbon/identity/scim/common/config/SCIMProviderDAO.java @@ -68,6 +68,7 @@ public List getAllProviders(String consumerId) throws IdentityS scimProviders.add(providerDTO); } } + connection.commit(); } catch (IdentityException e) { String errorMsg = "Error when getting an Identity Persistence Store instance."; log.error(errorMsg, e); @@ -113,6 +114,7 @@ public SCIMProviderDTO getProvider(String consumerId, String providerId) providerDTO.setBulkEPURL(rSet.getString(5)); } } + connection.commit(); } catch (IdentityException e) { String errorMsg = "Error when getting an Identity Persistence Store instance."; log.error(errorMsg, e); @@ -283,6 +285,7 @@ public boolean isExistingProvider(String consumerId, String providerId) if (rSet.next()) { isExistingProvider = true; } + connection.commit(); } catch (IdentityException e) { String errorMsg = "Error when getting an Identity Persistence Store instance."; log.error(errorMsg, e); @@ -313,6 +316,7 @@ public boolean isExistingConsumer(String consumerId) throws IdentitySCIMExceptio if (rSet.next()) { isExistingProvider = true; } + connection.commit(); } catch (IdentityException e) { String errorMsg = "Error when getting an Identity Persistence Store instance."; log.error(errorMsg, e); @@ -342,6 +346,7 @@ public boolean isFirstStartup() throws IdentitySCIMException { if (rSet.next()) { isFirstStartup = false; } + connection.commit(); } catch (IdentityException e) { String errorMsg = "Error when getting an Identity Persistence Store instance."; log.error(errorMsg, e); diff --git a/components/scim/org.wso2.carbon.identity.scim.common/src/main/java/org/wso2/carbon/identity/scim/common/group/GroupDAO.java b/components/scim/org.wso2.carbon.identity.scim.common/src/main/java/org/wso2/carbon/identity/scim/common/group/GroupDAO.java index 47a5862dd7..728860aa8e 100644 --- a/components/scim/org.wso2.carbon.identity.scim.common/src/main/java/org/wso2/carbon/identity/scim/common/group/GroupDAO.java +++ b/components/scim/org.wso2.carbon.identity.scim.common/src/main/java/org/wso2/carbon/identity/scim/common/group/GroupDAO.java @@ -98,6 +98,7 @@ public boolean isExistingGroup(String groupName, int tenantId) throws IdentitySC if (rSet.next()) { isExistingGroup = true; } + connection.commit(); } catch (IdentityException e) { String errorMsg = "Error when getting an Identity Persistence Store instance."; throw new IdentitySCIMException(errorMsg, e); @@ -128,6 +129,7 @@ private boolean isExistingAttribute(String attributeName, String groupName, int if (rSet.next()) { isExistingAttribute = true; } + connection.commit(); } catch (IdentityException e) { String errorMsg = "Error when getting an Identity Persistence Store instance."; throw new IdentitySCIMException(errorMsg, e); @@ -164,7 +166,7 @@ public void addSCIMGroupAttributes(int tenantId, String roleName, Map getSCIMGroupAttributes(int tenantId, String roleName) attributes.put(rSet.getString(1), rSet.getString(2)); } } + connection.commit(); } catch (IdentityException e) { String errorMsg = "Error when getting an Identity Persistence Store instance."; throw new IdentitySCIMException(errorMsg, e); @@ -296,6 +299,7 @@ public String getGroupNameById(int tenantId, String id) throws IdentitySCIMExcep //we assume only one result since group id and tenant id is unique. roleName = rSet.getString(1); } + connection.commit(); } catch (IdentityException e) { String errorMsg = "Error when getting an Identity Persistence Store instance."; throw new IdentitySCIMException(errorMsg, e); diff --git a/components/user-mgt/org.wso2.carbon.identity.user.account.association/src/main/java/org/wso2/carbon/identity/user/account/association/dao/UserAccountAssociationDAO.java b/components/user-mgt/org.wso2.carbon.identity.user.account.association/src/main/java/org/wso2/carbon/identity/user/account/association/dao/UserAccountAssociationDAO.java index 3757b0c69c..165f99083d 100644 --- a/components/user-mgt/org.wso2.carbon.identity.user.account.association/src/main/java/org/wso2/carbon/identity/user/account/association/dao/UserAccountAssociationDAO.java +++ b/components/user-mgt/org.wso2.carbon.identity.user.account.association/src/main/java/org/wso2/carbon/identity/user/account/association/dao/UserAccountAssociationDAO.java @@ -148,6 +148,7 @@ public List getAssociationsOfUser(String domainName, associationDTO.setTenantDomain(realmService.getTenantManager().getDomain(conUserTenantId)); accountAssociations.add(associationDTO); } + dbConnection.commit(); } catch (SQLException e) { throw new UserAccountAssociationServerException(UserAccountAssociationConstants.ErrorMessages .CONN_DELETE_DB_ERROR.getDescription(), e); @@ -190,6 +191,7 @@ public String getAssociationKeyOfUser(String domainName, int tenantId, if (resultSet.next()) { associationKey = resultSet.getString(1); } + dbConnection.commit(); } catch (SQLException e) { throw new UserAccountAssociationServerException(UserAccountAssociationConstants.ErrorMessages .ERROR_WHILE_RETRIEVING_ASSOC_KEY.getDescription @@ -262,6 +264,7 @@ public boolean isValidUserAssociation(String domainName, int tenantId, if (resultSet.next()) { valid = resultSet.getInt(1) > 0; } + dbConnection.commit(); } catch (SQLException e) { throw new UserAccountAssociationServerException(UserAccountAssociationConstants.ErrorMessages .CHECK_ASSOCIATION_DB_ERROR.getDescription(), e); diff --git a/components/user-mgt/org.wso2.carbon.identity.user.profile/src/main/java/org/wso2/carbon/identity/user/profile/mgt/UserProfileAdmin.java b/components/user-mgt/org.wso2.carbon.identity.user.profile/src/main/java/org/wso2/carbon/identity/user/profile/mgt/UserProfileAdmin.java index e12ba1fcf5..8f62b4a88e 100644 --- a/components/user-mgt/org.wso2.carbon.identity.user.profile/src/main/java/org/wso2/carbon/identity/user/profile/mgt/UserProfileAdmin.java +++ b/components/user-mgt/org.wso2.carbon.identity.user.profile/src/main/java/org/wso2/carbon/identity/user/profile/mgt/UserProfileAdmin.java @@ -630,6 +630,8 @@ public String getNameAssociatedWith(String idpID, String associatedID) throws Us prepStmt.setString(4, associatedID); resultSet = prepStmt.executeQuery(); + connection.commit(); + if (resultSet.next()) { String domainName = resultSet.getString(1); username = resultSet.getString(2); @@ -673,6 +675,7 @@ public AssociatedAccountDTO[] getAssociatedIDs() throws UserProfileException { prepStmt.setString(3, domainName); resultSet = prepStmt.executeQuery(); + connection.commit(); while (resultSet.next()) { associatedIDs.add(new AssociatedAccountDTO(resultSet.getString(1), resultSet.getString(2))); }