Grails Spring Security Facebook插件 - Connect按钮不会重定向到Facebook

时间:2015-07-22 09:44:59

标签: spring facebook maven grails spring-security

我在登录时成功使用Spring Security进行注册。现在我想通过Spring Security Facebook Plugin实现登录并注册Facebook帐户。

我成功运行了(demo application)但是当我尝试关注documentation时,我没有在我自己的应用程序中定向到Facebook来执行登录,但始终是:

http://localhost:8080/MYAPP/j_spring_security_facebook_redirect

因为我正在使用maven,我的依赖项位于pom.xml中,相关部分如下所示:

<dependency>
        <groupId>org.grails.plugins</groupId>
        <artifactId>spring-security-core</artifactId>
        <version>2.0-RC4</version>
        <scope>compile</scope>
        <type>zip</type>
    </dependency>

    <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-facebook</artifactId>
        <version>2.0.1.RELEASE</version>
    </dependency>

    <!-- Facebook Spring Social Plugin -->
    <dependency>
        <groupId>org.grails.plugins</groupId>
        <artifactId>spring-security-facebook</artifactId>
        <version>0.17</version>
        <type>zip</type>
    </dependency>

我还实施了FacebookUser域名:

class FacebookUser {

long uid
String accessToken
Date accessTokenExpires

static belongsTo = [User]

static constraints = {
    uid unique: true
}

/* static mapWith = "mongo" */
}

在我的视图中,我有以下连接按钮的代码:

<facebookAuth:connect />

我的Config.groovy:

grails {
plugin {
    springsecurity {
        facebook {
            domain.classname='de.<MYDOMAIN>.<MYAPP>.FacebookUser'
            host='<MYDOMAIN>.de'

            domain.appUserConnectionPropertyName = 'User'
            appId = "<MYFBAPPID>"
            secret = "<MYFBSECRET>"

所以我不明白&#34; j_spring_security_facebook_redirect&#34;的映射在哪里?在演示应用程序中完成,我的应用程序中缺少的是打开Facebook网站而不是http://localhost:8080/MYAPP/j_spring_security_facebook_redirect

感谢任何提示!

更新

问题似乎出现在我的Config.groovy中,因为如果我删除配置的providerNames和filterNames它可以工作,但我需要配置,所以我不能删除它们,需要添加缺少的过滤器和提供程序。

graisl.plugin.springsecurity.providerNames = ['...', '...']
graisl.plugin.springsecurity.filterChain.filterNames = ['...', '...']

我使用所需的过滤器更新了提供者数据(在演示应用程序中记录它们),但它找不到它们:

providerNames = [
                'tokenAuthenticationProvider',
                'daoAuthenticationProvider',
                'rememberMeAuthenticationProvider',
                'FacebookAuthProvider'
        ]

        filterChain.filterNames = [
                'securityContextPersistenceFilter',
                'logoutFilter',
                'authenticationProcessingFilter',
                'tokenAuthenticationFilter',
                'basicAuthenticationFilter',
                'rememberMeAuthenticationFilter',
                'anonymousAuthenticationFilter',
                'exceptionTranslationFilter',
                'filterInvocationInterceptor',
                /* Facebook Security Filters */
                'MutableLogoutFilter',
                'FacebookAuthRedirectFilter',
                'RequestHolderAuthenticationFilter',
                'SecurityContextHolderAwareRequestFilter',
                'GrailsRememberMeAuthenticationFilter',
                'GrailsAnonymousAuthenticationFilter',
                'ExceptionTranslationFilter',
                'FilterSecurityInterceptor'
        ]

启动错误:

ERROR context.GrailsContextLoaderListener  - Error initializing the  application: No bean named 'FacebookAuthProvider' is defined

消息:没有名为&#39; FacebookAuthProvider&#39;已定义

1 个答案:

答案 0 :(得分:0)

最后解决了,这是我的相关Config.groovy grails.plugin.springsecurity ...现在:

            providerNames = [
                'tokenAuthenticationProvider',
                'daoAuthenticationProvider',
                'rememberMeAuthenticationProvider',
                /* Facebook Security Provider */
                'facebookAuthProvider'
        ]

        filterChain.filterNames = [
                'securityContextPersistenceFilter',
                'logoutFilter',
                'authenticationProcessingFilter',
                'tokenAuthenticationFilter',
                'basicAuthenticationFilter',
                'rememberMeAuthenticationFilter',
                'anonymousAuthenticationFilter',
                'exceptionTranslationFilter',
                'filterInvocationInterceptor',
                /* Facebook Security Filters */
                'facebookAuthRedirectFilter',
                'securityContextHolderAwareRequestFilter',
                'exceptionTranslationFilter',
        ]