use of org.wso2.carbon.identity.base.IdentityException in project carbon-identity-framework by wso2.
the class IdentityProviderManager method getExpressionNodes.
/**
* Get the filter node as a list.
*
* @param filter value of the filter.
* @return node tree.
* @throws IdentityProviderManagementClientException Error when validate filters.
*/
private List<ExpressionNode> getExpressionNodes(String filter) throws IdentityProviderManagementClientException {
// Filter example : name sw "te" and name ew "st" and isEnabled eq "true".
List<ExpressionNode> expressionNodes = new ArrayList<>();
FilterTreeBuilder filterTreeBuilder;
try {
if (StringUtils.isNotBlank(filter)) {
filterTreeBuilder = new FilterTreeBuilder(filter);
Node rootNode = filterTreeBuilder.buildTree();
setExpressionNodeList(rootNode, expressionNodes);
}
} catch (IOException | IdentityException e) {
String message = "Error occurred while validate filter, filter: " + filter;
throw IdPManagementUtil.handleClientException(IdPManagementConstants.ErrorMessage.ERROR_CODE_RETRIEVE_IDP, message, e);
}
return expressionNodes;
}
use of org.wso2.carbon.identity.base.IdentityException in project carbon-identity-framework by wso2.
the class UserInformationRecoveryService method getUserChallengeQuestion.
/**
* To get the challenge question for the user.
*
* @param userName
* @param confirmation
* @param questionId - Question id returned from the getUserChanllegneQuestionIds
* method.
* @return Populated question bean with the question details and the key.
* @throws IdentityMgtServiceException
*/
public UserChallengesDTO getUserChallengeQuestion(String userName, String confirmation, String questionId) throws IdentityMgtServiceException {
UserDTO userDTO = null;
UserChallengesDTO userChallengesDTO = new UserChallengesDTO();
if (log.isDebugEnabled()) {
log.debug("User challenge question request received with username :" + userName);
}
try {
userDTO = Utils.processUserId(userName);
} catch (IdentityException e) {
return handleChallengesError(VerificationBean.ERROR_CODE_INVALID_USER + " Error validating user : " + userName, null);
}
try {
if (IdentityMgtConfig.getInstance().isSaasEnabled()) {
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
carbonContext.setTenantId(userDTO.getTenantId());
carbonContext.setTenantDomain(userDTO.getTenantDomain());
}
RecoveryProcessor processor = IdentityMgtServiceComponent.getRecoveryProcessor();
VerificationBean bean;
try {
bean = processor.verifyConfirmationCode(20, userDTO.getUserId(), confirmation);
if (bean.isVerified()) {
bean = processor.updateConfirmationCode(40, userDTO.getUserId(), userDTO.getTenantId());
} else if (processor.verifyConfirmationCode(30, userDTO.getUserId(), confirmation).isVerified()) {
bean = processor.updateConfirmationCode(40, userDTO.getUserId(), userDTO.getTenantId());
} else {
bean.setVerified(false);
}
} catch (IdentityException e) {
userChallengesDTO = UserIdentityManagementUtil.getCustomErrorMessagesForChallengQuestions(e, userName);
if (userChallengesDTO == null) {
userChallengesDTO = handleChallengesError(VerificationBean.ERROR_CODE_INVALID_CODE + " Invalid confirmation code for user : " + userName, e);
}
return userChallengesDTO;
}
if (bean.isVerified()) {
userChallengesDTO = processor.getQuestionProcessor().getUserChallengeQuestion(userDTO.getUserId(), userDTO.getTenantId(), questionId);
userChallengesDTO.setKey(bean.getKey());
userChallengesDTO.setVerfied(true);
if (log.isDebugEnabled()) {
log.debug("User challenge question retrieved successfully");
}
} else {
if (log.isDebugEnabled()) {
log.debug("Verification failed for user. Error : " + bean.getError());
}
userChallengesDTO.setError(VerificationBean.ERROR_CODE_INVALID_USER + " " + bean.getError());
}
} finally {
if (IdentityMgtConfig.getInstance().isSaasEnabled()) {
PrivilegedCarbonContext.endTenantFlow();
}
}
return userChallengesDTO;
}
use of org.wso2.carbon.identity.base.IdentityException in project carbon-identity-framework by wso2.
the class JDBCUserRecoveryDataStore method store.
/**
* Stores identity data set.
*
* @throws IdentityException
*/
@Override
@Deprecated
public void store(UserRecoveryDataDO[] recoveryDataDOs) throws IdentityException {
Connection connection = IdentityDatabaseUtil.getDBConnection();
PreparedStatement prepStmt = null;
try {
prepStmt = connection.prepareStatement(SQLQuery.STORE_META_DATA);
for (UserRecoveryDataDO dataDO : recoveryDataDOs) {
prepStmt.setString(1, dataDO.getUserName().toLowerCase());
prepStmt.setInt(2, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
prepStmt.setString(3, dataDO.getCode().toLowerCase());
prepStmt.setString(4, dataDO.getSecret());
prepStmt.setString(5, dataDO.getExpireTime());
prepStmt.addBatch();
}
prepStmt.executeBatch();
IdentityDatabaseUtil.commitTransaction(connection);
} catch (SQLException e) {
IdentityDatabaseUtil.rollbackTransaction(connection);
throw IdentityException.error("Error while storing user identity data", e);
} finally {
IdentityDatabaseUtil.closeStatement(prepStmt);
IdentityDatabaseUtil.closeConnection(connection);
}
}
use of org.wso2.carbon.identity.base.IdentityException in project carbon-identity-framework by wso2.
the class JDBCUserRecoveryDataStore method load.
/**
* This method should return only one result. An exception will be thrown if
* duplicate entries found.
* This can be used to check if the given metada exist in the database or to
* check the validity.
*
* @return
* @throws IdentityException
*/
/**
* @param userName
* @param tenantId
* @return
* @throws IdentityException
*/
@Override
@Deprecated
public UserRecoveryDataDO[] load(String userName, int tenantId) throws IdentityException {
Connection connection = IdentityDatabaseUtil.getDBConnection(false);
PreparedStatement prepStmt = null;
ResultSet results = null;
try {
prepStmt = connection.prepareStatement(SQLQuery.LOAD_USER_METADATA);
prepStmt.setString(1, userName.toLowerCase());
prepStmt.setInt(2, IdentityTenantUtil.getTenantIdOfUser(userName));
results = prepStmt.executeQuery();
List<UserRecoveryDataDO> metada = new ArrayList<UserRecoveryDataDO>();
while (results.next()) {
metada.add(new UserRecoveryDataDO(results.getString(1), results.getInt(2), results.getString(3), results.getString(4)));
}
UserRecoveryDataDO[] resultMetadata = new UserRecoveryDataDO[metada.size()];
return metada.toArray(resultMetadata);
} catch (SQLException e) {
throw IdentityException.error("Error while reading user identity data", e);
} finally {
IdentityDatabaseUtil.closeResultSet(results);
IdentityDatabaseUtil.closeStatement(prepStmt);
IdentityDatabaseUtil.closeConnection(connection);
}
}
use of org.wso2.carbon.identity.base.IdentityException in project carbon-identity-framework by wso2.
the class RegistryRecoveryDataStore method invalidate.
@Override
public void invalidate(String code) throws IdentityException {
Registry registry = null;
try {
registry = IdentityMgtServiceComponent.getRegistryService().getConfigSystemRegistry(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
registry.beginTransaction();
String secretKeyPath = IdentityMgtConstants.IDENTITY_MANAGEMENT_DATA + RegistryConstants.PATH_SEPARATOR + code.toLowerCase();
if (registry.resourceExists(secretKeyPath)) {
registry.delete(secretKeyPath);
}
} catch (RegistryException e) {
log.error(e);
throw IdentityException.error("Error while invalidating user recovery data for code : " + code);
} finally {
if (registry != null) {
try {
registry.commitTransaction();
} catch (RegistryException e) {
log.error("Error while processing registry transaction", e);
}
}
}
}
Aggregations