春季社交/连接返回404 [英] Spring social /connect return 404

查看:172
本文介绍了春季社交/连接返回404的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在我的(maven)spring MVC安全(spring security)应用程序中配置spring社区,但是当我尝试访问 / connect / / connect / providerid ,我总是得到错误404



我的Glassfish服务器日志当我尝试访问时:

 信息:映射{[/ connect / {providerId}],methods = [POST],params = [],headers = [],consumes = [],生成= [],custom = []}转换为public org.springframework.web.servlet.view.RedirectView org.springframework.social.connect .web.ConnectController.connect(java.lang.String,org.springframework.web.context.request.NativeWebRequest)
Info:映射{[/ connect / {providerId}],methods = [DELETE],params = [],headers = [],consumes = [],生成= [],custom = []}转换为public org.springframework.web.servlet.view.RedirectView org.springframework.social.connect.web.ConnectController。 removeConnections(java.lang.String,org.springframework.web.context.request.NativeWebRequest)
Info:Mapped{[/ connect / {providerId}],方法= [GET],params = [error],headers = [],consumes = [],生成= [],custom = []}转换为public org.springframework.web.servlet。 view.RedirectView org.springframework.social.connect.web.ConnectController.oauth2ErrorCallback(java.lang.String,java.lang.String,java.lang.String,java.lang.String,org.springframework.web.context.request .NativeWebRequest)
Info:映射{[/ connect / {providerId} / {providerUserId}],方法= [DELETE],params = [],headers = [],consumes = [],产生= [] ,custom = []}转换为public org.springframework.web.servlet.view.RedirectView org.springframework.social.connect.web.ConnectController.removeConnection(java.lang.String,java.lang.String,org.springframework。 web.context.request.NativeWebRequest)
Info:映射{[/ connect],methods = [GET],params = [],headers = [],consumes = [],产生= [],custom = []}到public java.lang.String org.springframework.social.connect.web.ConnectController.connectionStatus(org.springframework.web.context.request.NativeWebRequest,org.spri ngframework.ui.Model)
Info:Mapped{[/ connect / {providerId}],methods = [GET],params = [],headers = [],consumes = [],产生= [],自定义= []}到公共java.lang.String org.springframework.social.connect.web.ConnectController.connectionStatus(java.lang.String,org.springframework.web.context.request.NativeWebRequest,org.springframework.ui .Model)
Info:Mapped {{/ connect / {providerId}],methods = [GET],params = [oauth_token],headers = [],consumes = [],产生= [],custom = []}to public org.springframework.web.servlet.view.RedirectView org.springframework.social.connect.web.ConnectController.oauth1Callback(java.lang.String,org.springframework.web.context.request.NativeWebRequest)
Info:映射{[/ connect / {providerId}],methods = [GET],params = [code],headers = [],consumes = [],产生= [],custom = []}公共org.springframework.web.servlet.view.RedirectView org.springframework.social.connect.web.ConnectController.oauth2Callback(java.lang.String,org.springframework.web.context.request.Nativ eWebRequest)
Info:映射的URL路径[/ resources / **]到类型为[class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]的处理程序
Info:寻找@ControllerAdvice:Root WebApplicationContext:启动日期[Thu May 14 16:06:15 PDT 2015];上下文层次结构的根
信息:使用Hibernate SessionFactory的DataSource [org.apache.commons.dbcp2.BasicDataSource@65a12534]用于HibernateTransactionManager
信息:创建过滤器链:org.springframework.security.web.util。 matcher.AnyRequestMatcher@1,[org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@5b252c00,org.springframework.security.web.context.SecurityContextPersistenceFilter@22de3dd7,org.springframework.security.web.header.HeaderWriterFilter @ 17b3d10,org.springframework.security.web.csrf.CsrfFilter@2bffe1ad,org.springframework.security.web.authentication.logout.LogoutFilter@68a35517,org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter@4d85d53d,org.springframework .security.web.savedrequest.RequestCacheAwareFilter @ 3d704ff,org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@57243fe2,org.springframework.security.web.authentication.AnonymousAuthenticationFi lter @ 53e99103,org.springframework.security.web.session.SessionManagementFilter@1917c313,org.springframework.security.web.access.ExceptionTranslationFilter@7977c9b0,org.springframework.security.web.access.intercept.FilterSecurityInterceptor@a742949]
Info:Root WebApplicationContext:初始化在3718完成ms
Info:WebModule [null] ServletContext.log():初始化Spring FrameworkServlet'DispatcherServlet'
Info:FrameworkServlet'DispatcherServlet':初始化开始
信息:FrameworkServlet'DispatcherServlet':初始化在37毫秒内完成
信息:在[/社交]
中加载应用程序[社交]信息:社交在6,291毫秒内成功部署。
严重:PWC6117:找不到文件null

这是我的社交配置类:

  @Configuration 
@EnableSocial
公共类SocialConfig实现了SocialConfigger {

@Autowired
DataSource dataSource;
$ b $ @Override
public void addConnectionFactories(ConnectionFactoryConfigurer cfConfig,Environment env){
cfConfig.addConnectionFactory(new LinkedInConnectionFactory(consumerKey,consumerSecret));

$ b @Override
public UsersConnectionRepository getUsersConnectionRepository(ConnectionFactoryLocator connectionFactoryLocator){
return new JdbcUsersConnectionRepository(dataSource,connectionFactoryLocator,Encryptors.noOpText());
}

@Override
public UserIdSource getUserIdSource(){
return new AuthenticationNameUserIdSource();

$ b @Bean
public ConnectController connectController(ConnectionFactoryLocator connectionFactoryLocator,ConnectionRepository connectionRepository){
返回新的ConnectController(connectionFactoryLocator,connectionRepository);


这是我的WebAppliactionInitializer类:

  public class WebInitializer实现WebApplicationInitializer {
$ b @Override
public void onStartup(ServletContext servletContext)throws ServletException { b $ b WebApplicationContext context = getContext();
servletContext.addListener(new ContextLoaderListener(context));
ServletRegistration.Dynamic dispatcher = servletContext.addServlet(DispatcherServlet,new DispatcherServlet(context));
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping(/);


private AnnotationConfigWebApplicationContext getContext(){
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
context.setConfigLocation(com.gfz.social.springmvc.config); //所有配置的java包
return context;
}

}

我已经检查过pom.xml。

 <! -  Spring Social  - > 
< dependency>
< groupId> org.springframework.social< / groupId>
< artifactId> spring-social-core< / artifactId>
< version> 1.1.0.RELEASE< / version>
< /依赖关系>

< dependency>
< groupId> org.springframework.social< / groupId>
< artifactId> spring-social-web< / artifactId>
< version> 1.1.0.RELEASE< / version>
< /依赖关系>

< dependency>
< groupId> org.springframework.social< / groupId>
< artifactId> spring-social-security< / artifactId>
< version> 1.1.0.RELEASE< / version>
< /依赖关系>

< dependency>
< groupId> org.springframework.social< / groupId>
< artifactId> spring-social-config< / artifactId>
< version> 1.1.0.RELEASE< / version>
< /依赖关系>

有人可以帮助我吗? (我已经尝试阅读参考代码和展示示例)
谢谢

解决方案

但是您是否在connect / {providerId} Connect或connect / {providerId} Connected中有任何视图(JSP,Thymeleaf或其他)?你有连接/状态的观点吗?如果不是,那么这就是404的一种可能性。

在/ connect路径回答的控制器方法收集应用程序中所有已知提供程序的连接状态信息,然后将其发送到名为connect / status 。对于大多数项目(使用JSP的项目),这意味着您需要一个名为status.jsp的名为/ connect(相对于您的视图保存的位置)的JSP文件。

对于提供者,每个提供者需要2个文件。例如,如果您在处理Facebook,您将请求/ connect / facebook,控制器将收集连接信息并将其发送到名为connect / facebookConnect的视图(如果您没有连接)或connect / facebookConnected(如果你有连接)。这意味着(在JSP情况下),您需要在/connect/facebookConnect.jsp和/connect/facebookConnected.jsp处使用JSP。



查看 https://github.com/spring-projects/spring-social-samples/tree/master/spring-social-showcase 。这个例子使用Thymeleaf而不是JSP,但是它演示了基本的想法。您可以在src / main / resources / views / connect中找到模板。如果这是一个JSP查看的应用程序,您可能会将它们放在src / main / webapp或src / main / webapp下的某个目录中。


I'm trying to configure spring social inside my (maven)spring MVC secured(spring security) application but when I try to access /connect/ or /connect/providerid , I always get error 404

Here is my Glassfish server log when I try to access:

Info:   Mapped "{[/connect/{providerId}],methods=[POST],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.view.RedirectView org.springframework.social.connect.web.ConnectController.connect(java.lang.String,org.springframework.web.context.request.NativeWebRequest)
Info:   Mapped "{[/connect/{providerId}],methods=[DELETE],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.view.RedirectView org.springframework.social.connect.web.ConnectController.removeConnections(java.lang.String,org.springframework.web.context.request.NativeWebRequest)
Info:   Mapped "{[/connect/{providerId}],methods=[GET],params=[error],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.view.RedirectView org.springframework.social.connect.web.ConnectController.oauth2ErrorCallback(java.lang.String,java.lang.String,java.lang.String,java.lang.String,org.springframework.web.context.request.NativeWebRequest)
Info:   Mapped "{[/connect/{providerId}/{providerUserId}],methods=[DELETE],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.view.RedirectView org.springframework.social.connect.web.ConnectController.removeConnection(java.lang.String,java.lang.String,org.springframework.web.context.request.NativeWebRequest)
Info:   Mapped "{[/connect],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String org.springframework.social.connect.web.ConnectController.connectionStatus(org.springframework.web.context.request.NativeWebRequest,org.springframework.ui.Model)
Info:   Mapped "{[/connect/{providerId}],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String org.springframework.social.connect.web.ConnectController.connectionStatus(java.lang.String,org.springframework.web.context.request.NativeWebRequest,org.springframework.ui.Model)
Info:   Mapped "{[/connect/{providerId}],methods=[GET],params=[oauth_token],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.view.RedirectView org.springframework.social.connect.web.ConnectController.oauth1Callback(java.lang.String,org.springframework.web.context.request.NativeWebRequest)
Info:   Mapped "{[/connect/{providerId}],methods=[GET],params=[code],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.view.RedirectView org.springframework.social.connect.web.ConnectController.oauth2Callback(java.lang.String,org.springframework.web.context.request.NativeWebRequest)
Info:   Mapped URL path [/resources/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
Info:   Looking for @ControllerAdvice: Root WebApplicationContext: startup date [Thu May 14 16:06:15 PDT 2015]; root of context hierarchy
Info:   Using DataSource [org.apache.commons.dbcp2.BasicDataSource@65a12534] of Hibernate SessionFactory for HibernateTransactionManager
Info:   Creating filter chain: org.springframework.security.web.util.matcher.AnyRequestMatcher@1, [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@5b252c00, org.springframework.security.web.context.SecurityContextPersistenceFilter@22de3dd7, org.springframework.security.web.header.HeaderWriterFilter@17b3d10, org.springframework.security.web.csrf.CsrfFilter@2bffe1ad, org.springframework.security.web.authentication.logout.LogoutFilter@68a35517, org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter@4d85d53d, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@3d704ff, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@57243fe2, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@53e99103, org.springframework.security.web.session.SessionManagementFilter@1917c313, org.springframework.security.web.access.ExceptionTranslationFilter@7977c9b0, org.springframework.security.web.access.intercept.FilterSecurityInterceptor@a742949]
Info:   Root WebApplicationContext: initialization completed in 3718 ms
Info:   WebModule[null] ServletContext.log():Initializing Spring FrameworkServlet 'DispatcherServlet'
Info:   FrameworkServlet 'DispatcherServlet': initialization started
Info:   FrameworkServlet 'DispatcherServlet': initialization completed in 37 ms
Info:   Loading application [social] at [/social]
Info:   social was successfully deployed in 6,291 milliseconds.
Severe:   PWC6117: File "null" not found

Here is my social config class:

@Configuration
@EnableSocial
public class SocialConfig implements SocialConfigurer {

    @Autowired
    DataSource dataSource;

    @Override
    public void addConnectionFactories(ConnectionFactoryConfigurer cfConfig, Environment env) {
        cfConfig.addConnectionFactory(new LinkedInConnectionFactory("consumerKey", "consumerSecret"));
    }

    @Override
    public UsersConnectionRepository getUsersConnectionRepository(ConnectionFactoryLocator connectionFactoryLocator) {
        return new JdbcUsersConnectionRepository(dataSource, connectionFactoryLocator, Encryptors.noOpText());
    }

    @Override
    public UserIdSource getUserIdSource() {
        return new AuthenticationNameUserIdSource();
    }

    @Bean
    public ConnectController connectController(ConnectionFactoryLocator connectionFactoryLocator, ConnectionRepository connectionRepository) {
        return new ConnectController(connectionFactoryLocator, connectionRepository);
    }
}

Here is my WebAppliactionInitializer class:

public class WebInitializer implements WebApplicationInitializer {

@Override
 public void onStartup(ServletContext servletContext) throws ServletException {
    WebApplicationContext context = getContext();
    servletContext.addListener(new ContextLoaderListener(context));
    ServletRegistration.Dynamic dispatcher = servletContext.addServlet("DispatcherServlet", new DispatcherServlet(context));
    dispatcher.setLoadOnStartup(1);
    dispatcher.addMapping("/");
}

 private AnnotationConfigWebApplicationContext getContext() {
    AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
    context.setConfigLocation("com.gfz.social.springmvc.config"); // java package with all configs
    return context;
}

}

I already checked the pom.xml

<!-- Spring Social -->
<dependency>
    <groupId>org.springframework.social</groupId>
    <artifactId>spring-social-core</artifactId>
        <version>1.1.0.RELEASE</version>
    </dependency>

<dependency>
    <groupId>org.springframework.social</groupId>
    <artifactId>spring-social-web</artifactId>
    <version>1.1.0.RELEASE</version>
</dependency>

<dependency>
    <groupId>org.springframework.social</groupId>
    <artifactId>spring-social-security</artifactId>
    <version>1.1.0.RELEASE</version>
</dependency>

<dependency>
    <groupId>org.springframework.social</groupId>
    <artifactId>spring-social-config</artifactId>
    <version>1.1.0.RELEASE</version>
</dependency>

Someone can help me? (I've already tried to read the reference code and the showcase examples) Thanks

解决方案

Just a guess, but do you happen to have any views (JSP, Thymeleaf, or otherwise) at "connect/{providerId}Connect" or "connect/{providerId}Connected"? Do you have a view at "connect/status" ? If not, then that's one possibility for the 404s.

The controller method answering at the "/connect" path collects connection status information for all known providers in the app and then sends that on to a view named "connect/status". For most projects (those using JSP), this means that you need a JSP file named "status.jsp" in a directory named "/connect" (relative to where your views are kept).

For a provider, you'll need 2 files for each provider. For example, if you're dealing with Facebook, you'll request "/connect/facebook" and the controller will collect connection information and send it on to a view named "connect/facebookConnect" (if you don't have a connection) or "connect/facebookConnected" (if you do have a connection). This means (in the JSP case) you'll need JSPs at "/connect/facebookConnect.jsp" and "/connect/facebookConnected.jsp".

Take a look at https://github.com/spring-projects/spring-social-samples/tree/master/spring-social-showcase. This example uses Thymeleaf instead of JSP, but it demonstrates the basic idea. You'll find the templates in src/main/resources/views/connect. If this was a JSP-viewed application, you'd likely put them in src/main/webapp or some directory underneath src/main/webapp.

这篇关于春季社交/连接返回404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆