@Override public Authentication load(final String data) { YamlAuthentication result = new Yaml().loadAs(data, YamlAuthentication.class); Preconditions.checkState(!Strings.isNullOrEmpty(result.getUsername()), "Authority configuration is invalid."); return new Authentication(result.getUsername(), result.getPassword()); } }
/** * Login. * * @param username connection username * @param authResponse connection auth response * @return login success or failure */ public boolean login(final String username, final byte[] authResponse) { Authentication authentication = GLOBAL_REGISTRY.getAuthentication(); if (Strings.isNullOrEmpty(authentication.getPassword())) { return authentication.getUsername().equals(username); } return authentication.getUsername().equals(username) && Arrays.equals(getAuthCipherBytes(authentication.getPassword()), authResponse); }
/** * Login. * * @param username connection username * @param authResponse connection auth response * @return login success or failure */ public boolean login(final String username, final byte[] authResponse) { Authentication authentication = GLOBAL_REGISTRY.getAuthentication(); if (Strings.isNullOrEmpty(authentication.getPassword())) { return authentication.getUsername().equals(username); } return authentication.getUsername().equals(username) && Arrays.equals(getAuthCipherBytes(authentication.getPassword()), authResponse); }
private static void initShardingOrchestrationFacade( final YamlProxyServerConfiguration serverConfig, final Map<String, YamlProxyRuleConfiguration> ruleConfigs, final ShardingOrchestrationFacade shardingOrchestrationFacade) { if (ruleConfigs.isEmpty()) { shardingOrchestrationFacade.init(); } else { shardingOrchestrationFacade.init(getDataSourceConfigurationMap(ruleConfigs), getRuleConfiguration(ruleConfigs), new Authentication(serverConfig.getAuthentication().getUsername(), serverConfig.getAuthentication().getPassword()), serverConfig.getConfigMap(), serverConfig.getProps()); } }
@Override public String dump(final Authentication authentication) { YamlAuthentication yamlAuthentication = new YamlAuthentication(); yamlAuthentication.setUsername(authentication.getUsername()); yamlAuthentication.setPassword(authentication.getPassword()); return new Yaml(new DefaultYamlRepresenter()).dumpAsMap(yamlAuthentication); } }
private static void initShardingOrchestrationFacade( final YamlProxyServerConfiguration serverConfig, final Map<String, YamlProxyRuleConfiguration> ruleConfigs, final ShardingOrchestrationFacade shardingOrchestrationFacade) { if (ruleConfigs.isEmpty()) { shardingOrchestrationFacade.init(); } else { shardingOrchestrationFacade.init(getDataSourceConfigurationMap(ruleConfigs), getRuleConfiguration(ruleConfigs), new Authentication(serverConfig.getAuthentication().getUsername(), serverConfig.getAuthentication().getPassword()), serverConfig.getConfigMap(), serverConfig.getProps()); } }
/** * Main entrance. * * @param args startup arguments * @throws InterruptedException interrupted exception * @throws IOException IO exception */ public static void main(final String[] args) throws InterruptedException, IOException { ShardingConfiguration shardingConfig = new ShardingConfigurationLoader().load(); int port = getPort(args); new ProxyListenerRegister().register(); if (null == shardingConfig.getServerConfiguration().getOrchestration()) { startWithoutRegistryCenter(shardingConfig.getRuleConfigurationMap(), new Authentication(shardingConfig.getServerConfiguration().getAuthentication().getUsername(), shardingConfig.getServerConfiguration().getAuthentication().getPassword()), shardingConfig.getServerConfiguration().getConfigMap(), shardingConfig.getServerConfiguration().getProps(), port); } else { startWithRegistryCenter(shardingConfig.getServerConfiguration(), shardingConfig.getRuleConfigurationMap().keySet(), shardingConfig.getRuleConfigurationMap(), port); } }
/** * Main entrance. * * @param args startup arguments * @throws InterruptedException interrupted exception * @throws IOException IO exception */ public static void main(final String[] args) throws InterruptedException, IOException { ShardingConfiguration shardingConfig = new ShardingConfigurationLoader().load(); int port = getPort(args); new ProxyListenerRegister().register(); if (null == shardingConfig.getServerConfiguration().getOrchestration()) { startWithoutRegistryCenter(shardingConfig.getRuleConfigurationMap(), new Authentication(shardingConfig.getServerConfiguration().getAuthentication().getUsername(), shardingConfig.getServerConfiguration().getAuthentication().getPassword()), shardingConfig.getServerConfiguration().getConfigMap(), shardingConfig.getServerConfiguration().getProps(), port); } else { startWithRegistryCenter(shardingConfig.getServerConfiguration(), shardingConfig.getRuleConfigurationMap().keySet(), shardingConfig.getRuleConfigurationMap(), port); } }