Search in sources :

Example 11 with Attribute

use of org.wso2.carbon.identity.configuration.mgt.core.model.Attribute in project carbon-identity-framework by wso2.

the class CarbonEntitlementDataFinder method getChildResources.

/**
 * This helps to find resources un a recursive manner
 *
 * @param node           attribute value node
 * @param parentResource parent resource Name
 * @return child resource set
 * @throws RegistryException throws
 */
private EntitlementTreeNodeDTO getChildResources(EntitlementTreeNodeDTO node, String parentResource) throws RegistryException {
    if (registry.resourceExists(parentResource)) {
        String[] resourcePath = parentResource.split("/");
        EntitlementTreeNodeDTO childNode = new EntitlementTreeNodeDTO(resourcePath[resourcePath.length - 1]);
        node.addChildNode(childNode);
        Resource root = registry.get(parentResource);
        if (root instanceof Collection) {
            Collection collection = (Collection) root;
            String[] resources = collection.getChildren();
            for (String resource : resources) {
                getChildResources(childNode, resource);
            }
        }
    }
    return node;
}
Also used : EntitlementTreeNodeDTO(org.wso2.carbon.identity.entitlement.dto.EntitlementTreeNodeDTO) Resource(org.wso2.carbon.registry.api.Resource) Collection(org.wso2.carbon.registry.core.Collection)

Example 12 with Attribute

use of org.wso2.carbon.identity.configuration.mgt.core.model.Attribute in project carbon-identity-framework by wso2.

the class IdentityProviderManager method getIdPs.

/**
 * Get all identity provider's Basic information along with additionally requested information depending on the
 * requiredAttributes.
 *
 * @param limit              Limit per page.
 * @param offset             Offset value.
 * @param filter             Filter value for IdP search.
 * @param sortOrder          Order of IdP ASC/DESC.
 * @param sortBy             The column value need to sort.
 * @param tenantDomain       TenantDomain of the user.
 * @param requiredAttributes Required attributes which needs to be return.
 * @return Identity Provider's Basic Information array along with requested attribute
 * information{@link IdpSearchResult}.
 * @throws IdentityProviderManagementException Server/client related error when getting list of Identity Providers.
 */
@Override
public IdpSearchResult getIdPs(Integer limit, Integer offset, String filter, String sortOrder, String sortBy, String tenantDomain, List<String> requiredAttributes) throws IdentityProviderManagementException {
    IdpSearchResult result = new IdpSearchResult();
    List<ExpressionNode> expressionNodes = getExpressionNodes(filter);
    setParameters(limit, offset, sortOrder, sortBy, filter, result);
    int tenantId = IdentityTenantUtil.getTenantId(tenantDomain);
    result.setTotalIDPCount(dao.getTotalIdPCount(tenantId, expressionNodes));
    result.setIdpList(dao.getPaginatedIdPsSearch(tenantId, expressionNodes, result.getLimit(), result.getOffSet(), result.getSortOrder(), result.getSortBy(), requiredAttributes));
    return result;
}
Also used : ExpressionNode(org.wso2.carbon.identity.core.model.ExpressionNode) IdpSearchResult(org.wso2.carbon.idp.mgt.model.IdpSearchResult)

Example 13 with Attribute

use of org.wso2.carbon.identity.configuration.mgt.core.model.Attribute 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());
        }
    }
}
Also used : ExpressionNode(org.wso2.carbon.identity.core.model.ExpressionNode)

Example 14 with Attribute

use of org.wso2.carbon.identity.configuration.mgt.core.model.Attribute in project carbon-identity-framework by wso2.

the class IdPManagementDAO method populateRequiredAttributesForIdentityProviderList.

/**
 * @param resultSet          ResultSet.
 * @param dbConnection       Database Connection.
 * @param requiredAttributes Required attributes which needs to be return.
 * @param tenantId           Tenant Id of the identity provider.
 * @param identityProvider   Identity Provider Object.
 * @throws SQLException
 * @throws IdentityProviderManagementServerException
 */
private void populateRequiredAttributesForIdentityProviderList(ResultSet resultSet, Connection dbConnection, List<String> requiredAttributes, int tenantId, IdentityProvider identityProvider) throws SQLException, IdentityProviderManagementServerException {
    int idpId = Integer.parseInt(identityProvider.getId());
    String idPName = identityProvider.getIdentityProviderName();
    try {
        if (CollectionUtils.isNotEmpty(requiredAttributes)) {
            for (String attribute : requiredAttributes) {
                switch(attribute) {
                    case IdPManagementConstants.IDP_IS_PRIMARY:
                        if ((IdPManagementConstants.IS_TRUE_VALUE).equals(resultSet.getString("IS_PRIMARY"))) {
                            identityProvider.setPrimary(true);
                        } else {
                            identityProvider.setPrimary(false);
                        }
                        break;
                    case IdPManagementConstants.IDP_HOME_REALM_ID:
                        identityProvider.setHomeRealmId(resultSet.getString("HOME_REALM_ID"));
                        break;
                    case IdPManagementConstants.IDP_IS_FEDERATION_HUB:
                        if ((IdPManagementConstants.IS_TRUE_VALUE).equals(resultSet.getString("IS_FEDERATION_HUB"))) {
                            identityProvider.setFederationHub(false);
                        }
                        break;
                    case IdPManagementConstants.IDP_CERTIFICATE:
                        identityProvider.setCertificate(getBlobValue(resultSet.getBinaryStream("CERTIFICATE")));
                        break;
                    case IdPManagementConstants.IDP_ALIAS:
                        identityProvider.setAlias(resultSet.getString("ALIAS"));
                        break;
                    case IdPManagementConstants.IDP_CLAIMS:
                        if (identityProvider.getClaimConfig() == null) {
                            identityProvider.setClaimConfig(new ClaimConfig());
                        }
                        if (IdPManagementConstants.IS_TRUE_VALUE.equals(resultSet.getString("IS_LOCAL_CLAIM_DIALECT"))) {
                            identityProvider.getClaimConfig().setLocalClaimDialect(true);
                        } else {
                            identityProvider.getClaimConfig().setLocalClaimDialect(false);
                        }
                        String userClaimUri = resultSet.getString("USER_CLAIM_URI");
                        String roleClaimUri = resultSet.getString("ROLE_CLAIM_URI");
                        if (identityProvider.getClaimConfig().isLocalClaimDialect()) {
                            identityProvider.setClaimConfig(getLocalIdPDefaultClaimValues(dbConnection, idPName, userClaimUri, roleClaimUri, idpId, tenantId));
                        } else {
                            // Get claim configuration.
                            identityProvider.setClaimConfig(getIdPClaimConfiguration(dbConnection, idPName, userClaimUri, roleClaimUri, idpId, tenantId));
                        }
                        break;
                    case IdPManagementConstants.IDP_ROLES:
                        identityProvider.setProvisioningRole(resultSet.getString("PROVISIONING_ROLE"));
                        // Get permission and role configuration.
                        identityProvider.setPermissionAndRoleConfig(getPermissionsAndRoleConfiguration(dbConnection, idPName, idpId, tenantId));
                        break;
                    case IdPManagementConstants.IDP_FEDERATED_AUTHENTICATORS:
                        String defaultAuthenticatorName = resultSet.getString("DEFAULT_AUTHENTICATOR_NAME");
                        // Get federated authenticators.
                        identityProvider.setFederatedAuthenticatorConfigs(getFederatedAuthenticatorConfigs(dbConnection, idPName, identityProvider, tenantId));
                        if (defaultAuthenticatorName != null && identityProvider.getFederatedAuthenticatorConfigs() != null) {
                            identityProvider.setDefaultAuthenticatorConfig(IdentityApplicationManagementUtil.getFederatedAuthenticator(identityProvider.getFederatedAuthenticatorConfigs(), defaultAuthenticatorName));
                        }
                        break;
                    case IdPManagementConstants.IDP_PROVISIONING:
                        JustInTimeProvisioningConfig jitProConfig = new JustInTimeProvisioningConfig();
                        if ((IdPManagementConstants.IS_TRUE_VALUE).equals(resultSet.getString("INBOUND_PROV_ENABLED"))) {
                            jitProConfig.setProvisioningEnabled(true);
                        } else {
                            jitProConfig.setProvisioningEnabled(false);
                        }
                        jitProConfig.setProvisioningUserStore(resultSet.getString("INBOUND_PROV_USER_STORE_ID"));
                        identityProvider.setJustInTimeProvisioningConfig(jitProConfig);
                        String defaultProvisioningConnectorConfigName = resultSet.getString("DEFAULT_PRO_CONNECTOR_NAME");
                        if (defaultProvisioningConnectorConfigName != null) {
                            ProvisioningConnectorConfig defaultProConnector = new ProvisioningConnectorConfig();
                            defaultProConnector.setName(defaultProvisioningConnectorConfigName);
                            identityProvider.setDefaultProvisioningConnectorConfig(defaultProConnector);
                        }
                        // Get provisioning connectors.
                        identityProvider.setProvisioningConnectorConfigs(getProvisioningConnectorConfigs(dbConnection, idPName, idpId, tenantId));
                        break;
                }
            }
        }
    } catch (IdentityProviderManagementException e) {
        throw new IdentityProviderManagementServerException("Error occurred while performing required " + "attribute filter", e);
    }
}
Also used : ClaimConfig(org.wso2.carbon.identity.application.common.model.ClaimConfig) JustInTimeProvisioningConfig(org.wso2.carbon.identity.application.common.model.JustInTimeProvisioningConfig) IdentityProviderManagementServerException(org.wso2.carbon.idp.mgt.IdentityProviderManagementServerException) IdentityProviderManagementException(org.wso2.carbon.idp.mgt.IdentityProviderManagementException) ProvisioningConnectorConfig(org.wso2.carbon.identity.application.common.model.ProvisioningConnectorConfig)

Example 15 with Attribute

use of org.wso2.carbon.identity.configuration.mgt.core.model.Attribute 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);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) FilterQueryBuilder(org.wso2.carbon.idp.mgt.model.FilterQueryBuilder)

Aggregations

Test (org.testng.annotations.Test)152 ArrayList (java.util.ArrayList)137 HashMap (java.util.HashMap)112 StreamDefinition (org.wso2.siddhi.query.api.definition.StreamDefinition)103 SimpleAttribute (org.wso2.charon3.core.attributes.SimpleAttribute)99 ComplexAttribute (org.wso2.charon3.core.attributes.ComplexAttribute)94 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)89 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)89 Event (org.wso2.siddhi.core.event.Event)85 InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)83 SiddhiApp (org.wso2.siddhi.query.api.SiddhiApp)83 Query (org.wso2.siddhi.query.api.execution.query.Query)83 MultiValuedAttribute (org.wso2.charon3.core.attributes.MultiValuedAttribute)82 Attribute (org.wso2.charon3.core.attributes.Attribute)73 QueryCallback (org.wso2.siddhi.core.query.output.callback.QueryCallback)73 CharonException (org.wso2.charon3.core.exceptions.CharonException)68 Map (java.util.Map)66 BadRequestException (org.wso2.charon3.core.exceptions.BadRequestException)62 OMAttribute (org.apache.axiom.om.OMAttribute)51 OMElement (org.apache.axiom.om.OMElement)51