예제 #1
0
  public void GeneralCollectionRenameTest() throws RegistryException {

    Resource r1 = registry.newResource();
    r1.setProperty("test", "rename");
    r1.setContent("some text");
    registry.put("/c2/rename3/c1/dummy", r1);

    registry.rename("/c2/rename3", "rename4");

    boolean failed = false;
    try {
      Resource originalR1 = registry.get("/c2/rename3/c1/dummy");
    } catch (RegistryException e) {
      failed = true;
    }
    assertTrue(
        "Resource should not be " + "accessible from the old path after renaming the parent.",
        failed);

    Resource newR1 = registry.get("/c2/rename4/c1/dummy");
    assertEquals(
        "Resource should contain a property with name test and value rename.",
        newR1.getProperty("test"),
        "rename");
  }
 /**
  * Remove trusted service
  *
  * @param groupName Group name
  * @param serviceName Service name
  * @param trustedService Trusted service name
  * @throws org.wso2.carbon.security.SecurityConfigException
  */
 private void removeTrustedService(String groupName, String serviceName, String trustedService)
     throws SecurityConfigException {
   Registry registry;
   String resourcePath;
   Resource resource;
   try {
     resourcePath =
         RegistryResources.SERVICE_GROUPS
             + groupName
             + RegistryResources.SERVICES
             + serviceName
             + "/trustedServices";
     registry = getConfigSystemRegistry();
     if (registry != null) {
       if (registry.resourceExists(resourcePath)) {
         resource = registry.get(resourcePath);
         if (resource.getProperty(trustedService) != null) {
           resource.removeProperty(trustedService);
         }
         registry.put(resourcePath, resource);
       }
     }
   } catch (Exception e) {
     String error = "Error occurred while removing trusted service for STS";
     log.error(error, e);
     throw new SecurityConfigException(error, e);
   }
 }
예제 #3
0
 /**
  * custom query for all the tags search is set as a resource and saved at the config
  * registry.space
  */
 private boolean setTagSearchQuery() {
   if (log.isDebugEnabled()) {
     log.debug("tag search customs query is set");
   }
   String tagsQueryPath =
       RegistryConstants.CONFIG_REGISTRY_BASE_PATH
           + RegistryConstants.QUERIES_COLLECTION_PATH
           + "/tags";
   try {
     if (!super.getUserRegistry().resourceExists(tagsQueryPath)) {
       // set-up query for tag-search.
       Resource resource = super.getUserRegistry().newResource();
       resource.setContent(
           "SELECT RT.REG_TAG_ID FROM REG_RESOURCE_TAG RT ORDER BY " + "RT.REG_TAG_ID");
       resource.setMediaType(RegistryConstants.SQL_QUERY_MEDIA_TYPE);
       resource.addProperty(
           RegistryConstants.RESULT_TYPE_PROPERTY_NAME, RegistryConstants.TAGS_RESULT_TYPE);
       super.getUserRegistry().put(tagsQueryPath, resource);
     }
     return true;
   } catch (RegistryException e) {
     log.error(e.getCause(), e);
     return false;
   }
 }
예제 #4
0
  @Test(groups = {"wso2.greg"})
  public void rootLevelCollectionRename() throws Exception {

    Resource r1 = registry.newResource();
    r1.setProperty("test", "rename");
    r1.setContent("some text");
    registry.put("/rename34k/c1/dummy", r1);

    registry.rename("/rename34k", "/rename44k");

    boolean failed = false;
    try {
      registry.get("/rename34k/c1/dummy");
    } catch (Exception e) {
      failed = true;
    }
    assertTrue(
        failed,
        "Resource should not be " + "accessible from the old path after renaming the parent.");

    Resource newR1 = registry.get("/rename44k/c1/dummy");
    assertEquals(
        newR1.getProperty("test"),
        "rename",
        "Resource should contain a property with name test and value rename.");
  }
예제 #5
0
  @Test(
      groups = {"wso2.greg"},
      description = "Metadata search by available Updater Name not",
      dependsOnMethods = "searchResourceByUpdater")
  public void searchResourceByUpdaterNot()
      throws SearchAdminServiceRegistryExceptionException, RemoteException, RegistryException {
    CustomSearchParameterBean searchQuery = new CustomSearchParameterBean();
    SearchParameterBean paramBean = new SearchParameterBean();
    paramBean.setUpdater(userName);
    ArrayOfString[] paramList = paramBean.getParameterList();

    searchQuery.setParameterValues(paramList);

    // to set updatedRangeNegate
    ArrayOfString updaterNameNegate = new ArrayOfString();
    updaterNameNegate.setArray(new String[] {"updaterNameNegate", "on"});

    searchQuery.addParameterValues(updaterNameNegate);

    AdvancedSearchResultsBean result =
        searchAdminServiceClient.getAdvancedSearchResults(searchQuery);
    Assert.assertNotNull(result.getResourceDataList(), "No Record Found");
    Assert.assertTrue(
        (result.getResourceDataList().length > 0), "No Record Found. set valid Updater name");
    for (ResourceData resource : result.getResourceDataList()) {
      Resource regResource = registry.get(resource.getResourcePath());
      if (regResource.getProperty("registry.link") == null) {
        Assert.assertFalse(
            regResource.getLastUpdaterUserName().contains(userName),
            "searched updater name not contain on actual Updater Name :"
                + resource.getResourcePath());
      }
    }
  }
예제 #6
0
  public void testResourcePropertyVersioning() throws Exception {

    Resource r1 = registry.newResource();
    r1.setContent("content 1");
    r1.addProperty("p1", "v1");
    registry.put("/v4/r1", r1);

    Resource r1v2 = registry.get("/v4/r1");
    r1v2.addProperty("p2", "v2");
    registry.put("/v4/r1", r1v2);
    registry.put("/v4/r1", r1v2);

    String[] r1Versions = registry.getVersions("/v4/r1");

    Resource r1vv1 = registry.get(r1Versions[1]);

    assertEquals(
        "r1's first version should contain a property p1 with value v1",
        r1vv1.getProperty("p1"),
        "v1");

    Resource r1vv2 = registry.get(r1Versions[0]);

    assertEquals(
        "r1's second version should contain a property p1 with value v1",
        r1vv2.getProperty("p1"),
        "v1");

    assertEquals(
        "r1's second version should contain a property p2 with value v2",
        r1vv2.getProperty("p2"),
        "v2");
  }
예제 #7
0
  public static boolean addHandler(Registry configSystemRegistry, String payload)
      throws RegistryException, XMLStreamException {
    String name;
    OMElement element = AXIOMUtil.stringToOM(payload);
    if (element != null) {
      name = element.getAttributeValue(new QName("class"));
    } else return false;

    if (isHandlerNameInUse(name))
      throw new RegistryException("The added handler name is already in use!");

    String path = getContextRoot() + name;
    Resource resource;
    if (!handlerExists(configSystemRegistry, name)) {
      resource = new ResourceImpl();
    } else {
      throw new RegistryException("The added handler name is already in use!");
    }
    resource.setContent(payload);
    try {
      configSystemRegistry.beginTransaction();
      configSystemRegistry.put(path, resource);
      generateHandler(configSystemRegistry, path);
      configSystemRegistry.commitTransaction();
    } catch (Exception e) {
      configSystemRegistry.rollbackTransaction();
      throw new RegistryException("Unable to generate handler", e);
    }
    return true;
  }
예제 #8
0
  public void testBackwardCompatibility() throws RegistryException {
    Registry rootRegistry = embeddedRegistryService.getSystemRegistry();
    Resource r1 = rootRegistry.newResource();
    r1.setContent("r1 content");
    rootRegistry.put("/test/comments/r1", r1);

    rootRegistry.addComment(
        "/test/comments/r1", new Comment("backward-compatibility1 on this resource :)"));
    rootRegistry.addComment(
        "/test/comments/r1", new Comment("backward-compatibility2 on this resource :)"));

    String sql =
        "SELECT REG_COMMENT_ID FROM REG_COMMENT C, REG_RESOURCE_COMMENT RC "
            + "WHERE C.REG_COMMENT_TEXT LIKE ? AND C.REG_ID=RC.REG_COMMENT_ID";

    Resource queryR = rootRegistry.newResource();
    queryR.setMediaType(RegistryConstants.SQL_QUERY_MEDIA_TYPE);
    queryR.addProperty(
        RegistryConstants.RESULT_TYPE_PROPERTY_NAME, RegistryConstants.COMMENTS_RESULT_TYPE);
    rootRegistry.put("/beep/x", queryR);
    Map<String, String> params = new HashMap<String, String>();
    params.put("query", sql);
    params.put(RegistryConstants.RESULT_TYPE_PROPERTY_NAME, RegistryConstants.COMMENTS_RESULT_TYPE);
    params.put("1", "backward-compatibility1%");
    Collection qResults = rootRegistry.executeQuery("/beep/x", params);

    String[] qPaths = (String[]) qResults.getContent();

    assertEquals("Query result count should be 1", qPaths.length, 1);
  }
예제 #9
0
  public String promoteService(String version, String currentPath, String promoteStatus)
      throws CustomLifecyclesChecklistAdminServiceExceptionException, RemoteException,
          RegistryException {
    ArrayOfString[] parameters = new ArrayOfString[2];
    String[] dependencyList = lifeCycleAdminServiceClient.getAllDependencies(currentPath);

    parameters[0] = new ArrayOfString();
    parameters[0].setArray(new String[] {dependencyList[0], version});
    parameters[1] = new ArrayOfString();
    parameters[1].setArray(new String[] {"preserveOriginal", "false"});

    String ACTION_PROMOTE = "Promote";
    String ASPECT_NAME = "DiffEnvironmentLC";
    lifeCycleAdminServiceClient.invokeAspectWithParams(
        currentPath, ASPECT_NAME, ACTION_PROMOTE, null, parameters);

    String newPath =
        "/_system/governance/branches/"
            + promoteStatus
            + "/services/"
            + NAMESPACE
            + "/"
            + version
            + "/"
            + SERVICE_NAME;

    Resource service = wsRegistryServiceClient.get(newPath);
    Assert.assertNotNull(service, "Service Not found on registry path " + newPath);
    Assert.assertEquals(service.getPath(), newPath, "Service not in branches/testing. " + newPath);

    return newPath;
  }
예제 #10
0
 public static boolean generateHandler(Registry configSystemRegistry, String resourceFullPath)
     throws RegistryException, XMLStreamException {
   RegistryContext registryContext = configSystemRegistry.getRegistryContext();
   if (registryContext == null) {
     return false;
   }
   Resource resource = configSystemRegistry.get(resourceFullPath);
   if (resource != null) {
     String content = null;
     if (resource.getContent() != null) {
       content = RegistryUtils.decodeBytes((byte[]) resource.getContent());
     }
     if (content != null) {
       OMElement handler = AXIOMUtil.stringToOM(content);
       if (handler != null) {
         OMElement dummy = OMAbstractFactory.getOMFactory().createOMElement("dummy", null);
         dummy.addChild(handler);
         try {
           configSystemRegistry.beginTransaction();
           boolean status =
               RegistryConfigurationProcessor.updateHandler(
                   dummy,
                   configSystemRegistry.getRegistryContext(),
                   HandlerLifecycleManager.USER_DEFINED_HANDLER_PHASE);
           configSystemRegistry.commitTransaction();
           return status;
         } catch (Exception e) {
           configSystemRegistry.rollbackTransaction();
           throw new RegistryException("Unable to add handler", e);
         }
       }
     }
   }
   return false;
 }
 @Test(
     groups = {"wso2.greg"},
     dependsOnMethods = {"addAssociationToCollection"})
 public void getCollectionAssociation() throws Exception {
   Resource r2 = registry.newCollection();
   String path = "/getcol1/getcol2/getcol3";
   r2.setDescription("this is test desc");
   r2.setProperty("test2", "value2");
   registry.put(path, r2);
   registry.addAssociation(path, "/vtr2121/test", "testasstype1");
   registry.addAssociation(path, "/vtr2122/test", "testasstype2");
   registry.addAssociation(path, "/vtr2123/test", "testasstype3");
   assertTrue(
       getAssocitionbyDestinationByType(path, "testasstype1", "/vtr2121/test"),
       "association Destination path not exist");
   assertTrue(
       getAssocitionbyDestinationByType(path, "testasstype2", "/vtr2122/test"),
       "association Destination path not exist");
   assertTrue(
       getAssocitionbyDestinationByType(path, "testasstype3", "/vtr2123/test"),
       "association Destination path not exist");
   assertTrue(getAssocitionbyType(path, "testasstype1"), "association Type not exist");
   assertTrue(getAssocitionbyType(path, "testasstype2"), "association Type not exist");
   assertTrue(getAssocitionbyType(path, "testasstype3"), "association Type not exist");
   assertTrue(
       getAssocitionbySourceByType(path, "testasstype1"), "association Source path not exist");
   assertTrue(
       getAssocitionbySourceByType(path, "testasstype2"), "association Source path not exist");
   assertTrue(
       getAssocitionbySourceByType(path, "testasstype3"), "association Source path not exist");
 }
 @Test(groups = {"wso2.greg"})
 public void addAssociationToResource() throws Exception {
   Resource r2 = registry.newResource();
   String path = "/testk12/testa/testbsp/test.txt";
   r2.setContent(new String("this is the content").getBytes());
   r2.setDescription("this is test desc");
   r2.setMediaType("plain/text");
   r2.setProperty("test2", "value2");
   registry.put(path, r2);
   registry.addAssociation(path, "/vtr2121/test", "testasstype1");
   registry.addAssociation(path, "/vtr2122/test", "testasstype2");
   registry.addAssociation(path, "/vtr2123/test", "testasstype3");
   assertTrue(
       associationPathExists(path, "/vtr2121/test"), "association Destination path not exist");
   assertTrue(
       associationPathExists(path, "/vtr2122/test"), "association Destination path not exist");
   assertTrue(
       associationPathExists(path, "/vtr2123/test"), "association Destination path not exist");
   assertTrue(associationTypeExists(path, "testasstype1"), "association Type not exist");
   assertTrue(associationTypeExists(path, "testasstype2"), "association Type not exist");
   assertTrue(associationTypeExists(path, "testasstype3"), "association Type not exist");
   assertTrue(associationSourcepathExists(path, path), "association Source path not exist");
   assertTrue(associationSourcepathExists(path, path), "association Source path not exist");
   assertTrue(associationSourcepathExists(path, path), "association Source path not exist");
 }
예제 #13
0
  public void persist(String path, byte[] resourceBytes, String tag) throws RegistryException {

    UserRegistry registry = initRegistry();

    try {
      registry.beginTransaction();
      Resource nodeResource = registry.newResource();
      nodeResource.setContent(resourceBytes);
      // store the resource in the registry
      registry.put(path, nodeResource);
      if (tag != null) {
        // apply the tag
        registry.applyTag(path, tag);
      }
      // commit
      registry.commitTransaction();

    } catch (RegistryException e) {
      String errorMsg = "Failed to persist the given resource in registry path " + path;
      log.error(errorMsg, e);
      // rollback
      try {
        registry.rollbackTransaction();

      } catch (RegistryException e1) {
        errorMsg = "Failed to rollback the transaction in registry path " + path;
        log.error(errorMsg, e1);
        throw e1;
      }
      throw e;
    }
  }
 @Test(
     groups = {"wso2.greg"},
     dependsOnMethods = {"addAssociationToResource"})
 public void getResourceAssociation() throws Exception {
   Resource r2 = registry.newResource();
   String path = "/testk1234/testa/testbsp/test.txt";
   r2.setContent(new String("this is the content").getBytes());
   r2.setDescription("this is test desc");
   r2.setMediaType("plain/text");
   r2.setProperty("test2", "value2");
   registry.addAssociation(path, "/vtr2121/test", "testasstype1");
   registry.addAssociation(path, "/vtr2122/test", "testasstype2");
   registry.addAssociation(path, "/vtr2123/test", "testasstype3");
   assertTrue(
       getAssocitionbyDestinationByType(path, "testasstype1", "/vtr2121/test"),
       "association Destination path not exist");
   assertTrue(
       getAssocitionbyDestinationByType(path, "testasstype2", "/vtr2122/test"),
       "association Destination path not exist");
   assertTrue(
       getAssocitionbyDestinationByType(path, "testasstype3", "/vtr2123/test"),
       "association Destination path not exist");
   assertTrue(getAssocitionbyType(path, "testasstype1"), "association Type not exist");
   assertTrue(getAssocitionbyType(path, "testasstype2"), "association Type not exist");
   assertTrue(getAssocitionbyType(path, "testasstype3"), "association Type not exist");
   assertTrue(
       getAssocitionbySourceByType(path, "testasstype1"), "association Source path not exist");
   assertTrue(
       getAssocitionbySourceByType(path, "testasstype2"), "association Source path not exist");
   assertTrue(
       getAssocitionbySourceByType(path, "testasstype3"), "association Source path not exist");
 }
예제 #15
0
 public boolean removeDomainMappingFromRegistry(String actualHost) throws Exception {
   boolean successfullyRemoved;
   try {
     registry.beginTransaction();
     String hostResourcePath = CartridgeConstants.DomainMappingInfo.HOSTINFO;
     if (registry.resourceExists(hostResourcePath)) {
       Resource hostResource = registry.get(hostResourcePath);
       Collection hostInfoCollection;
       if (hostResource instanceof Collection) {
         hostInfoCollection = (Collection) hostResource;
       } else {
         throw new Exception("Resource is not a collection " + hostResourcePath);
       }
       String[] paths = hostInfoCollection.getChildren();
       for (String path : paths) {
         Resource domainMapping = registry.get(path);
         String actualHostInRegistry =
             domainMapping.getProperty(CartridgeConstants.DomainMappingInfo.ACTUAL_HOST);
         if (actualHostInRegistry != null && actualHost.equalsIgnoreCase(actualHostInRegistry)) {
           registry.delete(path);
         }
       }
     }
     registry.commitTransaction();
     successfullyRemoved = true;
   } catch (RegistryException e) {
     registry.rollbackTransaction();
     log.error("Unable to remove the mapping", e);
     throw e;
   }
   return successfullyRemoved;
 }
예제 #16
0
  @Test(
      groups = {"wso2.greg"},
      description = "Metadata search by Updater Name pattern matching",
      dependsOnMethods = "searchResourceByUpdaterNot")
  public void searchResourceByUpdaterNamePattern()
      throws SearchAdminServiceRegistryExceptionException, RemoteException, RegistryException {
    CustomSearchParameterBean searchQuery = new CustomSearchParameterBean();
    SearchParameterBean paramBean = new SearchParameterBean();
    paramBean.setUpdater("adm%");
    ArrayOfString[] paramList = paramBean.getParameterList();

    searchQuery.setParameterValues(paramList);
    AdvancedSearchResultsBean result =
        searchAdminServiceClient.getAdvancedSearchResults(searchQuery);
    Assert.assertNotNull(result.getResourceDataList(), "No Record Found");
    Assert.assertTrue(
        (result.getResourceDataList().length > 0),
        "No Record Found. set valid Updater name pattern");
    for (ResourceData resourceData : result.getResourceDataList()) {
      Resource resource = registry.get(resourceData.getResourcePath());
      Assert.assertTrue(
          (resource.getLastUpdaterUserName().startsWith("adm")),
          "search word pattern not contain on Updater Name :" + resourceData.getResourcePath());
    }
  }
예제 #17
0
  private void multiValuedProperties() {
    String path = "/propTest/r1";
    Resource r1 = registry.newResource();

    try {
      r1.setContent("Some content for r1");

      r1.addProperty("p1", "p1v1");
      r1.addProperty("p1", "p1v2");
      registry.put(path, r1);

      Resource r1b = registry.get(path);
      List propValues = r1b.getPropertyValues("p1");

      assertTrue(
          "Property p1 of /propTest/r1 should contain the value p1v1", propValues.contains("p1v1"));

      assertTrue(
          "Property p1 of /propTest/r1 should contain the value p1v2", propValues.contains("p1v2"));

      deleteResources("/propTest");
      log.info("multiValuedProperties - Passed");
    } catch (RegistryException e) {

      log.error("multiValuedProperties RegistryException thrown :" + e.getMessage());
      Assert.fail("multiValuedProperties RegistryException thrown :" + e.getMessage());
    }
  }
예제 #18
0
  public void testRootLevelVersioning() throws Exception {

    Resource r1 = registry.newResource();
    r1.setContent("r1c1");
    registry.put("/vtr1", r1);

    registry.createVersion("/");

    Collection c2 = registry.newCollection();
    registry.put("/vtc2", c2);

    registry.createVersion("/");

    String[] rootVersions = registry.getVersions("/");

    Collection rootv0 = (Collection) registry.get(rootVersions[0]);
    String[] rootv0Children = (String[]) rootv0.getContent();
    assertTrue(
        "Root should have child vtr1", RegistryUtils.containsAsSubString("/vtr1", rootv0Children));
    assertTrue(
        "Root should have child vtc2", RegistryUtils.containsAsSubString("/vtc2", rootv0Children));

    Collection rootv1 = (Collection) registry.get(rootVersions[1]);
    String[] rootv1Children = (String[]) rootv1.getContent();
    assertTrue(
        "Root should have child vtr1", RegistryUtils.containsAsSubString("/vtr1", rootv1Children));
    assertFalse(
        "Root should not have child vtc2",
        RegistryUtils.containsAsSubString("/vtc2", rootv1Children));
  }
예제 #19
0
  private void populateResource() throws RegistryException {
    Resource initialResource = registry.newResource();

    //        Adding the resource for the first time
    //        user admin will be the creator and updater of this resource.
    initialResource.setContent("Test content");
    registry.put(resourcePath, initialResource);
  }
예제 #20
0
  /**
   * @param policyStoreDTO
   * @return
   */
  public static void addPolicyToPDP(PolicyStoreDTO policyStoreDTO) throws EntitlementException {

    Registry registry;
    String policyPath;
    Collection policyCollection;
    Resource resource;

    Map.Entry<PolicyStoreManageModule, Properties> entry =
        EntitlementServiceComponent.getEntitlementConfig()
            .getPolicyStore()
            .entrySet()
            .iterator()
            .next();
    String policyStorePath = entry.getValue().getProperty("policyStorePath");

    if (policyStorePath == null) {
      policyStorePath = "/repository/identity/Entitlement/actualStore/";
    }

    if (policyStoreDTO == null
        || policyStoreDTO.getPolicy() == null
        || policyStoreDTO.getPolicy().trim().length() == 0
        || policyStoreDTO.getPolicyId() == null
        || policyStoreDTO.getPolicyId().trim().length() == 0) {
      return;
    }

    try {
      registry = EntitlementServiceComponent.getRegistryService().getGovernanceSystemRegistry();

      if (registry.resourceExists(policyStorePath)) {
        policyCollection = (Collection) registry.get(policyStorePath);
      } else {
        policyCollection = registry.newCollection();
      }

      registry.put(policyStorePath, policyCollection);
      policyPath = policyStorePath + policyStoreDTO.getPolicyId();

      if (registry.resourceExists(policyPath)) {
        resource = registry.get(policyPath);
      } else {
        resource = registry.newResource();
      }

      resource.setProperty("policyOrder", Integer.toString(policyStoreDTO.getPolicyOrder()));
      resource.setContent(policyStoreDTO.getPolicy());
      resource.setMediaType("application/xacml-policy+xml");
      AttributeDTO[] attributeDTOs = policyStoreDTO.getAttributeDTOs();
      if (attributeDTOs != null) {
        setAttributesAsProperties(attributeDTOs, resource);
      }
      registry.put(policyPath, resource);
    } catch (RegistryException e) {
      log.error(e);
      throw new EntitlementException("Error while adding policy to PDP", e);
    }
  }
예제 #21
0
  /**
   * Method to obtain the custom UI media types.
   *
   * @param configSystemRegistry a configuration system registry instance.
   * @return a String of custom UI media types, in the format name:type,name:type,...
   * @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;
  }
예제 #22
0
 /**
  * This method is used to back up existing Files.
  *
  * @param registry registry instance.
  * @param path path of the rxt.
  * @param fileName file name of backed up rxt files.
  * @throws RegistryException
  */
 public static void backUpFiles(Registry registry, String path, String fileName)
     throws RegistryException {
   Resource resource = registry.get(path);
   try {
     contentToFile(resource.getContentStream(), fileName);
   } catch (FileNotFoundException e) {
     System.out.println("Could not read file content");
   }
 }
    public String[] getAvailableActions(RequestContext context) {
      Resource r = context.getResource();
      String state = r.getProperty(STATE_PROP);

      if (INIT.equals(state)) {
        return actions;
      }

      return null;
    }
예제 #24
0
 public static String getHandlerConfiguration(Registry configSystemRegistry, String name)
     throws RegistryException, XMLStreamException {
   String path = getContextRoot() + name;
   Resource resource;
   if (handlerExists(configSystemRegistry, name)) {
     resource = configSystemRegistry.get(path);
     return RegistryUtils.decodeBytes((byte[]) resource.getContent());
   }
   return null;
 }
예제 #25
0
  public void ResourceCopyTest() throws RegistryException {

    Resource r1 = registry.newResource();
    r1.setProperty("test", "copy");
    r1.setContent("c");
    registry.put("/test1/copy/c1/copy1", r1);

    Collection c1 = registry.newCollection();
    registry.put("/test1/move", c1);

    registry.copy("/test1/copy/c1/copy1", "/test1/copy/c2/copy2");

    Resource newR1 = registry.get("/test1/copy/c2/copy2");
    assertEquals(
        "Copied resource should have a property named 'test' with value 'copy'.",
        newR1.getProperty("test"),
        "copy");

    Resource oldR1 = registry.get("/test1/copy/c1/copy1");
    assertEquals(
        "Original resource should have a property named 'test' with value 'copy'.",
        oldR1.getProperty("test"),
        "copy");

    String newContent = new String((byte[]) newR1.getContent());
    String oldContent = new String((byte[]) oldR1.getContent());
    assertEquals("Contents are not equal in copied resources", newContent, oldContent);
  }
예제 #26
0
  public void testPermaLinksForResources() throws Exception {

    Resource r1 = registry.newResource();
    r1.setContent("r1c1");
    registry.put("/test/v13/r1", r1);
    registry.put("/test/v13/r1", r1);

    String[] r1Versions = registry.getVersions("/test/v13/r1");

    Resource r1e1 = registry.get(r1Versions[0]);
    assertEquals("Permalink incorrect", r1e1.getPermanentPath(), r1Versions[0]);

    r1e1.setContent("r1c2");
    registry.put("/test/v13/r1", r1e1);

    r1Versions = registry.getVersions("/test/v13/r1");

    Resource r1e2 = registry.get(r1Versions[0]);
    assertEquals("Permalink incorrect", r1e2.getPermanentPath(), r1Versions[0]);

    registry.restoreVersion(r1Versions[1]);

    Resource r1e3 = registry.get(r1Versions[1]);
    assertEquals("Permalink incorrect", r1e3.getPermanentPath(), r1Versions[1]);
  }
예제 #27
0
  private void removingProperties() {
    String path = "/props/t1/r1";
    Resource r1 = registry.newResource();
    try {
      r1.setContent("r1 content");

      r1.setProperty("p1", "v1");
      r1.setProperty("p2", "v2");
      registry.put(path, r1);

      Resource r1e1 = registry.get(path);
      r1e1.setContent("r1 content");
      r1e1.removeProperty("p1");
      registry.put(path, r1e1);

      Resource r1e2 = registry.get(path);

      assertEquals("Property is not removed.", r1e2.getProperty("p1"), null);
      assertNotNull("Wrong property is removed.", r1e2.getProperty("p2"));

      deleteResources("/props");
      log.info("removingProperties - Passed");
    } catch (RegistryException e) {

      log.error("removingProperties RegistryException thrown :" + e.getMessage());
      Assert.fail("removingProperties RegistryException thrown :" + e.getMessage());
    }
  }
예제 #28
0
  private void removingMultivaluedProperties() {
    String path = "/props/t2/r1";
    Resource r1 = registry.newResource();
    try {
      r1.setContent("r1 content");

      r1.addProperty("p1", "v1");
      r1.addProperty("p1", "v2");
      registry.put(path, r1);

      Resource r1e1 = registry.get(path);
      r1e1.setContent("r1 content updated");
      r1e1.removePropertyValue("p1", "v1");
      registry.put(path, r1e1);

      Resource r1e2 = registry.get(path);
      assertFalse("Property is not removed.", r1e2.getPropertyValues("p1").contains("v1"));
      assertTrue("Wrong property is removed.", r1e2.getPropertyValues("p1").contains("v2"));

      deleteResources("/props");
      log.info("removingMultivaluedProperties - Passed");
    } catch (RegistryException e) {

      log.error("removingMultivaluedProperties RegistryException thrown :" + e.getMessage());
      Assert.fail("removingMultivaluedProperties RegistryException thrown :" + e.getMessage());
    }
  }
 public void propertyAssertion(String policy_path) throws RegistryException {
   Resource resource;
   try {
     resource = registry.get(policy_path);
     assertEquals(resource.getProperty("creator"), "Aaaa", "WSDL Property - WSI creator");
     assertEquals(resource.getProperty("version"), "1.0.0", "WSDL Property - WSI version");
   } catch (RegistryException e) {
     log.error("Failed to Assert Properties :" + e);
     throw new RegistryException("Failed to Assert Properties :" + e);
   }
 }
예제 #30
0
 /**
  * Creates and returns an InputStream from the file path / http location given.
  *
  * @throws DataServiceFault
  * @see InputStream
  */
 public static InputStream getInputStreamFromPath(String path)
     throws IOException, DataServiceFault {
   InputStream ins;
   if (path.startsWith("http://")) {
     /* This is a url file path */
     URL url = new URL(path);
     ins = url.openStream();
   } else if (isRegistryPath(path)) {
     try {
       RegistryService registryService = DataServicesDSComponent.getRegistryService();
       if (registryService == null) {
         throw new DataServiceFault(
             "DBUtils.getInputStreamFromPath(): Registry service is not available");
       }
       Registry registry;
       if (path.startsWith(DBConstants.CONF_REGISTRY_PATH_PREFIX)) {
         if (path.length() > DBConstants.CONF_REGISTRY_PATH_PREFIX.length()) {
           path = path.substring(DBConstants.CONF_REGISTRY_PATH_PREFIX.length());
           registry = registryService.getConfigSystemRegistry(getCurrentTenantId());
         } else {
           throw new DataServiceFault("Empty configuration registry path given");
         }
       } else {
         if (path.length() > DBConstants.GOV_REGISTRY_PATH_PREFIX.length()) {
           path = path.substring(DBConstants.GOV_REGISTRY_PATH_PREFIX.length());
           registry = registryService.getGovernanceSystemRegistry(getCurrentTenantId());
         } else {
           throw new DataServiceFault("Empty governance registry path given");
         }
       }
       if (registry.resourceExists(path)) {
         Resource serviceResource = registry.get(path);
         ins = serviceResource.getContentStream();
       } else {
         throw new DataServiceFault(
             "The given XSLT resource path at '" + path + "' does not exist");
       }
     } catch (RegistryException e) {
       String msg = "Error in retrieving the resource: " + path;
       log.error(msg, e);
       throw new DataServiceFault(e, msg);
     }
   } else {
     File csvFile = new File(path);
     if (path.startsWith("." + File.separator) || path.startsWith(".." + File.separator)) {
       /* this is a relative path */
       path = csvFile.getAbsolutePath();
     }
     /* local file */
     ins = new FileInputStream(path);
   }
   return ins;
 }