Search in sources :

Example 1 with PublisherPropertyDTO

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

the class SimplePAPStatusDataHandler method readStatus.

private synchronized List<StatusHolder> readStatus(String path, String about) throws EntitlementException {
    Resource resource = null;
    Registry registry = null;
    int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
    try {
        registry = EntitlementServiceComponent.getRegistryService().getGovernanceSystemRegistry(tenantId);
        if (registry.resourceExists(path)) {
            resource = registry.get(path);
        }
    } catch (RegistryException e) {
        log.error(e);
        throw new EntitlementException("Error while persisting policy status", e);
    }
    List<StatusHolder> statusHolders = new ArrayList<StatusHolder>();
    if (resource != null && resource.getProperties() != null) {
        Properties properties = resource.getProperties();
        for (Map.Entry<Object, Object> entry : properties.entrySet()) {
            PublisherPropertyDTO dto = new PublisherPropertyDTO();
            dto.setId((String) entry.getKey());
            Object value = entry.getValue();
            if (value instanceof ArrayList) {
                List list = (ArrayList) entry.getValue();
                if (list != null && list.size() > 0 && list.get(0) != null) {
                    StatusHolder statusHolder = new StatusHolder(about);
                    if (list.size() > 0 && list.get(0) != null) {
                        statusHolder.setType((String) list.get(0));
                    }
                    if (list.size() > 1 && list.get(1) != null) {
                        statusHolder.setTimeInstance((String) list.get(1));
                    } else {
                        continue;
                    }
                    if (list.size() > 2 && list.get(2) != null) {
                        String user = (String) list.get(2);
                        statusHolder.setUser(user);
                    } else {
                        continue;
                    }
                    if (list.size() > 3 && list.get(3) != null) {
                        statusHolder.setKey((String) list.get(3));
                    }
                    if (list.size() > 4 && list.get(4) != null) {
                        statusHolder.setSuccess(Boolean.parseBoolean((String) list.get(4)));
                    }
                    if (list.size() > 5 && list.get(5) != null) {
                        statusHolder.setMessage((String) list.get(5));
                    }
                    if (list.size() > 6 && list.get(6) != null) {
                        statusHolder.setTarget((String) list.get(6));
                    }
                    if (list.size() > 7 && list.get(7) != null) {
                        statusHolder.setTargetAction((String) list.get(7));
                    }
                    if (list.size() > 8 && list.get(8) != null) {
                        statusHolder.setVersion((String) list.get(8));
                    }
                    statusHolders.add(statusHolder);
                }
            }
        }
    }
    if (statusHolders.size() > 0) {
        StatusHolder[] array = statusHolders.toArray(new StatusHolder[statusHolders.size()]);
        java.util.Arrays.sort(array, new StatusHolderComparator());
        if (statusHolders.size() > maxRecodes) {
            statusHolders = new ArrayList<StatusHolder>();
            for (int i = 0; i < maxRecodes; i++) {
                statusHolders.add(array[i]);
            }
            persistStatus(path, statusHolders, true);
        } else {
            statusHolders = new ArrayList<StatusHolder>(Arrays.asList(array));
        }
    }
    return statusHolders;
}
Also used : Resource(org.wso2.carbon.registry.core.Resource) ArrayList(java.util.ArrayList) Registry(org.wso2.carbon.registry.core.Registry) Properties(java.util.Properties) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) StatusHolder(org.wso2.carbon.identity.entitlement.dto.StatusHolder) PublisherPropertyDTO(org.wso2.carbon.identity.entitlement.dto.PublisherPropertyDTO) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map)

Example 2 with PublisherPropertyDTO

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

the class PolicyPublisher method populateProperties.

private void populateProperties(PublisherDataHolder holder, PublisherDataHolder oldHolder, Resource resource) {
    PublisherPropertyDTO[] propertyDTOs = holder.getPropertyDTOs();
    for (PublisherPropertyDTO dto : propertyDTOs) {
        if (dto.getId() != null && dto.getValue() != null && dto.getValue().trim().length() > 0) {
            ArrayList<String> list = new ArrayList<String>();
            if (dto.isSecret()) {
                PublisherPropertyDTO propertyDTO = null;
                if (oldHolder != null) {
                    propertyDTO = oldHolder.getPropertyDTO(dto.getId());
                }
                if (propertyDTO == null || !propertyDTO.getValue().equalsIgnoreCase(dto.getValue())) {
                    try {
                        String encryptedValue = CryptoUtil.getDefaultCryptoUtil().encryptAndBase64Encode(dto.getValue().getBytes());
                        dto.setValue(encryptedValue);
                    } catch (CryptoException e) {
                        log.error("Error while encrypting secret value of subscriber. " + "Secret would not be persist.", e);
                        continue;
                    }
                }
            }
            list.add(dto.getValue());
            list.add(dto.getDisplayName());
            list.add(Integer.toString(dto.getDisplayOrder()));
            list.add(Boolean.toString(dto.isRequired()));
            list.add(Boolean.toString(dto.isSecret()));
            resource.setProperty(dto.getId(), list);
        }
    }
    resource.setProperty(PublisherDataHolder.MODULE_NAME, holder.getModuleName());
}
Also used : ArrayList(java.util.ArrayList) PublisherPropertyDTO(org.wso2.carbon.identity.entitlement.dto.PublisherPropertyDTO) CryptoException(org.wso2.carbon.core.util.CryptoException)

Example 3 with PublisherPropertyDTO

use of org.wso2.carbon.identity.entitlement.dto.PublisherPropertyDTO in project product-is by wso2.

the class EntitlementPolicyAdminServiceTestCase method testUpdateSubscriber.

// @Test(groups = "wso2.is", description = "Check getting subscriber Ids", dependsOnMethods="testOrderPolicy")
// public void testEnableDisablePolicy() throws Exception{
// entitlementPolicyClient.enableDisablePolicy(POLICY_1_ID, false);
// entitlementPolicyClient.enableDisablePolicy(POLICY_1_ID, true);
// }
@Test(groups = "wso2.is", description = "Check getting subscriber", dependsOnMethods = "testOrderPolicy")
public void testUpdateSubscriber() throws Exception {
    PublisherDataHolder holder = new PublisherDataHolder();
    holder.setModuleName("test2");
    PublisherPropertyDTO propertyDto = new PublisherPropertyDTO();
    propertyDto.setId("subscriberId");
    propertyDto.setValue("1002");
    PublisherPropertyDTO[] propertyDTOs = new PublisherPropertyDTO[1];
    propertyDTOs[0] = propertyDto;
    holder.setPropertyDTOs(propertyDTOs);
    entitlementPolicyClient.updateSubscriber(holder);
}
Also used : PublisherDataHolder(org.wso2.carbon.identity.entitlement.stub.dto.PublisherDataHolder) PublisherPropertyDTO(org.wso2.carbon.identity.entitlement.stub.dto.PublisherPropertyDTO) ISIntegrationTest(org.wso2.identity.integration.common.utils.ISIntegrationTest) Test(org.testng.annotations.Test)

Example 4 with PublisherPropertyDTO

use of org.wso2.carbon.identity.entitlement.dto.PublisherPropertyDTO in project product-is by wso2.

the class EntitlementPolicyAdminServiceTestCase method testAddSubscriber.

@Test(groups = "wso2.is", description = "Check getting subscriber", dependsOnMethods = "testGetStatusData")
public void testAddSubscriber() throws Exception {
    PublisherDataHolder holder = new PublisherDataHolder();
    holder.setModuleName("test");
    PublisherPropertyDTO propertyDto = new PublisherPropertyDTO();
    propertyDto.setId("subscriberId");
    propertyDto.setValue("1001");
    PublisherPropertyDTO[] propertyDTOs = new PublisherPropertyDTO[1];
    propertyDTOs[0] = propertyDto;
    holder.setPropertyDTOs(propertyDTOs);
    entitlementPolicyClient.addSubscriber(holder);
}
Also used : PublisherDataHolder(org.wso2.carbon.identity.entitlement.stub.dto.PublisherDataHolder) PublisherPropertyDTO(org.wso2.carbon.identity.entitlement.stub.dto.PublisherPropertyDTO) ISIntegrationTest(org.wso2.identity.integration.common.utils.ISIntegrationTest) Test(org.testng.annotations.Test)

Example 5 with PublisherPropertyDTO

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

the class PropertyDTOComparator method compare.

@Override
public int compare(Object o1, Object o2) {
    PublisherPropertyDTO dto1 = (PublisherPropertyDTO) o1;
    PublisherPropertyDTO dto2 = (PublisherPropertyDTO) o2;
    if (dto1.getDisplayOrder() < dto2.getDisplayOrder()) {
        return -1;
    } else if (dto1.getDisplayOrder() == dto2.getDisplayOrder()) {
        return 0;
    } else {
        return 1;
    }
}
Also used : PublisherPropertyDTO(org.wso2.carbon.identity.entitlement.stub.dto.PublisherPropertyDTO)

Aggregations

PublisherPropertyDTO (org.wso2.carbon.identity.entitlement.dto.PublisherPropertyDTO)4 ArrayList (java.util.ArrayList)3 PublisherPropertyDTO (org.wso2.carbon.identity.entitlement.stub.dto.PublisherPropertyDTO)3 Map (java.util.Map)2 Test (org.testng.annotations.Test)2 PublisherDataHolder (org.wso2.carbon.identity.entitlement.dto.PublisherDataHolder)2 PublisherDataHolder (org.wso2.carbon.identity.entitlement.stub.dto.PublisherDataHolder)2 Resource (org.wso2.carbon.registry.core.Resource)2 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)2 ISIntegrationTest (org.wso2.identity.integration.common.utils.ISIntegrationTest)2 List (java.util.List)1 Properties (java.util.Properties)1 CryptoException (org.wso2.carbon.core.util.CryptoException)1 EntitlementException (org.wso2.carbon.identity.entitlement.EntitlementException)1 StatusHolder (org.wso2.carbon.identity.entitlement.dto.StatusHolder)1 Collection (org.wso2.carbon.registry.core.Collection)1 Registry (org.wso2.carbon.registry.core.Registry)1