Skip to content

Instantly share code, notes, and snippets.

@sfussenegger
Created May 16, 2011 15:13
Show Gist options
  • Save sfussenegger/974620 to your computer and use it in GitHub Desktop.
Save sfussenegger/974620 to your computer and use it in GitHub Desktop.
Spring configuration for spring-social with spring-security, i.e. spring-social-security
<dependencies>
<dependency>
<groupId>at.molindo.social</groupId>
<artifactId>spring-social-security</artifactId>
<version>1.0.0.BUILD-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>at.molindo.social</groupId>
<artifactId>spring-social-facebook-security</artifactId>
<version>1.0.0.BUILD-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.social</groupId>
<artifactId>spring-social-twitter</artifactId>
<version>1.0.0.BUILD-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>org.springframework.social</groupId>
<artifactId>spring-social-core</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<repositories>
<repository>
<id>sonatype-nexus-snapshots</id>
<name>Sonatype Nexus Snapshots</name>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<releases><enabled>false</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:security="http://www.springframework.org/schema/security"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
">
<security:authentication-manager alias="authManager">
<security:authentication-provider ref="socialAuthenticationProvider" />
</security:authentication-manager>
<!-- START servlet filters -->
<bean id="springSecurityFilter" class="org.springframework.security.web.FilterChainProxy">
<security:filter-chain-map path-type="ant">
<security:filter-chain pattern="/**" filters="httpSessionContextIntegrationFilter,socialAuthFilter" />
</security:filter-chain-map>
</bean>
<bean id="httpSessionContextIntegrationFilter"
class="org.springframework.security.web.context.SecurityContextPersistenceFilter" />
<bean id="socialAuthFilter" class="org.springframework.social.security.SocialAuthenticationFilter">
<property name="authManager" ref="authManager" />
<property name="filterProcessesUrl" value="/auth" />
<property name="rememberMeServices" ref="rememberMeService" />
<property name="usersConnectionRepository" ref="usersConnectionRepository" />
<property name="userIdExtractor">
<bean class="org.example.UserAccountIdExtractor" />
</property>
<property name="authServiceLocator" ref="connectionFactoryLocator" />
</bean>
<!-- END servlet filters -->
<!-- START social auth -->
<bean id="socialAuthenticationProvider" class="org.springframework.social.security.SocialAuthenticationProvider">
<property name="usersConnectionRepository" ref="usersConnectionRepository" />
<property name="userDetailsService" ref="userDetailsService" />
</bean>
<bean id="connectionFactoryRegistry" class="org.springframework.social.security.SocialAuthenticationServiceRegistry">
<property name="authenticationServices">
<util:list>
<bean class="org.springframework.social.facebook.security.FacebookCookieAuthenticationService">
<property name="connectionFactory">
<bean class="org.springframework.social.facebook.connect.FacebookConnectionFactory">
<constructor-arg index="0" value="${org.example.facebook.appId}" />
<constructor-arg index="1" value="${org.example.facebook.secret}" />
</bean>
</property>
<property name="OAuthEnabled" value="true" />
<property name="appId" value="${org.example.facebook.appId}" />
<property name="appSecret" value="${org.example.facebook.secret}" />
</bean>
<bean class="org.springframework.social.security.provider.OAuth1AuthenticationService">
<property name="connectionFactory">
<bean class="org.springframework.social.twitter.connect.TwitterConnectionFactory">
<constructor-arg index="0" value="${org.example.twitter.key}" />
<constructor-arg index="1" value="${org.example.twitter.secret}" />
</bean>
</property>
</bean>
</util:list>
</property>
</bean>
<alias name="connectionFactoryRegistry" alias="connectionFactoryLocator" />
<!-- END social auth -->
</beans>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment