-
Notifications
You must be signed in to change notification settings - Fork 525
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add multi-node auth information sharing function #1350
Changes from 16 commits
d6a32da
a4d7b2e
b43b699
431f5bc
2836392
bba8e75
f2cc09c
2b953b9
b10030b
7fdbbd5
c354121
c1dc32b
eec6ae2
14a7e6d
3c78da1
ce81669
fd508d6
b1660b7
d2747a6
e2a3bad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,8 +100,8 @@ public final class HugeGraphAuthProxy implements HugeGraph { | |
private static final Logger LOG = Log.logger(HugeGraphAuthProxy.class); | ||
|
||
private final HugeGraph hugegraph; | ||
private final TaskScheduler taskScheduler; | ||
private final UserManager userManager; | ||
private final TaskSchedulerProxy taskScheduler; | ||
private final UserManagerProxy userManager; | ||
|
||
public HugeGraphAuthProxy(HugeGraph hugegraph) { | ||
LOG.info("Wrap graph '{}' with HugeGraphAuthProxy", hugegraph.name()); | ||
|
@@ -652,6 +652,12 @@ public UserManager userManager() { | |
return this.userManager; | ||
} | ||
|
||
@Override | ||
public void swichUserManager(UserManager userManager) { | ||
this.verifyAdminPermission(); | ||
this.userManager.swichUserManager(userManager); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. swich -> switch |
||
} | ||
|
||
@Override | ||
public RaftGroupManager raftGroupManager(String group) { | ||
this.verifyAdminPermission(); | ||
|
@@ -1044,7 +1050,7 @@ private boolean hasTaskPermission(HugeTask<?> task) { | |
|
||
class UserManagerProxy implements UserManager { | ||
|
||
private final UserManager userManager; | ||
private UserManager userManager; | ||
|
||
public UserManagerProxy(UserManager origin) { | ||
this.userManager = origin; | ||
|
@@ -1345,6 +1351,11 @@ public RolePermission loginUser(String username, String password) { | |
setContext(context); | ||
} | ||
} | ||
|
||
private void swichUserManager(UserManager userManager) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. swich -> switch |
||
this.userManager = userManager; | ||
hugegraph.swichUserManager(userManager); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
} | ||
} | ||
|
||
class VariablesProxy implements Variables { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -222,6 +222,115 @@ public static synchronized ServerOptions instance() { | |
"hugegraph:9fd95c9c-711b-415b-b85f-d4df46ba5c31" | ||
); | ||
|
||
public static final ConfigOption<String> AUTH_REMOTE_URL = | ||
new ConfigOption<>( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. define as ListConfigOption for multi auth servers |
||
"auth.remote_url", | ||
"If the address is empty, it provide auth service, " + | ||
"otherwise it is auth client and also provide auth service " + | ||
"through rpc forwarding. The remote url can be set to " + | ||
"multiple addresses, which are linked by ','.", | ||
null, | ||
"" | ||
); | ||
|
||
public static final ConfigOption<Integer> RPC_SERVER_PORT = | ||
new ConfigOption<>( | ||
"rpc.server_port", | ||
"The port bound by rpc server to provide services.", | ||
rangeInt(1, Integer.MAX_VALUE), | ||
8099 | ||
); | ||
|
||
public static final ConfigOption<String> RPC_SERVER_HOST = | ||
new ConfigOption<>( | ||
"rpc.server_host", | ||
"The hosts/ips bound by rpc server to provide " + | ||
"services.", | ||
disallowEmpty(), | ||
"0.0.0.0" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. set default value 127.0.0.1 |
||
); | ||
javeme marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
public static final ConfigOption<Integer> RPC_SERVER_TIMEOUT = | ||
new ConfigOption<>( | ||
"rpc.server_timeout", | ||
"The timeout(in seconds) of rpc server execution.", | ||
rangeInt(1, Integer.MAX_VALUE), | ||
30 | ||
); | ||
|
||
public static final ConfigOption<Integer> RPC_CLIENT_CONNECT_TIMEOUT = | ||
new ConfigOption<>( | ||
"rpc.client_connect_timeout", | ||
"The timeout(in seconds) of rpc client connect to rpc " + | ||
"server.", | ||
rangeInt(1, Integer.MAX_VALUE), | ||
20 | ||
); | ||
|
||
public static final ConfigOption<Integer> RPC_CLIENT_RECONNECT_PERIOD = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also update rpc.client_reconnect_timeout |
||
new ConfigOption<>( | ||
"rpc.client_reconnect_timeout", | ||
"The timeout(in seconds) of rpc client reconnect to rpc " + | ||
"server.", | ||
rangeInt(1, Integer.MAX_VALUE), | ||
20 | ||
); | ||
javeme marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
public static final ConfigOption<Integer> RPC_CLIENT_READ_TIMEOUT = | ||
new ConfigOption<>( | ||
"rpc.client_read_timeout", | ||
"The timeout(in seconds) of rpc client read from rpc " + | ||
"server.", | ||
rangeInt(1, Integer.MAX_VALUE), | ||
40 | ||
); | ||
|
||
public static final ConfigOption<Integer> RPC_CLIENT_RETRIES = | ||
new ConfigOption<>( | ||
"rpc.client_retries", | ||
"Failed retry number of rpc client calls to rpc Server.", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Server => server -- to keep the same style with other options |
||
rangeInt(1, Integer.MAX_VALUE), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can the min value be 0? |
||
3 | ||
); | ||
|
||
public static final ConfigOption<String> RPC_CLIENT_LOAD_BALANCER = | ||
new ConfigOption<>( | ||
"rpc.client_load_balancer", | ||
"The rpc client uses a load-balancing algorithm to " + | ||
"access multiple rpc servers in one cluster. Default " + | ||
"value is 'consistentHash', means forwording by request " + | ||
"parameters.", | ||
allowValues("random", "localPref", "roundRobin", | ||
"consistentHash", "weightRoundRobin"), | ||
"consistentHash" | ||
); | ||
|
||
public static final ConfigOption<String> RPC_PROTOCOL = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we rename to RPC_SERVER_PROTOCOL? |
||
new ConfigOption<>( | ||
"rpc.protocol", | ||
"Rpc communication protocol, client and server need to " + | ||
"be specified at the same time, and can match.", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. client and server need to be specified the same value |
||
allowValues("bolt", "rest", "dubbo", "h2c", "http"), | ||
"bolt" | ||
); | ||
|
||
public static final ConfigOption<Integer> RPC_CONFIG_ORDER = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is the option required There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this option is not set, the sofa-rpc log may be lost. |
||
new ConfigOption<>( | ||
"rpc.config_order", | ||
"Sofa rpc configuration file loading order, the larger " + | ||
"the more later loading", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add "." |
||
rangeInt(1, Integer.MAX_VALUE), | ||
999 | ||
); | ||
|
||
public static final ConfigOption<String> RPC_LOGGER_IMPL = | ||
new ConfigOption<>( | ||
"rpc.logger_impl", | ||
"Sofa rpc log implementation class.", | ||
disallowEmpty(), | ||
"com.alipay.sofa.rpc.log.SLF4JLoggerImpl" | ||
); | ||
|
||
public static final ConfigOption<String> SSL_KEYSTORE_FILE = | ||
new ConfigOption<>( | ||
"ssl.keystore_file", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright 2017 HugeGraph Authors | ||
* | ||
* 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 com.baidu.hugegraph.rpc; | ||
|
||
import com.alipay.sofa.rpc.config.ConsumerConfig; | ||
import com.baidu.hugegraph.auth.UserManager; | ||
import com.baidu.hugegraph.config.HugeConfig; | ||
|
||
public class RpcClientProvider { | ||
|
||
public final RpcConsumerConfig rpcConsumerConfig; | ||
|
||
public RpcClientProvider(HugeConfig conf) { | ||
RpcCommonConfig.initRpcConfigs(conf); | ||
this.rpcConsumerConfig = new RpcConsumerConfig(); | ||
this.rpcConsumerConfig.addConsumerConfig(UserManager.class, conf); | ||
} | ||
|
||
public UserManager userManager() { | ||
return (UserManager) this.serviceProxy(UserManager.class.getName()); | ||
} | ||
|
||
public Object serviceProxy(String serviceName) { | ||
ConsumerConfig config = this.rpcConsumerConfig.consumerConfig(serviceName); | ||
return config.refer(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright 2017 HugeGraph Authors | ||
* | ||
* 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 com.baidu.hugegraph.rpc; | ||
|
||
import java.util.Map; | ||
|
||
import com.alipay.sofa.rpc.common.RpcConfigs; | ||
import com.baidu.hugegraph.config.HugeConfig; | ||
import com.baidu.hugegraph.config.ServerOptions; | ||
|
||
public class RpcCommonConfig { | ||
|
||
public static void initRpcConfigs(HugeConfig conf) { | ||
RpcConfigs.putValue("rpc.config.order", | ||
conf.get(ServerOptions.RPC_CONFIG_ORDER)); | ||
RpcConfigs.putValue("logger.impl", | ||
conf.get(ServerOptions.RPC_LOGGER_IMPL)); | ||
} | ||
|
||
public static void initRpcConfigs(String key, Object value) { | ||
RpcConfigs.putValue(key, value); | ||
} | ||
|
||
public static void initRpcConfigs(Map<String, Object> conf) { | ||
for(Map.Entry<String, Object> entry : conf.entrySet()) { | ||
RpcConfigs.putValue(entry.getKey(), entry.getValue()); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
switch -> switch