diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PIPDevice.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PIPDevice.java index e758e2ca7ee..a77eb02ec20 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PIPDevice.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PIPDevice.java @@ -24,7 +24,6 @@ import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.core.dto.DeviceType; import java.sql.Timestamp; -import java.util.List; import java.util.Map; //TODO : @@ -34,7 +33,7 @@ public class PIPDevice { private DeviceType deviceType; private DeviceIdentifier deviceIdentifier; private String ownershipType; - private List userIds; + private String userId; private String roles[]; private String latitude; private String longitude; @@ -67,12 +66,12 @@ public class PIPDevice { this.ownershipType = ownershipType; } - public List getUserIds() { - return userIds; + public String getUserId() { + return userId; } - public void setUserIds(List userIds) { - this.userIds = userIds; + public void setUserId(String userId) { + this.userId = userId; } public String[] getRoles() { diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyFilter.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyFilter.java index 32a86d9de09..b636d5d9c39 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyFilter.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/src/main/java/org/wso2/carbon/policy/mgt/common/PolicyFilter.java @@ -19,18 +19,16 @@ package org.wso2.carbon.policy.mgt.common; -import org.wso2.carbon.policy.mgt.common.Policy; - import java.util.List; public interface PolicyFilter { - void filterRolesBasedPolicies(String roles[], List policies); + List filterRolesBasedPolicies(String roles[], List policies); - void filterOwnershipTypeBasedPolicies(String ownershipType, List policies); + List filterOwnershipTypeBasedPolicies(String ownershipType, List policies); - void filterDeviceTypeBasedPolicies(String deviceType, List policies); + List filterDeviceTypeBasedPolicies(String deviceType, List policies); - void filterUserBasedPolicies(List usernames, List policies); + List filterUserBasedPolicies(String username, List policies); } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyFilterImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyFilterImpl.java index 0927bfc64b5..0676b68a04c 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyFilterImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyFilterImpl.java @@ -33,13 +33,14 @@ public class PolicyFilterImpl implements PolicyFilter { private static final Log log = LogFactory.getLog(PolicyFilterImpl.class); @Override - public void filterRolesBasedPolicies(String roles[], List policies) { + public List filterRolesBasedPolicies(String roles[], List policies) { List temp = new ArrayList(); for (Policy policy : policies) { List tempRoles = policy.getRoles(); if (tempRoles.isEmpty()) { + temp.add(policy); continue; } if (PolicyManagementConstants.ANY.equalsIgnoreCase(tempRoles.get(0))) { @@ -56,12 +57,11 @@ public class PolicyFilterImpl implements PolicyFilter { } } } - policies = temp; - + return temp; } @Override - public void filterOwnershipTypeBasedPolicies(String ownershipType, List policies) { + public List filterOwnershipTypeBasedPolicies(String ownershipType, List policies) { List temp = new ArrayList(); for (Policy policy : policies) { @@ -70,22 +70,22 @@ public class PolicyFilterImpl implements PolicyFilter { temp.add(policy); } } - policies = temp; + return temp; } @Override - public void filterDeviceTypeBasedPolicies(String deviceType, List policies) { + public List filterDeviceTypeBasedPolicies(String deviceType, List policies) { List temp = new ArrayList(); for (Policy policy : policies) { if (deviceType.equalsIgnoreCase(policy.getProfile().getDeviceType().getName())) { temp.add(policy); } } - policies = temp; + return temp; } @Override - public void filterUserBasedPolicies(List usernames, List policies) { + public List filterUserBasedPolicies(String username, List policies) { List temp = new ArrayList(); for (Policy policy : policies) { @@ -95,13 +95,11 @@ public class PolicyFilterImpl implements PolicyFilter { continue; } for (String user : users) { - if(usernames.contains(user)) { + if(username.equalsIgnoreCase(user)) { temp.add(policy); } } } - policies = temp; + return temp; } - - } diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyInformationPointImpl.java b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyInformationPointImpl.java index f4c5576a9ec..441d66bf29d 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyInformationPointImpl.java +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/main/java/org/wso2/carbon/policy/mgt/core/impl/PolicyInformationPointImpl.java @@ -71,6 +71,7 @@ public class PolicyInformationPointImpl implements PolicyInformationPoint { pipDevice.setRoles(getRoleOfDevice(device)); pipDevice.setDeviceType(deviceType); pipDevice.setDeviceIdentifier(deviceIdentifier); + pipDevice.setUserId(device.getOwner()); // TODO : Find a way to retrieve the timestamp and location (lat, long) of the device // pipDevice.setLongitude(); @@ -92,16 +93,16 @@ public class PolicyInformationPointImpl implements PolicyInformationPoint { PolicyFilter policyFilter = new PolicyFilterImpl(); if (pipDevice.getDeviceType() != null) { - policyFilter.filterDeviceTypeBasedPolicies(pipDevice.getDeviceType().getName(), policies); + policies = policyFilter.filterDeviceTypeBasedPolicies(pipDevice.getDeviceType().getName(), policies); } - if (!pipDevice.getOwnershipType().isEmpty()) { - policyFilter.filterOwnershipTypeBasedPolicies(pipDevice.getOwnershipType(), policies); + if (pipDevice.getOwnershipType() != null && !pipDevice.getOwnershipType().isEmpty()) { + policies = policyFilter.filterOwnershipTypeBasedPolicies(pipDevice.getOwnershipType(), policies); } if (pipDevice.getRoles() != null) { - policyFilter.filterRolesBasedPolicies(pipDevice.getRoles(), policies); + policies = policyFilter.filterRolesBasedPolicies(pipDevice.getRoles(), policies); } - if(pipDevice.getUserIds()!=null) { - policyFilter.filterUserBasedPolicies(pipDevice.getUserIds(), policies); + if(pipDevice.getUserId() != null && !pipDevice.getUserId().isEmpty()) { + policies = policyFilter.filterUserBasedPolicies(pipDevice.getUserId(), policies); } return policies;