-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ShardingProxy supports multiple users and authorizedSchemas (#2237)
* rename to UserChangedListenerTest * use AuthenticationChangedListenerTest * use UserYamlSwapperTest * modify authentication * Authentication changed event * Authentication changed listener * modify AUTHENTICATION_YAML * check style * check style * modify swap() * add AuthenticationYamlSwapperTest.java * use Authentication() * modify AUTHENTICATION_YAML * Authentication engine for MySQL. * login() * Authentication engine * modify unit cases in MySQLAuthenticationHandlerTest.java * setAuthentication() * use Authentication * modify javadoc * modify javadoc * modify loadServerConfiguration() * use authentication in loadServerConfiguration * modify unit cases * add user * add UserYamlSwapper * modify YamlAuthentication * use YamlUser * delete new YamlAuthentication() * add YamlUser.java * modify AUTHENTICATION_YAML content * use Collections * use Collections * modify config * use Collections * modify unit cases * prefer to use Collections * modify swap() * add isAuthorizedSchema() * isAuthorizedSchema() * add userName * modify assertMarshal() * getSchemaNames() * mock(BackendConnection.class) * new ShowDatabasesBackendHandler(backendConnection) * modify setUp() * modify setUp() * !authorizedSchemas.isEmpty() * trimResults() * isAuthorizedSchema() * modify isAuthorizedSchema() * isAuthorizedSchema(final String schema) * rename to ProxyUser * rename to ProxyUserYamlSwapperTest * modify examples * use ProxyUserYamlSwapperTest * use ProxyUser * use ProxyUser * Proxy user YAML swapper * rename to ProxyUserYamlSwapper * use ProxyUserYamlSwapper * ProxyUserYamlSwapperTest * USE YamlProxyUser * rename to YamlProxyUser * use YamlProxyUser * use YamlProxyUser * rename to YamlAuthenticationConfiguration * rename to YamlAuthenticationConfiguration * use YamlAuthenticationConfiguration * use YamlAuthenticationConfiguration * rename to YamlProxyUserConfiguration * use YamlProxyUserConfiguration * use YamlProxyUserConfiguration
- Loading branch information
1 parent
7f4faf2
commit 5020861
Showing
31 changed files
with
371 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...ore/sharding-core-common/src/main/java/org/apache/shardingsphere/core/rule/ProxyUser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* 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.rule; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
import java.util.Collection; | ||
|
||
/** | ||
* Proxy user. | ||
* | ||
* @author panjuan | ||
*/ | ||
@RequiredArgsConstructor | ||
@Getter | ||
public final class ProxyUser { | ||
|
||
private final String password; | ||
|
||
private final Collection<String> authorizedSchemas; | ||
} |
37 changes: 37 additions & 0 deletions
37
...va/org/apache/shardingsphere/core/yaml/config/common/YamlAuthenticationConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* 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.config.common; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
import org.apache.shardingsphere.core.yaml.config.YamlConfiguration; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* Authentication configuration for YAML. | ||
* | ||
* @author panjuan | ||
*/ | ||
@Getter | ||
@Setter | ||
public final class YamlAuthenticationConfiguration implements YamlConfiguration { | ||
|
||
private Map<String, YamlProxyUserConfiguration> users = new HashMap<>(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
.../src/main/java/org/apache/shardingsphere/core/yaml/swapper/impl/ProxyUserYamlSwapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* 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.swapper.impl; | ||
|
||
import com.google.common.base.Joiner; | ||
import com.google.common.base.Splitter; | ||
import com.google.common.base.Strings; | ||
import org.apache.shardingsphere.core.rule.ProxyUser; | ||
import org.apache.shardingsphere.core.yaml.config.common.YamlProxyUserConfiguration; | ||
import org.apache.shardingsphere.core.yaml.swapper.YamlSwapper; | ||
|
||
import java.util.Collections; | ||
|
||
/** | ||
* Proxy user YAML swapper. | ||
* | ||
* @author zhangliang | ||
*/ | ||
public final class ProxyUserYamlSwapper implements YamlSwapper<YamlProxyUserConfiguration, ProxyUser> { | ||
|
||
@Override | ||
public YamlProxyUserConfiguration swap(final ProxyUser data) { | ||
YamlProxyUserConfiguration result = new YamlProxyUserConfiguration(); | ||
result.setPassword(data.getPassword()); | ||
String authorizedSchemas = null == data.getAuthorizedSchemas() ? "" : Joiner.on(',').join(data.getAuthorizedSchemas()); | ||
result.setAuthorizedSchemas(authorizedSchemas); | ||
return result; | ||
} | ||
|
||
@Override | ||
public ProxyUser swap(final YamlProxyUserConfiguration yamlConfiguration) { | ||
if (Strings.isNullOrEmpty(yamlConfiguration.getAuthorizedSchemas())) { | ||
return new ProxyUser(yamlConfiguration.getPassword(), Collections.<String>emptyList()); | ||
} | ||
return new ProxyUser(yamlConfiguration.getPassword(), Splitter.on(',').trimResults().splitToList(yamlConfiguration.getAuthorizedSchemas())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.