Package org.wso2.carbon.registry.core.config

Examples of org.wso2.carbon.registry.core.config.RegistryContext


     * @throws RegistryException if the operation failed.
     */
    @Deprecated
    @SuppressWarnings("unused")
    public static UserRealm getBootstrapRealm() throws RegistryException {
        RegistryContext registryContext = RegistryContext.getBaseInstance();
        if (registryContext == null) {
            String msg = "Registry context is null. Failed to get the registry context.";
            log.error(msg);
            throw new RegistryException(msg);
        }
        if (registryContext.getRealmService() == null) {
            String msg = "Error in getting the bootstrap realm. " +
                    "The realm service is not available.";
            log.error(msg);
            throw new RegistryException(msg);
        }
        try {
            UserRealm realm = registryContext.getRealmService().getBootstrapRealm();
            return new RegistryRealm(realm);
        } catch (Exception e) {
            String msg = "Error in getting the user realm for main tenant.";
            log.error(msg);
            throw new RegistryException(msg, e);
View Full Code Here


        }
        if (CurrentSession.getUserRealm() != null) {
            // we are already checking the unchrooted paths, so no more work
            return localPath;
        }
        RegistryContext registryContext = RegistryContext.getBaseInstance();
        if (registryContext == null) {
            // adding non-path resources at the start-up
            return localPath;
        }
        String chrootPrefix = registryContext.getRegistryRoot();
        if (chrootPrefix == null ||
                chrootPrefix.length() == 0 ||
                chrootPrefix.equals(RegistryConstants.ROOT_PATH)) {
            return localPath;
        }
View Full Code Here

    public void testSimpleLifecycle() throws Exception {
        final String RESOURCE = "/r1";
        final String LIFECYCLE = "simpleLifecycle";

        RegistryContext context = registry.getRegistryContext();
        context.selectDBConfig("h2-db");
        context.addAspect(LIFECYCLE, new SimpleLifecycle(), 0);

        String [] aspects = registry.getAvailableAspects();
        assertTrue(aspects.length > 0);
        boolean found = false;
        for (String aspect : aspects) {
View Full Code Here

            } else {
                configStream =
                        config.getServletContext().getResourceAsStream("/WEB-INF/registry.xml");
            }

            RegistryContext registryContext = RegistryContext.getBaseInstance(configStream,
                    new RegistryContext.RegURLSupplier() {
                        public String getURL() {
                            return config.getServletContext().getRealPath("/WEB-INF");
                        }
                    });

            embeddedRegistryService = registryContext.getEmbeddedRegistryService();

            // create a system registry and put it in the context
            UserRegistry systemRegistry = embeddedRegistryService.getConfigSystemRegistry();

            // add configured handers to the jdbc registry
            // note: no need to do this here. this is done inside the registry context
            //Iterator<HandlerConfiguration> handlers =
            //        registryContext.getHandlerConfigurations().iterator();
            //while (handlers.hasNext()) {
            //    HandlerConfiguration handlerConfiguration = handlers.next();
            //    registryContext.getHandlerManager().addHandler(0,
            //            handlerConfiguration.getFilter(), handlerConfiguration.getHandler());
            //}

            // create system resources

            NodeGroupLock.lock(NodeGroupLock.INITIALIZE_LOCK);

            if (log.isTraceEnabled()) {
                log.trace("Creating system collections used in WSO2 Registry server.");
            }

            if (!systemRegistry.resourceExists("/system")) {

                try {
                    boolean inTransaction = Transaction.isStarted();
                    if (!inTransaction) {
                        systemRegistry.beginTransaction();
                    }
                    Collection systemCollection = systemRegistry.newCollection();
                    String systemDesc = "This collection is used to store system data of the " +
                            "WSO2 Registry server. User nor the admins of the registry are not expected " +
                            "to edit any content of this collection. Changing content of this collection " +
                            "may result in unexpected behaviors.";
                    systemCollection.setDescription(systemDesc);
                    systemRegistry.put("/system", systemCollection);

                    Collection advancedQueryCollection = systemRegistry.newCollection();
                    String advaceDesc = "This collection is used to store auto generated queries " +
                            "to support various combinations of advanced search criteria. " +
                            "This is initialy empty and gets filled as advanced search is " +
                            "executed from the web UI.";
                    advancedQueryCollection.setDescription(advaceDesc);
                    systemRegistry.put("/system/queries/advanced", advancedQueryCollection);
                    if (!inTransaction) {
                        systemRegistry.commitTransaction();
                    }
                } catch (Exception e) {
                    String msg = "Unable to setup system collections used by the Carbon server.";
                    log.error(msg, e);
                    systemRegistry.rollbackTransaction();
                    throw new RegistryException(e.getMessage(), e);
                }
            }

            try {
                AuthorizationManager ac = systemRegistry.getUserRealm().getAuthorizationManager();
                RealmConfiguration realmConfig;
                realmConfig = registryContext.getRealmService().getBootstrapRealmConfiguration();
                String systemUserName = CarbonConstants.REGISTRY_SYSTEM_USERNAME;


                ac.clearResourceAuthorizations("/system");
View Full Code Here

     * @throws RegistryException if the operation failed.
     */
    public static String getCollectionMediaTypeMappings(Registry configSystemRegistry)
            throws RegistryException {

        RegistryContext registryContext = configSystemRegistry.getRegistryContext();

        if (getCollectionMediaTypeMappings(registryContext) != null) {
            return getCollectionMediaTypeMappings(registryContext);
        }

        Resource resource;
        String mediaTypeString = null;

        String resourcePath = MIME_TYPE_COLLECTION + RegistryConstants.PATH_SEPARATOR +
                RESOURCE_MIME_TYPE_INDEX;

        // TODO: Adding the media types should ideally be done by the handler associated with the
        // media type
        if (!configSystemRegistry.resourceExists(resourcePath)) {
            getResourceMediaTypeMappings(configSystemRegistry);
        }
        if (!configSystemRegistry.resourceExists(resourcePath + RegistryConstants.PATH_SEPARATOR +
                COLLECTION_MIME_TYPE_INDEX)) {
            resource = configSystemRegistry.newResource();
            resource.setProperty("synapse", "application/vnd.apache.synapse");
            resource.setProperty("esb", "application/vnd.wso2.esb");
            resource.setProperty("axis2", "application/vnd.apache.axis2");
            resource.setProperty("wsas", "application/vnd.wso2.wsas");
            resource.setDescription("This resource contains the media Types associated with " +
                    "collections on the Registry. Add, Edit or Delete properties to Manage Media " +
                    "Types.");
            configSystemRegistry.put(resourcePath + RegistryConstants.PATH_SEPARATOR +
                    COLLECTION_MIME_TYPE_INDEX, resource);
        } else {
            resource = configSystemRegistry.get(resourcePath + RegistryConstants.PATH_SEPARATOR +
                    COLLECTION_MIME_TYPE_INDEX);
        }
        Properties properties = resource.getProperties();
        if (properties.size() > 0) {
            Set<Object> keySet = properties.keySet();
            for (Object key : keySet) {
                if (key instanceof String) {
                    String ext = (String) key;
                    if (RegistryUtils.isHiddenProperty(ext)) {
                        continue;
                    }
                    String value = resource.getProperty(ext);
                    String mediaTypeMapping = ext + ":" + value;
                    if (mediaTypeString == null) {
                        mediaTypeString = mediaTypeMapping;
                    } else {
                        mediaTypeString = mediaTypeString + "," + mediaTypeMapping;
                    }
                }
            }
        }
        registryContext.setCollectionMediaTypes(mediaTypeString);
        return mediaTypeString;
    }
View Full Code Here

     * @throws RegistryException if the operation failed.
     */
    public static String getCustomUIMediaTypeMappings(Registry configSystemRegistry)
            throws RegistryException {

        RegistryContext registryContext = configSystemRegistry.getRegistryContext();

        if (getCustomUIMediaTypeMappings(registryContext) != null) {
            return getCustomUIMediaTypeMappings(registryContext);
        }

        Resource resource;
        String mediaTypeString = null;

        String resourcePath = MIME_TYPE_COLLECTION + RegistryConstants.PATH_SEPARATOR +
                RESOURCE_MIME_TYPE_INDEX;

        // TODO: Adding the media types should ideally be done by the handler associated with the
        // media type
        if (!configSystemRegistry.resourceExists(resourcePath)) {
            getResourceMediaTypeMappings(configSystemRegistry);
        }
        if (!configSystemRegistry.resourceExists(resourcePath + RegistryConstants.PATH_SEPARATOR +
                CUSTOM_UI_MIME_TYPE_INDEX)) {
            resource = configSystemRegistry.newResource();
            resource.setProperty("profiles", "application/vnd.wso2-profiles+xml");
            //resource.setProperty("service", "application/vnd.wso2-service+xml");
            resource.setDescription("This resource contains the media Types associated with " +
                    "custom user interfaces on the Registry. Add, Edit or Delete properties to " +
                    "Manage Media Types.");
            configSystemRegistry.put(resourcePath + RegistryConstants.PATH_SEPARATOR +
                    CUSTOM_UI_MIME_TYPE_INDEX, resource);
        } else {
            resource = configSystemRegistry.get(resourcePath + RegistryConstants.PATH_SEPARATOR +
                    CUSTOM_UI_MIME_TYPE_INDEX);
        }
        Properties properties = resource.getProperties();
        if (properties.size() > 0) {
            Set<Object> keySet = properties.keySet();
            for (Object key : keySet) {
                if (key instanceof String) {
                    String ext = (String) key;
                    if (RegistryUtils.isHiddenProperty(ext)) {
                        continue;
                    }
                    String value = resource.getProperty(ext);
                    String mediaTypeMapping = ext + ":" + value;
                    if (mediaTypeString == null) {
                        mediaTypeString = mediaTypeMapping;
                    } else {
                        mediaTypeString = mediaTypeString + "," + mediaTypeMapping;
                    }
                }
            }
        }
        registryContext.setCustomUIMediaTypes(mediaTypeString);
        return mediaTypeString;
    }
View Full Code Here

     * @throws RegistryException if the operation failed.
     */
    public static String getResourceMediaTypeMappings(Registry configSystemRegistry)
            throws RegistryException {

        RegistryContext registryContext = configSystemRegistry.getRegistryContext();

        if (getResourceMediaTypeMappings(registryContext) != null) {
            return getResourceMediaTypeMappings(registryContext);
        }

        Resource resource;
        String mediaTypeString = null;

        String resourcePath = MIME_TYPE_COLLECTION + RegistryConstants.PATH_SEPARATOR +
                RESOURCE_MIME_TYPE_INDEX;

        if (!configSystemRegistry.resourceExists(resourcePath)) {
            resource = configSystemRegistry.newCollection();
        } else {
            resource = configSystemRegistry.get(resourcePath);
            Properties properties = resource.getProperties();
            if (properties.size() > 0) {
                Set<Object> keySet = properties.keySet();
                for (Object key : keySet) {
                    if (key instanceof String) {
                        String ext = (String) key;
                        if (RegistryUtils.isHiddenProperty(ext)) {
                            continue;
                        }
                        String value = resource.getProperty(ext);
                        String mediaTypeMapping = ext + ":" + value;
                        if (mediaTypeString == null) {
                            mediaTypeString = mediaTypeMapping;
                        } else {
                            mediaTypeString = mediaTypeString + "," + mediaTypeMapping;
                        }
                    }
                }
            }
            registryContext.setResourceMediaTypes(mediaTypeString);
            return mediaTypeString;
        }

        BufferedReader reader;
        try {
            File mimeFile = getMediaTypesFile();
            reader = new BufferedReader(new InputStreamReader(new FileInputStream(mimeFile)));
        } catch (Exception e) {
            String msg = "Failed to read the the media type definitions file. Only a limited " +
                    "set of media type definitions will be populated. ";
            log.error(msg, e);
            mediaTypeString = "txt:text/plain,jpg:image/jpeg,gif:image/gif";
            registryContext.setResourceMediaTypes(mediaTypeString);
            return mediaTypeString;
        }


        try {
            while (reader.ready()) {
                String mediaTypeData = reader.readLine().trim();
                if (mediaTypeData.startsWith("#")) {
                    // ignore the comments
                    continue;
                }

                if (mediaTypeData.length() == 0) {
                    // ignore the blank lines
                    continue;
                }

                // mime.type file delimits media types:extensions by tabs. if there is no
                // extension associated with a media type, there are no tabs in the line. so we
                // don't need such lines.
                if (mediaTypeData.indexOf("\t") > 0) {

                    String[] parts = mediaTypeData.split("\t+");
                    if (parts.length == 2 && parts[0].length() > 0 && parts[1].length() > 0) {

                        // there can multiple extensions associated with a single media type. in
                        // that case, extensions are delimited by a space.
                        String[] extensions = parts[1].trim().split(" ");
                        for (String extension : extensions) {
                            if (extension.length() > 0) {
                                String mediaTypeMapping = extension + ":" + parts[0];
                                resource.setProperty(extension, parts[0]);
                                if (mediaTypeString == null) {
                                    mediaTypeString = mediaTypeMapping;
                                } else {
                                    mediaTypeString = mediaTypeString + "," + mediaTypeMapping;
                                }
                            }
                        }
                    }
                }
            }
            resource.setDescription("This collection contains the media Types available for " +
                    "resources on the Registry. Add, Edit or Delete properties to Manage Media " +
                    "Types.");
            Resource collection = configSystemRegistry.newCollection();
            collection.setDescription("This collection lists the media types available on the " +
                    "Registry Server. Before changing an existing media type, please make sure " +
                    "to alter existing resources/collections and related configuration details.");
            configSystemRegistry.put(MIME_TYPE_COLLECTION, collection);
            configSystemRegistry.put(resourcePath, resource);

        } catch (IOException e) {
            String msg = "Could not read the media type mappings file from the location: ";
            throw new RegistryException(msg);

        } finally {
            try {
                reader.close();
            } catch (IOException ignore) {
            }
        }
        registryContext.setResourceMediaTypes(mediaTypeString);
        return mediaTypeString;
    }
View Full Code Here

        // get the realm config to retrieve admin username, password
        realmConfig = ctx.getRealmService().getBootstrapRealmConfiguration();
        Registry adminRegistry = embeddedRegistryService.getUserRegistry(
            realmConfig.getAdminUserName(), realmConfig.getAdminPassword());
        RegistryContext registryContext = adminRegistry.getRegistryContext();
        MyPrivateHandler myPrivateHandler = new MyPrivateHandler();

        HandlerManager handlerManager = registryContext.getHandlerManager();

        URLMatcher myPrivateHandlerMatcher = new URLMatcher();
        myPrivateHandlerMatcher.setGetPattern(".*/to/my/private/handler");
        myPrivateHandlerMatcher.setPutPattern(".*/to/my/private/handler");
        handlerManager.addHandler(
View Full Code Here

        UserRegistry userRegistry =
                (UserRegistry) request.getSession()
                        .getAttribute(RegistryConstants.ROOT_REGISTRY_INSTANCE);

        String anonymousUser;
        RegistryContext registryContext = RegistryContext.getBaseInstance();
        if (registryContext != null) {
            anonymousUser = CarbonConstants.REGISTRY_ANONNYMOUS_USERNAME;
        } else {
            return false;
        }
View Full Code Here

        tenantId = CurrentSession.getTenantId();
        if (tenantId < 0) {
            tenantId = CarbonContextHolder.getCurrentCarbonContextHolder().getTenantId();
        }
        String resourceCachePath;
        RegistryContext registryContext = registry.getRegistryContext();
        if (registryContext == null) {
            registryContext = RegistryContext.getBaseInstance();
        }
        if (registry instanceof EmbeddedRegistry) {
            resourceCachePath = path;
        } else {
            resourceCachePath = RegistryUtils.getAbsolutePath(registryContext, path);
        }
        DataBaseConfiguration dataBaseConfiguration =
                registryContext.getDefaultDataBaseConfiguration();
        if (dataBaseConfiguration != null) {
            connectionId = dataBaseConfiguration.getUserName() + "@" +
                    dataBaseConfiguration.getDbUrl();
        }
View Full Code Here

TOP

Related Classes of org.wso2.carbon.registry.core.config.RegistryContext

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.