Fixed bugs in policy

4.x.x
mharindu 10 years ago
parent 6586eb028c
commit 1ed6eec02f

@ -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<String> 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<String> getUserIds() {
return userIds;
public String getUserId() {
return userId;
}
public void setUserIds(List<String> userIds) {
this.userIds = userIds;
public void setUserId(String userId) {
this.userId = userId;
}
public String[] getRoles() {

@ -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<Policy> policies);
List<Policy> filterRolesBasedPolicies(String roles[], List<Policy> policies);
void filterOwnershipTypeBasedPolicies(String ownershipType, List<Policy> policies);
List<Policy> filterOwnershipTypeBasedPolicies(String ownershipType, List<Policy> policies);
void filterDeviceTypeBasedPolicies(String deviceType, List<Policy> policies);
List<Policy> filterDeviceTypeBasedPolicies(String deviceType, List<Policy> policies);
void filterUserBasedPolicies(List<String> usernames, List<Policy> policies);
List<Policy> filterUserBasedPolicies(String username, List<Policy> policies);
}

@ -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<Policy> policies) {
public List<Policy> filterRolesBasedPolicies(String roles[], List<Policy> policies) {
List<Policy> temp = new ArrayList<Policy>();
for (Policy policy : policies) {
List<String> 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<Policy> policies) {
public List<Policy> filterOwnershipTypeBasedPolicies(String ownershipType, List<Policy> policies) {
List<Policy> temp = new ArrayList<Policy>();
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<Policy> policies) {
public List<Policy> filterDeviceTypeBasedPolicies(String deviceType, List<Policy> policies) {
List<Policy> temp = new ArrayList<Policy>();
for (Policy policy : policies) {
if (deviceType.equalsIgnoreCase(policy.getProfile().getDeviceType().getName())) {
temp.add(policy);
}
}
policies = temp;
return temp;
}
@Override
public void filterUserBasedPolicies(List<String> usernames, List<Policy> policies) {
public List<Policy> filterUserBasedPolicies(String username, List<Policy> policies) {
List<Policy> temp = new ArrayList<Policy>();
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;
}
}

@ -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;

Loading…
Cancel
Save