gpt4 book ai didi

java - Spring 4/Spring 社交 - PageNotFound - 在 DispatcherServlet 中未找到带有 URI 的 HTTP 请求的映射

转载 作者:行者123 更新时间:2023-12-01 10:32:26 36 4
gpt4 key购买 nike

我正在按照此示例将 Spring Social 与 JWT(无状态)集成。

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

这是我的 spring 日志输出

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

日志中告诉我一些信息的行是

警告 org.springframework.web.servlet.PageNotFound- 在名为“dispatcher”的 DispatcherServlet 中未找到带有 URI [/api/signin] 的 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 和处理它的 Controller (Spring Social 的一部分)之间的链接。

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

最佳答案

已解决。这是由于DB不一致造成的。用户已从“用户”表中删除,但其相应的“UserConnection”行(Spring Social 在该表中为每个提供者创建一行)仍然存在。全部删除后,问题就解决了。

关于java - Spring 4/Spring 社交 - PageNotFound - 在 DispatcherServlet 中未找到带有 URI 的 HTTP 请求的映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35017874/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com