SHARE
TWEET

Untitled

a guest Oct 12th, 2017 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.vmware.vshield.flow.appvisibility.facade.impl;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.HashMap;
  5. import java.util.List;
  6. import java.util.Map;
  7. import java.util.Set;
  8.  
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.stereotype.Service;
  11. import org.springframework.transaction.annotation.Transactional;
  12.  
  13. import com.vmware.vshield.app.global.AppConstants;
  14. import com.vmware.vshield.firewall.dto.ObjectType;
  15. import com.vmware.vshield.flow.appvisibility.facade.AppVisibilityRuleContainerFacade;
  16. import com.vmware.vshield.flow.appvisibility.model.AppVisibilityRuleContainer;
  17. import com.vmware.vshield.flow.appvisibility.service.IAppVisibilityRuleRecommendationService;
  18. import com.vmware.vshield.vsm.application.service.ApplicationService;
  19. import com.vmware.vshield.vsm.applicationgroup.model.ApplicationGroup;
  20. import com.vmware.vshield.vsm.applicationgroup.service.ApplicationGroupService;
  21. import com.vmware.vshield.vsm.aspects.security.VsmSecured;
  22. import com.vmware.vshield.vsm.common.CommonConstants;
  23. import com.vmware.vshield.vsm.common.DomainObjectPageAttribute;
  24. import com.vmware.vshield.vsm.converter.ApplicationDtoConverter;
  25. import com.vmware.vshield.vsm.converter.ApplicationGroupDtoConverter;
  26. import com.vmware.vshield.vsm.converter.DomainObjectFilterConverter;
  27. import com.vmware.vshield.vsm.converter.IPSetDtoConverter;
  28. import com.vmware.vshield.vsm.converter.PagingInfoConverter;
  29. import com.vmware.vshield.vsm.converter.SecurityGroupDtoConverter;
  30. import com.vmware.vshield.vsm.dto.ApplicationDto;
  31. import com.vmware.vshield.vsm.dto.ApplicationGroupDto;
  32. import com.vmware.vshield.vsm.dto.DataPage;
  33. import com.vmware.vshield.vsm.dto.ExtendedAttributeDto;
  34. import com.vmware.vshield.vsm.dto.IPSetDto;
  35. import com.vmware.vshield.vsm.dto.PagingInfo;
  36. import com.vmware.vshield.vsm.dto.QueryOperator;
  37. import com.vmware.vshield.vsm.dto.SecurityGroupDto;
  38. import com.vmware.vshield.vsm.filter.DomainObjectFilter;
  39. import com.vmware.vshield.vsm.ipset.service.IPSetService;
  40. import com.vmware.vshield.vsm.model.Application;
  41. import com.vmware.vshield.vsm.model.ExtendedAttribute;
  42. import com.vmware.vshield.vsm.model.IPSet;
  43. import com.vmware.vshield.vsm.security.model.Permission;
  44. import com.vmware.vshield.vsm.securitygroup.model.SecurityGroup;
  45. import com.vmware.vshield.vsm.securitygroup.service.SecurityGroupService;
  46. import com.vmware.vshield.vsm.utils.Logger;
  47.  
  48. /**
  49.  * Implements AppVisibilityRulesFacade interface. Provides methods that allows
  50.  * management of firewall rules related operations via AppVisibility tool.
  51.  *
  52.  */
  53. @Service
  54. public class AppVisibilityRuleContainerFacadeImpl implements AppVisibilityRuleContainerFacade {
  55.  
  56.     Logger logger = Logger.getLogger();
  57.  
  58.     @Autowired
  59.     IAppVisibilityRuleRecommendationService ruleRecommendationService;
  60.     @Autowired
  61.     private IPSetService ipSetService;
  62.     @Autowired
  63.     private SecurityGroupService securityGroupService;
  64.     @Autowired
  65.     private ApplicationService applicationService;
  66.     @Autowired
  67.     private ApplicationGroupService applicationGroupService;
  68.     @Autowired
  69.     private IPSetDtoConverter ipSetDtoConverter;
  70.     @Autowired
  71.     private SecurityGroupDtoConverter securityGroupDtoConverter;
  72.     @Autowired
  73.     private ApplicationDtoConverter applicationDtoConverter;
  74.     @Autowired
  75.     private ApplicationGroupDtoConverter applicationGroupDtoConverter;
  76.     @Autowired
  77.     private PagingInfoConverter pagingInfoConverter;
  78.     @Autowired
  79.     private DomainObjectFilterConverter domainObjectFilterConverter;
  80.  
  81.  
  82.     @Override
  83.     @Transactional(readOnly = true)
  84.     @VsmSecured(objectid = CommonConstants.GLOBAL_ROOT_ID, featurename = AppConstants.AUTH_FLOW, permission = Permission.READ)
  85.     public DataPage<IPSetDto> IPSetList(Long sessionId, String scope, PagingInfo pagingInfo, String filterValue, List<String> filterColumns){
  86.  
  87.         DomainObjectPageAttribute doPagingInfo = pagingInfoConverter.toDo(pagingInfo);
  88.  
  89.         Map<String, String> extendedAtts = new HashMap<String, String>();
  90.         extendedAtts.put("isReadOnly", "true");
  91.         extendedAtts.put("isHidden", "true");
  92.  
  93.         DomainObjectFilter<IPSet> filter = domainObjectFilterConverter.toDomainObjectFilter(IPSet.class, filterValue, filterColumns, extendedAtts, QueryOperator.NOT_EQUAL);
  94.  
  95.  
  96.  
  97.         List<AppVisibilityRuleContainer> containers = ruleRecommendationService.getFilteredContainers(sessionId,
  98.                 ObjectType.IP_SET, true, filterValue);
  99.  
  100.         if (containers != null) {
  101.             ArrayList<String> unPublishedEntitiesIds = new ArrayList<String>();
  102.               for (AppVisibilityRuleContainer container : containers) {
  103.                   unPublishedEntitiesIds.add(container.getValue());
  104.               }
  105.               filter.setObjectIds(unPublishedEntitiesIds);
  106.           }
  107.  
  108.         List<IPSet> ipSets = null;
  109.  
  110.         if (scope == null) {
  111.             ipSets = ipSetService.list(doPagingInfo, filter);
  112.         } else {
  113.             ipSets = ipSetService.list(scope, doPagingInfo, filter);
  114.         }
  115.         pagingInfo.setTotalCount(doPagingInfo.getTotalCount());
  116.  
  117.         List<IPSetDto> dtos = new ArrayList<IPSetDto>();
  118.         IPSetDto dto;
  119.         for(IPSet set: ipSets) {
  120.             dto = ipSetDtoConverter.toDto(set);
  121.             dtos.add(dto);
  122.         }
  123.  
  124.         DataPage<IPSetDto> dataPage = new DataPage<IPSetDto>();
  125.         dataPage.setData(dtos);
  126.         dataPage.setPagingInfo(pagingInfo);
  127.  
  128.         return dataPage;
  129.     }
  130.  
  131.     @Override
  132.     @Transactional(readOnly = true)
  133.     @VsmSecured(objectid = CommonConstants.GLOBAL_ROOT_ID, featurename = AppConstants.AUTH_FLOW, permission = Permission.READ)
  134.     public DataPage<SecurityGroupDto> securityGroupList(Long sessionId, String scope, PagingInfo pagingInfo, String filterValue, List<String> filterColumns){
  135.  
  136.         DomainObjectPageAttribute doPagingInfo = pagingInfoConverter.toDo(pagingInfo);
  137.  
  138.         Map<String, String> extendedAtts = new HashMap<String, String>();
  139.         extendedAtts.put("isReadOnly", "true");
  140.         extendedAtts.put("isHidden", "true");
  141.  
  142.         DomainObjectFilter<SecurityGroup> filter = domainObjectFilterConverter.toDomainObjectFilter(SecurityGroup.class, filterValue, filterColumns, extendedAtts, QueryOperator.NOT_EQUAL);
  143.  
  144.  
  145.  
  146.         List<AppVisibilityRuleContainer> containers = ruleRecommendationService.getFilteredContainers(sessionId,
  147.                 ObjectType.SECURITY_GROUP, true, filterValue);
  148.  
  149.         if (containers != null) {
  150.             ArrayList<String> unPublishedEntitiesIds = new ArrayList<String>();
  151.               for (AppVisibilityRuleContainer container : containers) {
  152.                   unPublishedEntitiesIds.add(container.getValue());
  153.               }
  154.               filter.setObjectIds(unPublishedEntitiesIds);
  155.           }
  156.  
  157.         List<SecurityGroup> securityGroups = null;
  158.  
  159.         if (scope == null) {
  160.             securityGroups = securityGroupService.list(doPagingInfo, filter);
  161.         } else {
  162.             securityGroups = securityGroupService.list(scope, doPagingInfo, filter);
  163.         }
  164.         pagingInfo.setTotalCount(doPagingInfo.getTotalCount());
  165.  
  166.         List<SecurityGroupDto> dtos = new ArrayList<SecurityGroupDto>();
  167.         SecurityGroupDto dto;
  168.        
  169.        
  170.         logger.debug("sec-groups: " + securityGroups);
  171.         logger.debug("sec-groups-length: " + securityGroups.size());
  172.         for(SecurityGroup set: securityGroups) {
  173.             Set<ExtendedAttribute> extAttrs = set.getExtendedAttributes();
  174.             if(extAttrs != null) {
  175.                 for(ExtendedAttribute ettrDto : extAttrs){
  176.                     if( ettrDto != null && "isHidden".equals(ettrDto.getName()) && "true".equals(ettrDto.getValue())){
  177.                         logger.debug("dto-value: " + set);
  178.                         logger.debug("SecurityGroupError - got hidden attribute so skipping it lalal");
  179.                     }else {
  180.                         dto = securityGroupDtoConverter.toDto(set);
  181.                         dtos.add(dto);
  182.                         logger.debug("added-dto: " + dtos);
  183.                         logger.debug("added-dto-length: " + dtos.size());
  184.                     }
  185.                 }
  186.             }
  187.  
  188.         }
  189.        
  190.         logger.debug("final-dto: " + dtos);
  191.         logger.debug("final-dto-length: " + dtos.size());
  192.        
  193.  
  194.         DataPage<SecurityGroupDto> dataPage = new DataPage<SecurityGroupDto>();
  195.         dataPage.setData(dtos);
  196.         dataPage.setPagingInfo(pagingInfo);
  197.  
  198.         return dataPage;
  199.     }
  200.  
  201.     @Override
  202.     @Transactional(readOnly = true)
  203.     @VsmSecured(objectid = CommonConstants.GLOBAL_ROOT_ID, featurename = AppConstants.AUTH_FLOW, permission = Permission.READ)
  204.     public DataPage<ApplicationDto> applicationList(Long sessionId, String scope, PagingInfo pagingInfo, String filterValue, List<String> filterColumns){
  205.  
  206.         DomainObjectPageAttribute doPagingInfo = pagingInfoConverter.toDo(pagingInfo);
  207.  
  208.         Map<String, String> extendedAtts = new HashMap<String, String>();
  209.         extendedAtts.put("isReadOnly", "true");
  210.         extendedAtts.put("isHidden", "true");
  211.  
  212.         DomainObjectFilter<Application> filter = domainObjectFilterConverter.toDomainObjectFilter(Application.class, filterValue, filterColumns, extendedAtts, QueryOperator.NOT_EQUAL);
  213.  
  214.         ArrayList<String> unPublishedEntitiesIds = new ArrayList<String>();
  215.  
  216.         List<AppVisibilityRuleContainer> containers = ruleRecommendationService.getFilteredContainers(sessionId,
  217.                 ObjectType.APPLICATION, true, filterValue);
  218.  
  219.         if (containers != null) {
  220.               for (AppVisibilityRuleContainer container : containers) {
  221.                   unPublishedEntitiesIds.add(container.getValue());
  222.               }
  223.               filter.setObjectIds(unPublishedEntitiesIds);
  224.           }
  225.  
  226.         List<Application> applications = null;
  227.  
  228.         if (scope == null) {
  229.             applications = applicationService.list(doPagingInfo, filter);
  230.         } else {
  231.             applications = applicationService.list(scope, doPagingInfo, filter);
  232.         }
  233.         pagingInfo.setTotalCount(doPagingInfo.getTotalCount());
  234.  
  235.         List<ApplicationDto> dtos = new ArrayList<ApplicationDto>();
  236.         ApplicationDto dto;
  237.         for(Application set: applications) {
  238.             dto = applicationDtoConverter.toDto(set);
  239.             dtos.add(dto);
  240.         }
  241.  
  242.         DataPage<ApplicationDto> dataPage = new DataPage<ApplicationDto>();
  243.         dataPage.setData(dtos);
  244.         dataPage.setPagingInfo(pagingInfo);
  245.  
  246.         return dataPage;
  247.     }
  248.  
  249.     @Override
  250.     @Transactional(readOnly = true)
  251.     @VsmSecured(objectid = CommonConstants.GLOBAL_ROOT_ID, featurename = AppConstants.AUTH_FLOW, permission = Permission.READ)
  252.     public DataPage<ApplicationGroupDto> applicationGroupList(Long sessionId, String scope, PagingInfo pagingInfo, String filterValue, List<String> filterColumns){
  253.  
  254.         DomainObjectPageAttribute doPagingInfo = pagingInfoConverter.toDo(pagingInfo);
  255.  
  256.         Map<String, String> extendedAtts = new HashMap<String, String>();
  257.         extendedAtts.put("isReadOnly", "true");
  258.         extendedAtts.put("isHidden", "true");
  259.  
  260.         DomainObjectFilter<ApplicationGroup> filter = domainObjectFilterConverter.toDomainObjectFilter(ApplicationGroup.class, filterValue, filterColumns, extendedAtts, QueryOperator.NOT_EQUAL);
  261.  
  262.         ArrayList<String> unPublishedEntitiesIds = new ArrayList<String>();
  263.  
  264.         List<AppVisibilityRuleContainer> containers = ruleRecommendationService.getFilteredContainers(sessionId,
  265.                 ObjectType.APPLICATON_GROUP, true, filterValue);
  266.  
  267.         if (containers != null) {
  268.               for (AppVisibilityRuleContainer container : containers) {
  269.                   unPublishedEntitiesIds.add(container.getValue());
  270.               }
  271.               filter.setObjectIds(unPublishedEntitiesIds);
  272.           }
  273.  
  274.         List<ApplicationGroup> applicationGroups = null;
  275.  
  276.         if (scope == null) {
  277.             applicationGroups = applicationGroupService.list(doPagingInfo, filter);
  278.         } else {
  279.             applicationGroups = applicationGroupService.list(scope, doPagingInfo, filter);
  280.         }
  281.         pagingInfo.setTotalCount(doPagingInfo.getTotalCount());
  282.  
  283.         List<ApplicationGroupDto> dtos = new ArrayList<ApplicationGroupDto>();
  284.         ApplicationGroupDto dto;
  285.         for(ApplicationGroup set: applicationGroups) {
  286.             dto = applicationGroupDtoConverter.toDto(set);
  287.             dtos.add(dto);
  288.         }
  289.  
  290.         DataPage<ApplicationGroupDto> dataPage = new DataPage<ApplicationGroupDto>();
  291.         dataPage.setData(dtos);
  292.         dataPage.setPagingInfo(pagingInfo);
  293.  
  294.         return dataPage;
  295.     }
  296. }
RAW Paste Data
Top