當前位置: 首頁>>代碼示例>>Java>>正文


Java InterceptorRegistry類代碼示例

本文整理匯總了Java中org.springframework.web.servlet.config.annotation.InterceptorRegistry的典型用法代碼示例。如果您正苦於以下問題:Java InterceptorRegistry類的具體用法?Java InterceptorRegistry怎麽用?Java InterceptorRegistry使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


InterceptorRegistry類屬於org.springframework.web.servlet.config.annotation包,在下文中一共展示了InterceptorRegistry類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: addInterceptors

import org.springframework.web.servlet.config.annotation.InterceptorRegistry; //導入依賴的package包/類
/**
 * 添加令牌處理攔截器,檢查請求頭是否帶有效的令牌。
 */
@Override
public void addInterceptors(InterceptorRegistry registry) {
    InterceptorRegistration interceptor = registry.addInterceptor(tokenInterceptor);

    String pathPatterns = devcloudProperties.getPathPatterns();
    log.info("Interceptor path patterns: " + pathPatterns);

    if (pathPatterns == null || pathPatterns.isEmpty()) {
        return;
    }

    String[] paths = pathPatterns.split(",");
    if (paths == null || paths.length == 0) {
        return;
    }

    for (String path : paths) {
        interceptor.addPathPatterns(path);
    }
}
 
開發者ID:kenly333,項目名稱:service-hive,代碼行數:24,代碼來源:DevCloudWebMvcConfigurer.java

示例2: addInterceptors

import org.springframework.web.servlet.config.annotation.InterceptorRegistry; //導入依賴的package包/類
@Override
public void addInterceptors(InterceptorRegistry registry) {
    //接口簽名認證攔截器,該簽名認證比較簡單,實際項目中可以使用Json Web Token或其他更好的方式替代。
    if (!"dev".equals(env)) { //開發環境忽略簽名認證
        registry.addInterceptor(new HandlerInterceptorAdapter() {
            @Override
            public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
                //驗證簽名
                boolean pass = validateSign(request);
                if (pass) {
                    return true;
                } else {
                    logger.warn("簽名認證失敗,請求接口:{},請求IP:{},請求參數:{}",
                            request.getRequestURI(), getIpAddress(request), JSON.toJSONString(request.getParameterMap()));

                    Result result = new Result();
                    result.setCode(ResultCode.UNAUTHORIZED).setMessage("簽名認證失敗");
                    responseResult(response, result);
                    return false;
                }
            }
        });
    }
}
 
開發者ID:jeikerxiao,項目名稱:SpringBootStudy,代碼行數:25,代碼來源:WebMvcConfig.java

示例3: baseConfigurerBean

import org.springframework.web.servlet.config.annotation.InterceptorRegistry; //導入依賴的package包/類
@Bean
	public WebMvcConfigurerAdapter baseConfigurerBean(@Named final ScooldRequestInterceptor sri) {
		return new WebMvcConfigurerAdapter() {
			@Override
			public void addInterceptors(InterceptorRegistry registry) {
				super.addInterceptors(registry);
				registry.addInterceptor(sri);
			}

//			@Override
//			public void addResourceHandlers(ResourceHandlerRegistry registry) {
//				registry.addResourceHandler("/images/**").addResourceLocations("/static/images/")
//					.setCacheControl(CacheControl.maxAge(1, TimeUnit.HOURS).cachePublic());
//				registry.addResourceHandler("/styles/**").addResourceLocations("/static/styles/")
//					.setCacheControl(CacheControl.maxAge(1, TimeUnit.HOURS).cachePublic());
//				registry.addResourceHandler("/scripts/**").addResourceLocations("/static/scripts/")
//					.setCacheControl(CacheControl.maxAge(1, TimeUnit.HOURS).cachePublic());
//			}
		};
	}
 
開發者ID:Erudika,項目名稱:scoold,代碼行數:21,代碼來源:ScooldServer.java

示例4: addInterceptors

import org.springframework.web.servlet.config.annotation.InterceptorRegistry; //導入依賴的package包/類
@Override
public void addInterceptors(InterceptorRegistry registry) {
	String[] swaggerPaths = {"/swagger-resources/**", "/v2/api-docs"};
	if(!disableCors){
		registry.addInterceptor(new CorsHeaderInterceptor());
	}
	if(parseAuthorizationHeader && !jwtValue) {
		if(enableSwagger2) {
			registry.addInterceptor(authorizationHeaderInterceptor()).excludePathPatterns(swaggerPaths);
		}else{
			registry.addInterceptor(authorizationHeaderInterceptor());
		}
	}
	if(jwtValue) {
		if(enableSwagger2){
			registry.addInterceptor(jwtTokenInterceptor()).excludePathPatterns(swaggerPaths);
		}else{
			registry.addInterceptor(jwtTokenInterceptor());
		}
	}
	super.addInterceptors(registry);
}
 
開發者ID:profullstack,項目名稱:spring-seed,代碼行數:23,代碼來源:SpringSeedRestApiMvcConfigration.java

示例5: registerTenantInterceptorWithIgnorePathPattern

import org.springframework.web.servlet.config.annotation.InterceptorRegistry; //導入依賴的package包/類
/**
 * Registered interceptor to all request except passed urls.
 * @param registry helps with configuring a list of mapped interceptors.
 * @param interceptor the interceptor
 */
protected void registerTenantInterceptorWithIgnorePathPattern(
                InterceptorRegistry registry, HandlerInterceptor interceptor) {
    InterceptorRegistration tenantInterceptorRegistration = registry.addInterceptor(interceptor);
    tenantInterceptorRegistration.addPathPatterns("/**");

    List<String> tenantIgnorePathPatterns = getTenantIgnorePathPatterns();
    Objects.requireNonNull(tenantIgnorePathPatterns, "tenantIgnorePathPatterns can't be null");

    for (String pattern : tenantIgnorePathPatterns) {
        tenantInterceptorRegistration.excludePathPatterns(pattern);
    }

    LOGGER.info("Added handler interceptor '{}' to all urls, exclude {}", interceptor.getClass()
                    .getSimpleName(), tenantIgnorePathPatterns);
}
 
開發者ID:xm-online,項目名稱:xm-commons,代碼行數:21,代碼來源:XmWebMvcConfigurerAdapter.java

示例6: addInterceptors

import org.springframework.web.servlet.config.annotation.InterceptorRegistry; //導入依賴的package包/類
/**
 * 攔截器鏈
 * @param registry
 */
@Override
public void addInterceptors(InterceptorRegistry registry) {
    // 多個攔截器組成一個攔截器鏈
    // addPathPatterns 用於添加攔截規則
    // excludePathPatterns 用戶排除攔截
    registry.addInterceptor(new MallInterceptor())
            .addPathPatterns("/manage/**", "/app/**")
            // 不攔截登錄接口
            .excludePathPatterns("/app/user/login");
    //registry.addInterceptor(new MyInterceptor2()).addPathPatterns("/**");
    super.addInterceptors(registry);
}
 
開發者ID:jeikerxiao,項目名稱:X-mall,代碼行數:17,代碼來源:MallWebAppConfigurer.java

示例7: addInterceptors

import org.springframework.web.servlet.config.annotation.InterceptorRegistry; //導入依賴的package包/類
@Override
    public void addInterceptors(InterceptorRegistry registry) {
        if(twoFaEnabeld){
            log.info("2FA is ENABLED");
//            registry.addInterceptor( verifyInterceptorBean() )
//                .excludePathPatterns("/static/**", "/webjars/**", "/verify");
        }else{
            log.info("2FA is DISABLED");
        }
     
    }
 
開發者ID:peterjurkovic,項目名稱:travel-agency,代碼行數:12,代碼來源:WebConfiguration.java

示例8: addInterceptors

import org.springframework.web.servlet.config.annotation.InterceptorRegistry; //導入依賴的package包/類
/**
 * Adds http request interceptor copying headers from the request to the context
 *
 * @param registry the interceptor registry
 */
@Override
public void addInterceptors(InterceptorRegistry registry) {
    registry.addInterceptor(new PreservesHttpHeadersInterceptor(properties.buildEntriesFilter())).addPathPatterns(
            "/**");
    log.info("Context propagation enabled for http request on keys={}.", properties.getKeys());
}
 
開發者ID:enadim,項目名稱:spring-cloud-ribbon-extensions,代碼行數:12,代碼來源:PreservesHeadersInboundHttpRequestStrategy.java

示例9: addInterceptors

import org.springframework.web.servlet.config.annotation.InterceptorRegistry; //導入依賴的package包/類
/**
 * {@inheritDoc}
 */
@Override
public final void addInterceptors(InterceptorRegistry registry) {
    registerTenantInterceptorWithIgnorePathPattern(registry, tenantInterceptor);
    registerXmLoggingInterceptor(registry);

    xmAddInterceptors(registry);
}
 
開發者ID:xm-online,項目名稱:xm-commons,代碼行數:11,代碼來源:XmWebMvcConfigurerAdapter.java

示例10: addInterceptors

import org.springframework.web.servlet.config.annotation.InterceptorRegistry; //導入依賴的package包/類
/**
 * 攔截器
 *
 * @param registry
 */
@Override
public void addInterceptors(InterceptorRegistry registry) {
    // addPathPatterns 用於添加攔截規則
    // excludePathPatterns 用戶排除攔截
    registry.addInterceptor(new MyInterceptor()).addPathPatterns("/learn/**").excludePathPatterns("login/**");
    super.addInterceptors(registry);
}
 
開發者ID:leon66666,項目名稱:spring-boot-frameset,代碼行數:13,代碼來源:MyWebMvcConfigurerAdapter.java

示例11: setUp

import org.springframework.web.servlet.config.annotation.InterceptorRegistry; //導入依賴的package包/類
@Before
public void setUp() {
  sut = new ApplicationConfig();
  server = mock(Server.class);
  registry = mock(InterceptorRegistry.class);
  when(server.getThreadPool()).thenReturn(new ThreadPool() {
    @Override
    public void join() throws InterruptedException {
      // Do nothing. This is just a unit test.
    }

    @Override
    public int getThreads() {
      return 0;
    }

    @Override
    public int getIdleThreads() {
      return 0;
    }

    @Override
    public boolean isLowOnThreads() {
      return false;
    }

    @Override
    public void execute(Runnable command) {
      // Do nothing. This is just a unit test.
    }
  });
}
 
開發者ID:janweinschenker,項目名稱:servlet4-demo,代碼行數:33,代碼來源:ApplicationConfigTest.java

示例12: addInterceptors

import org.springframework.web.servlet.config.annotation.InterceptorRegistry; //導入依賴的package包/類
@Override
public void addInterceptors(InterceptorRegistry registry) {
    // 多個攔截器組成一個攔截器鏈
    // addPathPatterns 用於添加攔截規則
    // excludePathPatterns 用戶排除攔截
    registry.addInterceptor(new UserInterceptorHandler()).addPathPatterns("/**").excludePathPatterns("/login.html").excludePathPatterns("/im/**");
    super.addInterceptors(registry);
}
 
開發者ID:uckefu,項目名稱:uckefu,代碼行數:9,代碼來源:UKWebAppConfigurer.java

示例13: addInterceptors

import org.springframework.web.servlet.config.annotation.InterceptorRegistry; //導入依賴的package包/類
@Override
public void addInterceptors(final InterceptorRegistry registry) {

    for (final EntityManagerFactory entityManagerFactory : entityManagerFactories) {
        final OpenEntityManagerInViewInterceptor openEntityManagerInViewInterceptor = new OpenEntityManagerInViewInterceptor();
        openEntityManagerInViewInterceptor.setEntityManagerFactory(entityManagerFactory);
        registry.addWebRequestInterceptor(openEntityManagerInViewInterceptor);
    }

    super.addInterceptors(registry);
}
 
開發者ID:MinBZK,項目名稱:OperatieBRP,代碼行數:12,代碼來源:WebConfiguratie.java

示例14: adapter

import org.springframework.web.servlet.config.annotation.InterceptorRegistry; //導入依賴的package包/類
@Bean
public WebMvcConfigurerAdapter adapter() {
    return new WebMvcConfigurerAdapter() {
        @Override
        public void addInterceptors(InterceptorRegistry registry) {
            registry.addInterceptor(new LogExecutionInterceptor());
        }
    };
}
 
開發者ID:JUGIstanbul,項目名稱:second-opinion-api,代碼行數:10,代碼來源:SecondOpinionConfiguration.java

示例15: addInterceptors

import org.springframework.web.servlet.config.annotation.InterceptorRegistry; //導入依賴的package包/類
@Override
public void addInterceptors(InterceptorRegistry registry) {
    registry.addInterceptor(loggingInterceptor)
        .addPathPatterns("/**");
    if (enabledAuth) {
        registry.addInterceptor(authInterceptor)
            .addPathPatterns("/api/**")
            .excludePathPatterns("/api/login");

    }
}
 
開發者ID:shout-star,項目名稱:uroborosql-springboot-demo,代碼行數:12,代碼來源:MvcConfig.java


注:本文中的org.springframework.web.servlet.config.annotation.InterceptorRegistry類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。