public void updateRolePermission(List<QueueRolePermission> queueRolePermissions,
String queueName) throws MessageBoxException {
String queueResourcePath = MessageBoxConstants.MB_QUEUE_STORAGE_PATH + "/" + queueName;
UserRealm userRealm = CarbonContext.getCurrentContext().getUserRealm();
String role;
try {
String loggedInUser = CarbonContext.getCurrentContext().getUsername();
if (!userRealm.getAuthorizationManager().isUserAuthorized(
loggedInUser, queueResourcePath,
MessageBoxConstants.MB_PERMISSION_CHANGE_PERMISSION)) {
if (!Utils.isAdmin(loggedInUser)) {
throw new MessageBoxException(" User " + loggedInUser + " can not change" +
" the permissions of " + queueName);
}
}
for (QueueRolePermission queueRolePermission : queueRolePermissions) {
role = queueRolePermission.getRoleName();
if (queueRolePermission.isAllowedToConsume()) {
if (!userRealm.getAuthorizationManager().isRoleAuthorized(
role, queueResourcePath, MessageBoxConstants.MB_PERMISSION_CONSUME)) {
userRealm.getAuthorizationManager().authorizeRole(
role, queueResourcePath, MessageBoxConstants.MB_PERMISSION_CONSUME);
}
} else {
if (userRealm.getAuthorizationManager().isRoleAuthorized(
role, queueResourcePath, MessageBoxConstants.MB_PERMISSION_CONSUME)) {
userRealm.getAuthorizationManager().denyRole(
role, queueResourcePath, MessageBoxConstants.MB_PERMISSION_CONSUME);
}
}
if (queueRolePermission.isAllowedToPublish()) {
if (!userRealm.getAuthorizationManager().isRoleAuthorized(
role, queueResourcePath, MessageBoxConstants.MB_PERMISSION_PUBLISH)) {
userRealm.getAuthorizationManager().authorizeRole(
role, queueResourcePath, MessageBoxConstants.MB_PERMISSION_PUBLISH);
}
} else {
if (userRealm.getAuthorizationManager().isRoleAuthorized(
role, queueResourcePath, MessageBoxConstants.MB_PERMISSION_PUBLISH)) {
userRealm.getAuthorizationManager().denyRole(
role, queueResourcePath, MessageBoxConstants.MB_PERMISSION_PUBLISH);
}
}
}
setQueueUpdatedTime(queueName);