You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2020/02/07 14:54:14 UTC

[GitHub] [incubator-shardingsphere] beckhampu opened a new pull request #4205: Add class filter Constructor to restrict the illegal class from YAML

beckhampu opened a new pull request #4205: Add class filter Constructor to restrict the illegal class from YAML
URL: https://github.com/apache/incubator-shardingsphere/pull/4205
 
 
   Fixes #4199.
   
   Changes proposed in this pull request:
   -  add class filter constructor.
   -  modify YamlEngine.Map<?, ?> unmarshal() method ,add parameter 'acceptClasses'.
   -  modiry three calls of this method.
   - add ut case.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-shardingsphere] kimmking commented on a change in pull request #4205: Add class filter Constructor to restrict the illegal class from YAML

Posted by GitBox <gi...@apache.org>.
kimmking commented on a change in pull request #4205: Add class filter Constructor to restrict the illegal class from YAML
URL: https://github.com/apache/incubator-shardingsphere/pull/4205#discussion_r376964251
 
 

 ##########
 File path: sharding-core/sharding-core-common/src/test/java/org/apache/shardingsphere/core/yaml/engine/YamlEngineTest.java
 ##########
 @@ -38,11 +44,25 @@ public void assertUnmarshal() {
     @SuppressWarnings("unchecked")
     @Test
     public void assertUnmarshalMap() {
-        Map<String, Object> actual = (Map<String, Object>) YamlEngine.unmarshal("password: pwd\nauthorizedSchemas: db1");
+        Map<String, Object> actual = (Map<String, Object>) YamlEngine.unmarshal("password: pwd\nauthorizedSchemas: db1", Collections.<Class<?>>emptyList());
         assertThat(actual.get("password").toString(), is("pwd"));
         assertThat(actual.get("authorizedSchemas").toString(), is("db1"));
     }
     
+    @Test(expected = ConstructorException.class)
+    public void assertUnmarshalMapWithIllegalClasses() {
+        YamlEngine.unmarshal("url: !!java.net.URLClassLoader [[!!java.net.URL [\"http://localhost\"]]]", Collections.<Class<?>>emptyList());
 
 Review comment:
   "url: !!java.net.URLClassLoader [[!!java.net.URL [\"http://localhost\"]]]"
   
   maybe not enough

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-shardingsphere] coveralls edited a comment on issue #4205: Add class filter Constructor to restrict the illegal class from YAML

Posted by GitBox <gi...@apache.org>.
coveralls edited a comment on issue #4205: Add class filter Constructor to restrict the illegal class from YAML
URL: https://github.com/apache/incubator-shardingsphere/pull/4205#issuecomment-583454036
 
 
   ## Pull Request Test Coverage Report for [Build 1645](https://coveralls.io/builds/28592603)
   
   * **10** of **11**   **(90.91%)**  changed or added relevant lines in **5** files are covered.
   * **2** unchanged lines in **1** file lost coverage.
   * Overall coverage increased (+**0.02%**) to **67.529%**
   
   ---
   
   |  Changes Missing Coverage | Covered Lines | Changed/Added Lines | % |
   | :-----|--------------|--------|---: |
   | [sharding-ui/sharding-ui-backend/src/main/java/org/apache/shardingsphere/ui/util/ConfigurationYamlConverter.java](https://coveralls.io/builds/28592603/source?filename=sharding-ui%2Fsharding-ui-backend%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fshardingsphere%2Fui%2Futil%2FConfigurationYamlConverter.java#L62) | 0 | 1 | 0.0%
   <!-- | **Total:** | **10** | **11** | **90.91%** | -->
   
   |  Files with Coverage Reduction | New Missed Lines | % |
   | :-----|--------------|--: |
   | [sharding-orchestration/sharding-orchestration-core/src/main/java/org/apache/shardingsphere/orchestration/internal/util/IpUtils.java](https://coveralls.io/builds/28592603/source?filename=sharding-orchestration%2Fsharding-orchestration-core%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fshardingsphere%2Forchestration%2Finternal%2Futil%2FIpUtils.java#L74) | 2 | 80.0% |
   <!-- | **Total:** | **2** |  | -->
   
   |  Totals | [![Coverage Status](https://coveralls.io/builds/28592603/badge)](https://coveralls.io/builds/28592603) |
   | :-- | --: |
   | Change from base [Build 9373](https://coveralls.io/builds/28590005): |  0.02% |
   | Covered Lines: | 11297 |
   | Relevant Lines: | 16729 |
   
   ---
   ##### 💛  - [Coveralls](https://coveralls.io)
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-shardingsphere] terrymanu commented on a change in pull request #4205: Add class filter Constructor to restrict the illegal class from YAML

Posted by GitBox <gi...@apache.org>.
terrymanu commented on a change in pull request #4205: Add class filter Constructor to restrict the illegal class from YAML
URL: https://github.com/apache/incubator-shardingsphere/pull/4205#discussion_r376444330
 
 

 ##########
 File path: sharding-core/sharding-core-common/src/main/java/org/apache/shardingsphere/core/yaml/engine/ClassFilterConstructor.java
 ##########
 @@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF 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.
+ */
+
+package org.apache.shardingsphere.core.yaml.engine;
+
+import lombok.RequiredArgsConstructor;
+import org.yaml.snakeyaml.constructor.Constructor;
+
+import java.util.Collection;
+
+/**
+ * Class filter Constructor for YAML load as map.
+ *
+ * @author chenqingyang
+ */
+@RequiredArgsConstructor
+public final class ClassFilterConstructor extends Constructor {
+    
+    private final Collection<Class<?>> acceptClasses;
+    
+    @Override
+    protected Class<?> getClassForName(final String name) throws ClassNotFoundException {
+        for (Class<? extends Object> clz : acceptClasses) {
 
 Review comment:
   may change name from `clz` to `each`

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-shardingsphere] coveralls commented on issue #4205: Add class filter Constructor to restrict the illegal class from YAML

Posted by GitBox <gi...@apache.org>.
coveralls commented on issue #4205: Add class filter Constructor to restrict the illegal class from YAML
URL: https://github.com/apache/incubator-shardingsphere/pull/4205#issuecomment-583454036
 
 
   ## Pull Request Test Coverage Report for [Build 1643](https://coveralls.io/builds/28591614)
   
   * **10** of **11**   **(90.91%)**  changed or added relevant lines in **5** files are covered.
   * **2** unchanged lines in **1** file lost coverage.
   * Overall coverage increased (+**0.02%**) to **67.529%**
   
   ---
   
   |  Changes Missing Coverage | Covered Lines | Changed/Added Lines | % |
   | :-----|--------------|--------|---: |
   | [sharding-ui/sharding-ui-backend/src/main/java/org/apache/shardingsphere/ui/util/ConfigurationYamlConverter.java](https://coveralls.io/builds/28591614/source?filename=sharding-ui%2Fsharding-ui-backend%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fshardingsphere%2Fui%2Futil%2FConfigurationYamlConverter.java#L62) | 0 | 1 | 0.0%
   <!-- | **Total:** | **10** | **11** | **90.91%** | -->
   
   |  Files with Coverage Reduction | New Missed Lines | % |
   | :-----|--------------|--: |
   | [sharding-orchestration/sharding-orchestration-core/src/main/java/org/apache/shardingsphere/orchestration/internal/util/IpUtils.java](https://coveralls.io/builds/28591614/source?filename=sharding-orchestration%2Fsharding-orchestration-core%2Fsrc%2Fmain%2Fjava%2Forg%2Fapache%2Fshardingsphere%2Forchestration%2Finternal%2Futil%2FIpUtils.java#L74) | 2 | 80.0% |
   <!-- | **Total:** | **2** |  | -->
   
   |  Totals | [![Coverage Status](https://coveralls.io/builds/28591614/badge)](https://coveralls.io/builds/28591614) |
   | :-- | --: |
   | Change from base [Build 9373](https://coveralls.io/builds/28590005): |  0.02% |
   | Covered Lines: | 11297 |
   | Relevant Lines: | 16729 |
   
   ---
   ##### 💛  - [Coveralls](https://coveralls.io)
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-shardingsphere] beckhampu commented on a change in pull request #4205: Add class filter Constructor to restrict the illegal class from YAML

Posted by GitBox <gi...@apache.org>.
beckhampu commented on a change in pull request #4205: Add class filter Constructor to restrict the illegal class from YAML
URL: https://github.com/apache/incubator-shardingsphere/pull/4205#discussion_r376451397
 
 

 ##########
 File path: sharding-core/sharding-core-common/src/main/java/org/apache/shardingsphere/core/yaml/engine/ClassFilterConstructor.java
 ##########
 @@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF 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.
+ */
+
+package org.apache.shardingsphere.core.yaml.engine;
+
+import lombok.RequiredArgsConstructor;
+import org.yaml.snakeyaml.constructor.Constructor;
+
+import java.util.Collection;
+
+/**
+ * Class filter Constructor for YAML load as map.
+ *
+ * @author chenqingyang
+ */
+@RequiredArgsConstructor
+public final class ClassFilterConstructor extends Constructor {
+    
+    private final Collection<Class<?>> acceptClasses;
+    
+    @Override
+    protected Class<?> getClassForName(final String name) throws ClassNotFoundException {
+        for (Class<? extends Object> clz : acceptClasses) {
 
 Review comment:
   ok!

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-shardingsphere] kimmking commented on a change in pull request #4205: Add class filter Constructor to restrict the illegal class from YAML

Posted by GitBox <gi...@apache.org>.
kimmking commented on a change in pull request #4205: Add class filter Constructor to restrict the illegal class from YAML
URL: https://github.com/apache/incubator-shardingsphere/pull/4205#discussion_r376964187
 
 

 ##########
 File path: sharding-core/sharding-core-common/src/test/java/org/apache/shardingsphere/core/yaml/engine/YamlEngineTest.java
 ##########
 @@ -38,11 +44,25 @@ public void assertUnmarshal() {
     @SuppressWarnings("unchecked")
     @Test
     public void assertUnmarshalMap() {
-        Map<String, Object> actual = (Map<String, Object>) YamlEngine.unmarshal("password: pwd\nauthorizedSchemas: db1");
+        Map<String, Object> actual = (Map<String, Object>) YamlEngine.unmarshal("password: pwd\nauthorizedSchemas: db1", Collections.<Class<?>>emptyList());
         assertThat(actual.get("password").toString(), is("pwd"));
         assertThat(actual.get("authorizedSchemas").toString(), is("db1"));
     }
     
+    @Test(expected = ConstructorException.class)
+    public void assertUnmarshalMapWithIllegalClasses() {
+        YamlEngine.unmarshal("url: !!java.net.URLClassLoader [[!!java.net.URL [\"http://localhost\"]]]", Collections.<Class<?>>emptyList());
 
 Review comment:
   "url: !!java.net.URLClassLoader [[!!java.net.URL [\"http://localhost\"]]]"
   
   maybe not enough

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [incubator-shardingsphere] terrymanu merged pull request #4205: Add class filter Constructor to restrict the illegal class from YAML

Posted by GitBox <gi...@apache.org>.
terrymanu merged pull request #4205: Add class filter Constructor to restrict the illegal class from YAML
URL: https://github.com/apache/incubator-shardingsphere/pull/4205
 
 
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services