org.springframework.mock.web.MockFilterConfig Java Examples
The following examples show how to use
org.springframework.mock.web.MockFilterConfig.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Log4jMdcLoggingFilterTest.java From herd with Apache License 2.0 | 6 votes |
@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(); }
Example #2
Source File: HttpHeaderAuthenticationFilterTest.java From herd with Apache License 2.0 | 6 votes |
@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(); } }
Example #3
Source File: HttpHeaderAuthenticationFilterTest.java From herd with Apache License 2.0 | 6 votes |
@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(); } }
Example #4
Source File: HttpHeaderAuthenticationFilterTest.java From herd with Apache License 2.0 | 6 votes |
@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(); } }
Example #5
Source File: HttpHeaderAuthenticationFilterTest.java From herd with Apache License 2.0 | 6 votes |
@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(); } }
Example #6
Source File: HttpHeaderAuthenticationFilterTest.java From herd with Apache License 2.0 | 6 votes |
@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(); } }
Example #7
Source File: HttpHeaderAuthenticationFilterTest.java From herd with Apache License 2.0 | 6 votes |
@Test public void testHttpHeaderAuthenticationFilterUserWithMultiRoleHeaderNameRegexNoRole() throws Exception { modifyPropertySourceInEnvironment(getDefaultSecurityEnvironmentVariablesWithMultiHeaderRoles()); try { MockHttpServletRequest request = getRequestWithHeaders("testUserId", "testFirstName", "testLastName", "testEmail", "", "Wed, 11 Mar 2015 10:24:09"); request.addHeader("useridSuffix", "suffix"); // Invalidate user session if exists. invalidateApplicationUser(request); httpHeaderAuthenticationFilter.init(new MockFilterConfig()); httpHeaderAuthenticationFilter.doFilter(request, new MockHttpServletResponse(), new MockFilterChain()); validateHttpHeaderApplicationUser("testUserId" + "@suffix", "testFirstName", "testLastName", "testEmail", (String) null, "Wed, 11 Mar 2015 10:24:09", null, null); } finally { restorePropertySourceInEnvironment(); } }
Example #8
Source File: HttpHeaderAuthenticationFilterTest.java From herd with Apache License 2.0 | 6 votes |
@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(); } }
Example #9
Source File: Log4jMdcLoggingFilterTest.java From herd with Apache License 2.0 | 6 votes |
@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(); }
Example #10
Source File: TrustedUserAuthenticationFilterTest.java From herd with Apache License 2.0 | 6 votes |
@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(); } }
Example #11
Source File: TrustedUserAuthenticationFilterTest.java From herd with Apache License 2.0 | 6 votes |
@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(); } }
Example #12
Source File: LoggingFilterTest.java From servlet-logging-filter with Apache License 2.0 | 6 votes |
@Test public void testDoFilter_MarkeredOnly() throws Exception { MockFilterConfig filterConfig = new MockFilterConfig(); filterConfig.addInitParameter("disablePrefix", "true"); loggingFilter.init(filterConfig); when(logger.isDebugEnabled()).thenReturn(true); when(logger.isTraceEnabled()).thenReturn(true); loggingFilter.doFilter(httpServletRequest, httpServletResponse, filterChain); verify(logger).isDebugEnabled(); verify(logger).debug(getMarker("REQUEST"), "{\"sender\":\"127.0.0.1\",\"method\":\"GET\",\"path\":\"http://localhost:8080/test\",\"params\":{\"param1\":\"1000\"},\"headers\":{\"Accept\":\"application/json\",\"Content-Type\":\"text/plain\"},\"body\":\"Test request body\"}"); verify(logger).debug(getMarker("RESPONSE"), "{\"status\":200,\"headers\":{\"Content-Type\":\"text/plain\"},\"body\":\"Test response body\"}"); }
Example #13
Source File: LoggingFilterTest.java From servlet-logging-filter with Apache License 2.0 | 6 votes |
@Test public void testDoFilter_JsonOnly() throws Exception { MockFilterConfig filterConfig = new MockFilterConfig(); filterConfig.addInitParameter("disablePrefix", "true"); filterConfig.addInitParameter("disableMarker", "true"); loggingFilter.init(filterConfig); when(logger.isDebugEnabled()).thenReturn(true); when(logger.isTraceEnabled()).thenReturn(true); loggingFilter.doFilter(httpServletRequest, httpServletResponse, filterChain); verify(logger).isDebugEnabled(); verify(logger).debug("{\"sender\":\"127.0.0.1\",\"method\":\"GET\",\"path\":\"http://localhost:8080/test\",\"params\":{\"param1\":\"1000\"},\"headers\":{\"Accept\":\"application/json\",\"Content-Type\":\"text/plain\"},\"body\":\"Test request body\"}"); verify(logger).debug("{\"status\":200,\"headers\":{\"Content-Type\":\"text/plain\"},\"body\":\"Test response body\"}"); }
Example #14
Source File: CrnkFilterTest.java From crnk-framework with Apache License 2.0 | 6 votes |
@Before public void before() throws Exception { filter = new CrnkFilter() { @Override protected void initCrnk(CrnkBoot boot) { boot.addModule(new ServletTestModule()); } }; servletContext = new MockServletContext(); ((MockServletContext) servletContext).setContextPath(""); filterConfig = new MockFilterConfig(servletContext); ((MockFilterConfig) filterConfig).addInitParameter(CrnkProperties.WEB_PATH_PREFIX, "/api"); ((MockFilterConfig) filterConfig).addInitParameter(CrnkProperties.RESOURCE_DEFAULT_DOMAIN, RESOURCE_DEFAULT_DOMAIN); filter.init(filterConfig); }
Example #15
Source File: ConditionalDelegatingFilterProxyTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void init() throws Exception { FilterConfig config = new MockFilterConfig(); filter = new PatternMappingFilterProxy(delegate, "/"); filter.init(config); assertThat(delegate.filterConfig, is(config)); }
Example #16
Source File: HttpHeaderAuthenticationFilterTest.java From herd with Apache License 2.0 | 5 votes |
@Test public void testHttpHeaderAuthenticationFilterWithDatabaseConnectionError() throws Exception { setupTestFunctions("testRole"); modifyPropertySourceInEnvironment(getDefaultSecurityEnvironmentVariables()); ApplicationUserBuilder applicationUserBuilder = (ApplicationUserBuilder) ReflectionTestUtils.getField(httpHeaderAuthenticationFilter, "applicationUserBuilder"); try { MockHttpServletRequest request = getRequestWithHeaders(USER_ID, "testFirstName", "testLastName", "testEmail", "testRole", "Wed, 11 Mar 2015 10:24:09"); ApplicationUserBuilder mockApplicationUserBuilder = Mockito.mock(ApplicationUserBuilder.class); Mockito.when(mockApplicationUserBuilder.buildNoRoles(any(HttpServletRequest.class))).thenThrow(PersistenceException.class); // Invalidate user session if exists. invalidateApplicationUser(request); ReflectionTestUtils.setField(httpHeaderAuthenticationFilter, "applicationUserBuilder", mockApplicationUserBuilder); httpHeaderAuthenticationFilter.init(new MockFilterConfig()); MockHttpServletResponse mockHttpServletResponse = new MockHttpServletResponse(); httpHeaderAuthenticationFilter.doFilter(request, mockHttpServletResponse, new MockFilterChain()); assertEquals(500, mockHttpServletResponse.getStatus()); ErrorInformation errorInformation = new ErrorInformation(); errorInformation.setStatusCode(500); errorInformation.setStatusDescription("Internal Server Error"); errorInformation.setMessage("javax.persistence.PersistenceException"); errorInformation.setMessageDetails(new ArrayList<>()); assertEquals(xmlHelper.objectToXml(errorInformation), mockHttpServletResponse.getContentAsString()); } finally { restorePropertySourceInEnvironment(); } // reset application user builder ReflectionTestUtils.setField(httpHeaderAuthenticationFilter, "applicationUserBuilder", applicationUserBuilder); }
Example #17
Source File: HttpHeaderAuthenticationFilterTest.java From herd with Apache License 2.0 | 5 votes |
@Test(expected = IllegalArgumentException.class) public void testHttpHeaderAuthenticationFilterUserWithMultipleRoleHeaderNameRegexAndSingleRoleHeaderTogether() throws Exception { Map<String, Object> overrideMap = getDefaultSecurityEnvironmentVariables(); overrideMap.put(ConfigurationValue.SECURITY_HTTP_HEADER_NAMES.getKey(), "useridHeader=userId|firstNameHeader=firstName" + "|lastNameHeader=lastName|emailHeader=email|rolesHeader=roles|sessionInitTimeHeader=sessionInitTime"); overrideMap.put(ConfigurationValue.SECURITY_HTTP_HEADER_NAME_ROLE_REGEX.getKey(), "priv(.+)"); overrideMap.put(ConfigurationValue.SECURITY_HTTP_HEADER_ROLE_VALUE.getKey(), "valid"); modifyPropertySourceInEnvironment(overrideMap); try { MockHttpServletRequest request = getRequestWithHeaders("testUserId", "testFirstName", "testLastName", "testEmail", "noRoleMemberOf", "Wed, 11 Mar 2015 10:24:09"); request.addHeader("privtestrole2", "valid"); // Invalidate user session if exists. invalidateApplicationUser(request); httpHeaderAuthenticationFilter.init(new MockFilterConfig()); httpHeaderAuthenticationFilter.doFilter(request, new MockHttpServletResponse(), new MockFilterChain()); //exception is throw if singleRoleHeaderValue and multiRoleHeaders are found validateHttpHeaderApplicationUser("testUserId", "testFirstName", "testLastName", "testEmail", "testrole1", "Wed, 11 Mar 2015 10:24:09", null, null); } finally { restorePropertySourceInEnvironment(); } }
Example #18
Source File: HttpHeaderAuthenticationFilterTest.java From herd with Apache License 2.0 | 5 votes |
@Test public void testHttpHeaderAuthenticationFilterUserWithMultiRoleHeaderNameRegexMultiRoles() throws Exception { String testUserId = "testUser"; String userIdSuffix = "suffix"; String userIdWithSuffix = testUserId + "@" + userIdSuffix; modifyPropertySourceInEnvironment(getDefaultSecurityEnvironmentVariablesWithMultiHeaderRoles()); try { MockHttpServletRequest request = getRequestWithHeaders(testUserId, "testFirstName", "testLastName", "testEmail", "", "Wed, 11 Mar 2015 10:24:09"); request.addHeader("privtestrole1", "valid"); request.addHeader("privtestrole2", "valid"); request.addHeader("useridSuffix", userIdSuffix); // 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(userIdWithSuffix, "testFirstName", "testLastName", "testEmail", expectedRoles, "Wed, 11 Mar 2015 10:24:09", null, null); } finally { restorePropertySourceInEnvironment(); } }
Example #19
Source File: HttpHeaderAuthenticationFilterTest.java From herd with Apache License 2.0 | 5 votes |
@Test public void testHttpHeaderAuthenticationFilterUserWithMultiRoleHeaderNameRegexNoUseridSuffix() throws Exception { Map<String, Object> overrideMap = getDefaultSecurityEnvironmentVariables(); overrideMap.put(ConfigurationValue.SECURITY_HTTP_HEADER_NAMES.getKey(), "useridHeader=userId|firstNameHeader=firstName" + "|lastNameHeader=lastName|emailHeader=email|sessionInitTimeHeader=sessionInitTime"); modifyPropertySourceInEnvironment(overrideMap); try { MockHttpServletRequest request = getRequestWithHeaders("testUserId", "testFirstName", "testLastName", "testEmail", "", "Wed, 11 Mar 2015 10:24:09"); request.addHeader("useridSuffix", "suffix"); // Invalidate user session if exists. invalidateApplicationUser(request); httpHeaderAuthenticationFilter.init(new MockFilterConfig()); httpHeaderAuthenticationFilter.doFilter(request, new MockHttpServletResponse(), new MockFilterChain()); validateHttpHeaderApplicationUser("testUserId", "testFirstName", "testLastName", "testEmail", (String) null, "Wed, 11 Mar 2015 10:24:09", null, null); } finally { restorePropertySourceInEnvironment(); } }
Example #20
Source File: PrincipalFilterTest.java From sinavi-jfw with Apache License 2.0 | 5 votes |
@Before public void setup() { request = new MockHttpServletRequest(); response = new MockHttpServletResponse(); config = new MockFilterConfig(); principal = new PrincipalStub("stub"); }
Example #21
Source File: SpecHelper.java From javalite with Apache License 2.0 | 5 votes |
@Before @BeforeEach public void atStart() { sessionFacade = new SessionTestFacade(new MockHttpSession()); setTemplateLocation("src/main/webapp/WEB-INF/views");//default location of all views RequestContext.setTLs(null, new MockHttpServletResponse(), new MockFilterConfig(), new AppContext(), new RequestVo(), null); }
Example #22
Source File: AppIntegrationSpec.java From javalite with Apache License 2.0 | 5 votes |
@Before @BeforeEach public void beforeAppIntegrationSpec() throws ServletException { requestDispatcher.init(new MockFilterConfig()); context = requestDispatcher.getContext(); if(!suppressDb){ DBSpecHelper.openTestConnections(); } }
Example #23
Source File: RequestSpec.java From javalite with Apache License 2.0 | 5 votes |
@Before public final void setup() throws ServletException{ replaceError(); config = new MockFilterConfig(); dispatcher = new RequestDispatcher(); request = new MockHttpServletRequest(); request.setContextPath("/test_context"); dispatcher.init(config); response = new MockHttpServletResponse(); RequestContext.clear(); RequestContext.setTLs(request, response, config, new AppContext(), new RequestVo(), null); Configuration.getTemplateManager().setTemplateLocation("src/test/views"); }
Example #24
Source File: HttpHeaderAuthenticationFilterTest.java From herd with Apache License 2.0 | 5 votes |
@Test public void testHttpHeaderAuthenticationFilterInvalidateSessionOnWrongHeader() throws Exception { modifyPropertySourceInEnvironment(getDefaultSecurityEnvironmentVariables()); try { MockHttpServletRequest request = getRequestWithHeaders(USER_ID, "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(USER_ID, "testFirstName", "testLastName", "testEmail", "testRole", "Wed, 11 Mar 2015 10:24:09", null, null); // Try again with no header, user should be invalidated. httpHeaderAuthenticationFilter.doFilter(new MockHttpServletRequest(), new MockHttpServletResponse(), new MockFilterChain()); Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); assertNull(authentication); } finally { restorePropertySourceInEnvironment(); } }
Example #25
Source File: ConditionalDelegatingFilterProxyTests.java From spring-analysis-note with MIT License | 5 votes |
@Test public void init() throws Exception { FilterConfig config = new MockFilterConfig(); filter = new PatternMappingFilterProxy(delegate, "/"); filter.init(config); assertThat(delegate.filterConfig, is(config)); }
Example #26
Source File: ConditionalDelegatingFilterProxyTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void init() throws Exception { FilterConfig config = new MockFilterConfig(); filter = new PatternMappingFilterProxy(delegate, "/"); filter.init(config); assertThat(delegate.filterConfig, is(config)); }
Example #27
Source File: KatharsisFilterTest.java From katharsis-framework with Apache License 2.0 | 5 votes |
@Before public void before() throws Exception { katharsisFilter = new KatharsisFilter(); servletContext = new MockServletContext(); ((MockServletContext) servletContext).setContextPath(""); filterConfig = new MockFilterConfig(servletContext); ((MockFilterConfig) filterConfig).addInitParameter(KatharsisProperties.WEB_PATH_PREFIX, "/api"); ((MockFilterConfig) filterConfig).addInitParameter(KatharsisProperties.RESOURCE_SEARCH_PACKAGE, RESOURCE_SEARCH_PACKAGE); ((MockFilterConfig) filterConfig).addInitParameter(KatharsisProperties.RESOURCE_DEFAULT_DOMAIN, RESOURCE_DEFAULT_DOMAIN); katharsisFilter.init(filterConfig); }
Example #28
Source File: SampleKatharsisFilterTest.java From katharsis-framework with Apache License 2.0 | 5 votes |
@Before public void before() throws Exception { katharsisFilter = new SampleKatharsisFilter(); servletContext = new MockServletContext(); ((MockServletContext) servletContext).setContextPath(""); filterConfig = new MockFilterConfig(servletContext); ((MockFilterConfig) filterConfig).addInitParameter(KatharsisProperties.WEB_PATH_PREFIX, "/api"); ((MockFilterConfig) filterConfig).addInitParameter(KatharsisProperties.RESOURCE_SEARCH_PACKAGE, RESOURCE_SEARCH_PACKAGE); ((MockFilterConfig) filterConfig).addInitParameter(KatharsisProperties.RESOURCE_DEFAULT_DOMAIN, RESOURCE_DEFAULT_DOMAIN); katharsisFilter.init(filterConfig); }
Example #29
Source File: TrustedUserAuthenticationFilterTest.java From herd with Apache License 2.0 | 5 votes |
@Test public void testTrustedUserFilter() throws Exception { // Override configuration. Map<String, Object> overrideMap = new HashMap<>(); overrideMap.put(ConfigurationValue.SECURITY_ENABLED_SPEL_EXPRESSION.getKey(), "false"); modifyPropertySourceInEnvironment(overrideMap); try { // Invalidate user session if exists. invalidateApplicationUser(null); trustedUserAuthenticationFilter.init(new MockFilterConfig()); trustedUserAuthenticationFilter.doFilter(new MockHttpServletRequest(), new MockHttpServletResponse(), new MockFilterChain()); validateTrustedApplicationUser(); // retry with same request. trustedUserAuthenticationFilter.doFilter(new MockHttpServletRequest(), new MockHttpServletResponse(), new MockFilterChain()); validateTrustedApplicationUser(); } finally { // Restore the property sources so we don't affect other tests. restorePropertySourceInEnvironment(); } }
Example #30
Source File: TrustedUserAuthenticationFilterTest.java From herd with Apache License 2.0 | 5 votes |
@Test public void testTrustedUserFilterSwitchTrustedUser() throws Exception { // Override configuration. Map<String, Object> overrideMap = getDefaultSecurityEnvironmentVariables(); overrideMap.put(ConfigurationValue.SECURITY_ENABLED_SPEL_EXPRESSION.getKey(), "false"); modifyPropertySourceInEnvironment(overrideMap); // Create HttpHeader user in session. MockHttpServletRequest request = getRequestWithHeaders("testUser", "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()); assertNoUserInContext(); // Now apply the trusted user filter to ensure that user is switched to trusted user try { trustedUserAuthenticationFilter.init(new MockFilterConfig()); trustedUserAuthenticationFilter.doFilter(new MockHttpServletRequest(), new MockHttpServletResponse(), new MockFilterChain()); validateTrustedApplicationUser(); } finally { // Restore the property sources so we don't affect other tests. restorePropertySourceInEnvironment(); } }