Quantcast
Channel: Spring Community Forums - Social
Viewing all articles
Browse latest Browse all 145

How to use org.springframework.social.security.SocialAuthenti cationFilter?

$
0
0
Hi,

I'm trying to use org.springframework.social.security classes before they are released, so please help me if you can. My question is how to use SocialAuthenticationFilter.

In Spring Social QuickStart example, there is ProviderSignInController to handle OAuth dance. If I use SocialAuthenticationFilter, do I still need it or not?

Here is the security.xml:

Code:

        <http use-expressions="true" entry-point-ref="socialAuthenticationEntryPoint">
                <custom-filter position="PRE_AUTH_FILTER" ref="socialAuthenticationFilter" />
                <logout logout-url="/signout" delete-cookies="JSESSIONID" />
                <intercept-url pattern="/resources/**" access="permitAll" />
                <intercept-url pattern="/signin" access="permitAll" />
                <intercept-url pattern="/signin/*" access="permitAll" />
                <intercept-url pattern="/admin/**" access="hasRole('ROLE_ADMIN')" />
                <intercept-url pattern="/**" access="permitAll" />
        </http>

        <authentication-manager alias="authenticationManager">
                <authentication-provider ref="socialAuthenticationProvider" />
        </authentication-manager>

The JavaConfig with related configuration beans:

Code:

    @Bean
    public SocialAuthenticationServiceLocator socialAuthenticationServiceLocator() {
        SocialAuthenticationServiceRegistry registry = new SocialAuthenticationServiceRegistry();
        OAuth2ConnectionFactory<Google> googleConnectionFactory = new GoogleConnectionFactory(environment.getProperty("google.clientId"),
                environment.getProperty("google.clientSecret"));
        OAuth2AuthenticationService<Google> googleAuthenticationService = new OAuth2AuthenticationService<Google>(googleConnectionFactory);
        googleAuthenticationService.setScope("https://www.googleapis.com/auth/userinfo.profile");
        registry.addAuthenticationService(googleAuthenticationService);
        return registry;
    }

    @Inject
    private AuthenticationManager authenticationManager;

    @Bean
    public SocialAuthenticationFilter socialAuthenticationFilter() {
        SocialAuthenticationFilter filter = new SocialAuthenticationFilter(authenticationManager, accountService(),
                usersConnectionRepository(), socialAuthenticationServiceLocator());
        filter.setFilterProcessesUrl("/signin");
        return filter;
    }

    @Bean
    public SocialAuthenticationProvider socialAuthenticationProvider(){
        return new SocialAuthenticationProvider(usersConnectionRepository(), accountService());
    }
   
    @Bean
    public LoginUrlAuthenticationEntryPoint socialAuthenticationEntryPoint(){
        return new LoginUrlAuthenticationEntryPoint("/signin");
    }

Not sure this is the correct way to use it.

So far I can sign in with google, but still struggle with SocialAuthenticationToken.

Thanks.

Viewing all articles
Browse latest Browse all 145

Trending Articles