use of org.wso2.carbon.identity.user.functionality.mgt.exception.UserFunctionalityManagementServerException in project carbon-identity-framework by wso2.
the class UserFunctionalityManagerImpl method isUserIdExists.
private boolean isUserIdExists(String userId, int tenantId) throws UserFunctionalityManagementClientException, UserFunctionalityManagementServerException {
boolean isUserExists;
try {
UniqueIDUserStoreManager uniqueIdEnabledUserStoreManager = getUniqueIdEnabledUserStoreManager(UserFunctionalityManagerComponentDataHolder.getInstance().getRealmService(), IdentityTenantUtil.getTenantDomain(tenantId));
isUserExists = uniqueIdEnabledUserStoreManager.isExistingUserWithID(userId);
return isUserExists;
} catch (UserStoreException e) {
if (isUserNotExistingError(e, userId)) {
if (log.isDebugEnabled()) {
log.debug("Cannot retrieve user from userId: " + userId, e);
}
throw buildUserNotFoundError();
}
throw new UserFunctionalityManagementServerException(UserFunctionalityMgtConstants.ErrorMessages.ERROR_OCCURRED_WHILE_RETRIEVING_USER.getCode(), UserFunctionalityMgtConstants.ErrorMessages.ERROR_OCCURRED_WHILE_RETRIEVING_USER.getDescription());
}
}
use of org.wso2.carbon.identity.user.functionality.mgt.exception.UserFunctionalityManagementServerException in project carbon-identity-framework by wso2.
the class UserFunctionalityManagerDAOImpl method deleteMappingForUser.
/**
* {@inheritDoc}
*/
@Override
public void deleteMappingForUser(String userId, int tenantId, String functionalityIdentifier) throws UserFunctionalityManagementServerException {
JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate();
try {
jdbcTemplate.executeUpdate(UserFunctionalityMgtConstants.SqlQueries.DELETE_FUNCTIONALITY_MAPPING, preparedStatement -> {
preparedStatement.setString(1, userId);
preparedStatement.setInt(2, tenantId);
preparedStatement.setString(3, functionalityIdentifier);
});
} catch (DataAccessException e) {
String message = String.format("Error occurred while deleting functionality from DB for functionality Id: %s, user " + "Id: %s and tenant Id: %d.", functionalityIdentifier, userId, tenantId);
if (log.isDebugEnabled()) {
log.debug(message, e);
}
throw new UserFunctionalityManagementServerException(message, e);
}
}
use of org.wso2.carbon.identity.user.functionality.mgt.exception.UserFunctionalityManagementServerException in project carbon-identity-framework by wso2.
the class UserFunctionalityManagerDAOImpl method getFunctionalityLockStatus.
/**
* {@inheritDoc}
*/
@Override
public FunctionalityLockStatus getFunctionalityLockStatus(String userId, int tenantId, String functionalityIdentifier) throws UserFunctionalityManagementServerException {
FunctionalityLockStatus functionalityLockStatus;
JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate();
try {
functionalityLockStatus = jdbcTemplate.fetchSingleRecord(UserFunctionalityMgtConstants.SqlQueries.GET_FUNCTIONALITY_LOCK_STATUS, ((resultSet, i) -> new FunctionalityLockStatus(resultSet.getBoolean("IS_FUNCTIONALITY_LOCKED"), resultSet.getLong("FUNCTIONALITY_UNLOCK_TIME"), resultSet.getString("FUNCTIONALITY_LOCK_REASON_CODE"), resultSet.getString("FUNCTIONALITY_LOCK_REASON"))), preparedStatement -> {
preparedStatement.setString(1, userId);
preparedStatement.setInt(2, tenantId);
preparedStatement.setString(3, functionalityIdentifier);
});
} catch (DataAccessException e) {
String message = String.format("Error occurred while retrieving functionality lock status from DB for " + "functionality identifier: %s, user Id: %s and tenant Id: %d.", functionalityIdentifier, userId, tenantId);
if (log.isDebugEnabled()) {
log.debug(message, e);
}
throw new UserFunctionalityManagementServerException(message, e);
}
return functionalityLockStatus;
}
use of org.wso2.carbon.identity.user.functionality.mgt.exception.UserFunctionalityManagementServerException in project carbon-identity-framework by wso2.
the class UserFunctionalityPropertyDAOImpl method deleteAllPropertiesForTenant.
/**
* {@inheritDoc}
*/
@Override
public void deleteAllPropertiesForTenant(int tenantId) throws UserFunctionalityManagementServerException {
JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate();
try {
String query;
if (isOracleDB()) {
if (StringUtils.isEmpty(TABLE_NAME)) {
TABLE_NAME = getOracleTableName();
}
query = String.format(UserFunctionalityMgtConstants.SqlQueries.DELETE_ALL_PROPERTIES_FOR_TENANT_ORACLE, TABLE_NAME);
} else {
query = UserFunctionalityMgtConstants.SqlQueries.DELETE_ALL_PROPERTIES_FOR_TENANT;
}
jdbcTemplate.executeUpdate(query, preparedStatement -> {
preparedStatement.setInt(1, tenantId);
});
} catch (DataAccessException e) {
String message = String.format("Error occurred while deleting functionality lock properties from DB for tenant" + " Id: %d.", tenantId);
if (log.isDebugEnabled()) {
log.debug(message, e);
}
throw new UserFunctionalityManagementServerException(message, e);
}
}
use of org.wso2.carbon.identity.user.functionality.mgt.exception.UserFunctionalityManagementServerException in project carbon-identity-framework by wso2.
the class UserFunctionalityPropertyDAOImpl method addProperties.
/**
* {@inheritDoc}
*/
@Override
public void addProperties(String userId, int tenantId, String functionalityIdentifier, Map<String, String> propertiesToAdd) throws UserFunctionalityManagementServerException {
JdbcTemplate jdbcTemplate = JdbcUtils.getNewTemplate();
for (Map.Entry<String, String> entry : propertiesToAdd.entrySet()) {
String propertyName = entry.getKey();
String propertyValue = entry.getValue();
try {
String query;
if (isOracleDB()) {
if (StringUtils.isEmpty(TABLE_NAME)) {
TABLE_NAME = getOracleTableName();
}
query = String.format(UserFunctionalityMgtConstants.SqlQueries.INSERT_PROPERTY_ORACLE, TABLE_NAME);
} else {
query = UserFunctionalityMgtConstants.SqlQueries.INSERT_PROPERTY;
}
jdbcTemplate.executeUpdate(query, preparedStatement -> {
preparedStatement.setString(1, UUID.randomUUID().toString());
preparedStatement.setString(2, userId);
preparedStatement.setInt(3, tenantId);
preparedStatement.setString(4, functionalityIdentifier);
preparedStatement.setString(5, propertyName);
preparedStatement.setString(6, propertyValue);
});
} catch (DataAccessException e) {
String message = String.format("Error occurred while adding the property: %s for functionality: %s in user: %s," + " tenant id: %d", propertyName, functionalityIdentifier, userId, tenantId);
if (log.isDebugEnabled()) {
log.debug(message, e);
}
throw new UserFunctionalityManagementServerException(message, e);
}
}
}
Aggregations