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 d1fecfe4f6..b1ee346dbf 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 @@ -175,7 +175,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), @@ -184,7 +184,6 @@ public IdentityMetadataDO loadMetadata(String userName, int tenantId, String met if (results.next()) { throw new IdentityException("Duplicate entry found for " + metadataType); } - connection.commit(); return null; } 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 b08a053635..2df9a69bfc 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 @@ -2360,10 +2360,10 @@ 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); } - dbConnection.commit(); } catch (IdentityException e) { throw new IdentityApplicationManagementException("Error occurred while reading Identity Provider by name" + ".", 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 41bf991b80..768ecd0b72 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 @@ -162,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); @@ -169,7 +170,6 @@ public String getOAuthTokenSecret(String token, Boolean isAccessToken) throws Id log.error("Invalid token : " + token); throw new IdentityException("Invalid token. No such token is issued"); } - 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 a087e1fc1b..8c64e240ed 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 @@ -287,6 +287,7 @@ public AccessTokenDO retrieveLatestAccessToken(String consumerKey, String userNa prepStmt.setString(3, scope); } ResultSet resultSet = prepStmt.executeQuery(); + connection.commit(); if (resultSet.next()) { boolean returnToken = false; @@ -323,11 +324,9 @@ public AccessTokenDO retrieveLatestAccessToken(String consumerKey, String userNa accessTokenDO.setAccessToken(accessToken); accessTokenDO.setRefreshToken(refreshToken); accessTokenDO.setTokenState(tokenState); - connection.commit(); return accessTokenDO; } } - connection.commit(); return null; } catch (SQLException e) { String errorMsg = "Error occurred while trying to retrieve latest 'ACTIVE' " + 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 96f129c26f..02e6230197 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 @@ -380,10 +380,10 @@ 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); } - dbConnection.commit(); } catch (IdentityException e) { throw new IdentityApplicationManagementException("Error while reading Identity Provider by name.", e); } finally { 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 5b6fad1aeb..6a3546b1a1 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,13 +630,14 @@ 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); if(!"PRIMARY".equals(domainName)) { username = domainName + CarbonConstants.DOMAIN_SEPARATOR + username; } - connection.commit(); return username; }