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


Java MockFilterConfig类代码示例

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


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

示例1: delegatingFilterProxyRegistrationBeansSkipsTargetBeanNames

import org.springframework.mock.web.MockFilterConfig; //导入依赖的package包/类
@Test
public void delegatingFilterProxyRegistrationBeansSkipsTargetBeanNames()
		throws Exception {
	addEmbeddedServletContainerFactoryBean();
	DelegatingFilterProxyRegistrationBean initializer = new DelegatingFilterProxyRegistrationBean(
			"filterBean");
	this.context.registerBeanDefinition("initializerBean",
			beanDefinition(initializer));
	BeanDefinition filterBeanDefinition = beanDefinition(
			new IllegalStateException("Create FilterBean Failure"));
	filterBeanDefinition.setLazyInit(true);
	this.context.registerBeanDefinition("filterBean", filterBeanDefinition);
	this.context.refresh();
	ServletContext servletContext = getEmbeddedServletContainerFactory()
			.getServletContext();
	verify(servletContext, atMost(1)).addFilter(anyString(),
			this.filterCaptor.capture());
	// Up to this point the filterBean should not have been created, calling
	// the delegate proxy will trigger creation and an exception
	this.thrown.expect(BeanCreationException.class);
	this.thrown.expectMessage("Create FilterBean Failure");
	this.filterCaptor.getValue().init(new MockFilterConfig());
	this.filterCaptor.getValue().doFilter(new MockHttpServletRequest(),
			new MockHttpServletResponse(), new MockFilterChain());
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:26,代码来源:EmbeddedWebApplicationContextTests.java

示例2: configureFilterConfig

import org.springframework.mock.web.MockFilterConfig; //导入依赖的package包/类
@Before
public void configureFilterConfig() {
    MockApplication application = new MockApplication();

    MockServletContext context = new MockServletContext(application, "");
    context.setAttribute("nada", ServerContext.WORKLIST);

    filterConfig = new MockFilterConfig(context);
    filterConfig.addInitParameter(SSOFilter.URL_EXCLUDE_PATTERN_PARAM, "/rest");
    filterConfig.addInitParameter(SSOFilter.CLIENT_LOGOUT_URL, "/logout");
    filterConfig.addInitParameter(SSOConfigurableFilter.SINGULAR_CONTEXT_ATTRIBUTE, "nada");

    request = new MockHttpServletRequest(application, new MockHttpSession(context), context){
        @Override
        public String getContextPath() {
            return ServerContext.WORKLIST.getUrlPath();
        }
    };

    response = new MockHttpServletResponse(request);

}
 
开发者ID:opensingular,项目名称:singular-server,代码行数:23,代码来源:SSOFilterTest.java

示例3: testTrustedUserFilterSecurityEnabled

import org.springframework.mock.web.MockFilterConfig; //导入依赖的package包/类
@Test
public void testTrustedUserFilterSecurityEnabled() throws Exception
{
    // Override configuration.
    Map<String, Object> overrideMap = new HashMap<>();
    overrideMap.put(ConfigurationValue.SECURITY_ENABLED_SPEL_EXPRESSION.getKey(), "true");
    modifyPropertySourceInEnvironment(overrideMap);

    try
    {
        // Invalidate user session if exists.
        invalidateApplicationUser(null);

        trustedUserAuthenticationFilter.init(new MockFilterConfig());
        trustedUserAuthenticationFilter.doFilter(new MockHttpServletRequest(), new MockHttpServletResponse(), new MockFilterChain());

        assertNoUserInContext();
    }
    finally
    {
        // Restore the property sources so we don't affect other tests.
        restorePropertySourceInEnvironment();
    }
}
 
开发者ID:FINRAOS,项目名称:herd,代码行数:25,代码来源:TrustedUserAuthenticationFilterTest.java

示例4: testTrustedUserFilterNoSpel

import org.springframework.mock.web.MockFilterConfig; //导入依赖的package包/类
@Test
public void testTrustedUserFilterNoSpel() throws Exception
{
    // Override configuration.
    Map<String, Object> overrideMap = new HashMap<>();
    overrideMap.put(ConfigurationValue.SECURITY_ENABLED_SPEL_EXPRESSION.getKey(), "");
    modifyPropertySourceInEnvironment(overrideMap);

    try
    {
        // Invalidate user session if exists.
        invalidateApplicationUser(null);

        trustedUserAuthenticationFilter.init(new MockFilterConfig());
        trustedUserAuthenticationFilter.doFilter(new MockHttpServletRequest(), new MockHttpServletResponse(), new MockFilterChain());

        assertNoUserInContext();
    }
    finally
    {
        // Restore the property sources so we don't affect other tests.
        restorePropertySourceInEnvironment();
    }
}
 
开发者ID:FINRAOS,项目名称:herd,代码行数:25,代码来源:TrustedUserAuthenticationFilterTest.java

示例5: testHttpHeaderAuthenticationFilterNoHeaders

import org.springframework.mock.web.MockFilterConfig; //导入依赖的package包/类
@Test
public void testHttpHeaderAuthenticationFilterNoHeaders() throws Exception
{
    modifyPropertySourceInEnvironment(getDefaultSecurityEnvironmentVariables());

    try
    {
        // Invalidate user session if exists.
        invalidateApplicationUser(null);

        httpHeaderAuthenticationFilter.init(new MockFilterConfig());
        httpHeaderAuthenticationFilter.doFilter(new MockHttpServletRequest(), new MockHttpServletResponse(), new MockFilterChain());

        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        assertNull(authentication);
    }
    finally
    {
        restorePropertySourceInEnvironment();
    }
}
 
开发者ID:FINRAOS,项目名称:herd,代码行数:22,代码来源:HttpHeaderAuthenticationFilterTest.java

示例6: testHttpHeaderAuthenticationFilterNoRoles

import org.springframework.mock.web.MockFilterConfig; //导入依赖的package包/类
@Test
public void testHttpHeaderAuthenticationFilterNoRoles() throws Exception
{
    modifyPropertySourceInEnvironment(getDefaultSecurityEnvironmentVariables());

    try
    {
        MockHttpServletRequest request = getRequestWithHeaders(USER_ID, "testFirstName", "testLastName", "testEmail", null, "Wed, 11 Mar 2015 10:24:09");

        // Invalidate user session if exists.
        invalidateApplicationUser(request);

        httpHeaderAuthenticationFilter.init(new MockFilterConfig());
        httpHeaderAuthenticationFilter.doFilter(request, new MockHttpServletResponse(), new MockFilterChain());

        validateHttpHeaderApplicationUser(USER_ID, "testFirstName", "testLastName", "testEmail", (String) null, "Wed, 11 Mar 2015 10:24:09", null, null);
    }
    finally
    {
        restorePropertySourceInEnvironment();
    }
}
 
开发者ID:FINRAOS,项目名称:herd,代码行数:23,代码来源:HttpHeaderAuthenticationFilterTest.java

示例7: testHttpHeaderAuthenticationFilterNoSessionInitTime

import org.springframework.mock.web.MockFilterConfig; //导入依赖的package包/类
@Test
public void testHttpHeaderAuthenticationFilterNoSessionInitTime() throws Exception
{
    modifyPropertySourceInEnvironment(getDefaultSecurityEnvironmentVariables());

    try
    {
        MockHttpServletRequest request = getRequestWithHeaders(USER_ID, "testFirstName", "testLastName", "testEmail", null, null);

        // Invalidate user session if exists.
        invalidateApplicationUser(request);

        httpHeaderAuthenticationFilter.init(new MockFilterConfig());
        httpHeaderAuthenticationFilter.doFilter(request, new MockHttpServletResponse(), new MockFilterChain());

        validateHttpHeaderApplicationUser(USER_ID, "testFirstName", "testLastName", "testEmail", (String) null, null, null, null);
    }
    finally
    {
        restorePropertySourceInEnvironment();
    }
}
 
开发者ID:FINRAOS,项目名称:herd,代码行数:23,代码来源:HttpHeaderAuthenticationFilterTest.java

示例8: testHttpHeaderAuthenticationFilterMultipleRoles

import org.springframework.mock.web.MockFilterConfig; //导入依赖的package包/类
@Test
public void testHttpHeaderAuthenticationFilterMultipleRoles() throws Exception
{
    modifyPropertySourceInEnvironment(getDefaultSecurityEnvironmentVariables());

    try
    {
        MockHttpServletRequest request =
            getRequestWithHeaders(USER_ID, "testFirstName", "testLastName", "testEmail", "testRole1,testRole2", "Wed, 11 Mar 2015 10:24:09");
        // Invalidate user session if exists.
        invalidateApplicationUser(request);

        httpHeaderAuthenticationFilter.init(new MockFilterConfig());
        httpHeaderAuthenticationFilter.doFilter(request, new MockHttpServletResponse(), new MockFilterChain());

        Set<String> expectedRoles = new HashSet<>();
        expectedRoles.add("testRole1");
        expectedRoles.add("testRole2");
        validateHttpHeaderApplicationUser(USER_ID, "testFirstName", "testLastName", "testEmail", expectedRoles, "Wed, 11 Mar 2015 10:24:09", null, null);
    }
    finally
    {
        restorePropertySourceInEnvironment();
    }
}
 
开发者ID:FINRAOS,项目名称:herd,代码行数:26,代码来源:HttpHeaderAuthenticationFilterTest.java

示例9: testHttpHeaderAuthenticationFilterEmptyRoleRegex

import org.springframework.mock.web.MockFilterConfig; //导入依赖的package包/类
@Test
public void testHttpHeaderAuthenticationFilterEmptyRoleRegex() throws Exception
{
    Map<String, Object> overrideMap = getDefaultSecurityEnvironmentVariables();
    overrideMap.put(ConfigurationValue.SECURITY_HTTP_HEADER_ROLE_REGEX.getKey(), " ");
    modifyPropertySourceInEnvironment(overrideMap);

    try
    {
        MockHttpServletRequest request =
            getRequestWithHeaders(USER_ID, "testFirstName", "testLastName", "testEmail", "testRole1,testRole2", "Wed, 11 Mar 2015 10:24:09");
        // Invalidate user session if exists.
        invalidateApplicationUser(request);

        httpHeaderAuthenticationFilter.init(new MockFilterConfig());
        httpHeaderAuthenticationFilter.doFilter(request, new MockHttpServletResponse(), new MockFilterChain());

        Set<String> expectedRoles = new HashSet<>();
        validateHttpHeaderApplicationUser(USER_ID, "testFirstName", "testLastName", "testEmail", expectedRoles, "Wed, 11 Mar 2015 10:24:09", null, null);
    }
    finally
    {
        restorePropertySourceInEnvironment();
    }
}
 
开发者ID:FINRAOS,项目名称:herd,代码行数:26,代码来源:HttpHeaderAuthenticationFilterTest.java

示例10: testHttpHeaderAuthenticationFilterUserIdWithDomainName

import org.springframework.mock.web.MockFilterConfig; //导入依赖的package包/类
@Test
public void testHttpHeaderAuthenticationFilterUserIdWithDomainName() throws Exception
{
    modifyPropertySourceInEnvironment(getDefaultSecurityEnvironmentVariables());

    try
    {
        MockHttpServletRequest request =
            getRequestWithHeaders("[email protected]", "testFirstName", "testLastName", "testEmail", "testRole", "Wed, 11 Mar 2015 10:24:09");
        // Invalidate user session if exists.
        invalidateApplicationUser(request);

        httpHeaderAuthenticationFilter.init(new MockFilterConfig());
        httpHeaderAuthenticationFilter.doFilter(request, new MockHttpServletResponse(), new MockFilterChain());

        validateHttpHeaderApplicationUser("[email protected]", "testFirstName", "testLastName", "testEmail", "testRole", "Wed, 11 Mar 2015 10:24:09",
            null, null);
    }
    finally
    {
        restorePropertySourceInEnvironment();
    }
}
 
开发者ID:FINRAOS,项目名称:herd,代码行数:24,代码来源:HttpHeaderAuthenticationFilterTest.java

示例11: testLoggingNoUser

import org.springframework.mock.web.MockFilterConfig; //导入依赖的package包/类
@Test
public void testLoggingNoUser() throws Exception
{
    invalidateApplicationUser(null);

    // Apply user logging filter.
    Log4jMdcLoggingFilter filterUnderTest = new Log4jMdcLoggingFilter();
    filterUnderTest.init(new MockFilterConfig());
    MockFilterChain mockChain = new MockFilterChain();
    MockHttpServletRequest req = new MockHttpServletRequest();
    MockHttpServletResponse rsp = new MockHttpServletResponse();

    filterUnderTest.doFilter(req, rsp, mockChain);

    filterUnderTest.destroy();
}
 
开发者ID:FINRAOS,项目名称:herd,代码行数:17,代码来源:Log4jMdcLoggingFilterTest.java

示例12: testLoggingAnonymousUser

import org.springframework.mock.web.MockFilterConfig; //导入依赖的package包/类
@Test
public void testLoggingAnonymousUser() throws Exception
{
    invalidateApplicationUser(null);

    // Apply AnonymousAuthenticationFilter
    AnonymousAuthenticationFilter anonymousAuthenticationFilter = new AnonymousAuthenticationFilter("AnonymousFilterKey");
    anonymousAuthenticationFilter.doFilter(new MockHttpServletRequest(), new MockHttpServletResponse(), new MockFilterChain());
    
    // Apply user logging filter.
    Log4jMdcLoggingFilter filterUnderTest = new Log4jMdcLoggingFilter();
    filterUnderTest.init(new MockFilterConfig());
    MockFilterChain mockChain = new MockFilterChain();
    MockHttpServletRequest req = new MockHttpServletRequest();
    MockHttpServletResponse rsp = new MockHttpServletResponse();

    filterUnderTest.doFilter(req, rsp, mockChain);

    filterUnderTest.destroy();
}
 
开发者ID:FINRAOS,项目名称:herd,代码行数:21,代码来源:Log4jMdcLoggingFilterTest.java

示例13: testAdapter

import org.springframework.mock.web.MockFilterConfig; //导入依赖的package包/类
@Test
public void testAdapter() throws Exception {

    MockFilterConfig mockFilterConfig = new MockFilterConfig();
    mockFilterConfig.addInitParameter("foo", "bar");

    FilterServletConfigAdapter adapter = new FilterServletConfigAdapter(mockFilterConfig, "my-servlet");

    assertEquals("my-servlet", adapter.getServletName());
    assertEquals(mockFilterConfig.getServletContext(), adapter.getServletContext());
    assertEquals("bar", adapter.getInitParameter("foo"));

    Enumeration<String> initParameterNames = adapter.getInitParameterNames();
    assertNotNull(initParameterNames);
    assertTrue(initParameterNames.hasMoreElements());
    assertEquals("foo", initParameterNames.nextElement());
    assertFalse(initParameterNames.hasMoreElements());

}
 
开发者ID:sniffy,项目名称:sniffy,代码行数:20,代码来源:FilterServletConfigAdapterTest.java

示例14: testRedirectWithQueryString

import org.springframework.mock.web.MockFilterConfig; //导入依赖的package包/类
@Test
public void testRedirectWithQueryString() throws Exception {
    request.setQueryString("test=12456");
    request.setRequestURI("/test");
    request.setSecure(true);
    this.filter = new CasAuthenticationFilter();

    final MockFilterConfig config = new MockFilterConfig();
    config.addInitParameter("casServerLoginUrl", CAS_LOGIN_URL);
    config.addInitParameter("serverName", "localhost:8443");
    this.filter.init(config);

    this.filter.doFilter(request, response, filterChain);

    assertEquals(
            CAS_LOGIN_URL
                    + "?service="
                    + URLEncoder.encode("https://localhost:8443" + request.getRequestURI() + "?"
                            + request.getQueryString(), "UTF-8"), response.getRedirectedUrl());
}
 
开发者ID:NCIP,项目名称:caarray,代码行数:21,代码来源:CasAuthenticationFilterTest.java

示例15: before

import org.springframework.mock.web.MockFilterConfig; //导入依赖的package包/类
@Before
public void before() throws Exception {
	filter = new CrnkFilter();

	servletContext = new MockServletContext();
	((MockServletContext) servletContext).setContextPath("");
	filterConfig = new MockFilterConfig(servletContext);
	((MockFilterConfig) filterConfig).addInitParameter(CrnkProperties.WEB_PATH_PREFIX, "/api");
	((MockFilterConfig) filterConfig).addInitParameter(CrnkProperties.RESOURCE_SEARCH_PACKAGE, RESOURCE_SEARCH_PACKAGE);
	((MockFilterConfig) filterConfig).addInitParameter(CrnkProperties.RESOURCE_DEFAULT_DOMAIN, RESOURCE_DEFAULT_DOMAIN);

	filter.init(filterConfig);
}
 
开发者ID:crnk-project,项目名称:crnk-framework,代码行数:14,代码来源:CrnkFilterTest.java


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