Skip to content
This repository has been archived by the owner on Oct 5, 2021. It is now read-only.

Commit

Permalink
fixing IDENTITY-2938
Browse files Browse the repository at this point in the history
  • Loading branch information
hpmtissera committed May 21, 2015
1 parent c3d4388 commit b80955c
Show file tree
Hide file tree
Showing 17 changed files with 73 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1969,6 +1969,7 @@ public ApplicationBasicInfo[] getAllApplicationBasicInfo()
}
}
}
connection.commit();
} catch (SQLException | IdentityException e) {
throw new IdentityApplicationManagementException("Error while Reading all Applications");
} finally {
Expand Down Expand Up @@ -2273,6 +2274,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 {
Expand Down Expand Up @@ -2331,7 +2333,7 @@ private Map<String, String> 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 {
Expand Down Expand Up @@ -2398,12 +2400,12 @@ public List<String> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,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 {
Expand All @@ -126,10 +123,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 {
Expand All @@ -153,10 +147,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 {
Expand Down Expand Up @@ -201,12 +192,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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,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);
Expand All @@ -76,7 +75,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);
Expand Down Expand Up @@ -173,6 +171,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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,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);
Expand Down Expand Up @@ -185,6 +184,7 @@ 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);
Expand Down Expand Up @@ -219,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);
Expand Down Expand Up @@ -255,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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public List<IdentityProvider> getIdPs(Connection dbConnection, int tenantId, Str
idps.add(identityProvider);
}
}
dbConnection.commit();
return idps;
} catch (SQLException | IdentityException e) {
log.error(e.getMessage(), e);
Expand Down Expand Up @@ -996,6 +997,7 @@ public IdentityProvider getIdPByName(Connection dbConnection, String idPName, in
dbConnection, idPName, idpId, tenantId));

}
dbConnection.commit();
return federatedIdp;
} catch (SQLException | IdentityException e) {
IdentityApplicationManagementUtil.rollBack(dbConnection);
Expand Down Expand Up @@ -1145,6 +1147,7 @@ public IdentityProvider getIdPByAuthenticatorPropertyValue(Connection dbConnecti
dbConnection, idPName, idpId, tenantId));

}
dbConnection.commit();
return federatedIdp;
} catch (SQLException | IdentityException e) {
IdentityApplicationManagementUtil.rollBack(dbConnection);
Expand Down Expand Up @@ -1189,6 +1192,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(
Expand Down Expand Up @@ -1574,6 +1578,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 ";
Expand Down Expand Up @@ -1653,6 +1658,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));
Expand Down Expand Up @@ -2357,6 +2363,7 @@ private int getIdentityProviderIdByName(Connection dbConnection, String idpName,
if (rs.next()) {
return rs.getInt(1);
}
dbConnection.commit();
} catch (IdentityException e) {
throw new IdentityApplicationManagementException("Error occurred while reading Identity Provider by name" +
".", e);
Expand Down Expand Up @@ -2459,6 +2466,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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ public void addOAuthApplication(OAuthAppDO consumerAppDO) throws IdentityOAuthAd
prepStmt.setString(8, consumerAppDO.getGrantTypes());
prepStmt.execute();
connection.commit();

} catch (IdentityException e) {
String errorMsg = "Error when getting an Identity Persistence Store instance.";
log.error(errorMsg, e);
Expand Down Expand Up @@ -123,9 +122,7 @@ public String[] addOAuthConsumer(String username, int tenantId) throws IdentityO
// it is assumed that the OAuth version is 1.0a because this is required with OAuth 1.0a
prepStmt.setString(5, OAuthConstants.OAuthVersions.VERSION_1A);
prepStmt.execute();

connection.commit();

} catch (IdentityException e) {
String errorMsg = "Error when getting an Identity Persistence Store instance.";
log.error(errorMsg, e);
Expand Down Expand Up @@ -174,6 +171,7 @@ public OAuthAppDO[] getOAuthConsumerAppsOfUser(String username, int tenantId) th
}
}
oauthAppsOfUser = oauthApps.toArray(new OAuthAppDO[oauthApps.size()]);
connection.commit();
} catch (IdentityException e) {
String errorMsg = "Error when getting an Identity Persistence Store instance.";
log.error(errorMsg, e);
Expand Down Expand Up @@ -239,10 +237,8 @@ public OAuthAppDO getAppInformation(String consumerKey) throws InvalidOAuthClien
log.debug(message);
throw new InvalidOAuthClientException(message);
}
} catch (IdentityException e) {
log.debug(e.getMessage(), e);
throw new IdentityOAuth2Exception(e.getMessage());
} catch (SQLException e) {
connection.commit();
} catch (IdentityException | SQLException e) {
log.debug(e.getMessage(), e);
throw new IdentityOAuth2Exception(e.getMessage());
} finally {
Expand Down Expand Up @@ -302,10 +298,8 @@ public OAuthAppDO getAppInformationByAppName(String appName) throws InvalidOAuth
log.debug(message);
throw new InvalidOAuthClientException(message);
}
} catch (IdentityException e) {
log.debug(e.getMessage(), e);
throw new IdentityOAuth2Exception(e.getMessage());
} catch (SQLException e) {
connection.commit();
} catch (IdentityException | SQLException e) {
log.debug(e.getMessage(), e);
throw new IdentityOAuth2Exception(e.getMessage());
} finally {
Expand Down Expand Up @@ -389,6 +383,7 @@ private boolean isDuplicateApplication(String username, int tenantId, OAuthAppDO
if (rSet.next()) {
isDuplicateApp = true;
}
connection.commit();
} catch (IdentityException e) {
String errorMsg = "Error when getting an Identity Persistence Store instance.";
log.error(errorMsg, e);
Expand Down Expand Up @@ -419,6 +414,7 @@ private boolean isDuplicateConsumer(String consumerKey) throws IdentityOAuthAdmi
if (rSet.next()) {
isDuplicateConsumer = true;
}
connection.commit();
} catch (IdentityException e) {
String errorMsg = "Error when getting an Identity Persistence Store instance.";
log.error(errorMsg, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -167,6 +169,7 @@ 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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Loading

0 comments on commit b80955c

Please sign in to comment.