use of org.wso2.carbon.identity.base.IdentityRuntimeException in project carbon-identity-framework by wso2.
the class WorkflowPendingUserAuthnHandler method validatePendingApproval.
/**
* Validate whether the user account approval is pending.
*
* @param username Username.
* @throws IdentityEventException If an error occurred while validating pending approval.
*/
private void validatePendingApproval(String username, int tenantId) throws IdentityEventException {
boolean isPendingApproval;
try {
Entity entity = new Entity(MultitenantUtils.getTenantAwareUsername(username), WFConstant.WORKFLOW_ENTITY_TYPE, tenantId);
WorkflowManagementService workflowManagementService = new WorkflowManagementServiceImpl();
isPendingApproval = workflowManagementService.entityHasPendingWorkflowsOfType(entity, WFConstant.WORKFLOW_REQUEST_TYPE);
} catch (WorkflowException e) {
throw new IdentityEventException("Error occurred while checking the pending approvals for " + "the account of the user: " + username, e);
} catch (IdentityRuntimeException e) {
throw new IdentityEventException("Can't find the tenant domain for the user: " + username, e);
}
if (isPendingApproval) {
IdentityErrorMsgContext customErrorMessageContext = new IdentityErrorMsgContext(IdentityCoreConstants.USER_ACCOUNT_PENDING_APPROVAL_ERROR_CODE);
IdentityUtil.setIdentityErrorMsg(customErrorMessageContext);
throw new IdentityEventException(WorkflowErrorConstants.ErrorMessages.ERROR_CODE_USER_ACCOUNT_PENDING_APPROVAL.getCode(), WorkflowErrorConstants.ErrorMessages.ERROR_CODE_USER_ACCOUNT_PENDING_APPROVAL.getMessage());
}
}
use of org.wso2.carbon.identity.base.IdentityRuntimeException in project carbon-identity-framework by wso2.
the class SessionDataStore method removeSessionData.
public void removeSessionData(String key, String type, long nanoTime) {
if (!enablePersist) {
return;
}
if (tempDataCleanupEnabled && maxTempDataPoolSize > 0 && isTempCache(type)) {
tempAuthnContextDataDeleteQueue.push(new SessionContextDO(key, type, null, nanoTime));
return;
}
Connection connection = null;
try {
connection = IdentityDatabaseUtil.getSessionDBConnection(true);
} catch (IdentityRuntimeException e) {
log.error(e.getMessage(), e);
return;
}
PreparedStatement preparedStatement = null;
long timeoutNano = nanoTime + getCleanupTimeout(type, MultitenantConstants.INVALID_TENANT_ID);
try {
preparedStatement = connection.prepareStatement(getSessionStoreDBQuery(sqlInsertDELETE, type));
preparedStatement.setString(1, key);
preparedStatement.setString(2, type);
preparedStatement.setString(3, OPERATION_DELETE);
preparedStatement.setLong(4, nanoTime);
preparedStatement.setLong(5, timeoutNano);
preparedStatement.executeUpdate();
IdentityDatabaseUtil.commitTransaction(connection);
} catch (Exception e) {
IdentityDatabaseUtil.rollbackTransaction(connection);
log.error("Error while storing DELETE operation session data", e);
} finally {
IdentityDatabaseUtil.closeAllConnections(connection, null, preparedStatement);
}
if (log.isDebugEnabled()) {
log.debug("Removed SessionContextData from DB. key : " + key + " type : " + type);
}
}
use of org.wso2.carbon.identity.base.IdentityRuntimeException in project carbon-identity-framework by wso2.
the class SessionDataStore method removeExpiredSessionData.
/**
* Removes the records related to expired sessions from DB.
*/
private void removeExpiredSessionData(String sqlQuery) {
if (log.isDebugEnabled()) {
log.debug("DB query for removing expired data: " + sqlQuery);
}
long currentTime = FrameworkUtils.getCurrentStandardNano();
try (Connection connection = IdentityDatabaseUtil.getSessionDBConnection(true)) {
boolean deleteCompleted = false;
int totalDeletedEntries = 0;
while (!deleteCompleted) {
try (PreparedStatement statement = connection.prepareStatement(sqlQuery)) {
statement.setLong(1, currentTime);
int noOfDeletedRecords = statement.executeUpdate();
deleteCompleted = noOfDeletedRecords < deleteChunkSize;
totalDeletedEntries += noOfDeletedRecords;
// Commit the chunk deletion.
IdentityDatabaseUtil.commitTransaction(connection);
if (log.isDebugEnabled()) {
log.debug(String.format("Removed %d expired session records.", noOfDeletedRecords));
}
}
}
if (log.isDebugEnabled()) {
log.debug(String.format("Deleted total of %d entries", totalDeletedEntries));
}
} catch (SQLException | IdentityRuntimeException e) {
log.error("Error while removing session data from the database for nano time: " + currentTime, e);
}
}
use of org.wso2.carbon.identity.base.IdentityRuntimeException in project carbon-identity-framework by wso2.
the class SessionDataStore method removeInvalidatedSTOREOperations.
/**
* Removes STORE records related to DELETE records in IDN_AUTH_SESSION_STORE table
*/
private void removeInvalidatedSTOREOperations() {
Connection connection = null;
PreparedStatement statement = null;
try {
connection = IdentityDatabaseUtil.getSessionDBConnection(true);
} catch (IdentityRuntimeException e) {
log.error(e.getMessage(), e);
return;
}
try {
if (StringUtils.isBlank(sqlDeleteSTORETask)) {
String driverName = connection.getMetaData().getDriverName();
if (driverName.contains(MYSQL_DATABASE) || driverName.contains(MARIA_DATABASE)) {
sqlDeleteSTORETask = SQL_DELETE_STORE_OPERATIONS_TASK_MYSQL;
} else {
sqlDeleteSTORETask = SQL_DELETE_STORE_OPERATIONS_TASK;
}
}
statement = connection.prepareStatement(sqlDeleteSTORETask);
statement.execute();
IdentityDatabaseUtil.commitTransaction(connection);
return;
} catch (SQLException e) {
IdentityDatabaseUtil.rollbackTransaction(connection);
log.error("Error while removing STORE operation data from the database. ", e);
} finally {
IdentityDatabaseUtil.closeAllConnections(connection, null, statement);
}
}
use of org.wso2.carbon.identity.base.IdentityRuntimeException in project carbon-identity-framework by wso2.
the class SessionDataStore method persistSessionData.
public void persistSessionData(String key, String type, Object entry, long nanoTime, int tenantId) {
if (!enablePersist) {
return;
}
Connection connection = null;
try {
connection = IdentityDatabaseUtil.getSessionDBConnection(true);
} catch (IdentityRuntimeException e) {
log.error(e.getMessage(), e);
return;
}
long validityPeriodNano = 0L;
if (entry instanceof CacheEntry) {
validityPeriodNano = ((CacheEntry) entry).getValidityPeriod();
}
if (validityPeriodNano == 0L) {
validityPeriodNano = getCleanupTimeout(type, tenantId);
}
PreparedStatement preparedStatement = null;
try {
String sqlQuery = getSessionStoreDBQuery(sqlInsertSTORE, type);
preparedStatement = connection.prepareStatement(sqlQuery);
preparedStatement.setString(1, key);
preparedStatement.setString(2, type);
preparedStatement.setString(3, OPERATION_STORE);
setBlobObject(preparedStatement, entry, 4);
preparedStatement.setLong(5, nanoTime);
preparedStatement.setLong(6, nanoTime + validityPeriodNano);
preparedStatement.setInt(7, tenantId);
preparedStatement.executeUpdate();
IdentityDatabaseUtil.commitTransaction(connection);
} catch (SQLException | IOException | SessionSerializerException e) {
IdentityDatabaseUtil.rollbackTransaction(connection);
log.error("Error while storing session data", e);
} finally {
IdentityDatabaseUtil.closeAllConnections(connection, null, preparedStatement);
}
if (log.isDebugEnabled()) {
log.debug("Persisted SessionContextData to DB. key : " + key + " type : " + type);
}
}
Aggregations