Skip to content

Commit

Permalink
Add service layer support to manage the user defined local authentica…
Browse files Browse the repository at this point in the history
…tors
  • Loading branch information
Thisara-Welmilla committed Dec 1, 2024
1 parent 812538e commit d8a8ca1
Showing 1 changed file with 9 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.database.utils.jdbc.NamedPreparedStatement;
import org.wso2.carbon.identity.application.common.constant.AuthenticatorMgtErrorConstants.ErrorMessages;
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;
import org.wso2.carbon.identity.application.common.exception.AuthenticatorMgtException;
import org.wso2.carbon.identity.application.common.exception.AuthenticatorMgtServerException;
import org.wso2.carbon.identity.application.common.model.Property;
import org.wso2.carbon.identity.application.common.model.UserDefinedLocalAuthenticatorConfig;
import org.wso2.carbon.identity.application.common.util.AuthenticatorMgtExceptionBuilder.AuthenticatorMgtError;
import org.wso2.carbon.identity.base.AuthenticatorPropertyConstants.AuthenticationType;
import org.wso2.carbon.identity.base.AuthenticatorPropertyConstants.DefinedByType;
import org.wso2.carbon.identity.core.util.IdentityDatabaseUtil;
Expand All @@ -40,6 +40,8 @@
import java.util.ArrayList;
import java.util.List;

import static org.wso2.carbon.identity.application.common.util.AuthenticatorMgtExceptionBuilder.buildServerException;

/**
* This class implements the AuthenticatorManagementDAO interface which perform CRUD operation on database.
*/
Expand Down Expand Up @@ -83,9 +85,7 @@ public UserDefinedLocalAuthenticatorConfig addUserDefinedLocalAuthenticator(
IdentityTenantUtil.getTenantDomain(tenantId)));
}
IdentityDatabaseUtil.rollbackTransaction(dbConnection);

ErrorMessages error = ErrorMessages.ERROR_WHILE_ADDING_AUTHENTICATOR;
throw new AuthenticatorMgtServerException(error.getMessage(), error.getMessage(), error.getCode(), e);
throw buildServerException(AuthenticatorMgtError.ERROR_WHILE_ADDING_AUTHENTICATOR, e);
} finally {
IdentityDatabaseUtil.closeConnection(dbConnection);
}
Expand Down Expand Up @@ -127,8 +127,7 @@ public UserDefinedLocalAuthenticatorConfig updateUserDefinedLocalAuthenticator(
existingAuthenticatorConfig.getName(), IdentityTenantUtil.getTenantDomain(tenantId)));
}
IdentityDatabaseUtil.rollbackTransaction(dbConnection);
ErrorMessages error = ErrorMessages.ERROR_WHILE_UPDATING_AUTHENTICATOR;
throw new AuthenticatorMgtServerException(error.getMessage(), error.getMessage(), error.getCode(), e);
throw buildServerException(AuthenticatorMgtError.ERROR_WHILE_UPDATING_AUTHENTICATOR, e);
} finally {
IdentityDatabaseUtil.closeConnection(dbConnection);
}
Expand Down Expand Up @@ -175,8 +174,7 @@ public List<UserDefinedLocalAuthenticatorConfig> getAllUserDefinedLocalAuthentic
LOG.debug(String.format("Error while retrieving the all user defined local authenticators in tenant " +
"domain: %s.", IdentityTenantUtil.getTenantDomain(tenantId)));
}
ErrorMessages error = ErrorMessages.ERROR_WHILE_DELETING_AUTHENTICATOR;
throw new AuthenticatorMgtServerException(error.getMessage(), error.getMessage(), error.getCode(), e);
throw buildServerException(AuthenticatorMgtError.ERROR_WHILE_DELETING_AUTHENTICATOR, e);
}
}

Expand All @@ -199,8 +197,7 @@ public void deleteUserDefinedLocalAuthenticator(String authenticatorConfigName,
IdentityTenantUtil.getTenantDomain(tenantId)));
}
IdentityDatabaseUtil.rollbackTransaction(dbConnection);
ErrorMessages error = ErrorMessages.ERROR_WHILE_DELETING_AUTHENTICATOR;
throw new AuthenticatorMgtServerException(error.getMessage(), error.getMessage(), error.getCode(), e);
throw buildServerException(AuthenticatorMgtError.ERROR_WHILE_DELETING_AUTHENTICATOR, e);
} finally {
IdentityDatabaseUtil.closeConnection(dbConnection);
}
Expand Down Expand Up @@ -251,8 +248,7 @@ private UserDefinedLocalAuthenticatorConfig getUserDefinedLocalAuthenticatorByNa
IdentityDatabaseUtil.commitTransaction(dbConnection);
return config;
} catch (SQLException e) {
ErrorMessages error = ErrorMessages.ERROR_WHILE_RETRIEVING_AUTHENTICATOR_BY_NAME;
throw new AuthenticatorMgtServerException(error.getMessage(), error.getMessage(), error.getCode(), e);
throw buildServerException(AuthenticatorMgtError.ERROR_WHILE_RETRIEVING_AUTHENTICATOR_BY_NAME, e);
}
}

Expand Down Expand Up @@ -286,8 +282,7 @@ private int getAuthenticatorIdentifier(Connection dbConnection, String authentic
}
IdentityDatabaseUtil.commitTransaction(dbConnection);
}
throw new AuthenticatorMgtServerException(String.format("Authenticator with name: %s not found in the database."
, authenticatorConfigName));
throw buildServerException(AuthenticatorMgtError.ERROR_CODE_NO_AUTHENTICATOR_FOUND, authenticatorConfigName);
}

private void deletedAuthenticatorProperties(Connection dbConnection, int authenticatorConfigID, int tenantId)
Expand Down

0 comments on commit d8a8ca1

Please sign in to comment.