Package org.wso2.carbon.registry.common.beans

Examples of org.wso2.carbon.registry.common.beans.SubscriptionBean


* TODO: class description
*/
public final class Util {

    public static void checkAccess(String ownerTenantDomain, int ownerTenantId) {
        CarbonContext carbonContext = getCarbonContext();
        String callerTenantDomain = carbonContext.getTenantDomain();
        if (callerTenantDomain == null) {
            throw new IllegalStateException("Caller tenant domain cannot be null");
        }
        int callerTenantId = carbonContext.getTenantId();
        if (callerTenantId == MultitenantConstants.INVALID_TENANT_ID) {
            throw new IllegalStateException("Caller Tenant ID cannot be " + MultitenantConstants.INVALID_TENANT_ID);
        }

        if (callerTenantDomain.equals(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME) &&
View Full Code Here


                                        "],[" + callerTenantId + "]}");
        }
    }

    private static CarbonContext getCarbonContext() {
        CarbonContext carbonContext = CarbonContext.getThreadLocalCarbonContext();
        if (carbonContext == null) {
            throw new IllegalStateException("CarbonContext cannot be null");
        }
        return carbonContext;
    }
View Full Code Here

            PrivilegedCarbonContext.endTenantFlow();
        }
    }

    private void setTenantCredentialsInCarbonContext() {
        PrivilegedCarbonContext cc = PrivilegedCarbonContext.getThreadLocalCarbonContext();
        cc.setTenantId(ownerTenantId);
        cc.setTenantDomain(ownerTenantDomain);
    }
View Full Code Here

                } else {
                    url = realPath.substring(0, realPath.indexOf("/resourceContent?path="));
                }
            }
        }
        SubscriptionBean subscriptionBean = new SubscriptionBean();
        ResourcePath resourcePath = new ResourcePath(path);
        try {
            if (url == null || userName == null) {
                if (Utils.getRegistryEventingService() == null) {
                    throw new IllegalStateException("Subscription Manager not found");
                }
            } else if (Utils.getRegistryEventingService() == null) {
                throw new IllegalStateException("Remote Subscription Manager not found at: " + url);
            }
            List<Subscription> subscriptions = null;
            if (url == null || userName == null) {
                subscriptions = Utils.getRegistryEventingService().getAllSubscriptions();
            } else {
                subscriptions = Utils.getRegistryEventingService().getAllSubscriptions(userName, url);
            }
            log.debug("Found " + subscriptions.size() + " subscriptions");
            List<SubscriptionInstance> subscriptionInstances = new LinkedList<SubscriptionInstance>();
            for (Subscription subscription : subscriptions) {
                String testPath;
                if (!recurse) {
                    testPath = path;
                } else {
                    testPath = subscription.getTopicName();
                    if (testPath == null || testPath.lastIndexOf(RegistryConstants.PATH_SEPARATOR) <= 0
                            || !testPath.contains(path)) {
                        log.debug("path (invalid): " + testPath);
                        continue;
                    }
                    testPath = testPath.substring(RegistryEventingConstants.TOPIC_PREFIX.length(),
                            testPath.lastIndexOf(RegistryConstants.PATH_SEPARATOR));
                }
                log.debug("path: " + testPath);
                String username = null;
                if (subscription.getProperties() != null) {
                    if (subscription.getTenantId() != userRegistry.getCallerTenantId()) {
                        log.debug("TenantId for subscription doesn't match with the logged-in tenant");
                        continue;
                    }
                    username = subscription.getOwner();
                    if (username.indexOf("@") > 0) {
                        username = username.split("@")[0];
                    }
                    log.debug("Current User is: " + userRegistry.getUserName() + ". Owner of subscription is: " + username + ".");

                    if (username == null || !username.equals(userRegistry.getUserName())) {
                        if (!isAuthorized(userRegistry, testPath, AccessControlConstants.AUTHORIZE)) {
                            log.debug("User does not have AUTHORIZE priviledge to see this subscription");
                            continue;
                        }
                    } else if (!isAuthorized(userRegistry, testPath, ActionConstants.GET)) {
                        log.debug("User does not have GET priviledge to see this subscription");
                        continue;
                    }
                }
                SubscriptionInstance subscriptionInstance = populate(testPath, subscription);
                if (subscriptionInstance != null) {
                    subscriptionInstance.setOwner(username);
                    subscriptionInstances.add(subscriptionInstance);
                }
            }
            subscriptionBean.setSubscriptionInstances(subscriptionInstances.toArray(new SubscriptionInstance[0]));
            log.debug("Returning " + subscriptionInstances.size() + " subscriptions");
            subscriptionBean.setPathWithVersion(resourcePath.getPathWithVersion());
            subscriptionBean.setVersionView(!resourcePath.isCurrentVersion());
            subscriptionBean.setLoggedIn(
                    !RegistryConstants.ANONYMOUS_USER.equals(userRegistry.getUserName()));
            subscriptionBean.setUserName(userRegistry.getUserName());
            subscriptionBean.setRoles(getRolesOfUser(userRegistry, userRegistry.getUserName()));
            if (isAuthorized(userRegistry, path, AccessControlConstants.AUTHORIZE)) {
                subscriptionBean.setUserAccessLevel(SubscriptionBean.UserAccessLevel.AUTHORIZE);
            } else if (isAuthorized(userRegistry, path, ActionConstants.DELETE)) {
                subscriptionBean.setUserAccessLevel(SubscriptionBean.UserAccessLevel.DELETE);
            } else if (isAuthorized(userRegistry, path, ActionConstants.GET)) {
                subscriptionBean.setUserAccessLevel(SubscriptionBean.UserAccessLevel.READ);
            } else {
                subscriptionBean.setUserAccessLevel(SubscriptionBean.UserAccessLevel.NONE);
            }
            if (isAdmin(userRegistry, getRolesOfUser(userRegistry, userRegistry.getUserName()))) {
                subscriptionBean.setRoleAccessLevel(1);
            } else {
                subscriptionBean.setRoleAccessLevel(0);
            }
        } catch (EventBrokerException e) {
            String msg = "Failed to get subscriptions information of the resource " +
                    resourcePath + ". " + e.getMessage();
            log.error("Failed to get subscriptions information of the resource " +
                    resourcePath + ".", e);
            subscriptionBean.setErrorMessage(msg);
        }
        return subscriptionBean;
    }
View Full Code Here

        }
        return true;
    }

    public static SubscriptionBean subscribeAndPopulate(UserRegistry userRegistry, String path, String endpoint, String eventName, boolean doRest) {
        SubscriptionBean subscriptionBean = new SubscriptionBean();
        Resource resource = null;
        String url = null;
        String userName = null;
        try {
            resource = userRegistry.get(path);
        } catch (Exception e) {
            log.warn("Unable to fetch Resource at path: " + path);
            resource = null;
        }
        if (resource != null) {
            String isLink = resource.getProperty("registry.link");
            String mountPoint = resource.getProperty("registry.mountpoint");
            String targetPoint = resource.getProperty("registry.targetpoint");
            String realPath = resource.getProperty("registry.realpath");
            String actualPath = resource.getProperty("registry.actualpath");
            userName = resource.getProperty("registry.user");
            if (isLink != null && mountPoint != null && targetPoint != null) {
//                path = path.replace(mountPoint, targetPoint);
                path = actualPath;
            } else if (isLink != null && realPath != null && userName != null) {
                log.debug("Found mounted resource at: " + realPath);
                if (!realPath.contains("/registry/resourceContent?")) {
                    path = realPath;
                } else {
                    url = realPath.substring(0, realPath.indexOf("/resourceContent?path="));
                }
            }
        }
        ResourcePath resourcePath = new ResourcePath(path);
        try {
            subscriptionBean.setLoggedIn(!RegistryConstants.ANONYMOUS_USER.equals(userRegistry.getUserName()));
            List<SubscriptionInstance> subscriptionInstances = new LinkedList<SubscriptionInstance>();
            if (!subscriptionBean.getLoggedIn()) {
                throw new SecurityException("User is not logged in");
            } else if (!isAuthorized(userRegistry, path, ActionConstants.GET)) {
                throw new SecurityException("User does not have enough priviledges to subscribe");
            } else if (!hasPermissionToSubscribeViaEmail(userRegistry, path, endpoint)) {
                throw new SecurityException("User does not have enough priviledges to subscribe another user");
            } else if (Utils.getRegistryEventingService() == null) {
                throw new IllegalStateException("Registry Eventing Service Not Found");
            } else {
                Subscription subscription =
                        BuilderUtils.createSubscription(endpoint,
                                "http://wso2.org/registry/eventing/dialect/topicFilter",
                                RegistryEventingConstants.TOPIC_PREFIX + path +
                                        RegistryEvent.TOPIC_SEPARATOR + eventName);
                subscription.setEventDispatcherName(RegistryEventingConstants.TOPIC_PREFIX);
                int callerTenantId = userRegistry.getCallerTenantId();
                subscription.setTenantId(callerTenantId);
                String name = userRegistry.getUserName();
                if (callerTenantId != MultitenantConstants.SUPER_TENANT_ID &&
                        callerTenantId > -1) {
                    try {
                        SuperTenantCarbonContext.startTenantFlow();
                        SuperTenantCarbonContext currentContext =
                                SuperTenantCarbonContext.getCurrentContext();
                        currentContext.setTenantId(callerTenantId, true);
                        String tenantDomain = currentContext.getTenantDomain();
                        if (tenantDomain != null) {
                            name = name + "@" + tenantDomain;
                        }
                    } finally {
                        SuperTenantCarbonContext.endTenantFlow();
                    }
                }
                subscription.setOwner(name);
                Map<String, String> data = new HashMap<String, String>();
                if (doRest) {
                    data.put(RegistryEventingConstants.DO_REST, Boolean.toString(Boolean.TRUE));
                }
                subscription.setProperties(data);
                String subscriptionId;
                if (url == null || userName == null) {
                    subscriptionId =
                            Utils.getRegistryEventingService().subscribe(subscription);
                } else {
                    throw new UnsupportedOperationException("You cannot directly subscribe to a " +
                            "Remote Resource. Use the Registry Browser User Interface to add a " +
                            "Remote Subscription.");
                }
                if (subscriptionId == null) {
                    throw new IllegalStateException("Subscription Id invalid");
                }
                subscription.setId(subscriptionId);
                SubscriptionInstance subscriptionInstance = populate(path, subscription);
                if (subscriptionInstance != null) {
                    subscriptionInstance.setOwner(userRegistry.getUserName());
                    subscriptionInstances.add(subscriptionInstance);
                }
            }
            subscriptionBean.setSubscriptionInstances(subscriptionInstances.toArray(new SubscriptionInstance[0]));
            subscriptionBean.setPathWithVersion(resourcePath.getPathWithVersion());
            subscriptionBean.setVersionView(!resourcePath.isCurrentVersion());
            subscriptionBean.setUserName(userRegistry.getUserName());
            subscriptionBean.setRoles(getRolesOfUser(userRegistry, userRegistry.getUserName()));
            if (isAuthorized(userRegistry, path, AccessControlConstants.AUTHORIZE)) {
                subscriptionBean.setUserAccessLevel(SubscriptionBean.UserAccessLevel.AUTHORIZE);
            } else if (isAuthorized(userRegistry, path, ActionConstants.DELETE)) {
                subscriptionBean.setUserAccessLevel(SubscriptionBean.UserAccessLevel.DELETE);
            } else if (isAuthorized(userRegistry, path, ActionConstants.GET)) {
                subscriptionBean.setUserAccessLevel(SubscriptionBean.UserAccessLevel.READ);
            } else {
                subscriptionBean.setUserAccessLevel(SubscriptionBean.UserAccessLevel.NONE);
            }
            if (isAdmin(userRegistry, getRolesOfUser(userRegistry, userRegistry.getUserName()))) {
                subscriptionBean.setRoleAccessLevel(1);
            } else {
                subscriptionBean.setRoleAccessLevel(0);
            }
        } catch (Exception e) {
            String msg = "Failed to subscribe to information of the resource " +
                    resourcePath + ". " + e.getMessage();
            log.error("Failed to subscribe to information of the resource " +
                    resourcePath + ".", e);
            subscriptionBean.setErrorMessage(msg);
        }
        return subscriptionBean;
    }
View Full Code Here

        }

        public void run() {
            try {
                MessageContext msgCtx = ((Axis2MessageContext) synCtx).getAxis2MessageContext();
                Event<MessageContext> event = new Event(msgCtx);
                subscriptions = subscriptionManager.getMatchingSubscriptions(event);
            } catch (EventException e) {
                handleException("Matching subscriptions fetching error", e);
            }
View Full Code Here

     * @throws EventException event
     */
    private void processGetStatusRequest(MessageContext mc,
                                         ResponseMessageBuilder messageBuilder)
            throws AxisFault, EventException {
        Subscription subscription =
                SubscriptionMessageBuilder.createGetStatusMessage(mc);
        if (log.isDebugEnabled()) {
            log.debug("GetStatus request recived for SynapseSubscription ID : " +
                    subscription.getId());
        }
        subscription = subscriptionManager.getSubscription(subscription.getId());
        if (subscription != null) {
            if (log.isDebugEnabled()) {
                log.debug("Sending GetStatus responce for SynapseSubscription ID : " +
                        subscription.getId());
            }
            //send the responce
            SOAPEnvelope soapEnvelope = messageBuilder.genGetStatusResponse(subscription);
            dispatchResponse(soapEnvelope, EventingConstants.WSE_GET_STATUS_RESPONSE,
                    mc, false);
View Full Code Here

            // Adding static subscriptions
            List<Subscription> staticSubscriptionList =
                    eventSource.getSubscriptionManager().getStaticSubscriptions();
            for (Iterator<Subscription> iterator = staticSubscriptionList.iterator();
                 iterator.hasNext();) {
                Subscription staticSubscription = iterator.next();
                OMElement staticSubElem =
                        fac.createOMElement("subscription", XMLConfigConstants.SYNAPSE_OMNAMESPACE);
                staticSubElem.addAttribute(
                        fac.createOMAttribute("id", nullNS, staticSubscription.getId()));
                OMElement filterElem =
                        fac.createOMElement("filter", XMLConfigConstants.SYNAPSE_OMNAMESPACE);
                filterElem.addAttribute(fac.createOMAttribute("source", nullNS,
                        (String) staticSubscription.getFilterValue()));
                filterElem.addAttribute(fac.createOMAttribute("dialect", nullNS,
                        (String) staticSubscription.getFilterDialect()));
                staticSubElem.addChild(filterElem);
                OMElement endpointElem =
                        fac.createOMElement("endpoint", XMLConfigConstants.SYNAPSE_OMNAMESPACE);
                OMElement addressElem =
                        fac.createOMElement("address", XMLConfigConstants.SYNAPSE_OMNAMESPACE);
                addressElem.addAttribute(
                        fac.createOMAttribute("uri", nullNS, staticSubscription.getEndpointUrl()));
                endpointElem.addChild(addressElem);
                staticSubElem.addChild(endpointElem);
                if (staticSubscription.getExpires() != null) {
                    OMElement expiresElem =
                            fac.createOMElement("expires", XMLConfigConstants.SYNAPSE_OMNAMESPACE);
                    fac.createOMText(expiresElem,
                            ConverterUtil.convertToString(staticSubscription.getExpires()));
                    staticSubElem.addChild(expiresElem);
                }
                evenSourceElem.addChild(staticSubElem);
            }
View Full Code Here


    public SynapseSubscription() {
        this.setId(UIDGenerator.generateURNString());
        this.setDeliveryMode(EventingConstants.WSE_DEFAULT_DELIVERY_MODE);
        SubscriptionData subscriptionData = new SubscriptionData();
        subscriptionData.setProperty(SynapseEventingConstants.STATIC_ENTRY, "false");
        this.setSubscriptionData(subscriptionData);
    }
View Full Code Here

                    .getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "class"));
            if (clazz != null) {
                String className = clazz.getAttributeValue();
                try {
                    Class subscriptionManagerClass = Class.forName(className);
                    SubscriptionManager manager =
                            (SubscriptionManager) subscriptionManagerClass.newInstance();
                    Iterator itr = subscriptionManagerElem.getChildrenWithName(PROPERTIES_QNAME);
                    while (itr.hasNext()) {
                        OMElement propElem = (OMElement) itr.next();
                        String propName =
                                propElem.getAttribute(new QName("name")).getAttributeValue();
                        String propValue =
                                propElem.getAttribute(new QName("value")).getAttributeValue();
                        if (propName != null && !"".equals(propName.trim()) &&
                                propValue != null && !"".equals(propValue.trim())) {

                            propName = propName.trim();
                            propValue = propValue.trim();

                            PasswordManager passwordManager =
                                    PasswordManager.getInstance();
                            String key = eventSource.getName() + "." + propName;

                            if (passwordManager.isInitialized()
                                    && passwordManager.isTokenProtected(key)) {
                                eventSource.putConfigurationProperty(propName, propValue);
                                propValue = passwordManager.resolve(propValue);
                            }

                            manager.addProperty(propName, propValue);
                        }
                    }
                    eventSource.setSubscriptionManager(manager);
                    eventSource.getSubscriptionManager()
                            .init(); // Initialise before doing further processing, required for static subscriptions
View Full Code Here

TOP

Related Classes of org.wso2.carbon.registry.common.beans.SubscriptionBean

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.