Spring 4 / Spring social - PageNotFound - 在DispatcherServlet中找不到带URI的HTTP请求的映射

时间:2016-01-26 15:44:55

标签: java spring spring-mvc spring-security spring-social

我按照这个例子将Spring Social与JWT(无状态)集成在一起。

http://blog.jdriven.com/2015/01/stateless-spring-security-part-3-jwt-social-authentication/

这是我的春季日志输出

DEBUG org.springframework.security.web.FilterChainProxy- /auth/facebook at position 1 of 7 in additional filter chain; firing Filter: 'HeaderWriterFilter'
DEBUG org.springframework.security.web.header.writers.HstsHeaderWriter- Not injecting HSTS header since it did not match the requestMatcher org.springframework.security.web.header.writers.HstsHeaderWriter$SecureRequestMatcher@25ef2346
DEBUG org.springframework.security.web.FilterChainProxy- /auth/facebook at position 2 of 7 in additional filter chain; firing Filter: 'StatelessAuthenticationFilter'
DEBUG org.springframework.security.web.FilterChainProxy- /auth/facebook at position 3 of 7 in additional filter chain; firing Filter: 'SocialAuthenticationFilter'
DEBUG org.springframework.social.security.SocialAuthenticationFilter- Request is to process authentication
DEBUG org.springframework.social.security.SocialAuthenticationFilter- Authentication request failed: org.springframework.social.security.SocialAuthenticationRedirectException: 
DEBUG org.springframework.social.security.SocialAuthenticationFilter- Updated SecurityContextHolder to contain null Authentication
DEBUG org.springframework.social.security.SocialAuthenticationFilter- Delegating to authentication failure handler org.springframework.social.security.SocialAuthenticationFailureHandler@65dea49
DEBUG org.springframework.security.web.FilterChainProxy- /auth/facebook?code=AQAFgopGOJzTCdj---j8cN5GqdsmhpKuD0Yinu-&state=586d5c06-d2ec-484d-a430-8ebff2900e05 at position 1 of 7 in additional filter chain; firing Filter: 'HeaderWriterFilter'
DEBUG org.springframework.security.web.header.writers.HstsHeaderWriter- Not injecting HSTS header since it did not match the requestMatcher org.springframework.security.web.header.writers.HstsHeaderWriter$SecureRequestMatcher@25ef2346
DEBUG org.springframework.security.web.FilterChainProxy- /auth/facebook?code=AQAFgopGOJzTCdj-KER50kXm8lkxQTdqYlOuxcFwiDcCssw29Wp--j8cN5GqdsmhpKuD0Yinu-&state=586d5c06-d2ec-484d-a430-8ebff2900e05 at position 2 of 7 in additional filter chain; firing Filter: 'StatelessAuthenticationFilter'
DEBUG org.springframework.security.web.FilterChainProxy- /auth/facebook?code=-KER50kXm8lkxQTdqYlOuxcFwiDcCssw29Wp---&state=586d5c06-d2ec-484d-a430-8ebff2900e05 at position 3 of 7 in additional filter chain; firing Filter: 'SocialAuthenticationFilter'
DEBUG org.springframework.social.security.SocialAuthenticationFilter- Request is to process authentication
DEBUG org.springframework.web.client.RestTemplate- Created POST request for "https://graph.facebook.com/v2.5/oauth/access_token"
DEBUG org.springframework.web.client.RestTemplate- Setting request Accept header to [application/x-www-form-urlencoded, multipart/form-data, application/json, application/*+json]
DEBUG org.springframework.web.client.RestTemplate- Writing [{client_id=[119076044790683], client_secret=[49f4fadf74a562b6312eb0332be5b14e], code=[----], redirect_uri=[http://havefunhub.com:8081/api/auth/facebook], grant_type=[authorization_code]}] using [org.springframework.http.converter.FormHttpMessageConverter@5b7cf920]
DEBUG org.springframework.web.client.RestTemplate- POST request for "https://graph.facebook.com/v2.5/oauth/access_token" resulted in 200 (OK)
DEBUG org.springframework.web.client.RestTemplate- Reading [interface java.util.Map] as "application/json;charset=UTF-8" using [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@2448c6a1]
DEBUG org.springframework.web.client.RestTemplate- Created GET request for "https://graph.facebook.com/v2.5/me?fields=id%2Cname%2Clink"
DEBUG org.springframework.web.client.RestTemplate- Setting request Accept header to [application/json, application/*+json]
DEBUG org.springframework.web.client.RestTemplate- GET request for "https://graph.facebook.com/v2.5/me?fields=id%2Cname%2Clink" resulted in 200 (OK)
DEBUG org.springframework.web.client.RestTemplate- Reading [class org.springframework.social.facebook.api.User] as "application/json" using [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@784acd1f]
DEBUG org.springframework.security.authentication.ProviderManager- Authentication attempt using org.springframework.social.security.SocialAuthenticationProvider
DEBUG org.springframework.jdbc.core.JdbcTemplate- Executing prepared SQL query
DEBUG org.springframework.jdbc.core.JdbcTemplate- Executing prepared SQL statement [select userId from UserConnection where providerId = ? and providerUserId = ?]
DEBUG org.springframework.jdbc.datasource.DataSourceUtils- Fetching JDBC Connection from DataSource
DEBUG org.springframework.jdbc.datasource.DriverManagerDataSource- Creating new JDBC DriverManager Connection to [jdbc:mysql://localhost:3306/havefun?useEncoding=true&characterEncoding=UTF-8]
DEBUG org.springframework.jdbc.datasource.DataSourceUtils- Returning JDBC Connection to DataSource
DEBUG org.springframework.data.neo4j.transaction.Neo4jTransactionManager- Requesting to create or join a transaction
DEBUG org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler- Creating new EntityManager for shared EntityManager invocation
DEBUG org.springframework.jdbc.datasource.DriverManagerDataSource- Creating new JDBC DriverManager Connection to [jdbc:mysql://localhost:3306/havefun?useEncoding=true&characterEncoding=UTF-8]
DEBUG org.springframework.orm.jpa.EntityManagerFactoryUtils- Closing JPA EntityManager
DEBUG org.springframework.data.neo4j.transaction.Neo4jTransactionManager- Rollback requested: http://localhost:7474/db/data/transaction/35, status: OPEN
DEBUG org.springframework.data.neo4j.transaction.Neo4jTransactionManager- Rollback invoked
DEBUG org.springframework.social.security.SocialAuthenticationFilter- Authentication request failed: org.springframework.security.core.userdetails.UsernameNotFoundException: user not found
DEBUG org.springframework.social.security.SocialAuthenticationFilter- Updated SecurityContextHolder to contain null Authentication
DEBUG org.springframework.social.security.SocialAuthenticationFilter- Delegating to authentication failure handler org.springframework.social.security.SocialAuthenticationFailureHandler@65dea49
DEBUG org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler- Redirecting to /signin
DEBUG org.springframework.security.web.DefaultRedirectStrategy- Redirecting to '/api/signin'
DEBUG org.springframework.security.web.FilterChainProxy- /signin at position 1 of 7 in additional filter chain; firing Filter: 'HeaderWriterFilter'
DEBUG org.springframework.security.web.header.writers.HstsHeaderWriter- Not injecting HSTS header since it did not match the requestMatcher org.springframework.security.web.header.writers.HstsHeaderWriter$SecureRequestMatcher@25ef2346
DEBUG org.springframework.security.web.FilterChainProxy- /signin at position 2 of 7 in additional filter chain; firing Filter: 'StatelessAuthenticationFilter'
DEBUG org.springframework.security.web.FilterChainProxy- /signin at position 3 of 7 in additional filter chain; firing Filter: 'SocialAuthenticationFilter'
DEBUG org.springframework.security.web.FilterChainProxy- /signin at position 4 of 7 in additional filter chain; firing Filter: 'SecurityContextHolderAwareRequestFilter'
DEBUG org.springframework.security.web.FilterChainProxy- /signin at position 5 of 7 in additional filter chain; firing Filter: 'AnonymousAuthenticationFilter'
DEBUG org.springframework.security.web.authentication.AnonymousAuthenticationFilter- Populated SecurityContextHolder with anonymous token: 'org.springframework.security.authentication.AnonymousAuthenticationToken@6fa86552: Principal: anonymousUser; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@fffd148a: RemoteIpAddress: 127.0.0.1; SessionId: 261DFFE68998DB03A0CEC795038D4263; Granted Authorities: ROLE_ANONYMOUS'
DEBUG org.springframework.security.web.FilterChainProxy- /signin at position 6 of 7 in additional filter chain; firing Filter: 'ExceptionTranslationFilter'
DEBUG org.springframework.security.web.FilterChainProxy- /signin at position 7 of 7 in additional filter chain; firing Filter: 'FilterSecurityInterceptor'
DEBUG org.springframework.security.web.util.matcher.AntPathRequestMatcher- Checking match of request : '/signin'; against '/'
DEBUG org.springframework.security.web.util.matcher.AntPathRequestMatcher- Checking match of request : '/signin'; against '/favicon.ico'
DEBUG org.springframework.security.web.util.matcher.AntPathRequestMatcher- Checking match of request : '/signin'; against '/resources/**'
DEBUG org.springframework.security.web.util.matcher.AntPathRequestMatcher- Checking match of request : '/signin'; against '/auth/**'
DEBUG org.springframework.security.web.util.matcher.AntPathRequestMatcher- Request 'GET /signin' doesn't match 'POST /subscriptions/**
DEBUG org.springframework.security.web.util.matcher.AntPathRequestMatcher- Request 'GET /signin' doesn't match 'POST /verifications/**
DEBUG org.springframework.security.web.util.matcher.AntPathRequestMatcher- Checking match of request : '/signin'; against '/graph/**'
DEBUG org.springframework.security.web.util.matcher.AntPathRequestMatcher- Request '/signin' matched by universal pattern '/**'
DEBUG org.springframework.security.web.access.intercept.FilterSecurityInterceptor- Secure object: FilterInvocation: URL: /signin; Attributes: [permitAll]
DEBUG org.springframework.security.web.access.intercept.FilterSecurityInterceptor- Previously Authenticated: org.springframework.security.authentication.AnonymousAuthenticationToken@6fa86552: Principal: anonymousUser; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@fffd148a: RemoteIpAddress: 127.0.0.1; SessionId: 261DFFE68998DB03A0CEC795038D4263; Granted Authorities: ROLE_ANONYMOUS
DEBUG org.springframework.security.access.vote.AffirmativeBased- Voter: org.springframework.security.web.access.expression.WebExpressionVoter@41f8b39, returned: 1
DEBUG org.springframework.security.web.access.intercept.FilterSecurityInterceptor- Authorization successful
DEBUG org.springframework.security.web.access.intercept.FilterSecurityInterceptor- RunAsManager did not change Authentication object
DEBUG org.springframework.security.web.FilterChainProxy- /signin reached end of additional filter chain; proceeding with original chain
DEBUG org.springframework.web.servlet.DispatcherServlet- DispatcherServlet with name 'dispatcher' processing GET request for [/api/signin]
DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping- Looking up handler method for path /signin
DEBUG org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping- Did not find handler method for [/signin]
WARN  org.springframework.web.servlet.PageNotFound- No mapping found for HTTP request with URI [/api/signin] in DispatcherServlet with name 'dispatcher'
DEBUG org.springframework.web.servlet.DispatcherServlet- Successfully completed request
DEBUG org.springframework.security.web.access.ExceptionTranslationFilter- Chain processed normally

告诉我日志中的内容的行是

WARN org.springframework.web.servlet.PageNotFound-在DispatcherServlet中找不到带有URI [/ api / signin]的HTTP请求的映射,其名称为' dispatcher'

这是我的java配置

AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();

        ctx.setDisplayName("HaveFunHub Public API");

        //load profile dependent properties
        loadProfileProperties(ctx);

        ctx.scan("com.havefunhub.api.config", "com.havefunhub.api.security.config");

        ctx.setServletContext(servletContext);

        FilterRegistration.Dynamic corsFilter = servletContext.addFilter("corsFilter", CORSFilter.class);
        corsFilter.addMappingForUrlPatterns(null, false, "/*");
        corsFilter.setAsyncSupported(true);

        ServletRegistration.Dynamic servlet1 = servletContext.addServlet("dispatcher", new DispatcherServlet(ctx));
        servlet1.addMapping("/");
        servlet1.setLoadOnStartup(1);
        servlet1.setAsyncSupported(true);


        DelegatingFilterProxy springSecurityFilterChain = new DelegatingFilterProxy("springSecurityFilterChain", ctx);

        FilterRegistration.Dynamic springSecurity = servletContext.addFilter("springSecurityFilterChain",
                springSecurityFilterChain);
        springSecurity.addMappingForUrlPatterns(null, true, "/*");
        springSecurity.setAsyncSupported(true);

        //required for neo4j scoped bean session
        servletContext.addListener(new RequestContextListener());

这是我的安全性java配置

@Override
    protected void configure(HttpSecurity http) throws Exception {
        // Set a custom successHandler on the SocialAuthenticationFilter
        final SpringSocialConfigurer socialConfigurer = new SpringSocialConfigurer();
        socialConfigurer.addObjectPostProcessor(new ObjectPostProcessor<SocialAuthenticationFilter>() {
            @Override
            public <O extends SocialAuthenticationFilter> O postProcess(O socialAuthenticationFilter) {
                socialAuthenticationFilter.setAuthenticationSuccessHandler(socialAuthenticationSuccessHandler);
                socialAuthenticationFilter.setAlwaysUsePostLoginUrl(true);

                socialAuthenticationFilter.setPostLoginUrl(environment.getProperty("login.welcome.screen"));
                System.out.println("socialConfigurer that adds SocialAuthenticationFilter to Spring Security's filter chain is created and configured with socialAuthenticationSuccessHandler");
                logger.info("socialConfigurer that adds SocialAuthenticationFilter to Spring Security's filter chain is created and configured with socialAuthenticationSuccessHandler");
                return socialAuthenticationFilter;
            }
        });
      //add custom authentication filter for complete stateless JWT based authentication
                    .addFilterBefore(statelessAuthenticationFilter, AbstractPreAuthenticatedProcessingFilter.class)

                    //apply the configuration from the socialConfigurer (adds the SocialAuthenticationFilter)
                    .apply(socialConfigurer.userIdSource(userIdSource));

我之前已经完成了所有工作,但经过一些更改后它停止了工作。我无法确定哪个更改,但更重要的是引入Neo4j(使用spring-data存储库)。

我无法确定在哪里配置请求的URL与处理它的控制器之间的链接,这是春天社交的一部分。

任何建议都非常感谢。欢呼声。

1 个答案:

答案 0 :(得分:1)

解决。这是由于DB的不一致。用户已从&#39;用户&#39;中删除表但其对应的用户连接&#39; row(spring social在该表中为每个提供者创建一行)仍然存在。删除全部后,它清除了问题。