当前位置: 首页>>代码示例>>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;未经允许,请勿转载。