当前位置: 首页>>代码示例>>Java>>正文


Java HandlerInterceptorAdapter类代码示例

本文整理汇总了Java中org.springframework.web.servlet.handler.HandlerInterceptorAdapter的典型用法代码示例。如果您正苦于以下问题:Java HandlerInterceptorAdapter类的具体用法?Java HandlerInterceptorAdapter怎么用?Java HandlerInterceptorAdapter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


HandlerInterceptorAdapter类属于org.springframework.web.servlet.handler包,在下文中一共展示了HandlerInterceptorAdapter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: restAuthenticationThrottle

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; //导入依赖的package包/类
@ConditionalOnMissingBean(name = "restAuthenticationThrottle")
@Bean
public HandlerInterceptor restAuthenticationThrottle() {
    final String throttler = casProperties.getRest().getThrottler();
    if (StringUtils.isNotBlank(throttler) && this.applicationContext.containsBean(throttler)) {
        return this.applicationContext.getBean(throttler, HandlerInterceptor.class);
    }
    return new HandlerInterceptorAdapter() {
        @Override
        public boolean preHandle(final HttpServletRequest request,
                                 final HttpServletResponse response,
                                 final Object handler) {
            return true;
        }
    };
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:17,代码来源:CasRestConfiguration.java

示例2: addInterceptors

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; //导入依赖的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: webMvcConfigurer

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; //导入依赖的package包/类
@Bean
public WebMvcConfigurer webMvcConfigurer(List<HandlerMethodArgumentResolver> handlerMethodArgumentResolvers) {
    return new WebMvcConfigurerAdapter() {
        @Override
        public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
            super.addArgumentResolvers(argumentResolvers);
            argumentResolvers.addAll(handlerMethodArgumentResolvers);
        }

        @Override
        public void addInterceptors(InterceptorRegistry registry) {
            registry.addInterceptor(new HandlerInterceptorAdapter() {
                @Override
                public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
                    //clear thread local
                    ThreadLocalUtils.clear();
                }
            });
        }
    };
}
 
开发者ID:hs-web,项目名称:hsweb-framework,代码行数:22,代码来源:HswebAutoConfiguration.java

示例4: mappedInterceptors

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; //导入依赖的package包/类
@Test
public void mappedInterceptors() throws Exception {
	String path = "/foo";
	HandlerInterceptor interceptor = new HandlerInterceptorAdapter() {};
	MappedInterceptor mappedInterceptor = new MappedInterceptor(new String[] {path}, interceptor);

	TestRequestMappingInfoHandlerMapping hm = new TestRequestMappingInfoHandlerMapping();
	hm.registerHandler(new TestController());
	hm.setInterceptors(new Object[] { mappedInterceptor });
	hm.setApplicationContext(new StaticWebApplicationContext());

	HandlerExecutionChain chain = hm.getHandler(new MockHttpServletRequest("GET", path));
	assertNotNull(chain);
	assertNotNull(chain.getInterceptors());
	assertSame(interceptor, chain.getInterceptors()[0]);

	chain = hm.getHandler(new MockHttpServletRequest("GET", "/invalid"));
	assertNull(chain);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:RequestMappingInfoHandlerMappingTests.java

示例5: configure

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; //导入依赖的package包/类
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
    endpoints
        .tokenStore(tokenStore)
        .accessTokenConverter(accessTokenConverter())
        .reuseRefreshTokens(false)
        .userDetailsService(userDetailsService)
        .authorizationCodeServices(authorizationCodeServices)
        .requestFactory(new CustomOAuth2RequestFactory(clientDetailsService))
        .userApprovalHandler(userApprovalHandler)
        .authenticationManager(authenticationManager)
        .tokenGranter(tokenGranter(endpoints))
            .addInterceptor(new HandlerInterceptorAdapter() {
                @Override
                public boolean preHandle(HttpServletRequest hsr, HttpServletResponse rs, Object o) throws Exception {
                    rs.setHeader("Access-Control-Allow-Origin", hsr.getHeader("origin"));
                    rs.setHeader("Access-Control-Allow-Methods", "GET,POST,OPTIONS");
                    rs.setHeader("Access-Control-Max-Age", "3600");
                    rs.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization");
                    return true;
                }
            });
}
 
开发者ID:gravitee-io,项目名称:graviteeio-access-management,代码行数:24,代码来源:AuthorizationServerConfiguration.java

示例6: getCSPInterceptor

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; //导入依赖的package包/类
private HandlerInterceptor getCSPInterceptor() {
    return new HandlerInterceptorAdapter() {
        @Override
        public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
                ModelAndView modelAndView) throws Exception {
            // http://www.html5rocks.com/en/tutorials/security/content-security-policy/
            // lockdown policy
            response.addHeader("Content-Security-Policy", "default-src 'none'; "//block all by default
                    + " script-src 'self' https://js.stripe.com/ https://api.stripe.com/ https://ssl.google-analytics.com/ https://www.google.com/recaptcha/api.js https://www.gstatic.com/recaptcha/api2/ https://maps.googleapis.com/;"//
                    + " style-src 'self' 'unsafe-inline';" // unsafe-inline for style is acceptable...
                    + " img-src 'self' https: data:;"//
                    + " child-src 'self';"//webworker
                    + " frame-src 'self' https://js.stripe.com https://www.google.com;"
                    + " font-src 'self';"//
                    + " media-src blob: 'self';"//for loading camera api
                    + " connect-src 'self' https://api.stripe.com https://maps.googleapis.com/ https://geocoder.cit.api.here.com;" //<- currently stripe.js use jsonp but if they switch to xmlhttprequest+cors we will be ready
                    + (environment.acceptsProfiles(Initializer.PROFILE_DEBUG_CSP) ? " report-uri /report-csp-violation" : ""));
        }
    };
}
 
开发者ID:alfio-event,项目名称:alf.io,代码行数:21,代码来源:MvcConfiguration.java

示例7: addInterceptors

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; //导入依赖的package包/类
@Override
public void addInterceptors(InterceptorRegistry registry) {
	registry.addInterceptor(new HandlerInterceptorAdapter() {
		@Override
		public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
				ModelAndView modelAndView) throws Exception {

			if (handler instanceof HandlerMethod) {
				HandlerMethod handlerMethod = (HandlerMethod) handler;
				Navigation navSection = handlerMethod.getBean().getClass().getAnnotation(Navigation.class);
				if (navSection != null && modelAndView != null) {
					modelAndView.addObject("navSection", navSection.value().toString().toLowerCase());
				}
			}
		}
	});
}
 
开发者ID:spring-io,项目名称:sagan,代码行数:18,代码来源:MvcConfig.java

示例8: OidcHandlerInterceptorAdapter

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; //导入依赖的package包/类
public OidcHandlerInterceptorAdapter(final HandlerInterceptorAdapter requiresAuthenticationAccessTokenInterceptor,
                                     final HandlerInterceptorAdapter requiresAuthenticationAuthorizeInterceptor,
                                     final HandlerInterceptorAdapter requiresAuthenticationDynamicRegistrationInterceptor,
                                     final OidcConstants.DynamicClientRegistrationMode dynamicClientRegistrationMode) {
    super(requiresAuthenticationAccessTokenInterceptor, requiresAuthenticationAuthorizeInterceptor);
    this.requiresAuthenticationDynamicRegistrationInterceptor = requiresAuthenticationDynamicRegistrationInterceptor;
    this.dynamicClientRegistrationMode = dynamicClientRegistrationMode;
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:9,代码来源:OidcHandlerInterceptorAdapter.java

示例9: requiresAuthenticationDynamicRegistrationInterceptor

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; //导入依赖的package包/类
@Bean
public HandlerInterceptorAdapter requiresAuthenticationDynamicRegistrationInterceptor() {
    final String clients = Stream.of(
            Authenticators.CAS_OAUTH_CLIENT_BASIC_AUTHN,
            Authenticators.CAS_OAUTH_CLIENT_DIRECT_FORM,
            Authenticators.CAS_OAUTH_CLIENT_USER_FORM).collect(Collectors.joining(","));
    return new SecurityInterceptor(oauthSecConfig, clients);
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:9,代码来源:OidcConfiguration.java

示例10: oauthInterceptor

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; //导入依赖的package包/类
@Bean
public HandlerInterceptorAdapter oauthInterceptor() {
    final OidcProperties oidc = casProperties.getAuthn().getOidc();
    final OidcConstants.DynamicClientRegistrationMode mode =
            OidcConstants.DynamicClientRegistrationMode.valueOf(StringUtils.defaultIfBlank(
                    oidc.getDynamicClientRegistrationMode(),
                    OidcConstants.DynamicClientRegistrationMode.PROTECTED.name()));

    return new OidcHandlerInterceptorAdapter(requiresAuthenticationAccessTokenInterceptor,
            requiresAuthenticationAuthorizeInterceptor(),
            requiresAuthenticationDynamicRegistrationInterceptor(),
            mode);
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:14,代码来源:OidcConfiguration.java

示例11: addInterceptors

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; //导入依赖的package包/类
@Override
public void addInterceptors(InterceptorRegistry registry) {
	registry.addInterceptor(new HandlerInterceptorAdapter() {
		@Override
		public void postHandle(HttpServletRequest request,
				HttpServletResponse response, Object handler,
				ModelAndView modelAndView) throws Exception {
			HelloWorldController.this.setStatus(response.getStatus());
			HelloWorldController.this.latch.countDown();
		}
	});
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:13,代码来源:ErrorPageFilterIntegrationTests.java

示例12: addInterceptors

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; //导入依赖的package包/类
@Override
public void addInterceptors(InterceptorRegistry registry) {
	registry.addInterceptor(

			new HandlerInterceptorAdapter() {
				@Override
				public boolean preHandle(HttpServletRequest request,
										 HttpServletResponse response, Object handler) throws Exception {
					accessTokenContextRelay.copyToken();
					return true;
				}
			}

	);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-security,代码行数:16,代码来源:ResourceServerTokenRelayAutoConfiguration.java

示例13: getDefaultTemplateObjectsFiller

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; //导入依赖的package包/类
@Bean
public HandlerInterceptorAdapter getDefaultTemplateObjectsFiller() {
    return new HandlerInterceptorAdapter() {
        @Override
        public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
            Optional.ofNullable(modelAndView)
                .filter(mv -> !StringUtils.startsWith(mv.getViewName(), "redirect:"))
                .ifPresent(mv -> {
                    mv.addObject("request", request);
                    final ModelMap modelMap = mv.getModelMap();

                    boolean demoModeEnabled = environment.acceptsProfiles(Initializer.PROFILE_DEMO);

                    modelMap.put("demoModeEnabled", demoModeEnabled);

                    Optional.ofNullable(request.getAttribute("ALFIO_EVENT_NAME")).map(Object::toString).ifPresent(eventName -> {

                        List<?> availableLanguages = i18nManager.getEventLanguages(eventName);

                        modelMap.put("showAvailableLanguagesInPageTop", availableLanguages.size() > 1);
                        modelMap.put("availableLanguages", availableLanguages);
                    });

                    modelMap.putIfAbsent("event", null);
                    modelMap.putIfAbsent("pageTitle", "empty");
                    Event event = modelMap.get("event") == null ? null : modelMap.get("event") instanceof Event ? (Event) modelMap.get("event") : ((EventDescriptor) modelMap.get("event")).getEvent();
                    ConfigurationPathKey googleAnalyticsKey = Optional.ofNullable(event)
                        .map(e -> alfio.model.system.Configuration.from(e.getOrganizationId(), e.getId(), GOOGLE_ANALYTICS_KEY))
                        .orElseGet(() -> alfio.model.system.Configuration.getSystemConfiguration(GOOGLE_ANALYTICS_KEY));
                    modelMap.putIfAbsent("analyticsEnabled", StringUtils.isNotBlank(configurationManager.getStringConfigValue(googleAnalyticsKey, "")));


                    if(demoModeEnabled) {
                        modelMap.putIfAbsent("paypalTestUsername", configurationManager.getStringConfigValue(alfio.model.system.Configuration.getSystemConfiguration(PAYPAL_DEMO_MODE_USERNAME), "<missing>"));
                        modelMap.putIfAbsent("paypalTestPassword", configurationManager.getStringConfigValue(alfio.model.system.Configuration.getSystemConfiguration(PAYPAL_DEMO_MODE_PASSWORD), "<missing>"));
                    }
            });
        }
    };
}
 
开发者ID:alfio-event,项目名称:alf.io,代码行数:41,代码来源:MvcConfiguration.java

示例14: getCsrfInterceptor

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; //导入依赖的package包/类
@Bean
public HandlerInterceptor getCsrfInterceptor() {
    return new HandlerInterceptorAdapter() {
        @Override
        public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
            Optional.ofNullable(modelAndView).ifPresent(mv -> mv.addObject(WebSecurityConfig.CSRF_PARAM_NAME, request.getAttribute(CsrfToken.class.getName())));
        }
    };
}
 
开发者ID:alfio-event,项目名称:alf.io,代码行数:10,代码来源:MvcConfiguration.java

示例15: addInterceptors

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; //导入依赖的package包/类
@Override
public void addInterceptors(InterceptorRegistry registry) {
    super.addInterceptors(registry);
    HandlerInterceptor addShoppingCartInRequestHandlerInterceptor = new HandlerInterceptorAdapter() {

        @Override
        public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
            ShoppingCart shoppingCart = shoppingCartRepository.getCurrentShoppingCart(request);
            request.setAttribute("shoppingCart", shoppingCart);
        }
    };
    registry.addInterceptor(addShoppingCartInRequestHandlerInterceptor);
}
 
开发者ID:cloudbees-attic,项目名称:bees-shop-clickstart,代码行数:14,代码来源:WebConfig.java


注:本文中的org.springframework.web.servlet.handler.HandlerInterceptorAdapter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。