revert-70aa11f8
mharindu 9 years ago
commit 49cb4787c0

@ -118,7 +118,7 @@ public class GroupImpl implements Group {
@Override @Override
@GET @GET
@Produces("application/json") @Produces("application/json")
public Response getGroups(@QueryParam("start") int startIndex, @PathParam("length") int length) { public Response getGroups(@QueryParam("start") int startIndex, @QueryParam("length") int length) {
try { try {
PaginationResult paginationResult = DeviceMgtAPIUtils.getGroupManagementProviderService() PaginationResult paginationResult = DeviceMgtAPIUtils.getGroupManagementProviderService()
.getGroups(startIndex, length); .getGroups(startIndex, length);
@ -331,8 +331,7 @@ public class GroupImpl implements Group {
@Produces("application/json") @Produces("application/json")
public Response addSharing(@QueryParam("shareUser") String shareUser, public Response addSharing(@QueryParam("shareUser") String shareUser,
@PathParam("groupName") String groupName, @PathParam("owner") String owner, @PathParam("groupName") String groupName, @PathParam("owner") String owner,
@PathParam("roleName") String roleName, @PathParam("roleName") String roleName, String[] permissions) {
@FormParam("permissions") String[] permissions) {
try { try {
boolean isAdded = DeviceMgtAPIUtils.getGroupManagementProviderService().addGroupSharingRole( boolean isAdded = DeviceMgtAPIUtils.getGroupManagementProviderService().addGroupSharingRole(

@ -21,6 +21,11 @@ package org.wso2.carbon.device.mgt.jaxrs.api.impl;
import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException;
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationService;
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
import org.wso2.carbon.device.mgt.jaxrs.api.common.MDMAPIException; import org.wso2.carbon.device.mgt.jaxrs.api.common.MDMAPIException;
import org.wso2.carbon.device.mgt.jaxrs.api.util.DeviceMgtAPIUtils; import org.wso2.carbon.device.mgt.jaxrs.api.util.DeviceMgtAPIUtils;
import org.wso2.carbon.device.mgt.jaxrs.beans.PriorityUpdatedPolicyWrapper; import org.wso2.carbon.device.mgt.jaxrs.beans.PriorityUpdatedPolicyWrapper;
@ -97,6 +102,22 @@ public class PolicyImpl implements org.wso2.carbon.device.mgt.jaxrs.api.Policy {
private Response addPolicy(PolicyManagerService policyManagementService, ResponsePayload responseMsg, private Response addPolicy(PolicyManagerService policyManagementService, ResponsePayload responseMsg,
org.wso2.carbon.policy.mgt.common.Policy policy) { org.wso2.carbon.policy.mgt.common.Policy policy) {
List<Device> devices = policy.getDevices();
if (devices != null && devices.size() == 1) {
DeviceAccessAuthorizationService deviceAccessAuthorizationService = DeviceManagementDataHolder.getInstance().getDeviceAccessAuthorizationService();
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(devices.get(0).getDeviceIdentifier(), devices.get(0).getType());
PrivilegedCarbonContext threadLocalCarbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
String username = threadLocalCarbonContext.getUsername();
try {
if (!deviceAccessAuthorizationService.isUserAuthorized(deviceIdentifier, username)) {
return Response.status(Response.Status.UNAUTHORIZED).build();
}
} catch (DeviceAccessAuthorizationException e) {
String msg = "Device access authorization exception";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
try { try {
PolicyAdministratorPoint pap = policyManagementService.getPAP(); PolicyAdministratorPoint pap = policyManagementService.getPAP();
pap.addPolicy(policy); pap.addPolicy(policy);

@ -669,6 +669,12 @@
<url>/policies/inactive-policy</url> <url>/policies/inactive-policy</url>
<method>POST</method> <method>POST</method>
</Permission> </Permission>
<Permission>
<name>Add Policy</name>
<path>/device-mgt/user/policies/add</path>
<url>/policies/inactive-policy</url>
<method>POST</method>
</Permission>
<Permission> <Permission>
<name>List policies</name> <name>List policies</name>
@ -704,6 +710,12 @@
<url>/policies/active-policy</url> <url>/policies/active-policy</url>
<method>POST</method> <method>POST</method>
</Permission> </Permission>
<Permission>
<name>Add Policy</name>
<path>/device-mgt/user/policies/add</path>
<url>/policies/inactive-policy</url>
<method>POST</method>
</Permission>
<Permission> <Permission>
<name>Remove policy</name> <name>Remove policy</name>
@ -726,6 +738,20 @@
<method>GET</method> <method>GET</method>
</Permission> </Permission>
<Permission>
<name>List user policies</name>
<path>/device-mgt/user/policies/list</path>
<url>/policies</url>
<method>GET</method>
</Permission>
<Permission>
<name>List user policies</name>
<path>/device-mgt/user/policies/list</path>
<url>/policies/*</url>
<method>GET</method>
</Permission>
<Permission> <Permission>
<name>Update policy</name> <name>Update policy</name>
<path>/device-mgt/admin/policies/update</path> <path>/device-mgt/admin/policies/update</path>

@ -147,7 +147,7 @@ if (uriMatcher.match("/{context}/api/user/authenticate")) {
lastname = addUserFormData.lastname; lastname = addUserFormData.lastname;
emailAddress = addUserFormData.emailAddress; emailAddress = addUserFormData.emailAddress;
password = addUserFormData.password; password = addUserFormData.password;
userRoles = ["devicemgt-user"]; userRoles = ["internal/devicemgt-user"];
try { try {
result = userModule.registerUser(username, firstname, lastname, emailAddress, password, result = userModule.registerUser(username, firstname, lastname, emailAddress, password,

@ -28,6 +28,7 @@ var userModule = require("/app/modules/user.js")["userModule"];
var utility = require("/app/modules/utility.js")["utility"]; var utility = require("/app/modules/utility.js")["utility"];
var permissions = { var permissions = {
'/permission/admin/device-mgt/user': ['ui.execute'] '/permission/admin/device-mgt/user': ['ui.execute'],
'/permission/admin/device-mgt/api/application': ['ui.execute']
}; };
userModule.addRole("devicemgt-user", ["admin"], permissions); userModule.addRole("internal/devicemgt-user", ["admin"], permissions);

@ -668,6 +668,9 @@ var userModule = function () {
if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/roles/add")) { if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/roles/add")) {
permissions["ADD_ROLE"] = true; permissions["ADD_ROLE"] = true;
} }
if (publicMethods.isAuthorized("/permission/admin/device-mgt/admin/policies/add")) {
permissions["ADD_ADMIN_POLICY"] = true;
}
if (publicMethods.isAuthorized("/permission/admin/device-mgt/user/policies/add")) { if (publicMethods.isAuthorized("/permission/admin/device-mgt/user/policies/add")) {
permissions["ADD_POLICY"] = true; permissions["ADD_POLICY"] = true;
} }

@ -34,19 +34,34 @@
{{#zone "content"}} {{#zone "content"}}
<div class="container container-bg white-bg"> <div class="container container-bg white-bg">
<div class=" margin-top-double"> <div class=" margin-top-double">
<div class="row padding-top-double padding-bottom-double margin-bottom-double"> {{#if deviceTypes}}
<div class="col-lg-3 margin-top-double"> <div class="row padding-top-double padding-bottom-double margin-bottom-double">
<h1 class="grey ">{{groupName}} Analytics</h1> {{unit "cdmf.unit.analytics.date-range-picker" deviceTypes=deviceTypes}}
</div> </div>
{{unit "cdmf.unit.analytics.date-range-picker" deviceTypes=deviceTypes}} <hr>
</div> <div class="clear"></div>
<hr> <div id="div-chart">
<div class="clear"></div> {{#each deviceTypes}}
<div id="div-chart"> {{unit deviceAnalyticsViewUnitName devices=devices}}
{{#each deviceTypes}} {{/each}}
{{unit deviceAnalyticsViewUnitName devices=devices}} </div>
{{/each}} {{else}}
</div> <div id="ast-container" class="ast-container list-view">
<div class="ctrl-info-panel col-centered text-center wr-login">
<h2>You don't have any device assigned to this group to view analytics.</h2>
<br/>
<p class="text-center">
<a href="{{@app.context}}/devices" class="wr-btn">
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-add fw-stack-1x"></i>
</span>
Assign from My Devices
</a>
</p>
</div>
</div>
{{/if}}
</div> </div>
</div> </div>
{{/zone}} {{/zone}}

@ -21,31 +21,35 @@ function onRequest(context) {
var groupModule = require("/app/modules/group.js").groupModule; var groupModule = require("/app/modules/group.js").groupModule;
var groupName = context.uriParams.name; var groupName = context.uriParams.name;
var groupOwner = context.uriParams.owner; var groupOwner = context.uriParams.owner;
var deviceTypes = [];
var devices = groupModule.getGroupDevices(groupName, groupOwner).data; var devices = groupModule.getGroupDevices(groupName, groupOwner).data;
var page = {
for (var i = 0; i < devices.length; i++) { "groupName": groupName,
var hasDeviceType = false; "groupOwner": groupOwner,
for (var j = 0; j < deviceTypes.length; j++) { "title": groupName + " Analytics"
if (deviceTypes[j].type === devices[i].type) { };
deviceTypes[j].devices.push(devices[i]); if (devices) {
hasDeviceType = true; var deviceTypes = [];
break; for (var i = 0; i < devices.length; i++) {
var hasDeviceType = false;
for (var j = 0; j < deviceTypes.length; j++) {
if (deviceTypes[j].type === devices[i].type) {
deviceTypes[j].devices.push(devices[i]);
hasDeviceType = true;
break;
}
}
if (!hasDeviceType) {
var deviceType = {};
deviceType.type = devices[i].type;
deviceType.devices = [];
deviceType.devices.push(devices[i]);
deviceType.deviceAnalyticsViewUnitName = utility.getTenantedDeviceUnitName(deviceType.type, "analytics-view");
deviceTypes.push(deviceType);
} }
} }
if (!hasDeviceType) { page.deviceTypes = deviceTypes;
var deviceType = {}; page.devices = devices;
deviceType.type = devices[i].type;
deviceType.devices = [];
deviceType.devices.push(devices[i]);
deviceType.deviceAnalyticsViewUnitName = utility.getTenantedDeviceUnitName(deviceType.type, "analytics-view");
deviceTypes.push(deviceType);
}
} }
return { return page;
"groupName": groupName,
"groupOwner": groupOwner,
"deviceTypes": deviceTypes
};
} }

@ -1,7 +1,14 @@
{{unit "cdmf.unit.ui.title" pageTitle="Policy Management"}} {{unit "cdmf.unit.ui.title" pageTitle="Policy Management"}}
{{unit "cdmf.unit.data-tables-extended"}} {{unit "cdmf.unit.data-tables-extended"}}
{{#zone "topCss"}}
<style>
.thumbnail.icon:before {
padding-top: 0;
}
</style>
{{/zone}}
{{#zone "breadcrumbs"}} {{#zone "breadcrumbs"}}
<li> <li>
<a href="{{@app.context}}/"> <a href="{{@app.context}}/">
@ -16,24 +23,30 @@
{{/zone}} {{/zone}}
{{#zone "navbarActions"}} {{#zone "navbarActions"}}
<li> {{#if permissions.ADD_ADMIN_POLICY}}
<a href="{{@app.context}}/policy/add" class="cu-btn"> <li>
<a href="{{@app.context}}/policy/add" class="cu-btn">
<span class="icon fw-stack"> <span class="icon fw-stack">
<i class="fw fw-add fw-stack-1x"></i> <i class="fw fw-add fw-stack-1x"></i>
<i class="fw fw-ring fw-stack-2x"></i> <i class="fw fw-ring fw-stack-2x"></i>
</span> </span>
Add Policy Add Policy
</a> </a>
</li> </li>
<li> {{/if}}
<a href="{{@app.context}}/policy/priority" class="cu-btn"> {{#if permissions.CHANGE_POLICY_PRIORITY}}
<span class="icon fw-stack"> {{#equal noPolicy false}}
<i class="fw fw-throttling-policy fw-stack-1x"></i> <li>
<i class="fw fw-ring fw-stack-2x"></i> <a href="{{@app.context}}/policy/priority" class="cu-btn">
</span> <span class="icon fw-stack">
Policy Priority <i class="fw fw-throttling-policy fw-stack-1x"></i>
</a> <i class="fw fw-ring fw-stack-2x"></i>
</li> </span>
Policy Priority
</a>
</li>
{{/equal}}
{{/if}}
<li> <li>
<a href="#" class="cu-btn" id="appbar-btn-apply-changes"> <a href="#" class="cu-btn" id="appbar-btn-apply-changes">
<span class="icon fw-stack"> <span class="icon fw-stack">
@ -46,5 +59,565 @@
{{/zone}} {{/zone}}
{{#zone "content"}} {{#zone "content"}}
{{unit "cdmf.unit.policy.listing"}} {{#equal noPolicy true}}
<div id="ast-container" class="ast-container list-view">
<div class="ctrl-info-panel col-centered text-center wr-login">
<h2>You don't have any policy at the moment.</h2>
<br/>
{{#if permissions.ADD_ADMIN_POLICY}}
<p class="text-center">
<a href="{{@app.context}}/policy/add" class="wr-btn">
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-add fw-stack-1x"></i>
</span>
Add New Policy
</a>
</p>
{{/if}}
</div>
</div>
{{/equal}}
{{#equal noPolicy false}}
{{#equal isUpdated true}}
<input type="hidden" id="is-updated" name="country" value="UPDATED">
{{/equal}}
<div id="loading-content" class="col-centered">
<i class="fw fw-settings fw-spin fw-2x"></i>
Loading policies . . .
<br>
</div>
<div id="policy-listing-status" class="raw hidden">
<ul style="list-style-type: none;">
<li class="message message-info">
<h4>
<i class="icon fw fw-info"></i>
<a id="policy-listing-status-msg">{{policyListingStatusMsg}}</a>
</h4>
</li>
</ul>
</div>
<table class="table table-striped table-hover list-table display responsive nowrap data-table grid-view hidden"
id="policy-grid">
<thead>
<tr class="sort-row">
<th class="no-sort"></th>
<th class="no-sort"></th>
<th>By Platform</th>
<th>By Ownership Type</th>
<th>By Role</th>
<th>By User</th>
<th>By Compliance Type</th>
<th>By Status</th>
<th class="no-sort"></th>
</tr>
<tr class="filter-row filter-box">
<th class="no-sort"></th>
<th class="no-sort"></th>
<th data-for="By Platform" class="select-filter"></th>
<th data-for="By Ownership Type" class="select-filter"></th>
<th data-for="By Role" class="text-filter"></th>
<th data-for="By User" class="text-filter"></th>
<th data-for="By Compliance Type" class="select-filter"></th>
<th data-for="By Status" class="select-filter"></th>
<th class="no-sort"></th>
</tr>
<tr class="bulk-action-row">
<th colspan="9">
<ul class="tiles">
{{#if removePermitted}}
<li class="square">
<a href="#" data-click-event="remove-form"
class="btn square-element policy-remove-link"
data-toggle="modal" data-target="#modalDemo">
<span class="icon fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-delete fw-stack-1x"></i>
</span>
Remove
</a>
</li>
{{/if}}
<li class="square">
<a href="#" data-click-event="remove-form"
class="btn square-element policy-publish-link"
data-toggle="modal" data-target="#modalDemo">
<span class="icon fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="glyphicon glyphicon-floppy-saved"></i>
</span>
Publish
</a>
</li>
<li class="square">
<a href="#" data-click-event="remove-form"
class="btn square-element policy-unpublish-link"
data-toggle="modal" data-target="#modalDemo">
<span class="icon fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="glyphicon glyphicon-floppy-remove"></i>
</span>
Unpublish
</a>
</li>
</ul>
</th>
</tr>
</thead>
<tbody>
{{#each policyListToView}}
<tr data-type="selectable" data-id="{{id}}" data-status="{{status}}">
<td class="remove-padding icon-only content-fill viewEnabledIcon"
data-url="{{@app.context}}/policy/view?id={{id}}&type={{platform}}"
data-id="{{id}}">
<div class="thumbnail icon">
<img src="{{icon}}"/>
</div>
</td>
<td class="fade-edge" data-search="{{name}}" data-display="{{name}}">
<h4>{{name}}</h4>
<div>({{platform}})</div>
{{#equal status "Active/Updated"}}
<i class="fw fw-warning icon-success"></i> Active/Updated</span>
{{/equal}}
{{#equal status "Active"}}
<i class="fw fw-ok icon-success"></i> Active</span>
{{/equal}}
{{#equal status "Inactive/Updated"}}
<i class="fw fw-warning icon-warning"></i> Inactive/Updated</span>
{{/equal}}
{{#equal status "Inactive"}}
<i class="fw fw-error icon-danger"></i> Inactive</span>
{{/equal}}
</td>
<td class="fade-edge remove-padding-top" data-search="{{platform}}"
data-display="{{platform}}"></td>
<td class="fade-edge remove-padding-top" data-search="{{ownershipType}}"
data-display="{{ownershipType}}"
data-grid-label="Ownership">{{ownershipType}}</td>
<td id="policy-roles" class="fade-edge remove-padding-top" data-search="{{roles}}"
data-display="{{roles}}"
data-grid-label="Role(s)">{{roles}}</td>
<td id="policy-users" class="fade-edge remove-padding-top" data-search="{{users}}"
data-display="{{users}}" data-grid-label="User(s)">{{users}}</td>
<td class="fade-edge remove-padding-top" data-search="{{compliance}}"
data-display="{{compliance}}" data-grid-label="Compliance">{{compliance}}</td>
<td id="policy-status" class="fade-edge remove-padding-top" data-search="{{status}}"
data-display="{{status}}">
</td>
<td class="text-right content-fill text-left-on-grid-view no-wrap">
<a href="{{@app.context}}/policy/edit?id={{id}}&type={{platform}}"
data-id="{{id}}"
data-click-event="remove-form"
class="btn padding-reduce-on-grid-view policy-update-link">
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-edit fw-stack-1x"></i>
</span>
<span class="hidden-xs hidden-on-grid-view">Re-Configure</span>
</a>
</td>
</tr>
{{/each}}
<br class="c-both"/>
</tbody>
</table>
{{/equal}}
<br class="c-both"/>
<div id="content-filter-types" style="display: none">
<div class="sort-title">Sort By</div>
<div class="sort-options">
<a href="#">By Platform<span class="ico-sort-asc"></span></a>
<a href="#">By Ownership Type</a>
<a href="#">By Role</a>
<a href="#">By User</a>
<a href="#">By Compliance Type</a>
<a href="#">By Status</a>
</div>
</div>
<div id="remove-policy-modal-content" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>Do you really want to remove the selected policy(s)?</h3>
<div class="buttons">
<a href="#" id="remove-policy-yes-link" class="btn-operations">
Remove
</a>
<a href="#" id="remove-policy-cancel-link" class="btn-operations">
Cancel
</a>
</div>
</div>
</div>
</div>
</div>
<div id="remove-policy-success-content" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>Done. Selected policy was successfully removed.</h3>
<div class="buttons">
<a href="#" id="remove-policy-success-link" class="btn-operations">
Ok
</a>
</div>
</div>
</div>
</div>
</div>
<div id="remove-policy-error-content" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>An unexpected error occurred. Please try again later.</h3>
<div class="buttons">
<a href="#" id="remove-policy-error-link" class="btn-operations">
Ok
</a>
</div>
</div>
</div>
</div>
</div>
<div id="remove-policy-error-devices" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>You cannot remove policies that are already applied to devices. Please deselect
them and try
again.</h3>
<div class="buttons">
<a href="#" id="remove-policy-error-devices" class="btn-operations">
Ok
</a>
</div>
</div>
</div>
</div>
</div>
<div id="publish-policy-modal-content" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>Do you really want to publish the selected policy(s)?</h3>
<div class="buttons">
<a href="#" id="publish-policy-yes-link" class="btn-operations">Yes</a>
<a href="#" id="publish-policy-cancel-link" class="btn-operations">No</a>
</div>
</div>
</div>
</div>
</div>
<div id="publish-policy-success-content" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>Done. Selected policy was successfully published.</h3>
<div class="buttons">
<a href="#" id="publish-policy-success-link" class="btn-operations">
Ok
</a>
</div>
</div>
</div>
</div>
</div>
<div id="publish-policy-error-content" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>An unexpected error occurred. Please try again later.</h3>
<div class="buttons">
<a href="#" id="publish-policy-error-link" class="btn-operations">
Ok
</a>
</div>
</div>
</div>
</div>
</div>
<div id="unpublish-policy-modal-content" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>Do you really want to unpublish the selected policy(s)?</h3>
<div class="buttons">
<a href="#" id="unpublish-policy-yes-link" class="btn-operations">
Yes
</a>
<a href="#" id="unpublish-policy-cancel-link" class="btn-operations">
No
</a>
</div>
</div>
</div>
</div>
</div>
<div id="unpublish-policy-success-content" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>Done. Selected policy was successfully unpublished.</h3>
<div class="buttons">
<a href="#" id="unpublish-policy-success-link" class="btn-operations">
Ok
</a>
</div>
</div>
</div>
</div>
</div>
<div id="unpublish-policy-error-content" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>An unexpected error occurred. Please try again later.</h3>
<div class="buttons">
<a href="#" id="unpublish-policy-error-link" class="btn-operations">
Ok
</a>
</div>
</div>
</div>
</div>
</div>
<div id="save-policy-priorities-success-content" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>Done. New Policy priorities were successfully updated.</h3>
<div class="buttons">
<a href="#" id="save-policy-priorities-success-link" class="btn-operations">
Ok
</a>
</div>
</div>
</div>
</div>
</div>
<div id="save-policy-priorities-error-content" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>An unexpected error occurred. Please try again later.</h3>
<h4 class="message-from-server"></h4>
<div class="buttons">
<a href="#" id="save-policy-priorities-error-link" class="btn-operations">
Ok
</a>
</div>
</div>
</div>
</div>
</div>
<div id="change-policy-modal-content" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>Do you really want to apply changes to all policies?</h3>
<div class="buttons">
<a href="#" id="change-policy-yes-link" class="btn-operations">
Yes
</a>
<a href="#" id="change-policy-cancel-link" class="btn-operations">
No
</a>
</div>
</div>
</div>
</div>
</div>
<div id="change-policy-success-content" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>Done. Changes applied successfully.</h3>
<div class="buttons">
<a href="#" id="change-policy-success-link" class="btn-operations">
Ok
</a>
</div>
</div>
</div>
</div>
</div>
<div id="change-policy-error-content" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>An unexpected error occurred. Please try again later.</h3>
<div class="buttons">
<a href="#" id="change-policy-error-link" class="btn-operations">
Ok
</a>
</div>
</div>
</div>
</div>
</div>
<div id="errorPolicyUnPublish" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-error fw-stack-1x"></i>
</span>
Operation cannot be performed !
</h3>
<h4>
Please select a policy or a list of policies to unpublish.
</h4>
<div class="buttons">
<a href="javascript:hidePopup()" class="btn-operations">
Ok
</a>
</div>
</div>
</div>
</div>
</div>
<div id="errorPolicyUnPublishSelection" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-error fw-stack-1x"></i>
</span>
Operation cannot be performed !
</h3>
<h4>
You cannot select already inactive policies. Please deselect inactive policies
and try again.
</h4>
<div class="buttons">
<a href="javascript:hidePopup()" class="btn-operations">
Ok
</a>
</div>
</div>
</div>
</div>
</div>
<div id="errorPolicyPublishSelection" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-error fw-stack-1x"></i>
</span>
Operation cannot be performed !
</h3>
<h4>
You cannot select already active policies. Please deselect active policies and
try again.
</h4>
<div class="buttons">
<a href="javascript:hidePopup()" class="btn-operations">
Ok
</a>
</div>
</div>
</div>
</div>
</div>
<div id="errorPolicyPublish" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-error fw-stack-1x"></i>
</span>
Operation cannot be performed !
</h3>
<h4>
Please select a policy or a list of policies to publish.
</h4>
<div class="buttons">
<a href="javascript:hidePopup()" class="btn-operations">
Ok
</a>
</div>
</div>
</div>
</div>
</div>
<div id="errorPolicy" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-error fw-stack-1x"></i>
</span>
Operation cannot be performed !
</h3>
<h4>
Please select a policy or a list of policies to remove.
</h4>
<div class="buttons">
<a href="javascript:hidePopup()" class="btn-operations">
Ok
</a>
</div>
</div>
</div>
</div>
</div>
{{/zone}}
{{#zone "bottomJs"}}
{{js "js/policy-list.js"}}
{{/zone}} {{/zone}}

@ -16,14 +16,55 @@
* under the License. * under the License.
*/ */
function onRequest(context){ function onRequest(context) {
context.handlebars.registerHelper('equal', function (lvalue, rvalue, options) { context.handlebars.registerHelper('equal', function (lvalue, rvalue, options) {
if (arguments.length < 3) if (arguments.length < 3) {
throw new Error("Handlebars Helper equal needs 2 parameters"); throw new Error("Handlebars Helper equal needs 2 parameters");
if( lvalue!=rvalue ) { }
if (lvalue != rvalue) {
return options.inverse(this); return options.inverse(this);
} else { } else {
return options.fn(this); return options.fn(this);
} }
}); });
var page = {};
var policyModule = require("/app/modules/policy.js")["policyModule"];
var userModule = require("/app/modules/user.js")["userModule"];
var response = policyModule.getAllPolicies();
if (response["status"] == "success") {
var policyListToView = response["content"];
page["policyListToView"] = policyListToView;
var policyCount = policyListToView.length;
if (policyCount == 0) {
page["policyListingStatusMsg"] = "No policy is available to be displayed.";
page["saveNewPrioritiesButtonEnabled"] = false;
page["noPolicy"] = true;
} else if (policyCount == 1) {
page["saveNewPrioritiesButtonEnabled"] = false;
page["noPolicy"] = false;
page["isUpdated"] = response["updated"];
} else {
page["saveNewPrioritiesButtonEnabled"] = true;
page["noPolicy"] = false;
page["isUpdated"] = response["updated"];
}
} else {
// here, response["status"] == "error"
page["policyListToView"] = [];
page["policyListingStatusMsg"] = "An unexpected error occurred @ backend. Please try again later.";
page["saveNewPrioritiesButtonEnabled"] = false;
page["noPolicy"] = true;
}
if (userModule.isAuthorized("/permission/admin/device-mgt/policies/delete")) {
page["removePermitted"] = true;
}
if (userModule.isAuthorized("/permission/admin/device-mgt/policies/remove")) {
page["removePermitted"] = true;
}
if (userModule.isAuthorized("/permission/admin/device-mgt/policies/update")) {
page["editPermitted"] = true;
}
page.permissions = userModule.getUIPermissions();
return page;
} }

@ -264,7 +264,6 @@ $(document).ready(function () {
// Refreshing with success message // Refreshing with success message
$("#user-create-form").addClass("hidden"); $("#user-create-form").addClass("hidden");
$("#user-created-msg").removeClass("hidden"); $("#user-created-msg").removeClass("hidden");
generateQRCode("#user-created-msg .qr-code");
} else if (data["statusCode"] == 409) { } else if (data["statusCode"] == 409) {
$(errorMsg).text(data["messageFromServer"]); $(errorMsg).text(data["messageFromServer"]);
$(errorMsgWrapper).removeClass("hidden"); $(errorMsgWrapper).removeClass("hidden");
@ -273,6 +272,7 @@ $(document).ready(function () {
$(errorMsgWrapper).removeClass("hidden"); $(errorMsgWrapper).removeClass("hidden");
} }
}, function (data) { }, function (data) {
data = JSON.parse(data.responseText);
if (data["statusCode"] == 409) { if (data["statusCode"] == 409) {
$(errorMsg).text("User : " + username + " already exists. Pick another username."); $(errorMsg).text("User : " + username + " already exists. Pick another username.");
} else if (data["statusCode"] == 500) { } else if (data["statusCode"] == 500) {

@ -22,7 +22,7 @@
<div class="col-md-3 col-xs-3"> <div class="col-md-3 col-xs-3">
<div class="itm-wiz" data-step="policy-criteria"> <div class="itm-wiz" data-step="policy-criteria">
<div class="wiz-no">3</div> <div class="wiz-no">3</div>
<div class="wiz-lbl hidden-xs"><span>Assign to groups</span></div> <div class="wiz-lbl hidden-xs"><span>Assign</span></div>
</div> </div>
<br class="c-both"/> <br class="c-both"/>
</div> </div>

@ -1,550 +0,0 @@
{{#zone "topCss"}}
<style>
.thumbnail.icon:before {
padding-top: 0;
}
</style>
{{/zone}}
{{#equal isUpdated true}}
<input type="hidden" id="is-updated" name="country" value="UPDATED">
{{/equal}}
<div id="loading-content" class="col-centered">
<i class="fw fw-settings fw-spin fw-2x"></i>
Loading policies . . .
<br>
</div>
<div id="policy-listing-status" class="raw hidden">
<ul style="list-style-type: none;">
<li class="message message-info" >
<h4>
<i class="icon fw fw-info"></i>
<a id="policy-listing-status-msg">{{policyListingStatusMsg}}</a>
</h4>
</li>
</ul>
</div>
{{#equal noPolicy false}}
<table class="table table-striped table-hover list-table display responsive nowrap data-table grid-view hidden"
id="policy-grid">
<thead>
<tr class="sort-row">
<th class="no-sort"></th>
<th class="no-sort"></th>
<th>By Platform</th>
<th>By Ownership Type</th>
<th>By Role</th>
<th>By User</th>
<th>By Compliance Type</th>
<th>By Status</th>
<th class="no-sort"></th>
</tr>
<tr class="filter-row filter-box">
<th class="no-sort"></th>
<th class="no-sort"></th>
<th data-for="By Platform" class="select-filter"></th>
<th data-for="By Ownership Type" class="select-filter"></th>
<th data-for="By Role" class="text-filter"></th>
<th data-for="By User" class="text-filter"></th>
<th data-for="By Compliance Type" class="select-filter"></th>
<th data-for="By Status" class="select-filter"></th>
<th class="no-sort"></th>
</tr>
<tr class="bulk-action-row">
<th colspan="9">
<ul class="tiles">
{{#if removePermitted}}
<li class="square">
<a href="#" data-click-event="remove-form"
class="btn square-element policy-remove-link"
data-toggle="modal" data-target="#modalDemo">
<span class="icon fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-delete fw-stack-1x"></i>
</span>
Remove
</a>
</li>
{{/if}}
<li class="square">
<a href="#" data-click-event="remove-form"
class="btn square-element policy-publish-link"
data-toggle="modal" data-target="#modalDemo">
<span class="icon fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="glyphicon glyphicon-floppy-saved"></i>
</span>
Publish
</a>
</li>
<li class="square">
<a href="#" data-click-event="remove-form"
class="btn square-element policy-unpublish-link"
data-toggle="modal" data-target="#modalDemo">
<span class="icon fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="glyphicon glyphicon-floppy-remove"></i>
</span>
Unpublish
</a>
</li>
</ul>
</th>
</tr>
</thead>
<tbody>
{{#each policyListToView}}
<tr data-type="selectable" data-id="{{id}}" data-status="{{status}}">
<td class="remove-padding icon-only content-fill viewEnabledIcon"
data-url="{{@app.context}}/policy/view?id={{id}}&type={{platform}}"
data-id="{{id}}">
<div class="thumbnail icon">
<img src="{{icon}}"/>
</div>
</td>
<td class="fade-edge" data-search="{{name}}" data-display="{{name}}">
<h4>{{name}}</h4>
<div>({{platform}})</div>
{{#equal status "Active/Updated"}}
<i class="fw fw-warning icon-success"></i> Active/Updated</span>
{{/equal}}
{{#equal status "Active"}}
<i class="fw fw-ok icon-success"></i> Active</span>
{{/equal}}
{{#equal status "Inactive/Updated"}}
<i class="fw fw-warning icon-warning"></i> Inactive/Updated</span>
{{/equal}}
{{#equal status "Inactive"}}
<i class="fw fw-error icon-danger"></i> Inactive</span>
{{/equal}}
</td>
<td class="fade-edge remove-padding-top" data-search="{{platform}}"
data-display="{{platform}}"></td>
<td class="fade-edge remove-padding-top" data-search="{{ownershipType}}"
data-display="{{ownershipType}}"
data-grid-label="Ownership">{{ownershipType}}</td>
<td id="policy-roles" class="fade-edge remove-padding-top" data-search="{{roles}}"
data-display="{{roles}}"
data-grid-label="Role(s)">{{roles}}</td>
<td id="policy-users" class="fade-edge remove-padding-top" data-search="{{users}}"
data-display="{{users}}" data-grid-label="User(s)">{{users}}</td>
<td class="fade-edge remove-padding-top" data-search="{{compliance}}"
data-display="{{compliance}}" data-grid-label="Compliance">{{compliance}}</td>
<td id="policy-status" class="fade-edge remove-padding-top" data-search="{{status}}"
data-display="{{status}}">
</td>
<td class="text-right content-fill text-left-on-grid-view no-wrap">
<a href="{{@app.context}}/policy/edit?id={{id}}&type={{platform}}"
data-id="{{id}}"
data-click-event="remove-form"
class="btn padding-reduce-on-grid-view policy-update-link">
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-edit fw-stack-1x"></i>
</span>
<span class="hidden-xs hidden-on-grid-view">Re-Configure</span>
</a>
</td>
</tr>
{{/each}}
<br class="c-both"/>
</tbody>
</table>
{{/equal}}
<br class="c-both"/>
<div id="content-filter-types" style="display: none">
<div class="sort-title">Sort By</div>
<div class="sort-options">
<a href="#">By Platform<span class="ico-sort-asc"></span></a>
<a href="#">By Ownership Type</a>
<a href="#">By Role</a>
<a href="#">By User</a>
<a href="#">By Compliance Type</a>
<a href="#">By Status</a>
</div>
</div>
<div id="remove-policy-modal-content" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>Do you really want to remove the selected policy(s)?</h3>
<div class="buttons">
<a href="#" id="remove-policy-yes-link" class="btn-operations">
Remove
</a>
<a href="#" id="remove-policy-cancel-link" class="btn-operations">
Cancel
</a>
</div>
</div>
</div>
</div>
</div>
<div id="remove-policy-success-content" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>Done. Selected policy was successfully removed.</h3>
<div class="buttons">
<a href="#" id="remove-policy-success-link" class="btn-operations">
Ok
</a>
</div>
</div>
</div>
</div>
</div>
<div id="remove-policy-error-content" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>An unexpected error occurred. Please try again later.</h3>
<div class="buttons">
<a href="#" id="remove-policy-error-link" class="btn-operations">
Ok
</a>
</div>
</div>
</div>
</div>
</div>
<div id="remove-policy-error-devices" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>You cannot remove policies that are already applied to devices. Please deselect
them and try
again.</h3>
<div class="buttons">
<a href="#" id="remove-policy-error-devices" class="btn-operations">
Ok
</a>
</div>
</div>
</div>
</div>
</div>
<div id="publish-policy-modal-content" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>Do you really want to publish the selected policy(s)?</h3>
<div class="buttons">
<a href="#" id="publish-policy-yes-link" class="btn-operations">Yes</a>
<a href="#" id="publish-policy-cancel-link" class="btn-operations">No</a>
</div>
</div>
</div>
</div>
</div>
<div id="publish-policy-success-content" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>Done. Selected policy was successfully published.</h3>
<div class="buttons">
<a href="#" id="publish-policy-success-link" class="btn-operations">
Ok
</a>
</div>
</div>
</div>
</div>
</div>
<div id="publish-policy-error-content" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>An unexpected error occurred. Please try again later.</h3>
<div class="buttons">
<a href="#" id="publish-policy-error-link" class="btn-operations">
Ok
</a>
</div>
</div>
</div>
</div>
</div>
<div id="unpublish-policy-modal-content" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>Do you really want to unpublish the selected policy(s)?</h3>
<div class="buttons">
<a href="#" id="unpublish-policy-yes-link" class="btn-operations">
Yes
</a>
<a href="#" id="unpublish-policy-cancel-link" class="btn-operations">
No
</a>
</div>
</div>
</div>
</div>
</div>
<div id="unpublish-policy-success-content" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>Done. Selected policy was successfully unpublished.</h3>
<div class="buttons">
<a href="#" id="unpublish-policy-success-link" class="btn-operations">
Ok
</a>
</div>
</div>
</div>
</div>
</div>
<div id="unpublish-policy-error-content" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>An unexpected error occurred. Please try again later.</h3>
<div class="buttons">
<a href="#" id="unpublish-policy-error-link" class="btn-operations">
Ok
</a>
</div>
</div>
</div>
</div>
</div>
<div id="save-policy-priorities-success-content" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>Done. New Policy priorities were successfully updated.</h3>
<div class="buttons">
<a href="#" id="save-policy-priorities-success-link" class="btn-operations">
Ok
</a>
</div>
</div>
</div>
</div>
</div>
<div id="save-policy-priorities-error-content" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>An unexpected error occurred. Please try again later.</h3>
<h4 class="message-from-server"></h4>
<div class="buttons">
<a href="#" id="save-policy-priorities-error-link" class="btn-operations">
Ok
</a>
</div>
</div>
</div>
</div>
</div>
<div id="change-policy-modal-content" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>Do you really want to apply changes to all policies?</h3>
<div class="buttons">
<a href="#" id="change-policy-yes-link" class="btn-operations">
Yes
</a>
<a href="#" id="change-policy-cancel-link" class="btn-operations">
No
</a>
</div>
</div>
</div>
</div>
</div>
<div id="change-policy-success-content" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>Done. Changes applied successfully.</h3>
<div class="buttons">
<a href="#" id="change-policy-success-link" class="btn-operations">
Ok
</a>
</div>
</div>
</div>
</div>
</div>
<div id="change-policy-error-content" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>An unexpected error occurred. Please try again later.</h3>
<div class="buttons">
<a href="#" id="change-policy-error-link" class="btn-operations">
Ok
</a>
</div>
</div>
</div>
</div>
</div>
<div id="errorPolicyUnPublish" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-error fw-stack-1x"></i>
</span>
Operation cannot be performed !
</h3>
<h4>
Please select a policy or a list of policies to unpublish.
</h4>
<div class="buttons">
<a href="javascript:hidePopup()" class="btn-operations">
Ok
</a>
</div>
</div>
</div>
</div>
</div>
<div id="errorPolicyUnPublishSelection" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-error fw-stack-1x"></i>
</span>
Operation cannot be performed !
</h3>
<h4>
You cannot select already inactive policies. Please deselect inactive policies
and try again.
</h4>
<div class="buttons">
<a href="javascript:hidePopup()" class="btn-operations">
Ok
</a>
</div>
</div>
</div>
</div>
</div>
<div id="errorPolicyPublishSelection" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-error fw-stack-1x"></i>
</span>
Operation cannot be performed !
</h3>
<h4>
You cannot select already active policies. Please deselect active policies and
try again.
</h4>
<div class="buttons">
<a href="javascript:hidePopup()" class="btn-operations">
Ok
</a>
</div>
</div>
</div>
</div>
</div>
<div id="errorPolicyPublish" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-error fw-stack-1x"></i>
</span>
Operation cannot be performed !
</h3>
<h4>
Please select a policy or a list of policies to publish.
</h4>
<div class="buttons">
<a href="javascript:hidePopup()" class="btn-operations">
Ok
</a>
</div>
</div>
</div>
</div>
</div>
<div id="errorPolicy" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>
<span class="fw-stack">
<i class="fw fw-ring fw-stack-2x"></i>
<i class="fw fw-error fw-stack-1x"></i>
</span>
Operation cannot be performed !
</h3>
<h4>
Please select a policy or a list of policies to remove.
</h4>
<div class="buttons">
<a href="javascript:hidePopup()" class="btn-operations">
Ok
</a>
</div>
</div>
</div>
</div>
</div>
{{#zone "bottomJs"}}
{{js "js/policy-list.js"}}
{{/zone}}

@ -1,60 +0,0 @@
/*
* 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 log = new Log("policy-listing.js");
var policyModule = require("/app/modules/policy.js")["policyModule"];
var userModule = require("/app/modules/user.js")["userModule"];
var response = policyModule.getAllPolicies();
if (response["status"] == "success") {
var policyListToView = response["content"];
context["policyListToView"] = policyListToView;
var policyCount = policyListToView.length;
if (policyCount == 0) {
context["policyListingStatusMsg"] = "No policy is available to be displayed.";
context["saveNewPrioritiesButtonEnabled"] = false;
context["noPolicy"] = true;
} else if (policyCount == 1) {
context["saveNewPrioritiesButtonEnabled"] = false;
context["noPolicy"] = false;
context["isUpdated"] = response["updated"];
} else {
context["saveNewPrioritiesButtonEnabled"] = true;
context["noPolicy"] = false;
context["isUpdated"] = response["updated"];
}
} else {
// here, response["status"] == "error"
context["policyListToView"] = [];
context["policyListingStatusMsg"] = "An unexpected error occurred @ backend. Please try again later.";
context["saveNewPrioritiesButtonEnabled"] = false;
context["noPolicy"] = true;
}
if (userModule.isAuthorized("/permission/admin/device-mgt/policies/delete")) {
context["removePermitted"] = true;
}
if (userModule.isAuthorized("/permission/admin/device-mgt/policies/remove")) {
context["removePermitted"] = true;
}
if (userModule.isAuthorized("/permission/admin/device-mgt/policies/update")) {
context["editPermitted"] = true;
}
return context;
}

@ -29,7 +29,7 @@
<div id="role-create-error-msg" class="alert alert-danger hidden" role="alert"> <div id="role-create-error-msg" class="alert alert-danger hidden" role="alert">
<i class="icon fw fw-error"></i><span></span> <i class="icon fw fw-error"></i><span></span>
</div> </div>
<label class="wr-input-label">Domain</label> <label class="wr-input-label">Domain *</label>
<div class="wr-input-control"> <div class="wr-input-control">
<select id="domain" class="form-control select"> <select id="domain" class="form-control select">

@ -61,20 +61,6 @@
</a> </a>
</div> </div>
</div> </div>
<div id="child-deselect-error-content" class="hide">
<div class="content">
<div class="row">
<div class="col-lg-5 col-md-6 col-centered">
<h3>Can't deselect child permissions when parent permission is selected.</h3>
<div class="buttons">
<a href="#" id="child-deselect-error-link" class="btn-operations">
Ok
</a>
</div>
</div>
</div>
</div>
</div>
<!-- /content --> <!-- /content -->
</div> </div>
</div> </div>

@ -117,12 +117,8 @@ $(document).ready(function () {
$("#permissionList li input").click(function() { $("#permissionList li input").click(function() {
var parentInput = $(this).parents("ul:eq(1) > li").find('input:eq(0)'); var parentInput = $(this).parents("ul:eq(1) > li").find('input:eq(0)');
if(parentInput && parentInput.is(':checked')){ if(parentInput && parentInput.is(':checked')){
$(modalPopupContent).html($('#child-deselect-error-content').html()); parentInput.prop('checked', false);
showPopup(); return true;
$("a#child-deselect-error-link").click(function () {
hidePopup();
});
return false;
} }
}); });
$('#permissionList').tree_view(); $('#permissionList').tree_view();

@ -12,10 +12,14 @@
<div id="role-create-error-msg" class="alert alert-danger hidden" role="alert"> <div id="role-create-error-msg" class="alert alert-danger hidden" role="alert">
<i class="icon fw fw-error"></i><span></span> <i class="icon fw fw-error"></i><span></span>
</div> </div>
<label class="wr-input-label">Domain</label> <label class="wr-input-label">Domain *</label>
<div class="wr-input-control"> <div class="wr-input-control">
<input type="text" id="domain" class="form-control" placeholder="" <select id="domain" class="form-control select">
value="PRIMARY"/> <option>PRIMARY</option>
{{#each userStores}}
<option>{{this}}</option>
{{/each}}
</select>
</div> </div>
<label class="wr-input-label"> <label class="wr-input-label">
Role Name * Role Name *

@ -52,11 +52,18 @@ public class JWTClient {
private static Log log = LogFactory.getLog(JWTClient.class); private static Log log = LogFactory.getLog(JWTClient.class);
private JWTConfig jwtConfig; private JWTConfig jwtConfig;
private boolean isDefaultJWTClient;
public JWTClient(JWTConfig jwtConfig) { public JWTClient(JWTConfig jwtConfig) {
this.jwtConfig = jwtConfig; this.jwtConfig = jwtConfig;
} }
public JWTClient(JWTConfig jwtConfig, boolean isDefaultJWTClient) {
this.jwtConfig = jwtConfig;
this.isDefaultJWTClient = isDefaultJWTClient;
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@ -64,7 +71,7 @@ public class JWTClient {
throws JWTClientException { throws JWTClientException {
List<NameValuePair> params = new ArrayList<>(); List<NameValuePair> params = new ArrayList<>();
params.add(new BasicNameValuePair(JWTConstants.GRANT_TYPE_PARAM_NAME, JWTConstants.JWT_GRANT_TYPE)); params.add(new BasicNameValuePair(JWTConstants.GRANT_TYPE_PARAM_NAME, JWTConstants.JWT_GRANT_TYPE));
String assertion = JWTClientUtil.generateSignedJWTAssertion(username, jwtConfig); String assertion = JWTClientUtil.generateSignedJWTAssertion(username, jwtConfig, isDefaultJWTClient);
if (assertion == null) { if (assertion == null) {
throw new JWTClientException("JWT is not configured properly for user : " + username); throw new JWTClientException("JWT is not configured properly for user : " + username);
} }

@ -106,7 +106,7 @@ public class JWTClientManagerServiceImpl implements JWTClientManagerService{
if (isDefaultJwtClient) { if (isDefaultJwtClient) {
try { try {
JWTConfig jwtConfig = new JWTConfig(properties); JWTConfig jwtConfig = new JWTConfig(properties);
defaultJWTClient = new JWTClient(jwtConfig); defaultJWTClient = new JWTClient(jwtConfig, true);
addJWTClient(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, defaultJWTClient); addJWTClient(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, defaultJWTClient);
} catch (JWTClientAlreadyExistsException e) { } catch (JWTClientAlreadyExistsException e) {
log.warn("Attempting to register a jwt client for the super tenant" + log.warn("Attempting to register a jwt client for the super tenant" +

@ -33,6 +33,7 @@ import org.apache.http.conn.ssl.SSLContextBuilder;
import org.apache.http.conn.ssl.TrustSelfSignedStrategy; import org.apache.http.conn.ssl.TrustSelfSignedStrategy;
import org.apache.http.impl.client.HttpClients; import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils; import org.apache.http.util.EntityUtils;
import org.wso2.carbon.base.MultitenantConstants;
import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.core.util.KeyStoreManager; import org.wso2.carbon.core.util.KeyStoreManager;
import org.wso2.carbon.identity.jwt.client.extension.service.JWTClientManagerService; import org.wso2.carbon.identity.jwt.client.extension.service.JWTClientManagerService;
@ -193,7 +194,8 @@ public class JWTClientUtil {
tenantRegistryLoader.loadTenantRegistry(tenantId); tenantRegistryLoader.loadTenantRegistry(tenantId);
} }
public static String generateSignedJWTAssertion(String username, JWTConfig jwtConfig) throws JWTClientException { public static String generateSignedJWTAssertion(String username, JWTConfig jwtConfig, boolean isDefaultJWTClient)
throws JWTClientException {
try { try {
String subject = username; String subject = username;
long currentTimeMillis = System.currentTimeMillis(); long currentTimeMillis = System.currentTimeMillis();
@ -227,15 +229,27 @@ public class JWTClientUtil {
String privateKeyAlias = jwtConfig.getPrivateKeyAlias(); String privateKeyAlias = jwtConfig.getPrivateKeyAlias();
String privateKeyPassword = jwtConfig.getPrivateKeyPassword(); String privateKeyPassword = jwtConfig.getPrivateKeyPassword();
KeyStore keyStore; KeyStore keyStore;
RSAPrivateKey rsaPrivateKey; RSAPrivateKey rsaPrivateKey = null;
if (keyStorePath != null && !keyStorePath.isEmpty()) { if (keyStorePath != null && !keyStorePath.isEmpty()) {
String keyStorePassword = jwtConfig.getKeyStorePassword(); String keyStorePassword = jwtConfig.getKeyStorePassword();
keyStore = loadKeyStore(new File(keyStorePath), keyStorePassword, "JKS"); keyStore = loadKeyStore(new File(keyStorePath), keyStorePassword, "JKS");
rsaPrivateKey = (RSAPrivateKey) keyStore.getKey(privateKeyAlias, privateKeyPassword.toCharArray()); rsaPrivateKey = (RSAPrivateKey) keyStore.getKey(privateKeyAlias, privateKeyPassword.toCharArray());
} else { } else {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
KeyStoreManager tenantKeyStoreManager = KeyStoreManager.getInstance(tenantId); JWTClientUtil.loadTenantRegistry(tenantId);
rsaPrivateKey = (RSAPrivateKey) tenantKeyStoreManager.getDefaultPrivateKey(); if (!(MultitenantConstants.SUPER_TENANT_ID == tenantId) && !isDefaultJWTClient) {
KeyStoreManager tenantKeyStoreManager = KeyStoreManager.getInstance(tenantId);
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(true);
String ksName = tenantDomain.trim().replace('.', '-');
String jksName = ksName + ".jks";
rsaPrivateKey = (RSAPrivateKey) tenantKeyStoreManager.getPrivateKey(jksName, tenantDomain);
} else {
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID);
KeyStoreManager tenantKeyStoreManager = KeyStoreManager.getInstance(MultitenantConstants.SUPER_TENANT_ID);
rsaPrivateKey = (RSAPrivateKey) tenantKeyStoreManager.getDefaultPrivateKey();
PrivilegedCarbonContext.endTenantFlow();
}
} }
JWSSigner signer = new RSASSASigner(rsaPrivateKey); JWSSigner signer = new RSASSASigner(rsaPrivateKey);
SignedJWT signedJWT = new SignedJWT(new JWSHeader(JWSAlgorithm.RS256), claimsSet); SignedJWT signedJWT = new SignedJWT(new JWSHeader(JWSAlgorithm.RS256), claimsSet);

Loading…
Cancel
Save