我的服务器上有一个AngularJS应用程序,当我从我的Apache服务器请求它时工作正常,但是当我从我的Tomcat7服务器请求它时没有。
以下要求:
http://www.learnintouch.com/nitro-project/index.html
允许我使用应用程序登录表单登录并查看应用程序。
但是以下要求:
http://www.learnintouch.com:8080/nitro-project-rest/resources/index.html
弹出浏览器HTTP授权。
这是我的Spring Security配置:
http
.csrf().disable().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and().httpBasic().authenticationEntryPoint(restAuthenticationEntryPoint)
.and().authorizeRequests().antMatchers("/app/**").permitAll()
.and().authorizeRequests().antMatchers("/resources/**").permitAll()
.and().authorizeRequests().antMatchers(RESTConstants.SLASH + RESTConstants.ADMINS + RESTConstants.SLASH + RESTConstants.LOGIN).permitAll()
.and().authorizeRequests().antMatchers("/**").hasRole("ADMIN").anyRequest().authenticated();
网页配置:
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/index.html").addResourceLocations("/");
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
}
@Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
configurer.enable();
}
发送请求时:http://www.learnintouch.com:8080/nitro-project-rest/resources/index.html控制台输出为:
2014-11-14 13:20:32,755 DEBUG [DispatcherServlet] DispatcherServlet with name 'NITRo' processing GET request for [/nitro-project-rest/resources/scripts/scripts.acefeb1b.js]
2014-11-14 13:20:32,756 DEBUG [RequestMappingHandlerMapping] Looking up handler method for path /resources/scripts/scripts.acefeb1b.js
2014-11-14 13:20:32,768 DEBUG [RequestMappingHandlerMapping] Did not find handler method for [/resources/scripts/scripts.acefeb1b.js]
2014-11-14 13:20:32,771 DEBUG [SimpleUrlHandlerMapping] Matching patterns for request [/resources/scripts/scripts.acefeb1b.js] are [/resources/**]
2014-11-14 13:20:32,771 DEBUG [SimpleUrlHandlerMapping] URI Template variables for request [/resources/scripts/scripts.acefeb1b.js] are {}
2014-11-14 13:20:32,771 DEBUG [SimpleUrlHandlerMapping] Mapping [/resources/scripts/scripts.acefeb1b.js] to HandlerExecutionChain with handler [ResourceHttpRequestHandler [locations=[ServletContext resource [/resources/]], resolvers=[org.springframework.web.servlet.resource.PathResourceResolver@f60ab9]]] and 1 interceptor
2014-11-14 13:20:32,771 DEBUG [DispatcherServlet] Last-Modified value for [/nitro-project-rest/resources/scripts/scripts.acefeb1b.js] is: -1
2014-11-14 13:20:32,772 DEBUG [DispatcherServlet] Null ModelAndView returned to DispatcherServlet with name 'NITRo': assuming HandlerAdapter completed request handling
2014-11-14 13:20:32,773 DEBUG [DispatcherServlet] Successfully completed request
2014-11-14 13:20:32,773 DEBUG [ExceptionTranslationFilter] Chain processed normally
2014-11-14 13:20:32,773 DEBUG [SecurityContextPersistenceFilter] SecurityContextHolder now cleared, as request processing completed
2014-11-14 13:20:33,137 DEBUG [FilterChainProxy] /resources/modules/utils/view/menu.html at position 1 of 12 in additional filter chain; firing Filter: 'SimpleCORSFilter'
2014-11-14 13:20:33,137 DEBUG [FilterChainProxy] /resources/modules/utils/view/menu.html at position 2 of 12 in additional filter chain; firing Filter: 'WebAsyncManagerIntegrationFilter'
2014-11-14 13:20:33,137 DEBUG [FilterChainProxy] /resources/modules/utils/view/menu.html at position 3 of 12 in additional filter chain; firing Filter: 'SecurityContextPersistenceFilter'
2014-11-14 13:20:33,137 DEBUG [FilterChainProxy] /resources/modules/utils/view/menu.html at position 4 of 12 in additional filter chain; firing Filter: 'HeaderWriterFilter'
2014-11-14 13:20:33,137 DEBUG [HstsHeaderWriter] Not injecting HSTS header since it did not match the requestMatcher org.springframework.security.web.header.writers.HstsHeaderWriter$SecureRequestMatcher@a379e4
2014-11-14 13:20:33,137 DEBUG [FilterChainProxy] /resources/modules/utils/view/menu.html at position 5 of 12 in additional filter chain; firing Filter: 'LogoutFilter'
2014-11-14 13:20:33,137 DEBUG [AntPathRequestMatcher] Checking match of request : '/resources/modules/utils/view/menu.html'; against '/logout'
2014-11-14 13:20:33,137 DEBUG [FilterChainProxy] /resources/modules/utils/view/menu.html at position 6 of 12 in additional filter chain; firing Filter: 'BasicAuthenticationFilter'
2014-11-14 13:20:33,137 DEBUG [BasicAuthenticationFilter] Basic Authentication Authorization header found for user 'undefined'
2014-11-14 13:20:33,137 DEBUG [ProviderManager] Authentication attempt using com.nsn.nitro.project.rest.security.CustomAuthenticationProvider
2014-11-14 13:20:33,137 DEBUG [BasicAuthenticationFilter] Authentication request for failed: org.springframework.security.authentication.BadCredentialsException: The login undefined and password could not match.
2014-11-14 13:20:33,138 DEBUG [SecurityContextPersistenceFilter] SecurityContextHolder now cleared, as request processing completed
2014-11-14 13:20:33,146 DEBUG [FilterChainProxy] /resources/modules/admin/view/login.html at position 1 of 12 in additional filter chain; firing Filter: 'SimpleCORSFilter'
2014-11-14 13:20:33,146 DEBUG [FilterChainProxy] /resources/modules/admin/view/login.html at position 2 of 12 in additional filter chain; firing Filter: 'WebAsyncManagerIntegrationFilter'
2014-11-14 13:20:33,146 DEBUG [FilterChainProxy] /resources/modules/admin/view/login.html at position 3 of 12 in additional filter chain; firing Filter: 'SecurityContextPersistenceFilter'
2014-11-14 13:20:33,146 DEBUG [FilterChainProxy] /resources/modules/admin/view/login.html at position 4 of 12 in additional filter chain; firing Filter: 'HeaderWriterFilter'
2014-11-14 13:20:33,146 DEBUG [HstsHeaderWriter] Not injecting HSTS header since it did not match the requestMatcher org.springframework.security.web.header.writers.HstsHeaderWriter$SecureRequestMatcher@a379e4
2014-11-14 13:20:33,146 DEBUG [FilterChainProxy] /resources/modules/admin/view/login.html at position 5 of 12 in additional filter chain; firing Filter: 'LogoutFilter'
2014-11-14 13:20:33,146 DEBUG [AntPathRequestMatcher] Checking match of request : '/resources/modules/admin/view/login.html'; against '/logout'
2014-11-14 13:20:33,146 DEBUG [FilterChainProxy] /resources/modules/admin/view/login.html at position 6 of 12 in additional filter chain; firing Filter: 'BasicAuthenticationFilter'
2014-11-14 13:20:33,146 DEBUG [BasicAuthenticationFilter] Basic Authentication Authorization header found for user 'undefined'
2014-11-14 13:20:33,146 DEBUG [ProviderManager] Authentication attempt using com.nsn.nitro.project.rest.security.CustomAuthenticationProvider
2014-11-14 13:20:33,146 DEBUG [BasicAuthenticationFilter] Authentication request for failed: org.springframework.security.authentication.BadCredentialsException: The login undefined and password could not match.
2014-11-14 13:20:33,146 DEBUG [SecurityContextPersistenceFilter] SecurityContextHolder now cleared, as request processing completed