Skip to content

Commit

Permalink
Added user authorization fixes for topics. UI fixes. Code comments.er…
Browse files Browse the repository at this point in the history
…ror logging
  • Loading branch information
hemikak committed Feb 9, 2015
1 parent c59bf1e commit 974e7c8
Show file tree
Hide file tree
Showing 26 changed files with 2,083 additions and 625 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.wso2.carbon.event.admin.internal;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.event.admin.internal.exception.EventAdminException;
import org.wso2.carbon.event.admin.internal.util.EventAdminHolder;
import org.wso2.carbon.event.core.EventBroker;
Expand All @@ -10,39 +12,76 @@

import java.util.Calendar;

/**
* Provides necessary topic related functions as a web service
*/
public class TopicManagerAdminService {
private static Log log = LogFactory.getLog(TopicManagerAdminService.class);

/**
* Gets all the topics
*
* @return A topic node
* @throws EventAdminException
*/
public TopicNode getAllTopics() throws EventAdminException {
EventBroker eventBroker = EventAdminHolder.getInstance().getEventBroker();
try {
return eventBroker.getTopicManager().getTopicTree();
} catch (EventBrokerException e) {
log.error(e.getMessage(), e);
throw new EventAdminException("Error in accessing topic manager ", e);
}
}

/**
* Gets the permission roles for a topic
* Suppressing warning as this is used as a web service
*
* @param topic Topic name
* @return An array of TopicRolePermission
* @throws EventAdminException
*/
@SuppressWarnings("UnusedDeclaration")
public TopicRolePermission[] getTopicRolePermissions(String topic) throws EventAdminException {
EventBroker eventBroker = EventAdminHolder.getInstance().getEventBroker();
try {
return eventBroker.getTopicManager().getTopicRolePermission(topic);
} catch (EventBrokerException e) {
log.error(e.getMessage(), e);
throw new EventAdminException("Error in accessing topic manager", e);
}
}

/**
* Adds a new topic
*
* @param topic New topic name
* @throws EventAdminException
*/
public void addTopic(String topic) throws EventAdminException {
EventBroker eventBroker = EventAdminHolder.getInstance().getEventBroker();
try {
if (!eventBroker.getTopicManager().isTopicExists(topic)) {
eventBroker.getTopicManager().addTopic(topic);
}else {
throw new EventAdminException("Topic with name : "+ topic + " already exists!");
} else {
throw new EventAdminException("Topic with name : " + topic + " already exists!");
}
} catch (EventBrokerException e) {
log.error(e.getMessage(), e);
throw new EventAdminException(e.getMessage(), e);
}
}

/**
* Updates the permissions for roles of a topic
* Suppressing warning as this is used as a web service
*
* @param topic Topic name
* @param topicRolePermissions New roles with permissions
* @throws EventAdminException
*/
@SuppressWarnings("UnusedDeclaration")
public void updatePermission(String topic, TopicRolePermission[] topicRolePermissions)
throws EventAdminException {
EventBroker eventBroker = EventAdminHolder.getInstance().getEventBroker();
Expand All @@ -53,6 +92,17 @@ public void updatePermission(String topic, TopicRolePermission[] topicRolePermis
}
}

/**
* Gets all subscriptions for a topic with limited results to return
* Suppressing warning as this is used as a web service
*
* @param topic Topic name
* @param startingIndex Starting index of which the results should be returned
* @param maxSubscriptionCount The amount of results to be returned
* @return An array of Subscriptions
* @throws EventAdminException
*/
@SuppressWarnings("UnusedDeclaration")
public Subscription[] getAllWSSubscriptionsForTopic(String topic, int startingIndex,
int maxSubscriptionCount)
throws EventAdminException {
Expand Down Expand Up @@ -82,38 +132,75 @@ public Subscription[] getAllWSSubscriptionsForTopic(String topic, int startingIn
}
return subscriptionsDTO;
} catch (EventBrokerException e) {
log.error(e.getMessage(), e);
throw new EventAdminException("Error in accessing topic manager", e);
}
}

/**
* Gets all the subscriptions
* Suppressing warning as this is used as a web service
*
* @param topic Topic name
* @return An array of subscriptions
* @throws EventAdminException
*/
@SuppressWarnings("UnusedDeclaration")
public Subscription[] getWsSubscriptionsForTopic(String topic) throws EventAdminException {
EventBroker eventBroker = EventAdminHolder.getInstance().getEventBroker();
try {
return adaptSubscriptions(eventBroker.getTopicManager().getSubscriptions(topic, true));
} catch (EventBrokerException e) {
log.error(e.getMessage(), e);
throw new EventAdminException("Error in accessing topic manager", e);
}
}

/**
* Gets the total number of subscriptions for a topic
* Suppressing warning as this is used as a web service
*
* @param topic Topic name
* @return Number of subscriptions
* @throws EventAdminException
*/
@SuppressWarnings("UnusedDeclaration")
public int getAllWSSubscriptionCountForTopic(String topic) throws EventAdminException {
EventBroker eventBroker = EventAdminHolder.getInstance().getEventBroker();
try {
return eventBroker.getTopicManager().getSubscriptions(topic, true).length;
} catch (EventBrokerException e) {
log.error(e.getMessage(), e);
throw new EventAdminException("Error in accessing topic manager", e);
}
}

/**
* Gets the JMS subscriptions for a topic
* Suppressing warning as this is used as a web service
*
* @param topic Topic name
* @return An array of subscriptions
* @throws EventAdminException
*/
@SuppressWarnings("UnusedDeclaration")
public Subscription[] getJMSSubscriptionsForTopic(String topic)
throws EventAdminException {
EventBroker eventBroker = EventAdminHolder.getInstance().getEventBroker();
try {
return adaptSubscriptions(eventBroker.getTopicManager().getJMSSubscriptions(topic));
} catch (EventBrokerException e) {
throw new EventAdminException("Can not get the jms subscriptions", e);
log.error(e.getMessage(), e);
throw new EventAdminException("Cannot get the jms subscriptions", e);
}
}

/**
* Converting carbon event core subscription to carbon event internal subscription
*
* @param coreSubscription A carbon event core subscriptions
* @return A carbon event internal subscription
*/
private Subscription adaptSubscription(
org.wso2.carbon.event.core.subscription.Subscription coreSubscription) {
Calendar calendar = Calendar.getInstance();
Expand All @@ -132,6 +219,12 @@ private Subscription adaptSubscription(
return adminSubscription;
}

/**
* Converting carbon event core subscription array to carbon event internal subscription array
*
* @param subscriptions A carbon event core subscriptions array
* @return A carbon event internal subscription array
*/
private Subscription[] adaptSubscriptions(
org.wso2.carbon.event.core.subscription.Subscription[] subscriptions) {
Subscription[] adminSubscriptions = new Subscription[subscriptions.length];
Expand All @@ -156,20 +249,37 @@ private Subscription[] adaptSubscriptions(
return adminSubscriptions;
}

/**
* Gets user roles through topic manager
*
* @return A string array of roles
* @throws EventAdminException
*/
public String[] getUserRoles() throws EventAdminException {
EventBroker eventBroker = EventAdminHolder.getInstance().getEventBroker();
try {
return eventBroker.getTopicManager().getBackendRoles();
} catch (EventBrokerException e) {
log.error(e.getMessage(), e);
throw new EventAdminException("Error in getting User Roles from topic manager", e);
}
}

/**
* Removes a topic
* Suppressing warning as this is used as a web service
*
* @param topic Topic name
* @return true if topic existed to delete and deleted, false otherwise.
* @throws EventAdminException
*/
@SuppressWarnings("UnusedDeclaration")
public boolean removeTopic(String topic) throws EventAdminException {
EventBroker eventBroker = EventAdminHolder.getInstance().getEventBroker();
try {
return eventBroker.getTopicManager().removeTopic(topic);
} catch (EventBrokerException e) {
log.error(e.getMessage(), e);
throw new EventAdminException(e.getMessage(), e);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<!--
~ 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.
~
-->
<component xmlns="http://products.wso2.org/carbon">
<ManagementPermissions>
<ManagementPermission>
<DisplayName>Manage</DisplayName>
<ResourceId>/permission/admin/manage</ResourceId>
</ManagementPermission>
<ManagementPermission>
<DisplayName>Topic</DisplayName>
<ResourceId>/permission/admin/manage/topic</ResourceId>
</ManagementPermission>
<ManagementPermission>
<DisplayName>Add Topic/SubTopic</DisplayName>
<ResourceId>/permission/admin/manage/topic/addTopic</ResourceId>
</ManagementPermission>
<ManagementPermission>
<DisplayName>Browse Topic</DisplayName>
<ResourceId>/permission/admin/manage/topic/browseTopic</ResourceId>
</ManagementPermission>
<ManagementPermission>
<DisplayName>Delete Topic</DisplayName>
<ResourceId>/permission/admin/manage/topic/deleteTopic</ResourceId>
</ManagementPermission>
<ManagementPermission>
<DisplayName>Purge Topic</DisplayName>
<ResourceId>/permission/admin/manage/topic/purgeTopic</ResourceId>
</ManagementPermission>
</ManagementPermissions>
</component>

0 comments on commit 974e7c8

Please sign in to comment.