org.elasticsearch.threadpool.ThreadPool.getThreadContext()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(11.8k)|赞(0)|评价(0)|浏览(219)

本文整理了Java中org.elasticsearch.threadpool.ThreadPool.getThreadContext()方法的一些代码示例,展示了ThreadPool.getThreadContext()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ThreadPool.getThreadContext()方法的具体详情如下:
包路径:org.elasticsearch.threadpool.ThreadPool
类名称:ThreadPool
方法名:getThreadContext

ThreadPool.getThreadContext介绍

暂无

代码示例

代码示例来源:origin: floragunncom/search-guard

  1. public SearchGuardFilter(final PrivilegesEvaluator evalp, final AdminDNs adminDns,
  2. DlsFlsRequestValve dlsFlsValve, AuditLog auditLog, ThreadPool threadPool, ClusterService cs,
  3. ComplianceConfig complianceConfig, final CompatConfig compatConfig) {
  4. this.evalp = evalp;
  5. this.adminDns = adminDns;
  6. this.dlsFlsValve = dlsFlsValve;
  7. this.auditLog = auditLog;
  8. this.threadContext = threadPool.getThreadContext();
  9. this.cs = cs;
  10. this.complianceConfig = complianceConfig;
  11. this.compatConfig = compatConfig;
  12. }

代码示例来源:origin: floragunncom/search-guard

  1. public SearchGuardNonSslHttpServerTransport(final Settings settings, final NetworkService networkService, final BigArrays bigArrays,
  2. final ThreadPool threadPool, final NamedXContentRegistry namedXContentRegistry, final Dispatcher dispatcher) {
  3. super(settings, networkService, bigArrays, threadPool, namedXContentRegistry, dispatcher);
  4. this.threadContext = threadPool.getThreadContext();
  5. }

代码示例来源:origin: floragunncom/search-guard

  1. public XFFResolver(final ThreadPool threadPool) {
  2. super();
  3. this.threadContext = threadPool.getThreadContext();
  4. }

代码示例来源:origin: floragunncom/search-guard

  1. public SearchGuardRestFilter(final BackendRegistry registry, final AuditLog auditLog,
  2. final ThreadPool threadPool, final PrincipalExtractor principalExtractor,
  3. final Settings settings, final Path configPath, final CompatConfig compatConfig) {
  4. super();
  5. this.registry = registry;
  6. this.auditLog = auditLog;
  7. this.threadContext = threadPool.getThreadContext();
  8. this.principalExtractor = principalExtractor;
  9. this.settings = settings;
  10. this.configPath = configPath;
  11. this.compatConfig = compatConfig;
  12. }

代码示例来源:origin: floragunncom/search-guard

  1. protected final ThreadContext getThreadContext() {
  2. return threadPool.getThreadContext();
  3. }
  4. }

代码示例来源:origin: floragunncom/search-guard

  1. private ThreadContext getThreadContext() {
  2. return threadPool.getThreadContext();
  3. }

代码示例来源:origin: floragunncom/search-guard

  1. public TenantInfoAction(final Settings settings, final RestController controller,
  2. final PrivilegesEvaluator evaluator, final ThreadPool threadPool, final ClusterService clusterService, final AdminDNs adminDns) {
  3. super(settings);
  4. this.threadContext = threadPool.getThreadContext();
  5. this.evaluator = evaluator;
  6. this.clusterService = clusterService;
  7. this.adminDns = adminDns;
  8. controller.registerHandler(GET, "/_searchguard/tenantinfo", this);
  9. controller.registerHandler(POST, "/_searchguard/tenantinfo", this);
  10. }

代码示例来源:origin: floragunncom/search-guard

  1. public SearchGuardInfoAction(final Settings settings, final RestController controller, final PrivilegesEvaluator evaluator, final ThreadPool threadPool) {
  2. super(settings);
  3. this.threadContext = threadPool.getThreadContext();
  4. this.evaluator = evaluator;
  5. controller.registerHandler(GET, "/_searchguard/authinfo", this);
  6. controller.registerHandler(POST, "/_searchguard/authinfo", this);
  7. }

代码示例来源:origin: floragunncom/search-guard

  1. public KibanaInfoAction(final Settings settings, final RestController controller, final PrivilegesEvaluator evaluator, final ThreadPool threadPool) {
  2. super(settings);
  3. this.threadContext = threadPool.getThreadContext();
  4. this.evaluator = evaluator;
  5. controller.registerHandler(GET, "/_searchguard/kibanainfo", this);
  6. controller.registerHandler(POST, "/_searchguard/kibanainfo", this);
  7. }

代码示例来源:origin: floragunncom/search-guard

  1. @Override
  2. protected void doExecute(WhoAmIRequest request, ActionListener<WhoAmIResponse> listener) {
  3. final User user = threadPool.getThreadContext().getTransient(ConfigConstants.SG_USER);
  4. final String dn = user==null?threadPool.getThreadContext().getTransient(ConfigConstants.SG_SSL_TRANSPORT_PRINCIPAL):user.getName();
  5. final boolean isAdmin = adminDNs.isAdminDN(dn);
  6. final boolean isAuthenticated = isAdmin?true: user != null;
  7. final boolean isNodeCertificateRequest = HeaderHelper.isInterClusterRequest(threadPool.getThreadContext()) ||
  8. HeaderHelper.isTrustedClusterRequest(threadPool.getThreadContext());
  9. listener.onResponse(new WhoAmIResponse(dn, isAdmin, isAuthenticated, isNodeCertificateRequest));
  10. }
  11. }

代码示例来源:origin: floragunncom/search-guard

  1. public SearchGuardIndexSearcherWrapper(final IndexService indexService, final Settings settings, final AdminDNs adminDNs) {
  2. index = indexService.index();
  3. threadContext = indexService.getThreadPool().getThreadContext();
  4. this.searchguardIndex = settings.get(ConfigConstants.SEARCHGUARD_CONFIG_INDEX_NAME, ConfigConstants.SG_DEFAULT_CONFIG_INDEX);
  5. this.adminDns = adminDNs;
  6. }

代码示例来源:origin: floragunncom/search-guard

  1. .deserializeSafeFromHeader(threadPool.getThreadContext(), ConfigConstants.SG_FLS_FIELDS_HEADER);

代码示例来源:origin: floragunncom/search-guard

  1. String injectedUserString = threadPool.getThreadContext().getTransient(ConfigConstants.SG_INJECTED_USER);
  2. InetAddress iAdress = InetAddress.getByName(ipAndPort[0]);
  3. int port = Integer.parseInt(ipAndPort[1]);
  4. threadPool.getThreadContext().putTransient(ConfigConstants.SG_REMOTE_ADDRESS, new TransportAddress(iAdress, port));
  5. } catch (UnknownHostException | NumberFormatException e) {
  6. log.error("Cannot parse remote IP or port: {}, user injection failed.", parts[2], e);
  7. threadPool.getThreadContext().putTransient(ConfigConstants.SG_REMOTE_ADDRESS, xffResolver.resolve(request));
  8. threadPool.getThreadContext().putTransient(ConfigConstants.SG_USER, user);
  9. auditLog.logSucceededLogin(parts[0], true, null, request);
  10. if (log.isTraceEnabled()) {

代码示例来源:origin: floragunncom/search-guard

  1. @Override
  2. public Map<String, Supplier<HttpServerTransport>> getHttpTransports(Settings settings, ThreadPool threadPool, BigArrays bigArrays,
  3. CircuitBreakerService circuitBreakerService, NamedWriteableRegistry namedWriteableRegistry,
  4. NamedXContentRegistry xContentRegistry, NetworkService networkService, Dispatcher dispatcher) {
  5. if(sslOnly) {
  6. return super.getHttpTransports(settings, threadPool, bigArrays, circuitBreakerService, namedWriteableRegistry, xContentRegistry, networkService, dispatcher);
  7. }
  8. Map<String, Supplier<HttpServerTransport>> httpTransports = new HashMap<String, Supplier<HttpServerTransport>>(1);
  9. if(!disabled) {
  10. if (!client && httpSSLEnabled && !tribeNodeClient) {
  11. final ValidatingDispatcher validatingDispatcher = new ValidatingDispatcher(threadPool.getThreadContext(), dispatcher,
  12. settings, configPath, evaluateSslExceptionHandler());
  13. //TODO close sghst
  14. final SearchGuardHttpServerTransport sghst = new SearchGuardHttpServerTransport(settings, networkService, bigArrays,
  15. threadPool, sgks, evaluateSslExceptionHandler(), xContentRegistry, validatingDispatcher);
  16. httpTransports.put("com.floragunn.searchguard.http.SearchGuardHttpServerTransport",
  17. () -> sghst);
  18. } else if (!client && !tribeNodeClient) {
  19. httpTransports.put("com.floragunn.searchguard.http.SearchGuardHttpServerTransport",
  20. () -> new SearchGuardNonSslHttpServerTransport(settings, networkService, bigArrays, threadPool, xContentRegistry, dispatcher));
  21. }
  22. }
  23. return httpTransports;
  24. }

代码示例来源:origin: floragunncom/search-guard

  1. public Map<String, Tuple<Long, Settings>> loadConfigurations(Collection<String> configTypes, boolean logComplianceEvent) {
  2. final ThreadContext threadContext = threadPool.getThreadContext();
  3. final Map<String, Tuple<Long, Settings>> retVal = new HashMap<String, Tuple<Long, Settings>>();

代码示例来源:origin: floragunncom/search-guard

  1. public PrivilegesEvaluatorResponse evaluate(final ClusterService clusterService, final IndexNameExpressionResolver resolver, final Resolved requestedResolved, final User user,
  2. final SgRoles sgRoles, final PrivilegesEvaluatorResponse presponse) {
  3. ThreadContext threadContext = threadPool.getThreadContext();

代码示例来源:origin: floragunncom/search-guard

  1. public PrivilegesEvaluator(final ClusterService clusterService, final ThreadPool threadPool, final ConfigurationRepository configurationRepository, final ActionGroupHolder ah,
  2. final IndexNameExpressionResolver resolver, AuditLog auditLog, final Settings settings, final PrivilegesInterceptor privilegesInterceptor,
  3. final ClusterInfoHolder clusterInfoHolder) {
  4. super();
  5. this.configurationRepository = configurationRepository;
  6. this.clusterService = clusterService;
  7. this.resolver = resolver;
  8. this.auditLog = auditLog;
  9. this.threadContext = threadPool.getThreadContext();
  10. this.privilegesInterceptor = privilegesInterceptor;
  11. try {
  12. rolesMappingResolution = ConfigConstants.RolesMappingResolution.valueOf(settings.get(ConfigConstants.SEARCHGUARD_ROLES_MAPPING_RESOLUTION, ConfigConstants.RolesMappingResolution.MAPPING_ONLY.toString()).toUpperCase());
  13. } catch (Exception e) {
  14. log.error("Cannot apply roles mapping resolution",e);
  15. rolesMappingResolution = ConfigConstants.RolesMappingResolution.MAPPING_ONLY;
  16. }
  17. this.checkSnapshotRestoreWritePrivileges = settings.getAsBoolean(ConfigConstants.SEARCHGUARD_CHECK_SNAPSHOT_RESTORE_WRITE_PRIVILEGES,
  18. ConfigConstants.SG_DEFAULT_CHECK_SNAPSHOT_RESTORE_WRITE_PRIVILEGES);
  19. this.clusterInfoHolder = clusterInfoHolder;
  20. //this.typeSecurityDisabled = settings.getAsBoolean(ConfigConstants.SEARCHGUARD_DISABLE_TYPE_SECURITY, false);
  21. configModel = new ConfigModel(ah, configurationRepository);
  22. irr = new IndexResolverReplacer(resolver, clusterService, clusterInfoHolder);
  23. snapshotRestoreEvaluator = new SnapshotRestoreEvaluator(settings, auditLog);
  24. sgIndexAccessEvaluator = new SearchGuardIndexAccessEvaluator(settings, auditLog);
  25. dlsFlsEvaluator = new DlsFlsEvaluator(settings, threadPool);
  26. termsAggregationEvaluator = new TermsAggregationEvaluator();
  27. }

代码示例来源:origin: floragunncom/search-guard

  1. private SearchGuardLicense createOrGetTrial(String msg) {
  2. long created = System.currentTimeMillis();
  3. ThreadContext threadContext = threadPool.getThreadContext();
  4. try(StoredContext ctx = threadContext.stashContext()) {
  5. threadContext.putHeader(ConfigConstants.SG_CONF_REQUEST_HEADER, "true");
  6. GetResponse get = client.prepareGet(searchguardIndex, "sg", "tattr").get();
  7. if(get.isExists()) {
  8. created = (long) get.getSource().get("val");
  9. } else {
  10. try {
  11. client.index(new IndexRequest(searchguardIndex)
  12. .type("sg")
  13. .id("tattr")
  14. .setRefreshPolicy(RefreshPolicy.IMMEDIATE)
  15. .create(true)
  16. .source("{\"val\": "+System.currentTimeMillis()+"}", XContentType.JSON)).actionGet();
  17. } catch (VersionConflictEngineException e) {
  18. //ignore
  19. } catch (Exception e) {
  20. LOGGER.error("Unable to index tattr", e);
  21. }
  22. }
  23. }
  24. return SearchGuardLicense.createTrialLicense(formatDate(created), clusterService, msg);
  25. }
  26. }

代码示例来源:origin: floragunncom/search-guard

  1. private User impersonate(final TransportRequest tr, final User origPKIuser) throws ElasticsearchSecurityException {
  2. final String impersonatedUser = threadPool.getThreadContext().getHeader("sg_impersonate_as");
  3. if(Strings.isNullOrEmpty(impersonatedUser)) {
  4. return null; //nothing to do
  5. }
  6. if (!isInitialized()) {
  7. throw new ElasticsearchSecurityException("Could not check for impersonation because Search Guard is not yet initialized");
  8. }
  9. if (origPKIuser == null) {
  10. throw new ElasticsearchSecurityException("no original PKI user found");
  11. }
  12. User aU = origPKIuser;
  13. if (adminDns.isAdminDN(impersonatedUser)) {
  14. throw new ElasticsearchSecurityException("'"+origPKIuser.getName() + "' is not allowed to impersonate as an adminuser '" + impersonatedUser+"'");
  15. }
  16. try {
  17. if (impersonatedUser != null && !adminDns.isTransportImpersonationAllowed(new LdapName(origPKIuser.getName()), impersonatedUser)) {
  18. throw new ElasticsearchSecurityException("'"+origPKIuser.getName() + "' is not allowed to impersonate as '" + impersonatedUser+"'");
  19. } else if (impersonatedUser != null) {
  20. aU = new User(impersonatedUser);
  21. if(log.isDebugEnabled()) {
  22. log.debug("Impersonate from '{}' to '{}'",origPKIuser.getName(), impersonatedUser);
  23. }
  24. }
  25. } catch (final InvalidNameException e1) {
  26. throw new ElasticsearchSecurityException("PKI does not have a valid name ('" + origPKIuser.getName() + "'), should never happen",
  27. e1);
  28. }
  29. return aU;
  30. }

代码示例来源:origin: floragunncom/search-guard

  1. final String authorizationHeader = threadPool.getThreadContext().getHeader("Authorization");

相关文章