forked from community/device-mgt-core
Adding the policy management service and dao implementation, basic architecture is implemented here, only thing we have to do is to fill the method with relavant informations. PDP, PEP, PIP services are renamed.
parent
7056b01d18
commit
5a253b286e
@ -1,88 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* you may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.policy.mgt.common.impl;
|
||||
|
||||
import org.wso2.carbon.policy.mgt.common.*;
|
||||
|
||||
public class PolicyManagement implements PolicyAdministratorService {
|
||||
@Override
|
||||
public int addPolicy(Policy policy) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int addPolicyToDevice(String deviceId, String deviceType, Policy policy) throws FeatureManagementException, PolicyManagementException {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int addPolicyToDeviceType(String deviceType, Policy policy) throws FeatureManagementException, PolicyManagementException {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int addPolicyToRole(String roleName, Policy policy) throws FeatureManagementException, PolicyManagementException {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Policy getPolicy() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Policy getPolicyOfDevice(String deviceId, String deviceType) throws FeatureManagementException, PolicyManagementException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Policy getPolicyOfDeviceType(String deviceType) throws FeatureManagementException, PolicyManagementException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Policy getPolicyOfRole(String roleName) throws FeatureManagementException, PolicyManagementException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPolicyAvailableForDevice(String deviceId, String deviceType) throws PolicyManagementException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPolicyUsed(String deviceId, String deviceType) throws PolicyManagementException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPolicyUsed(String deviceId, String deviceType, Policy policy) throws PolicyManagementException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addProfile(Profile profile) throws PolicyManagementException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteProfile(int profileId) throws PolicyManagementException {
|
||||
|
||||
}
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2014, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* you may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wos2.carbon.policy.mgt.common;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
import org.wos2.carbon.policy.mgt.common.utils.PolicyCreator;
|
||||
import org.wso2.carbon.policy.mgt.common.FeatureManagementException;
|
||||
import org.wso2.carbon.policy.mgt.common.Policy;
|
||||
import org.wso2.carbon.policy.mgt.common.PolicyManagementException;
|
||||
import org.wso2.carbon.policy.mgt.common.impl.PolicyManagement;
|
||||
|
||||
public class PolicyManagementTestCase {
|
||||
|
||||
private static final Log log = LogFactory.getLog(PolicyManagementTestCase.class);
|
||||
|
||||
Policy policy = PolicyCreator.createPolicy();
|
||||
|
||||
private PolicyManagement policyManagement = new PolicyManagement();
|
||||
|
||||
@Test(groups = "policy.mgt.test", description = "Testing the adding policy to a device")
|
||||
public void testAddPolicy() throws FeatureManagementException, PolicyManagementException {
|
||||
Assert.assertEquals(policyManagement.addPolicyToDevice("1212-ESDD-12ER-7890", "MD", policy), 0);
|
||||
}
|
||||
|
||||
@Test(groups = "policy.mgt.test", description = "Testing the adding policy to a device type")
|
||||
public void testAddPolicyToDeviceType() throws FeatureManagementException, PolicyManagementException {
|
||||
Assert.assertEquals(policyManagement.addPolicyToDeviceType("MD", policy), 0);
|
||||
}
|
||||
|
||||
@Test(groups = "policy.mgt.test", description = "Testing the adding policy to a user Role")
|
||||
public void testAddPolicyToRole() throws FeatureManagementException, PolicyManagementException {
|
||||
Assert.assertEquals(policyManagement.addPolicyToRole("Admin", policy), 0);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (c) 2015 WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.policy.mgt.core.impl;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
|
||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.core.dao.impl.DeviceDAOImpl;
|
||||
import org.wso2.carbon.device.mgt.core.dto.Device;
|
||||
import org.wso2.carbon.policy.mgt.common.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class PolicyInformationPointImpl implements PolicyInformationPoint {
|
||||
|
||||
private static final Log log = LogFactory.getLog(PolicyInformationPointImpl.class);
|
||||
DeviceDAOImpl deviceDAO;
|
||||
|
||||
public PolicyInformationPointImpl() {
|
||||
deviceDAO = new DeviceDAOImpl(DeviceManagementDAOFactory.getDataSource());
|
||||
}
|
||||
|
||||
@Override
|
||||
public PIPDeviceData getDeviceData(DeviceIdentifier deviceIdentifier) throws PolicyManagementException {
|
||||
PIPDeviceData pipDeviceData = new PIPDeviceData();
|
||||
Device device;
|
||||
try {
|
||||
device = deviceDAO.getDevice(deviceIdentifier);
|
||||
pipDeviceData.setDevice(device);
|
||||
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
String msg = "Error occurred when retrieving the data related to device from the database.";
|
||||
log.error(msg, e);
|
||||
throw new PolicyManagementException(msg, e);
|
||||
}
|
||||
|
||||
return pipDeviceData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Policy> getRelatedPolicies(PIPDeviceData pipDeviceData) throws PolicyManagementException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Feature> getRelatedFeatures(String deviceType) throws FeatureManagementException {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (c) 2015 WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.simple.policy.decision.point;
|
||||
|
||||
public class PolicyEvaluationException extends Exception {
|
||||
|
||||
private String policyErrorMessage;
|
||||
|
||||
public String getPolicyErrorMessage() {
|
||||
return policyErrorMessage;
|
||||
}
|
||||
|
||||
public void setPolicyErrorMessage(String policyErrorMessage) {
|
||||
this.policyErrorMessage = policyErrorMessage;
|
||||
}
|
||||
|
||||
public PolicyEvaluationException(String message) {
|
||||
super(message);
|
||||
setPolicyErrorMessage(message);
|
||||
}
|
||||
|
||||
public PolicyEvaluationException(String message, Exception ex) {
|
||||
super(message, ex);
|
||||
setPolicyErrorMessage(message);
|
||||
}
|
||||
|
||||
public PolicyEvaluationException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
setPolicyErrorMessage(message);
|
||||
}
|
||||
|
||||
public PolicyEvaluationException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public PolicyEvaluationException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright (c) 2015 WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
|
||||
package org.wso2.carbon.simple.policy.decision.point;
|
||||
|
||||
import org.wso2.carbon.policy.mgt.common.PIPDeviceData;
|
||||
import org.wso2.carbon.policy.mgt.common.Policy;
|
||||
|
||||
public interface SimpleEvaluation {
|
||||
|
||||
void sortPolicy(Policy policy) throws PolicyEvaluationException;
|
||||
|
||||
Policy getEffectivePolicy(PIPDeviceData pipDeviceData) throws PolicyEvaluationException;
|
||||
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2015 WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||
*
|
||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||
* Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.wso2.carbon.simple.policy.decision.point;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.policy.mgt.common.PIPDeviceData;
|
||||
import org.wso2.carbon.policy.mgt.common.Policy;
|
||||
import org.wso2.carbon.policy.mgt.core.dao.impl.PolicyDAOImpl;
|
||||
|
||||
public class SimpleEvaluationImpl implements SimpleEvaluation {
|
||||
|
||||
private static final Log log = LogFactory.getLog(SimpleEvaluationImpl.class);
|
||||
|
||||
PolicyDAOImpl policyDAO;
|
||||
|
||||
|
||||
public SimpleEvaluationImpl() {
|
||||
policyDAO = new PolicyDAOImpl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sortPolicy(Policy policy) throws PolicyEvaluationException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Policy getEffectivePolicy(PIPDeviceData pipDeviceData) throws PolicyEvaluationException {
|
||||
return null;
|
||||
}
|
||||
}
|
Loading…
Reference in new issue