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;
}
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()]));
}
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++;
}
}
}
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);
}
}
}
}
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;
}
Aggregations