forked from community/device-mgt-core
Merge branch 'release-2.0.x' of https://github.com/wso2/carbon-device-mgt into mutual_ssl_feature
commit
65cb12b5ac
@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, 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.device.mgt.jaxrs.beans;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
|
import org.wso2.carbon.device.mgt.jaxrs.beans.BasePaginatedResult;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class DeviceToGroupsAssignment extends BasePaginatedResult {
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "List of device group ids.")
|
||||||
|
@JsonProperty("deviceGroupIds")
|
||||||
|
private List<Integer> deviceGroupIds = new ArrayList<>();
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "Device identifier of the device needed to be assigned with group")
|
||||||
|
@JsonProperty("deviceIdentifier")
|
||||||
|
private DeviceIdentifier deviceIdentifier;
|
||||||
|
|
||||||
|
|
||||||
|
public List<Integer> getDeviceGroupIds() {
|
||||||
|
return deviceGroupIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeviceGroupIds(List<Integer> deviceGroupIds) {
|
||||||
|
this.deviceGroupIds = deviceGroupIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DeviceIdentifier getDeviceIdentifier() {
|
||||||
|
return deviceIdentifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeviceIdentifier(DeviceIdentifier deviceIdentifier) {
|
||||||
|
this.deviceIdentifier = deviceIdentifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, 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.device.mgt.jaxrs.beans;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@ApiModel(value = "EnrollmentInvitation", description = "Holds data to send enrollment invitation to list of recipients.")
|
||||||
|
public class EnrollmentInvitation {
|
||||||
|
|
||||||
|
@ApiModelProperty(name = "deviceType", value = "Device type name.", required = true)
|
||||||
|
private String deviceType;
|
||||||
|
|
||||||
|
@ApiModelProperty(name = "recipients", value = "List of recipients.", required = true)
|
||||||
|
private List<String> recipients;
|
||||||
|
|
||||||
|
public String getDeviceType() {
|
||||||
|
return deviceType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeviceType(String deviceType) {
|
||||||
|
this.deviceType = deviceType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getRecipients() {
|
||||||
|
return recipients;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRecipients(List<String> recipients) {
|
||||||
|
this.recipients = recipients;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
{{!
|
||||||
|
Copyright (c) 2016, 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.
|
||||||
|
}}
|
||||||
|
|
||||||
|
{{unit "cdmf.unit.ui.title" pageTitle="Policy Management | View Policy"}}
|
||||||
|
|
||||||
|
{{#zone "breadcrumbs"}}
|
||||||
|
<li>
|
||||||
|
<a href="{{@app.context}}/">
|
||||||
|
<i class="icon fw fw-home"></i>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<!--suppress HtmlUnknownTarget -->
|
||||||
|
<a href="{{@app.context}}/policies">
|
||||||
|
Policies
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="#">
|
||||||
|
View
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
{{/zone}}
|
||||||
|
|
||||||
|
{{#zone "content"}}
|
||||||
|
{{unit "cdmf.unit.device.operation-mod"}}
|
||||||
|
{{unit "cdmf.unit.effective-policy.view"}}
|
||||||
|
{{/zone}}
|
@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function onRequest(context) {
|
||||||
|
var utility = require("/app/modules/utility.js")["utility"];
|
||||||
|
var deviceType = context.uriParams.deviceType;
|
||||||
|
var deviceId = context.uriParams.deviceId;
|
||||||
|
return {"deviceTypePolicyView": utility.getTenantedDeviceUnitName(deviceType, deviceId,"policy-view")};
|
||||||
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"version": "1.0.0",
|
||||||
|
"uri": "/policy/effective-policy/",
|
||||||
|
"layout": "cdmf.layout.default"
|
||||||
|
}
|
@ -1,15 +0,0 @@
|
|||||||
{
|
|
||||||
"permissionList":["device-mgt/admin/groups/view",
|
|
||||||
"device-mgt/groups/add",
|
|
||||||
"device-mgt/groups/devices/add",
|
|
||||||
"device-mgt/groups/devices/remove",
|
|
||||||
"device-mgt/groups/devices/view",
|
|
||||||
"device-mgt/groups/remove",
|
|
||||||
"device-mgt/groups/roles/create",
|
|
||||||
"device-mgt/groups/roles/view",
|
|
||||||
"device-mgt/groups/share",
|
|
||||||
"device-mgt/groups/update",
|
|
||||||
"device-mgt/groups/users/view",
|
|
||||||
"device-mgt/groups/view"
|
|
||||||
]
|
|
||||||
}
|
|
@ -0,0 +1,152 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
var policy = {};
|
||||||
|
var displayPolicy = function (policyPayloadObj) {
|
||||||
|
policy["name"] = policyPayloadObj["policyName"];
|
||||||
|
policy["platform"] = policyPayloadObj["profile"]["deviceType"];
|
||||||
|
// updating next-page wizard title with selected platform
|
||||||
|
$("#policy-heading").text(policy["platform"].toUpperCase() + " POLICY - " + policy["name"].toUpperCase());
|
||||||
|
$("#policy-platform").text(policy["platform"].toUpperCase());
|
||||||
|
$("#policy-assignment").text(policyPayloadObj.deviceGroups);
|
||||||
|
$("#policy-action").text(policyPayloadObj.compliance.toUpperCase());
|
||||||
|
$("#policy-description").text(policyPayloadObj["description"]);
|
||||||
|
var policyStatus = "Active";
|
||||||
|
if (policyPayloadObj["active"] == true && policyPayloadObj["updated"] == true) {
|
||||||
|
policyStatus = '<i class="fw fw-warning icon-success"></i> Active/Updated</span>';
|
||||||
|
} else if (policyPayloadObj["active"] == true && policyPayloadObj["updated"] == false) {
|
||||||
|
policyStatus = '<i class="fw fw-ok icon-success"></i> Active</span>';
|
||||||
|
} else if (policyPayloadObj["active"] == false && policyPayloadObj["updated"] == true) {
|
||||||
|
policyStatus = '<i class="fw fw-warning icon-warning"></i> Inactive/Updated</span>';
|
||||||
|
} else if (policyPayloadObj["active"] == false && policyPayloadObj["updated"] == false) {
|
||||||
|
policyStatus = '<i class="fw fw-error icon-danger"></i> Inactive</span>';
|
||||||
|
}
|
||||||
|
|
||||||
|
$("#policy-status").html(policyStatus);
|
||||||
|
|
||||||
|
if (policyPayloadObj.users == null) {
|
||||||
|
$("#policy-users").text("NONE");
|
||||||
|
}
|
||||||
|
else if (policyPayloadObj.users.length > 0) {
|
||||||
|
$("#policy-users").text(policyPayloadObj.users.toString().split(",").join(", "));
|
||||||
|
} else {
|
||||||
|
$("#users-row").addClass("hidden");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (policyPayloadObj.deviceGroups == null) {
|
||||||
|
$("#policy-groups").text("NONE");
|
||||||
|
} else if (policyPayloadObj.deviceGroups.length > 0) {
|
||||||
|
debugger;
|
||||||
|
var deviceGroups = policyPayloadObj.deviceGroups;
|
||||||
|
var assignedGroups = [];
|
||||||
|
for (var index in deviceGroups) {
|
||||||
|
if (deviceGroups.hasOwnProperty(index)) {
|
||||||
|
assignedGroups.push(deviceGroups[index].name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$("#policy-groups").text(assignedGroups.toString().split(",").join(", "));
|
||||||
|
} else {
|
||||||
|
$("#policy-groups").text("NONE");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (policyPayloadObj.roles == null) {
|
||||||
|
$("#policy-roles").text("NONE");
|
||||||
|
}
|
||||||
|
else if (policyPayloadObj.roles.length > 0) {
|
||||||
|
$("#policy-roles").text(policyPayloadObj.roles.toString().split(",").join(", "));
|
||||||
|
} else {
|
||||||
|
$("#roles-row").addClass("hidden");
|
||||||
|
}
|
||||||
|
|
||||||
|
var deviceType = policy["platform"];
|
||||||
|
var policyOperationsTemplateSrc = context + '/public/cdmf.unit.device.type.' + deviceType +
|
||||||
|
'.policy-view/templates/' + deviceType + '-policy-view.hbs';
|
||||||
|
var policyOperationsScriptSrc = context + '/public/cdmf.unit.device.type.' + deviceType +
|
||||||
|
'.policy-view/js/' + deviceType + '-policy-view.js';
|
||||||
|
var policyOperationsStylesSrc = context + '/public/cdmf.unit.device.type.' + deviceType +
|
||||||
|
'.policy-view/css/' + deviceType + '-policy-view.css';
|
||||||
|
var policyOperationsTemplateCacheKey = deviceType + '-policy-operations';
|
||||||
|
|
||||||
|
$.isResourceExists(policyOperationsTemplateSrc, function (status) {
|
||||||
|
if (status) {
|
||||||
|
$.template(policyOperationsTemplateCacheKey, policyOperationsTemplateSrc, function (template) {
|
||||||
|
var content = template();
|
||||||
|
$("#device-type-policy-operations").html(content).removeClass("hidden");
|
||||||
|
$(".policy-platform").addClass("hidden");
|
||||||
|
$.isResourceExists(policyOperationsScriptSrc, function (status) {
|
||||||
|
if (status) {
|
||||||
|
var script = document.createElement('script');
|
||||||
|
script.type = 'text/javascript';
|
||||||
|
script.src = policyOperationsScriptSrc;
|
||||||
|
$(".wr-advance-operations").prepend(script);
|
||||||
|
/*
|
||||||
|
This method should be implemented in the relevant plugin side and should include the logic to
|
||||||
|
populate the policy profile in the plugin specific UI.
|
||||||
|
*/
|
||||||
|
polulateProfileOperations(policyPayloadObj["profile"]["profileFeaturesList"]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
$.isResourceExists(policyOperationsStylesSrc, function (status) {
|
||||||
|
if (status) {
|
||||||
|
var style = document.createElement('link');
|
||||||
|
style.type = 'text/css';
|
||||||
|
style.rel = 'stylesheet';
|
||||||
|
style.href = policyOperationsStylesSrc;
|
||||||
|
$(".wr-advance-operations").prepend(style);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
$("#generic-policy-operations").removeClass("hidden");
|
||||||
|
}
|
||||||
|
$(".wr-advance-operations-init").addClass("hidden");
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method will return query parameter value given its name.
|
||||||
|
* @param name Query parameter name
|
||||||
|
* @returns {string} Query parameter value
|
||||||
|
*/
|
||||||
|
var getParameterByName = function (name) {
|
||||||
|
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
|
||||||
|
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
|
||||||
|
results = regex.exec(location.search);
|
||||||
|
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
|
||||||
|
};
|
||||||
|
|
||||||
|
$(document).ready(function () {
|
||||||
|
var policyPayloadObj;
|
||||||
|
// Adding initial state of wizard-steps.
|
||||||
|
invokerUtil.get(
|
||||||
|
"/api/device-mgt/v1.0" + "/policies/effective-policy/" + getParameterByName("type") + "/" + getParameterByName("id"),
|
||||||
|
// on success
|
||||||
|
function (data, textStatus, jqXHR) {
|
||||||
|
if (jqXHR.status == 200 && data) {
|
||||||
|
policyPayloadObj = JSON.parse(data);
|
||||||
|
displayPolicy(policyPayloadObj);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// on error
|
||||||
|
function (jqXHR) {
|
||||||
|
console.log(jqXHR);
|
||||||
|
// should be redirected to an error page
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
@ -0,0 +1,83 @@
|
|||||||
|
{{#zone "content"}}
|
||||||
|
{{!--#if isAuthorized--}}
|
||||||
|
{{#defineZone "policy-profile-top"}}
|
||||||
|
<div class="row wr-device-board">
|
||||||
|
<div class="col-lg-12 wr-secondary-bar">
|
||||||
|
<label id="policy-heading" class="device-id device-select">
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{/defineZone}}
|
||||||
|
|
||||||
|
<!-- #page-content-wrapper -->
|
||||||
|
<div class="page-content-wrapper">
|
||||||
|
<div class="row no-gutter add-padding-5x add-margin-top-5x" style="border: 1px solid #e4e4e4;">
|
||||||
|
<div class="media">
|
||||||
|
<div style="background: #11375B; color: #fff; padding: 10px; margin-bottom: 5px">
|
||||||
|
Policy Overview
|
||||||
|
</div>
|
||||||
|
{{#defineZone "policy-detail-properties"}}
|
||||||
|
<table class="table table-responsive table-striped" id="members">
|
||||||
|
<tbody>
|
||||||
|
<tr role="row" class="even">
|
||||||
|
<td class="sorting_1" style="padding:10px 15px; width: 14%;">Platform</td>
|
||||||
|
<td id="policy-platform" style="padding:10px 15px;"></td>
|
||||||
|
</tr>
|
||||||
|
<tr role="row" class="odd">
|
||||||
|
<td class="sorting_1" style="padding:10px 15px;">Groups</td>
|
||||||
|
<td id="policy-groups" style="padding:10px 15px;"></td>
|
||||||
|
</tr>
|
||||||
|
<tr role="row" class="even">
|
||||||
|
<td class="sorting_1" style="padding:10px 15px;">Action upon non-compliance</td>
|
||||||
|
<td id="policy-action" style="padding:10px 15px;"></td>
|
||||||
|
</tr>
|
||||||
|
<tr role="row" class="even">
|
||||||
|
<td class="sorting_1" style="padding:10px 15px;">Status</td>
|
||||||
|
<td id="policy-status" style="padding:10px 15px;"></td>
|
||||||
|
</tr>
|
||||||
|
<tr role="row" id="users-row" class="even">
|
||||||
|
<td class="sorting_1" style="padding:10px 15px;">Assigned Users</td>
|
||||||
|
<td id="policy-users" style="padding:10px 15px;"></td>
|
||||||
|
</tr>
|
||||||
|
<tr role="row" id="roles-row" class="even">
|
||||||
|
<td class="sorting_1" style="padding:10px 15px;">Assigned Roles</td>
|
||||||
|
<td id="policy-roles" style="padding:10px 15px;"></td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
{{/defineZone}}
|
||||||
|
<div style="background: #11375B; color: #fff; padding: 10px; margin-bottom: 5px">Description
|
||||||
|
</div>
|
||||||
|
<div class="add-margin-top-4x">
|
||||||
|
<div id="policy-description" class="panel-title-description"></div>
|
||||||
|
</div>
|
||||||
|
<br>
|
||||||
|
<div style="background: #11375B; color: #fff; padding: 10px; margin-bottom: 5px">
|
||||||
|
Profile Information
|
||||||
|
</div>
|
||||||
|
<div class="add-margin-top-4x">
|
||||||
|
<div id="policy-profile-main-error-msg" class="alert alert-danger hidden" role="alert">
|
||||||
|
<i class="icon fw fw-error"></i><span></span>
|
||||||
|
</div>
|
||||||
|
<div class="wr-advance-operations">
|
||||||
|
<div class='wr-advance-operations-init'>
|
||||||
|
<br/>
|
||||||
|
<i class='fw fw-settings fw-spin fw-2x'></i>
|
||||||
|
Loading Platform Features . . .
|
||||||
|
<br/>
|
||||||
|
<br/>
|
||||||
|
</div>
|
||||||
|
<div id="device-type-policy-operations" class="hidden">
|
||||||
|
</div>
|
||||||
|
<div id="generic-policy-operations" class="hidden">
|
||||||
|
{{unit "cdmf.unit.device.type.generic.policy-wizard"}}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{/zone}}
|
||||||
|
{{#zone "bottomJs"}}
|
||||||
|
{{js "js/view.js"}}
|
||||||
|
{{/zone}}
|
@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function onRequest(context) {
|
||||||
|
|
||||||
|
var utility = require("/app/modules/utility.js")["utility"];
|
||||||
|
var deviceType = context.uriParams.deviceType;
|
||||||
|
var deviceId = context.uriParams.deviceId;
|
||||||
|
|
||||||
|
return {"deviceTypePolicyView": utility.getTenantedDeviceUnitName(deviceType, deviceId,"policy-view")};
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"version" : "1.0.0"
|
||||||
|
}
|
@ -0,0 +1,112 @@
|
|||||||
|
/*
|
||||||
|
* 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.decision.point.internal;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.osgi.service.component.ComponentContext;
|
||||||
|
import org.wso2.carbon.policy.decision.point.merged.MergedEvaluationPoint;
|
||||||
|
import org.wso2.carbon.policy.mgt.common.PolicyEvaluationPoint;
|
||||||
|
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
|
||||||
|
import org.wso2.carbon.user.core.service.RealmService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @scr.component name="org.wso2.carbon.policy.decision.MergedPolicyEvaluationServiceComponent" immediate="true"
|
||||||
|
* @scr.reference name="user.realmservice.default"
|
||||||
|
* interface="org.wso2.carbon.user.core.service.RealmService"
|
||||||
|
* cardinality="1..1"
|
||||||
|
* policy="dynamic"
|
||||||
|
* bind="setRealmService"
|
||||||
|
* unbind="unsetRealmService"
|
||||||
|
* @scr.reference name="org.wso2.carbon.devicemgt.policy.manager"
|
||||||
|
* interface="org.wso2.carbon.policy.mgt.core.PolicyManagerService"
|
||||||
|
* cardinality="0..1"
|
||||||
|
* policy="dynamic"
|
||||||
|
* bind="setPolicyManagerService"
|
||||||
|
* unbind="unsetPolicyManagerService"
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class MergedPolicyEvaluationServiceComponent {
|
||||||
|
|
||||||
|
private static Log log = LogFactory.getLog(MergedPolicyEvaluationServiceComponent.class);
|
||||||
|
|
||||||
|
protected void activate(ComponentContext componentContext) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Activating the policy evaluation bundle.");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
componentContext.getBundleContext().registerService(PolicyEvaluationPoint.class.getName(),
|
||||||
|
new MergedEvaluationPoint(), null);
|
||||||
|
} catch (Throwable t) {
|
||||||
|
log.error("Error occurred while initializing the policy evaluation bundle");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void deactivate(ComponentContext componentContext) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("De-activating the policy evaluation bundle.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets Realm Service
|
||||||
|
*
|
||||||
|
* @param realmService An instance of RealmService
|
||||||
|
*/
|
||||||
|
protected void setRealmService(RealmService realmService) {
|
||||||
|
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Setting Realm Service");
|
||||||
|
}
|
||||||
|
PolicyDecisionPointDataHolder.getInstance().setRealmService(realmService);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unsets Realm Service
|
||||||
|
*
|
||||||
|
* @param realmService An instance of RealmService
|
||||||
|
*/
|
||||||
|
protected void unsetRealmService(RealmService realmService) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Unsetting Realm Service");
|
||||||
|
}
|
||||||
|
PolicyDecisionPointDataHolder.getInstance().setRealmService(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setPolicyManagerService(PolicyManagerService policyManagerService) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Unsetting PolicyManagerService Service");
|
||||||
|
}
|
||||||
|
PolicyDecisionPointDataHolder.getInstance().setPolicyManagerService(policyManagerService);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void unsetPolicyManagerService(PolicyManagerService policyManagerService) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Unsetting PolicyManagerService Service");
|
||||||
|
}
|
||||||
|
PolicyDecisionPointDataHolder.getInstance().setPolicyManagerService(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
// protected String getName() {
|
||||||
|
// return MergedPolicyEvaluationServiceComponent.class.getName();
|
||||||
|
// }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
2
components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/internal/PolicyDecisionPointDataHolder.java → components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/internal/PolicyDecisionPointDataHolder.java
2
components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/internal/PolicyDecisionPointDataHolder.java → components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/internal/PolicyDecisionPointDataHolder.java
12
components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/internal/PolicyEvaluationServiceComponent.java → components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/internal/PolicyEvaluationServiceComponent.java
12
components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/internal/PolicyEvaluationServiceComponent.java → components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/internal/PolicyEvaluationServiceComponent.java
@ -0,0 +1,134 @@
|
|||||||
|
/*
|
||||||
|
* 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.decision.point.merged;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
|
import org.wso2.carbon.policy.mgt.common.*;
|
||||||
|
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
|
||||||
|
import org.wso2.carbon.policy.decision.point.internal.PolicyDecisionPointDataHolder;
|
||||||
|
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class helps to merge related policies and return as a effective policy.
|
||||||
|
*/
|
||||||
|
public class MergedEvaluationPoint implements PolicyEvaluationPoint {
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(MergedEvaluationPoint.class);
|
||||||
|
private PolicyManagerService policyManagerService;
|
||||||
|
private static final String effectivePolicyName = "Effective-Policy";
|
||||||
|
private static final String policyEvaluationPoint = "Merged";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ProfileFeature> getEffectiveFeatures(DeviceIdentifier deviceIdentifier)
|
||||||
|
throws PolicyEvaluationException {
|
||||||
|
return this.getEffectivePolicy(deviceIdentifier).getProfile().getProfileFeaturesList();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return policyEvaluationPoint;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Policy getEffectivePolicy(DeviceIdentifier deviceIdentifier) throws PolicyEvaluationException {
|
||||||
|
PIPDevice pipDevice;
|
||||||
|
List<Policy> policyList;
|
||||||
|
Policy policy;
|
||||||
|
try {
|
||||||
|
policyManagerService = getPolicyManagerService();
|
||||||
|
if (policyManagerService == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
PolicyInformationPoint policyInformationPoint = policyManagerService.getPIP();
|
||||||
|
pipDevice = policyInformationPoint.getDeviceData(deviceIdentifier);
|
||||||
|
policyList = policyInformationPoint.getRelatedPolicies(pipDevice);
|
||||||
|
|
||||||
|
if (policyList.size() == 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set effective-policy information
|
||||||
|
Profile profile = new Profile();
|
||||||
|
policy = policyResolve(policyList);
|
||||||
|
profile.setProfileFeaturesList(policy.getProfile().getProfileFeaturesList());
|
||||||
|
policy.setProfile(profile);
|
||||||
|
Timestamp currentTimestamp = new Timestamp(Calendar.getInstance().getTime().getTime());
|
||||||
|
profile.setCreatedDate(currentTimestamp);
|
||||||
|
profile.setUpdatedDate(currentTimestamp);
|
||||||
|
profile.setDeviceType(deviceIdentifier.getType());
|
||||||
|
profile.setTenantId(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
|
||||||
|
// Set effective policy name
|
||||||
|
policy.setPolicyName(effectivePolicyName);
|
||||||
|
policy.setOwnershipType(pipDevice.getOwnershipType());
|
||||||
|
// Set effective policy Active and Updated
|
||||||
|
policy.setActive(true);
|
||||||
|
policy.setUpdated(true);
|
||||||
|
policy.setTenantId(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
|
||||||
|
String policyIds = "";
|
||||||
|
Collections.sort(policyList);
|
||||||
|
for (Policy appliedPolicy : policyList) {
|
||||||
|
policyIds += appliedPolicy.getId() + ", ";
|
||||||
|
}
|
||||||
|
policyIds = policyIds.substring(0, policyIds.length() - 2);
|
||||||
|
policy.setDescription("This is a system generated effective policy by merging Policy Id : " + policyIds);
|
||||||
|
// Need to set compliance of the effective policy. Get compliance of first policy using priority order
|
||||||
|
policy.setCompliance(policyList.get(0).getCompliance());
|
||||||
|
// Change default 0 effective policy id to (-1)
|
||||||
|
policy.setId(-1);
|
||||||
|
return policy;
|
||||||
|
} catch (PolicyManagementException e) {
|
||||||
|
String msg = "Error occurred when retrieving the policy related data from policy management service.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new PolicyEvaluationException(msg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Policy policyResolve(List<Policy> policyList) throws PolicyEvaluationException, PolicyManagementException {
|
||||||
|
Collections.sort(policyList, Collections.reverseOrder());
|
||||||
|
|
||||||
|
// Iterate through all policies
|
||||||
|
Map<String, ProfileFeature> featureMap = new HashMap<>();
|
||||||
|
for (Policy policy : policyList) {
|
||||||
|
List<ProfileFeature> profileFeaturesList = policy.getProfile().getProfileFeaturesList();
|
||||||
|
if (profileFeaturesList != null) {
|
||||||
|
for (ProfileFeature feature : profileFeaturesList) {
|
||||||
|
featureMap.put(feature.getFeatureCode(), feature);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get prioritized features list
|
||||||
|
List<ProfileFeature> newFeaturesList = new ArrayList<>(featureMap.values());
|
||||||
|
Profile profile = new Profile();
|
||||||
|
profile.setProfileFeaturesList(newFeaturesList);
|
||||||
|
Policy effectivePolicy = new Policy();
|
||||||
|
effectivePolicy.setProfile(profile);
|
||||||
|
return effectivePolicy;
|
||||||
|
}
|
||||||
|
|
||||||
|
private PolicyManagerService getPolicyManagerService() {
|
||||||
|
return PolicyDecisionPointDataHolder.getInstance().getPolicyManagerService();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
24
components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/PolicyEvaluationServiceImpl.java → components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/simple/PolicyEvaluationServiceImpl.java
24
components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/PolicyEvaluationServiceImpl.java → components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/simple/PolicyEvaluationServiceImpl.java
10
components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/SimpleEvaluationImpl.java → components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/simple/SimpleEvaluationImpl.java
10
components/policy-mgt/org.wso2.carbon.simple.policy.decision.point/src/main/java/org/wso2/carbon/simple/policy/decision/point/SimpleEvaluationImpl.java → components/policy-mgt/org.wso2.carbon.policy.decision.point/src/main/java/org/wso2/carbon/policy/decision/point/simple/SimpleEvaluationImpl.java
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue