Skip to content

Commit

Permalink
Address comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
Thisara-Welmilla committed Dec 11, 2024
1 parent 980a36b commit 3034668
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ public UserDefinedLocalAuthenticatorConfig addUserDefinedLocalAuthenticator(
}
authenticatorValidator.validateAuthenticatorName(authenticatorConfig.getName());
authenticatorValidator.validateForBlank(DISPLAY_NAME, authenticatorConfig.getDisplayName());
authenticatorValidator.validateDefinedByType(authenticatorConfig.getDefinedByType());

return dao.addUserDefinedLocalAuthenticator(
authenticatorConfig, IdentityTenantUtil.getTenantId(tenantDomain));
Expand All @@ -233,7 +232,6 @@ public UserDefinedLocalAuthenticatorConfig updateUserDefinedLocalAuthenticator(

UserDefinedLocalAuthenticatorConfig existingConfig = resolveExistingAuthenticator(
authenticatorConfig.getName(), tenantDomain);
authenticatorValidator.validateDefinedByType(existingConfig.getDefinedByType());
authenticatorValidator.validateForBlank(DISPLAY_NAME, authenticatorConfig.getDisplayName());

return dao.updateUserDefinedLocalAuthenticator(
Expand All @@ -252,7 +250,6 @@ public void deleteUserDefinedLocalAuthenticator(String authenticatorName, String

UserDefinedLocalAuthenticatorConfig existingConfig = resolveExistingAuthenticator(
authenticatorName, tenantDomain);
authenticatorValidator.validateDefinedByType(existingConfig.getDefinedByType());

dao.deleteUserDefinedLocalAuthenticator(authenticatorName, existingConfig,
IdentityTenantUtil.getTenantId(tenantDomain));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.wso2.carbon.database.utils.jdbc.NamedJdbcTemplate;
import org.wso2.carbon.database.utils.jdbc.NamedPreparedStatement;
import org.wso2.carbon.database.utils.jdbc.exceptions.DataAccessException;
import org.wso2.carbon.database.utils.jdbc.exceptions.TransactionException;
import org.wso2.carbon.identity.application.common.constant.AuthenticatorMgtSQLConstants.Column;
import org.wso2.carbon.identity.application.common.constant.AuthenticatorMgtSQLConstants.Query;
import org.wso2.carbon.identity.application.common.dao.AuthenticatorManagementDAO;
Expand Down Expand Up @@ -192,16 +191,14 @@ public void deleteUserDefinedLocalAuthenticator(String authenticatorConfigName,

NamedJdbcTemplate jdbcTemplate = new NamedJdbcTemplate(IdentityDatabaseUtil.getDataSource());
try {
jdbcTemplate.withTransaction(template -> {
return template.executeQuery(Query.DELETE_AUTHENTICATOR_SQL,
(resultSet, rowNumber) -> null,
statement -> {
statement.setString(Column.NAME, authenticatorConfigName);
statement.setInt(Column.TENANT_ID, tenantId);
statement.executeUpdate();
});
});
} catch (TransactionException e) {

jdbcTemplate.executeUpdate(Query.DELETE_AUTHENTICATOR_SQL,
statement -> {
statement.setString(Column.NAME, authenticatorConfigName);
statement.setInt(Column.TENANT_ID, tenantId);
statement.executeUpdate();
});
} catch (DataAccessException e) {
if (LOG.isDebugEnabled()) {
LOG.debug(String.format("Error while deleting the authenticator: %s in tenant domain: %s. " +
"Rolling back deleted Authenticator information.", authenticatorConfigName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public UserDefinedLocalAuthenticatorConfig addUserDefinedLocalAuthenticator(
LOG.debug("Error while creating the user defined local authenticator: " + authenticatorConfig.getName() +
" in Tenant Domain: " + IdentityTenantUtil.getTenantDomain(tenantId) +
". Rolling back created authenticator information, and associated action.");
throw handleAuthenticatorMgtException(e);
throw handleAuthenticatorMgtException(e.getCause());
}
}

Expand All @@ -91,7 +91,7 @@ public UserDefinedLocalAuthenticatorConfig updateUserDefinedLocalAuthenticator(U
newAuthenticatorConfig.getName() + " in Tenant Domain: " +
IdentityTenantUtil.getTenantDomain(tenantId) +
". Rolling back updated authenticator information, and associated action.");
throw handleAuthenticatorMgtException(e);
throw handleAuthenticatorMgtException(e.getCause());
}
}

Expand Down Expand Up @@ -131,7 +131,7 @@ public void deleteUserDefinedLocalAuthenticator(String authenticatorConfigName,
LOG.debug("Error while deleting the user defined local authenticator: " + authenticatorConfigName +
" in Tenant Domain: " + IdentityTenantUtil.getTenantDomain(tenantId) +
". Rolling back deleted authenticator information, and associated action.");
throw handleAuthenticatorMgtException(e);
throw handleAuthenticatorMgtException(e.getCause());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,4 @@ public void validateAuthenticatorName(String name) throws AuthenticatorMgtClient
name, AUTHENTICATOR_NAME_REGEX);
}
}

/**
* Validate the authenticator is a user defined by authenticator.
*
* @param definedByType The defined by type of the authenticator config.
* @throws AuthenticatorMgtClientException if the authenticator is not a user defined authenticator.
*/
public void validateDefinedByType(DefinedByType definedByType)
throws AuthenticatorMgtClientException {

if (definedByType != DefinedByType.USER) {
throw buildClientException(AuthenticatorMgtError.ERROR_OP_ON_SYSTEM_AUTHENTICATOR);
}
}
}

0 comments on commit 3034668

Please sign in to comment.