Trick 5 years ago
parent
commit
06f20bdad3

+ 5 - 0
business/es-service/pom.xml

@ -71,6 +71,11 @@
            <groupId>org.elasticsearch</groupId>
            <artifactId>elasticsearch</artifactId>
        </dependency>
        <dependency>
            <groupId>org.elasticsearch.plugin</groupId>
            <artifactId>shield</artifactId>
            <version>2.4.6</version>
        </dependency>
        <!--   poi xml导入导出工具 end -->
    </dependencies>

+ 43 - 8
business/es-service/src/main/java/com/yihu/jw/es/es/ElasticFactory.java

@ -8,6 +8,7 @@ import org.elasticsearch.client.Client;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.shield.ShieldPlugin;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
@ -31,6 +32,8 @@ public class ElasticFactory {
    private String tHost;// 59.61.92.90:9066,59.61.92.90:9068
    @Value("${es.clusterName}")
    private String clusterName;
    @Value("${es.securityUser}")
    private String securityUser;
//-----------------------------------jestClient----------------------------------------
    /**
@ -85,21 +88,53 @@ public class ElasticFactory {
     *
     * @throws UnknownHostException
     */
    private synchronized void initTranClient() throws UnknownHostException {
        if (transportClient == null) {
            String[] hosts = tHost.split(",");
            Settings settings = Settings.settingsBuilder()
                    // .put("client.transport.sniff", true)//开启嗅探功能
                    .put("cluster.name", StringUtils.isEmpty(clusterName) ? "jkzl" : clusterName)//默认集群名字是jkzl
                    .build();
//    private synchronized void initTranClient() throws UnknownHostException {
//        if (transportClient == null) {
//            String[] hosts = tHost.split(",");
//            Settings settings = Settings.settingsBuilder()
//                    // .put("client.transport.sniff", true)//开启嗅探功能
//                    .put("cluster.name", StringUtils.isEmpty(clusterName) ? "jkzl" : clusterName)//默认集群名字是jkzl
//                    .build();
//
//            transportClient = TransportClient.builder().settings(settings).build();
//
//            for (String oneHost : hosts) {
//                String[] hostAndport = oneHost.split(":");
//                transportClient.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(hostAndport[0]), Integer.valueOf(hostAndport[1])));
//            }
//        }
//    }
            transportClient = TransportClient.builder().settings(settings).build();
    /**
     * 9300
     *
     * @throws UnknownHostException
     */
    private synchronized void initTranClient() throws Exception {
        if (transportClient == null) {
            String[] hosts = tHost.split(",");
            Settings settings = getSettings();
            transportClient = TransportClient.builder().addPlugin(ShieldPlugin.class).settings(settings).build();
            for (String oneHost : hosts) {
                String[] hostAndport = oneHost.split(":");
                transportClient.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(hostAndport[0]), Integer.valueOf(hostAndport[1])));
            }
        }
    }
    /**
     * 配置连接
     * @return
     * @throws Exception
     */
    private Settings getSettings() throws Exception {
        Settings.Builder settingBuilder = Settings.settingsBuilder();
        settingBuilder.put("cluster.name", clusterName);
        settingBuilder.put("shield.user", securityUser);
        settingBuilder.put("client.transport.sniff", false);
        settingBuilder.put("transport.address.list", tHost);
        return settingBuilder.build();
    }
}

+ 1 - 1
gateway/ag-basic/src/main/java/com/yihu/jw/gateway/filter/BasicZuulFilter.java

@ -212,7 +212,7 @@ public class BasicZuulFilter extends ZuulFilter {
                "declare | sitename |net user|xp_cmdshell|or |exec |execute |create |" +
                "table |from |grant |use |group_concat|column_name|" +
                "information_schema.columns|table_schema|union |where |select |update |order |by |like |" +
                "--|%|#";//过滤掉的sql关键字,可以手动添加
                "--|%";//过滤掉的sql关键字,可以手动添加
        String[] badStrs = badStr.split("\\|");
        for (int i = 0; i < badStrs.length; i++) {
            if (str.indexOf(badStrs[i]) >= 0) {

+ 2 - 2
svr/svr-internet-hospital/src/main/resources/application.yml

@ -200,8 +200,8 @@ es:
    Statistics: hlw_quota_test
  type:
    Statistics: hlw_quota_test
  host:  http://172.26.0.112:9200
  tHost: 172.26.0.112:9300
  host:  http://172.26.0.55:9200
  tHost: 172.26.0.55:9300
  clusterName: jkzl
  securityUser: elastic:changeme