Search in sources :

Example 11 with AttributeDTO

use of org.wso2.carbon.identity.entitlement.dto.AttributeDTO in project carbon-identity-framework by wso2.

the class ConfigurationEndpointUtils method getAttributeDTO.

public static AttributeDTO getAttributeDTO(Attribute attribute) {
    AttributeDTO attributeDTO = new AttributeDTO();
    attributeDTO.setKey(attribute.getKey());
    attributeDTO.setValue(attribute.getValue());
    return attributeDTO;
}
Also used : AttributeDTO(org.wso2.carbon.identity.configuration.mgt.endpoint.dto.AttributeDTO)

Example 12 with AttributeDTO

use of org.wso2.carbon.identity.entitlement.dto.AttributeDTO in project carbon-identity-framework by wso2.

the class EntitlementPolicyAdminService method getAllPolicies.

/**
 * This method paginates policies
 *
 * @param policyTypeFilter   policy type to filter
 * @param policySearchString policy search String
 * @param pageNumber         page number
 * @param isPDPPolicy        whether this is a PDP policy or PAP policy
 * @return paginated and filtered policy set
 * @throws org.wso2.carbon.identity.entitlement.EntitlementException throws
 */
public PaginatedPolicySetDTO getAllPolicies(String policyTypeFilter, String policySearchString, int pageNumber, boolean isPDPPolicy) throws EntitlementException {
    List<PolicyDTO> policyDTOList = new ArrayList<PolicyDTO>();
    PolicyDTO[] policyDTOs = null;
    if (isPDPPolicy) {
        policyDTOs = EntitlementAdminEngine.getInstance().getPolicyStoreManager().getLightPolicies();
    } else {
        policyDTOs = EntitlementAdminEngine.getInstance().getPapPolicyStoreManager().getAllLightPolicyDTOs();
    }
    policySearchString = policySearchString.replace("*", ".*");
    Pattern pattern = Pattern.compile(policySearchString, Pattern.CASE_INSENSITIVE);
    for (PolicyDTO policyDTO : policyDTOs) {
        boolean useAttributeFiler = false;
        // Filter out policies based on policy type
        if (!policyTypeFilter.equals(EntitlementConstants.PolicyType.POLICY_ALL) && (!policyTypeFilter.equals(policyDTO.getPolicyType()) && !(EntitlementConstants.PolicyType.POLICY_ENABLED.equals(policyTypeFilter) && policyDTO.isActive()) && !(EntitlementConstants.PolicyType.POLICY_DISABLED.equals(policyTypeFilter) && !policyDTO.isActive()))) {
            continue;
        }
        if (policySearchString != null && policySearchString.trim().length() > 0) {
            if (!isPDPPolicy) {
                // Filter out policies based on attribute value
                PolicyDTO metaDataPolicyDTO = EntitlementAdminEngine.getInstance().getPapPolicyStoreManager().getMetaDataPolicy(policyDTO.getPolicyId());
                AttributeDTO[] attributeDTOs = metaDataPolicyDTO.getAttributeDTOs();
                if (attributeDTOs != null) {
                    for (AttributeDTO attributeDTO : attributeDTOs) {
                        if (policySearchString.equalsIgnoreCase(attributeDTO.getAttributeValue())) {
                            useAttributeFiler = true;
                            break;
                        }
                    }
                }
            }
            if (!useAttributeFiler) {
                // Filter out policies based on policy Search String
                if (policySearchString.trim().length() > 0) {
                    Matcher matcher = pattern.matcher(policyDTO.getPolicyId());
                    if (!matcher.matches()) {
                        continue;
                    }
                }
            }
        }
        policyDTOList.add(policyDTO);
    }
    // Do the pagination and return the set of policies.
    return doPaging(pageNumber, policyDTOList.toArray(new PolicyDTO[policyDTOList.size()]));
}
Also used : AttributeDTO(org.wso2.carbon.identity.entitlement.dto.AttributeDTO) Pattern(java.util.regex.Pattern) PolicyDTO(org.wso2.carbon.identity.entitlement.dto.PolicyDTO) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList)

Example 13 with AttributeDTO

use of org.wso2.carbon.identity.entitlement.dto.AttributeDTO in project carbon-identity-framework by wso2.

the class EntitlementUtil method setAttributesAsProperties.

/**
 * This helper method creates properties object which contains the policy meta data.
 *
 * @param attributeDTOs List of AttributeDTO
 * @param resource      registry resource
 */
public static void setAttributesAsProperties(AttributeDTO[] attributeDTOs, Resource resource) {
    int attributeElementNo = 0;
    if (attributeDTOs != null) {
        for (AttributeDTO attributeDTO : attributeDTOs) {
            resource.setProperty("policyMetaData" + attributeElementNo, attributeDTO.getCategory() + "," + attributeDTO.getAttributeValue() + "," + attributeDTO.getAttributeId() + "," + attributeDTO.getAttributeDataType());
            attributeElementNo++;
        }
    }
}
Also used : AttributeDTO(org.wso2.carbon.identity.entitlement.dto.AttributeDTO)

Example 14 with AttributeDTO

use of org.wso2.carbon.identity.entitlement.dto.AttributeDTO in project carbon-identity-framework by wso2.

the class PolicySearch method processCombinations.

/**
 * Helper method to get all possible combination for given set of attributes based on category
 *
 * @param i
 * @param categories
 * @param attributesMap
 * @param dtoList
 * @param requestSet
 */
private void processCombinations(int i, List<String> categories, Map<String, Set<AttributeDTO>> attributesMap, List<AttributeDTO> dtoList, Set<List<AttributeDTO>> requestSet) {
    if (categories.size() > i) {
        String category = categories.get(i);
        i++;
        if (category != null) {
            List<AttributeDTO> currentList = new ArrayList<AttributeDTO>(dtoList);
            Set<AttributeDTO> attributeDTOs = attributesMap.get(category);
            for (AttributeDTO dto : attributeDTOs) {
                dtoList.add(dto);
                processCombinations(i, categories, attributesMap, dtoList, requestSet);
                requestSet.add(dtoList);
                dtoList = new ArrayList<AttributeDTO>(currentList);
            }
        }
    }
}
Also used : AttributeDTO(org.wso2.carbon.identity.entitlement.dto.AttributeDTO) ArrayList(java.util.ArrayList)

Example 15 with AttributeDTO

use of org.wso2.carbon.identity.entitlement.dto.AttributeDTO in project carbon-identity-framework by wso2.

the class PolicySearch method getEntitledAttributes.

/**
 * gets all entitled attributes for given set of attributes
 * this an universal method to do policy search and find entitlement attributes
 *
 * @param identifier      identifier to separate out the attributes that is used for search
 *                        this is not required and can be null
 * @param givenAttributes user provided attributes
 * @return all the attributes that is entitled
 */
public EntitledResultSetDTO getEntitledAttributes(String identifier, AttributeDTO[] givenAttributes) {
    String cacheKey = "";
    if (cachingEnable) {
        int hashCode = 0;
        for (AttributeDTO dto : givenAttributes) {
            hashCode = hashCode + (31 * dto.hashCode());
        }
        cacheKey = identifier + hashCode;
        SearchResult searchResult = policySearchCache.getFromCache(cacheKey);
        if (searchResult != null) {
            if (log.isDebugEnabled()) {
                log.debug("PDP Search Cache Hit");
            }
            return searchResult.getResultSetDTO();
        } else {
            if (log.isDebugEnabled()) {
                log.debug("PDP Search Cache Miss");
            }
        }
    }
    EntitledResultSetDTO result = new EntitledResultSetDTO();
    Set<EntitledAttributesDTO> resultAttributes = new HashSet<EntitledAttributesDTO>();
    Set<AttributeDTO> attributeDTOs = new HashSet<AttributeDTO>(Arrays.asList(givenAttributes));
    for (PolicyFinderModule finderModule : finderModules) {
        Map<String, Set<AttributeDTO>> attributesMap = finderModule.getSearchAttributes(identifier, attributeDTOs);
        int supportedSearchScheme = finderModule.getSupportedSearchAttributesScheme();
        Set<List<AttributeDTO>> requestSet = getPossibleRequests(attributesMap, supportedSearchScheme);
        if (requestSet == null) {
            log.error("Invalid Search scheme in policy finder : " + finderModule.getModuleName());
        } else {
            for (List<AttributeDTO> attributeDTOList : requestSet) {
                if (getResponse(attributeDTOList)) {
                    EntitledAttributesDTO dto = new EntitledAttributesDTO();
                    dto.setAttributeDTOs(attributeDTOList.toArray(new AttributeDTO[attributeDTOList.size()]));
                    resultAttributes.add(dto);
                }
            }
        }
    }
    result.setAdvanceResult(true);
    result.setEntitledAttributesDTOs(resultAttributes.toArray(new EntitledAttributesDTO[resultAttributes.size()]));
    if (cachingEnable) {
        SearchResult searchResult = new SearchResult();
        searchResult.setResultSetDTO(result);
        policySearchCache.addToCache(cacheKey, searchResult);
        if (log.isDebugEnabled()) {
            int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
            log.debug("PDP Decision Cache Updated for tenantId " + tenantId);
        }
    }
    return result;
}
Also used : EntitledAttributesDTO(org.wso2.carbon.identity.entitlement.dto.EntitledAttributesDTO) Set(java.util.Set) HashSet(java.util.HashSet) AttributeDTO(org.wso2.carbon.identity.entitlement.dto.AttributeDTO) PolicyFinderModule(org.wso2.carbon.identity.entitlement.policy.finder.PolicyFinderModule) ArrayList(java.util.ArrayList) List(java.util.List) EntitledResultSetDTO(org.wso2.carbon.identity.entitlement.dto.EntitledResultSetDTO) HashSet(java.util.HashSet)

Aggregations

AttributeDTO (org.wso2.carbon.identity.entitlement.dto.AttributeDTO)21 ArrayList (java.util.ArrayList)10 Iterator (java.util.Iterator)9 OMElement (org.apache.axiom.om.OMElement)8 HashSet (java.util.HashSet)6 QName (javax.xml.namespace.QName)5 EntitlementException (org.wso2.carbon.identity.entitlement.EntitlementException)5 List (java.util.List)4 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)4 Set (java.util.Set)3 Map (java.util.Map)2 Properties (java.util.Properties)2 EntitledAttributesDTO (org.wso2.carbon.identity.entitlement.dto.EntitledAttributesDTO)2 EntitledResultSetDTO (org.wso2.carbon.identity.entitlement.dto.EntitledResultSetDTO)2 PolicyDTO (org.wso2.carbon.identity.entitlement.dto.PolicyDTO)2 PolicyFinderModule (org.wso2.carbon.identity.entitlement.policy.finder.PolicyFinderModule)2 Collection (org.wso2.carbon.registry.core.Collection)2 Registry (org.wso2.carbon.registry.core.Registry)2 Resource (org.wso2.carbon.registry.core.Resource)2 IOException (java.io.IOException)1