use of org.wso2.carbon.identity.core.model.ExpressionNode 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.core.model.ExpressionNode in project carbon-identity-framework by wso2.
the class IdPManagementDAO method appendFilterQuery.
/**
* Create a sql query and prepared statement for filter.
*
* @param expressionNodes list of filters.
* @param filterQueryBuilder Sql builder object.
* @throws IdentityProviderManagementClientException throw invalid filer attribute exception.
*/
private void appendFilterQuery(List<ExpressionNode> expressionNodes, FilterQueryBuilder filterQueryBuilder) throws IdentityProviderManagementClientException {
StringBuilder filter = new StringBuilder();
if (CollectionUtils.isEmpty(expressionNodes)) {
filterQueryBuilder.setFilterQuery(IdPManagementConstants.EMPTY_STRING);
} else {
for (ExpressionNode expressionNode : expressionNodes) {
String operation = expressionNode.getOperation();
String value = expressionNode.getValue();
String attributeName = expressionNode.getAttributeValue();
if (StringUtils.isNotBlank(attributeName) && StringUtils.isNotBlank(value) && StringUtils.isNotBlank(operation)) {
switch(attributeName) {
case IdPManagementConstants.IDP_NAME:
attributeName = IdPManagementConstants.NAME;
break;
case IdPManagementConstants.IDP_DESCRIPTION:
attributeName = IdPManagementConstants.DESCRIPTION;
break;
case IdPManagementConstants.IDP_HOME_REALM_ID:
attributeName = IdPManagementConstants.HOME_REALM_ID;
break;
case IdPManagementConstants.IDP_IS_ENABLED:
attributeName = IdPManagementConstants.IS_ENABLED;
break;
case IdPManagementConstants.IDP_UUID:
attributeName = IdPManagementConstants.UUID;
break;
default:
String message = "Invalid filter attribute name. Filter attribute : " + attributeName;
throw IdPManagementUtil.handleClientException(IdPManagementConstants.ErrorMessage.ERROR_CODE_RETRIEVE_IDP, message);
}
if (IdPManagementConstants.EQ.equals(operation)) {
filter.append(attributeName).append(" = ? AND ");
filterQueryBuilder.setFilterAttributeValue(value);
} else if (IdPManagementConstants.SW.equals(operation)) {
filter.append(attributeName).append(" like ? AND ");
filterQueryBuilder.setFilterAttributeValue(value + "%");
} else if (IdPManagementConstants.EW.equals(operation)) {
filter.append(attributeName).append(" like ? AND ");
filterQueryBuilder.setFilterAttributeValue("%" + value);
} else if (IdPManagementConstants.CO.equals(operation)) {
filter.append(attributeName).append(" like ? AND ");
filterQueryBuilder.setFilterAttributeValue("%" + value + "%");
} else {
String message = "Invalid filter value. filter: " + operation;
throw IdPManagementUtil.handleClientException(IdPManagementConstants.ErrorMessage.ERROR_CODE_RETRIEVE_IDP, message);
}
}
}
if (StringUtils.isBlank(filter.toString())) {
filterQueryBuilder.setFilterQuery(IdPManagementConstants.EMPTY_STRING);
} else {
filterQueryBuilder.setFilterQuery(filter.toString());
}
}
}
use of org.wso2.carbon.identity.core.model.ExpressionNode in project carbon-identity-framework by wso2.
the class IdPManagementDAO method getCountOfFilteredIdPs.
/**
* Get number of IdP count for a matching filter.
*
* @param tenantId Tenant Id of the identity provider.
* @param expressionNode filter value list for IdP search.
* @return number of IdP count for a given filter
* @throws IdentityProviderManagementServerException Error when getting count of Identity Providers.
* @throws IdentityProviderManagementClientException Error when append the filer string.
*/
int getCountOfFilteredIdPs(int tenantId, List<ExpressionNode> expressionNode) throws IdentityProviderManagementServerException, IdentityProviderManagementClientException {
String sqlStmt = IdPManagementConstants.SQLQueries.GET_IDP_COUNT_SQL;
int countOfFilteredIdp = 0;
FilterQueryBuilder filterQueryBuilder = new FilterQueryBuilder();
appendFilterQuery(expressionNode, filterQueryBuilder);
Map<Integer, String> filterAttributeValue = filterQueryBuilder.getFilterAttributeValue();
sqlStmt = sqlStmt + filterQueryBuilder.getFilterQuery() + IdPManagementConstants.SQLQueries.GET_IDP_COUNT_SQL_TAIL;
try (Connection dbConnection = IdentityDatabaseUtil.getDBConnection(false);
PreparedStatement prepStmt = dbConnection.prepareStatement(sqlStmt)) {
for (Map.Entry<Integer, String> prepareStatement : filterAttributeValue.entrySet()) {
prepStmt.setString(prepareStatement.getKey(), prepareStatement.getValue());
}
prepStmt.setInt(filterAttributeValue.entrySet().size() + 1, tenantId);
try (ResultSet rs = prepStmt.executeQuery()) {
if (rs.next()) {
countOfFilteredIdp = Integer.parseInt(rs.getString(1));
}
}
} catch (SQLException e) {
String message = "Error occurred while retrieving Identity Provider count for a tenant : " + IdentityTenantUtil.getTenantDomain(tenantId);
throw IdPManagementUtil.handleServerException(IdPManagementConstants.ErrorMessage.ERROR_CODE_CONNECTING_DATABASE, message, e);
}
return countOfFilteredIdp;
}
use of org.wso2.carbon.identity.core.model.ExpressionNode in project carbon-identity-framework by wso2.
the class IdPManagementDAO method getIdPsSearch.
/**
* Get all identity provider's Basic information along with additionally requested information depends on the
* requiredAttributes for a given matching filter.
*
* @param tenantId Tenant Id of the identity provider.
* @param expressionNode List of filter value for IdP search.
* @param limit Limit per page.
* @param offset Offset value.
* @param sortOrder Order of IdP ASC/DESC.
* @param sortBy The attribute need to sort.
* @param requiredAttributes Required attributes which needs to be return.
* @return Identity Provider's Basic Information array along with requested attribute information.
* @throws IdentityProviderManagementServerException Error when getting list of Identity Providers.
* @throws IdentityProviderManagementClientException Error when append the filer string.
*/
List<IdentityProvider> getIdPsSearch(int tenantId, List<ExpressionNode> expressionNode, int limit, int offset, String sortOrder, String sortBy, List<String> requiredAttributes) throws IdentityProviderManagementServerException, IdentityProviderManagementClientException {
FilterQueryBuilder filterQueryBuilder = new FilterQueryBuilder();
appendFilterQuery(expressionNode, filterQueryBuilder);
String sortedOrder = sortBy + " " + sortOrder;
try (Connection dbConnection = IdentityDatabaseUtil.getDBConnection(false);
ResultSet resultSet = getIdpQueryResultSet(dbConnection, sortedOrder, tenantId, offset, limit, filterQueryBuilder, requiredAttributes)) {
return populateIdentityProviderList(resultSet, dbConnection, requiredAttributes, tenantId);
} catch (SQLException e) {
String message = "Error occurred while retrieving Identity Provider for tenant: " + IdentityTenantUtil.getTenantDomain(tenantId);
throw IdPManagementUtil.handleServerException(IdPManagementConstants.ErrorMessage.ERROR_CODE_CONNECTING_DATABASE, message, e);
}
}
use of org.wso2.carbon.identity.core.model.ExpressionNode in project carbon-identity-framework by wso2.
the class IdPManagementDAOTest method getIdPsSearchWithExpressionNodesData.
@DataProvider
public Object[][] getIdPsSearchWithExpressionNodesData() {
ExpressionNode expressionNode1 = new ExpressionNode();
expressionNode1.setAttributeValue("name");
expressionNode1.setOperation("co");
expressionNode1.setValue("IdP");
List<ExpressionNode> expressionNodesList1 = new ArrayList<>();
expressionNodesList1.add(expressionNode1);
ExpressionNode expressionNode2 = new ExpressionNode();
List<ExpressionNode> expressionNodesList2 = new ArrayList<>();
expressionNode2.setAttributeValue("name");
expressionNode2.setOperation("eq");
expressionNode2.setValue("testIdP1");
expressionNodesList2.add(expressionNode2);
ExpressionNode expressionNode3 = new ExpressionNode();
List<ExpressionNode> expressionNodesList3 = new ArrayList<>();
expressionNode3.setAttributeValue("name");
expressionNode3.setOperation("ew");
expressionNode3.setValue("2");
expressionNodesList3.add(expressionNode3);
return new Object[][] { { SAMPLE_TENANT_ID, expressionNodesList1, 2, 0, "ASC", "NAME", 2, "testIdP1" }, { SAMPLE_TENANT_ID, expressionNodesList1, 2, 0, "DESC", "NAME", 2, "testIdP2" }, { SAMPLE_TENANT_ID2, expressionNodesList1, 1, 1, "ASC", "NAME", 0, "" }, { SAMPLE_TENANT_ID, expressionNodesList2, 1, 0, "ASC", "NAME", 1, "testIdP1" }, { SAMPLE_TENANT_ID, expressionNodesList3, 1, 0, "ASC", "NAME", 1, "testIdP2" } };
}
Aggregations