try {
if (!userRealm.getAuthorizationManager().isUserAuthorized(
loggedInUser, topicResourcePath,
EventBrokerConstants.EB_PERMISSION_CHANGE_PERMISSION)) {
if (!JavaUtil.isAdmin(loggedInUser)) {
throw new EventBrokerException(" User " + loggedInUser + " can not change" +
" the permissions of " + topicName);
}
}
for (TopicRolePermission topicRolePermission : topicRolePermissions) {
role = topicRolePermission.getRoleName();
if (topicRolePermission.isAllowedToSubscribe()) {
if (!userRealm.getAuthorizationManager().isRoleAuthorized(
role, topicResourcePath, EventBrokerConstants.EB_PERMISSION_SUBSCRIBE)) {
userRealm.getAuthorizationManager().authorizeRole(
role, topicResourcePath, EventBrokerConstants.EB_PERMISSION_SUBSCRIBE);
}
} else {
if (userRealm.getAuthorizationManager().isRoleAuthorized(
role, topicResourcePath, EventBrokerConstants.EB_PERMISSION_SUBSCRIBE)) {
userRealm.getAuthorizationManager().denyRole(
role, topicResourcePath, EventBrokerConstants.EB_PERMISSION_SUBSCRIBE);
}
}
if (topicRolePermission.isAllowedToPublish()) {
if (!userRealm.getAuthorizationManager().isRoleAuthorized(
role, topicResourcePath, EventBrokerConstants.EB_PERMISSION_PUBLISH)) {
userRealm.getAuthorizationManager().authorizeRole(
role, topicResourcePath, EventBrokerConstants.EB_PERMISSION_PUBLISH);
}
} else {
if (userRealm.getAuthorizationManager().isRoleAuthorized(
role, topicResourcePath, EventBrokerConstants.EB_PERMISSION_PUBLISH)) {
userRealm.getAuthorizationManager().denyRole(
role, topicResourcePath, EventBrokerConstants.EB_PERMISSION_PUBLISH);
}
}
}
} catch (UserStoreException e) {
throw new EventBrokerException("Can not access the user store manager", e);
}
}