use of org.wso2.carbon.identity.core.model.ExpressionNode in project identity-api-server by wso2.
the class ServerApplicationManagementService method getAllApplications.
public ApplicationListResponse getAllApplications(Integer limit, Integer offset, String filter, String sortOrder, String sortBy, String requiredAttributes) {
handleNotImplementedCapabilities(sortOrder, sortBy, requiredAttributes);
String tenantDomain = ContextLoader.getTenantDomainFromContext();
boolean isEqualFilterUsed = false;
limit = validateAndGetLimit(limit);
offset = validateAndGetOffset(offset);
// Format the filter to a value that can be interpreted by the backend.
ExpressionNode expressionNode = buildFilterNode(filter);
String formattedFilter = null;
if (expressionNode != null) {
// Handle eq operation as special case, there will be only one application with a given name in tenant.
if (isEqualOperation(expressionNode)) {
isEqualFilterUsed = true;
}
formattedFilter = generateFilterStringForBackend(expressionNode.getAttributeValue(), expressionNode.getOperation(), expressionNode.getValue());
}
String username = ContextLoader.getUsernameFromContext();
try {
int totalResults = getApplicationManagementService().getCountOfApplications(tenantDomain, username, formattedFilter);
ApplicationBasicInfo[] filteredAppList;
if (isEqualFilterUsed) {
ApplicationBasicInfo applicationBasicInfo = getApplicationManagementService().getApplicationBasicInfoByName(expressionNode.getValue(), tenantDomain);
if (applicationBasicInfo == null) {
filteredAppList = new ApplicationBasicInfo[0];
} else {
filteredAppList = new ApplicationBasicInfo[] { applicationBasicInfo };
}
} else {
filteredAppList = getApplicationManagementService().getApplicationBasicInfo(tenantDomain, username, formattedFilter, offset, limit);
}
int resultsInCurrentPage = filteredAppList.length;
return new ApplicationListResponse().totalResults(totalResults).startIndex(offset + 1).count(resultsInCurrentPage).applications(getApplicationListItems(filteredAppList)).links(Util.buildPaginationLinks(limit, offset, totalResults, APPLICATION_MANAGEMENT_PATH_COMPONENT).entrySet().stream().map(link -> new Link().rel(link.getKey()).href(link.getValue())).collect(Collectors.toList()));
} catch (IdentityApplicationManagementException e) {
String msg = "Error listing applications of tenantDomain: " + tenantDomain;
throw handleIdentityApplicationManagementException(e, msg);
}
}
use of org.wso2.carbon.identity.core.model.ExpressionNode in project identity-api-server by wso2.
the class ServerAuthenticatorManagementService method getExpressionNodesForIdp.
private List<ExpressionNode> getExpressionNodesForIdp(String filter) {
// Filter example : name sw go and (tag eq 2fa or tag eq Social-Login)
List<ExpressionNode> expressionNodes = new ArrayList<>();
FilterTreeBuilder filterTreeBuilder;
try {
if (StringUtils.isNotBlank(filter)) {
filterTreeBuilder = new FilterTreeBuilder(filter);
Node rootNode = filterTreeBuilder.buildTree();
setExpressionNodeListForIdp(rootNode, expressionNodes);
}
} catch (IOException | IdentityException e) {
throw buildClientError(Constants.ErrorMessage.ERROR_CODE_INVALID_FILTER_FORMAT, null);
}
return expressionNodes;
}
use of org.wso2.carbon.identity.core.model.ExpressionNode in project identity-api-server by wso2.
the class ServerAuthenticatorManagementService method validateFilter.
private void validateFilter(Node rootNode) {
if (!(rootNode instanceof OperationNode)) {
String attributeValue = ((ExpressionNode) rootNode).getAttributeValue();
String operation = ((ExpressionNode) rootNode).getOperation();
if (StringUtils.equalsIgnoreCase(attributeValue, Constants.FilterAttributes.NAME)) {
if (StringUtils.equalsIgnoreCase(operation, Constants.FilterOperations.SW) || StringUtils.equalsIgnoreCase(operation, Constants.FilterOperations.EQ)) {
return;
} else {
throw handleException(Response.Status.NOT_IMPLEMENTED, Constants.ErrorMessage.ERROR_CODE_UNSUPPORTED_FILTER_OPERATION_FOR_NAME, operation);
}
} else if (StringUtils.equalsIgnoreCase(attributeValue, Constants.FilterAttributes.TAG)) {
if (StringUtils.equalsIgnoreCase(operation, Constants.FilterOperations.EQ)) {
return;
} else {
throw handleException(Response.Status.NOT_IMPLEMENTED, Constants.ErrorMessage.ERROR_CODE_UNSUPPORTED_FILTER_OPERATION_FOR_TAG, operation);
}
} else {
throw buildClientError(Constants.ErrorMessage.ERROR_CODE_UNSUPPORTED_FILTER_ATTRIBUTE, attributeValue);
}
}
Node rootNodeLeftNode = rootNode.getLeftNode();
Node rootNodeRightNode = rootNode.getRightNode();
boolean nameFiltering = false;
boolean tagAvailableInLeftNode = false;
boolean tagAvailableInRightNode = false;
if (rootNodeLeftNode instanceof ExpressionNode) {
String attributeValue = ((ExpressionNode) rootNodeLeftNode).getAttributeValue();
nameFiltering = attributeValue.equals(Constants.FilterAttributes.NAME);
tagAvailableInLeftNode = attributeValue.equals(Constants.FilterAttributes.TAG);
if (!(nameFiltering || tagAvailableInLeftNode)) {
throw buildClientError(Constants.ErrorMessage.ERROR_CODE_UNSUPPORTED_FILTER_ATTRIBUTE, attributeValue);
}
String operation = ((ExpressionNode) rootNodeLeftNode).getOperation();
if (nameFiltering && (!(StringUtils.equalsIgnoreCase(operation, Constants.FilterOperations.SW) || StringUtils.equalsIgnoreCase(operation, Constants.FilterOperations.EQ)))) {
throw handleException(Response.Status.NOT_IMPLEMENTED, Constants.ErrorMessage.ERROR_CODE_UNSUPPORTED_FILTER_OPERATION_FOR_NAME, operation);
}
if (tagAvailableInLeftNode && !StringUtils.equalsIgnoreCase(operation, Constants.FilterOperations.EQ)) {
throw handleException(Response.Status.NOT_IMPLEMENTED, Constants.ErrorMessage.ERROR_CODE_UNSUPPORTED_FILTER_OPERATION_FOR_TAG, operation);
}
} else {
validateChildNode(rootNodeLeftNode);
}
if (rootNodeRightNode instanceof ExpressionNode) {
String attributeValue = ((ExpressionNode) rootNodeRightNode).getAttributeValue();
tagAvailableInRightNode = attributeValue.equals(Constants.FilterAttributes.TAG);
boolean nameAvailableInRightNode = attributeValue.equals(Constants.FilterAttributes.NAME);
if (!(tagAvailableInRightNode || nameAvailableInRightNode)) {
throw buildClientError(Constants.ErrorMessage.ERROR_CODE_UNSUPPORTED_FILTER_ATTRIBUTE, attributeValue);
}
if (nameFiltering && nameAvailableInRightNode) {
throw handleException(Response.Status.NOT_IMPLEMENTED, Constants.ErrorMessage.ERROR_CODE_UNSUPPORTED_FILTER_FOR_MULTIPLE_NAMES, null);
}
String operation = ((ExpressionNode) rootNodeRightNode).getOperation();
if (!nameFiltering) {
nameFiltering = nameAvailableInRightNode;
if (nameFiltering && (!(StringUtils.equalsIgnoreCase(operation, Constants.FilterOperations.SW) || StringUtils.equalsIgnoreCase(operation, Constants.FilterOperations.EQ)))) {
throw handleException(Response.Status.NOT_IMPLEMENTED, Constants.ErrorMessage.ERROR_CODE_UNSUPPORTED_FILTER_OPERATION_FOR_NAME, operation);
}
}
if (tagAvailableInRightNode && !StringUtils.equalsIgnoreCase(operation, Constants.FilterOperations.EQ)) {
throw handleException(Response.Status.NOT_IMPLEMENTED, Constants.ErrorMessage.ERROR_CODE_UNSUPPORTED_FILTER_OPERATION_FOR_TAG, operation);
}
} else {
validateChildNode(rootNodeRightNode);
}
String operation = ((OperationNode) rootNode).getOperation();
if (nameFiltering && !StringUtils.equalsIgnoreCase(operation, Constants.ComplexQueryOperations.AND)) {
throw handleException(Response.Status.NOT_IMPLEMENTED, Constants.ErrorMessage.ERROR_CODE_UNSUPPORTED_COMPLEX_QUERY_OPERATION_FOR_NAME, operation);
}
if (tagAvailableInLeftNode && tagAvailableInRightNode && !StringUtils.equalsIgnoreCase(operation, Constants.ComplexQueryOperations.OR)) {
throw handleException(Response.Status.NOT_IMPLEMENTED, Constants.ErrorMessage.ERROR_CODE_UNSUPPORTED_COMPLEX_QUERY_OPERATION_FOR_TAG, operation);
}
}
use of org.wso2.carbon.identity.core.model.ExpressionNode in project identity-api-server by wso2.
the class ServerAuthenticatorManagementService method buildAuthenticatorsListResponse.
private List<Authenticator> buildAuthenticatorsListResponse(String filter, List<String> requestedAttributeList, String localAuthNames, String authenticatorNameFilterOperator, ArrayList<String> filterTagsList, LocalAuthenticatorConfig[] localAuthenticatorConfigs, RequestPathAuthenticatorConfig[] requestPathAuthenticatorConfigs, List<IdentityProvider> identityProviders) {
int maximumItemsPerPage = IdentityUtil.getMaximumItemPerPage();
List<Authenticator> authenticators = new ArrayList<>();
if (localAuthenticatorConfigs != null) {
for (LocalAuthenticatorConfig config : localAuthenticatorConfigs) {
addLocalAuthenticator(config, authenticators, localAuthNames, authenticatorNameFilterOperator, filterTagsList, maximumItemsPerPage);
}
}
if ((authenticators.size() < maximumItemsPerPage) && requestPathAuthenticatorConfigs != null) {
for (RequestPathAuthenticatorConfig config : requestPathAuthenticatorConfigs) {
addLocalAuthenticator(config, authenticators, localAuthNames, authenticatorNameFilterOperator, filterTagsList, maximumItemsPerPage);
}
}
if (StringUtils.isBlank(filter)) {
if ((authenticators.size() < maximumItemsPerPage) && identityProviders != null) {
for (IdentityProvider identityProvider : identityProviders) {
if (authenticators.size() < maximumItemsPerPage) {
List<String> configTagsListDistinct = getDistinctTags(identityProvider);
addIdp(identityProvider, authenticators, configTagsListDistinct);
}
}
}
} else {
List<ExpressionNode> expressionNodesForIdp = getExpressionNodesForIdp(filter);
int idPCountToBeRetrieved = maximumItemsPerPage - authenticators.size();
IdpSearchResult idpSearchResult;
try {
idpSearchResult = AuthenticatorsServiceHolder.getInstance().getIdentityProviderManager().getIdPs(idPCountToBeRetrieved, null, null, null, ContextLoader.getTenantDomainFromContext(), requestedAttributeList, expressionNodesForIdp);
identityProviders = idpSearchResult.getIdPs();
if (identityProviders != null) {
addIdPsToAuthenticatorList(maximumItemsPerPage, identityProviders, authenticators, filterTagsList);
int limit = idpSearchResult.getLimit();
int offSet = idpSearchResult.getOffSet();
int totalIdpCount = idpSearchResult.getTotalIDPCount();
while (authenticators.size() < maximumItemsPerPage && limit > 0 && offSet >= 0 && totalIdpCount > (limit + offSet)) {
identityProviders = new ArrayList<>();
getFilteredIdPs(limit, offSet, requestedAttributeList, identityProviders, expressionNodesForIdp);
addIdPsToAuthenticatorList(maximumItemsPerPage, identityProviders, authenticators, filterTagsList);
offSet = offSet + limit;
}
}
} catch (IdentityProviderManagementException e) {
throw handleIdPException(e, Constants.ErrorMessage.ERROR_CODE_ERROR_LISTING_IDPS, null);
}
}
return authenticators;
}
use of org.wso2.carbon.identity.core.model.ExpressionNode in project identity-api-server by wso2.
the class ServerAuthenticatorManagementService method getExpressionNodesForAuthenticator.
private List<ExpressionNode> getExpressionNodesForAuthenticator(String filter) {
// Filter example : name sw go and (tag eq 2fa or tag eq Social-Login)
List<ExpressionNode> expressionNodes = new ArrayList<>();
FilterTreeBuilder filterTreeBuilder;
try {
if (StringUtils.isNotBlank(filter)) {
filterTreeBuilder = new FilterTreeBuilder(filter);
Node rootNode = filterTreeBuilder.buildTree();
validateFilter(rootNode);
setExpressionNodeListForAuthenticator(rootNode, expressionNodes);
}
} catch (IOException | IdentityException e) {
throw buildClientError(Constants.ErrorMessage.ERROR_CODE_INVALID_FILTER_FORMAT, null);
}
return expressionNodes;
}
Aggregations