2016-01-26 31 views
0

我按照此示例将Spring Social与JWT(无状态)集成。Spring 4/Spring社交 - PageNotFound - 在DispatcherServlet中找不到具有URI的HTTP请求的映射

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.se[email protected]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.spr[email protected]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.se[email protected]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 [[email protected]f920] 
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.springfr[email protected]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.springfr[email protected]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.spr[email protected]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.se[email protected]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.sprin[email protected]6fa86552: Principal: anonymousUser; Credentials: [PROTECTED]; Authenticated: true; Details: org.sprin[email protected]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.sprin[email protected]6fa86552: Principal: anonymousUser; Credentials: [PROTECTED]; Authenticated: true; Details: org.sprin[email protected]fffd148a: RemoteIpAddress: 127.0.0.1; SessionId: 261DFFE68998DB03A0CEC795038D4263; Granted Authorities: ROLE_ANONYMOUS 
DEBUG org.springframework.security.access.vote.AffirmativeBased- Voter: org.sp[email protected]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]进行名称为'dispatcher'的HTTP请求

这是我的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和处理它的控制器之间的链接,这是Spring社交的一部分。

任何建议非常感谢。干杯。

回答

1

已解决。这是由于DB不一致造成的。用户从'user'表中删除,但其对应的'UserConnection'行(春季社交在该表中为每个提供商创建了一行)仍然存在。删除全部后,它清除了问题。

相关问题