Skip to content

Demonstrates adding spring-social and spring-social-security capability to a Roo generated project using SocialSignin ProviderService modules for component-scanning configuration and to provide a thin API access abstraction layer. Also showcases spring-social-roo-connection-repository, a Roo-persitence backed ConnectionRepository implementation

Notifications You must be signed in to change notification settings

socialsignin/socialsignin-roo-showcase

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

52 Commits
 
 
 
 
 
 
 
 

Repository files navigation

socialsignin-roo-showcase

This project demonstrates how to add spring-social capability to a Roo generated project, using a number of SocialSignin projects to help developers to get up and running quickly:

  • spring-social-security is used for local-user authentication based on third party connection status, removing the need for local username/password account management

  • socialsignin-provider modules are used, allowing

    • developers to obtain and interact with spring-social APIs directly for a number of common-use cases, rather than dealing with lower-level spring-social connection API

    • easy configuration and registration of spring-social components through component-scanning

  • spring-social-roo-connection-repository is used to enable Roo-backed JPA persistence to be used to store connections instead of using the Jdbc versions in the spring-social-core library.

To run this application:

This project was created using Roo as follows:

project --topLevelPackage org.socialsignin.roo.showcase --projectName socialsignin-roo-showcase --java 6 --packaging JAR
web mvc setup
security setup
jpa setup --provider HIBERNATE --database HYPERSONIC_IN_MEMORY

  • SocialSignIn repo and dependencies added to pom:
  <repository>
    	<id>opensourceagility-snapshots</id>
   		<url>http://repo.opensourceagility.com/snapshots </url>
	</repository>
 <!-- Start SocialSignin dependencies -->
		<dependency>
			<groupId>org.socialsignin</groupId>
			<artifactId>socialsignin-twitter</artifactId>
			<version>1.1.0-SNAPSHOT</version>
		</dependency>
		<dependency>
			<groupId>javax.persistence</groupId>
			<artifactId>persistence-api</artifactId>
			<version>1.0</version>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>cglib</groupId>
			<artifactId>cglib</artifactId>
			<version>2.2.2</version>
		</dependency>
		<dependency>
			<groupId>org.socialsignin</groupId>
			<artifactId>spring-social-security</artifactId>
			<version>1.1.0-SNAPSHOT</version>
		</dependency>
		<dependency>
			<groupId>org.springframework.social</groupId>
			<artifactId>spring-social-roo-connectionrepository</artifactId>
			<version>1.1.0-SNAPSHOT</version>
		</dependency>
			<dependency>
			<groupId>org.springframework.social</groupId>
			<artifactId>spring-social-config-extension</artifactId>
			<version>1.1.0-SNAPSHOT</version>
		</dependency>
		<!-- End SocialSignin dependencies -->

  • Showcase code created:

  • View modifications to support this showcase code

    Added showcase instructions and a link to ShowcaseController url to index.jspx

    Created sociallogin.jspx to support a user logging in via a third-party-provider and signUpForm.jspx for username selection on signup, made some minor amendments to existing header to display logged in status, and added messages to messages.properties to support these views. Created corresponding tiles view definitions.

    AuthenticationDetailViewPreparer component created and wired into default.jspx default.jspx, so as to make authentication information available to all views.

  • Config modifications to support this showcase code

    Properties file created

    SocialConfig configuration class created

     <class>org.springframework.social.connect.roo.UserConnection</class> 
    

    added to persistence.xml

    Modified applicationContext.xml, applicationContext-security.xml and webmvc-config.xml as follows:

    In applicationContext.xml, component scan for SocialSignIn Provider modules, Spring Social Security and Roo-based UsersConnectionRepository

     	<context:component-scan base-package="org.socialsignin.provider"/>
     
     	<!--  Component scan for Spring Social Security  -->
     	<context:component-scan base-package="org.socialsignin.springsocial.security"/>
     
     	<!--  Component scan for Roo managed peristence for ConnectionRepository  -->
     	<context:component-scan base-package="org.springframework.social.connect.roo">
         	<context:exclude-filter expression=".*_Roo_.*" type="regex"/>
     	</context:component-scan>   
    

    In applicationContext-security.xml

    Create an entry point for your security

     	<beans:bean id="springSocialSecurityEntryPoint" class="org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint">
     <beans:property name="loginFormUrl" value="/sociallogin"/>
     </beans:bean>
    

    Replace form-login element with

     <custom-filter position="FORM_LOGIN_FILTER" ref="springSocialSecurityAuthenticationFilter" />
    

    set autoconfig= false and add entry-point-ref="springSocialSecurityEntryPoint".

    Add reference to spring-social-security access denied handler for provider-specific access denied pages

     <access-denied-handler ref="springSocialSecurityAccessDeniedHandler"/>
    

    Remove authenticated provider definition from the authentication manager bean

    Protect our resources:

         <intercept-url pattern="/myTweets" access="hasRole('ROLE_USER_TWITTER')" />
         <intercept-url pattern="/promote" access="hasRole('ROLE_USER_TWITTER')" />
         <intercept-url pattern="/announce" access="hasRole('ROLE_USER_TWITTER')" />
    

    Add optional remember-me support

    In webmvc-config.xml

    Added component scan for org.socialsignin.springsocial.security package to allow SignUpController to be registered

    Added property placeholder configuration to allow our socialsignin.properties file to be picked up by web components.

    Added a preparer factory to tiles configurer, allowing application to use view preparer spring beans to provide auth information to all views.

     <property name="preparerFactoryClass" value= "org.springframework.web.servlet.view.tiles2.SpringBeanPreparerFactory"/>
    

    Added Spring-Social's ProviderSignInController and ConnectController to allow application to perform OAuth-dance.

     <bean class="org.springframework.social.connect.web.ConnectController">
     		<property name="interceptors" ref="connectInterceptorList" />
     </bean>
    
         <bean class="org.springframework.social.connect.web.ProviderSignInController" >
     	<property name="signUpUrl" value="/signup" />
     	<property name="postSignInUrl" value="/authenticate" />
     </bean>
    

    Note that here we are wiring in spring-social-security's connectInterceptorList to ensure uniqueness of social connections amonsgt users and to add provider-specific authentication roles to be granted to the user. We send the postSignInUrl to "/authenticate" which is the url registered for our authentication filter.

    Changed "login" to "sociallogin" in view-controller path so our social login view is accessible

About

Demonstrates adding spring-social and spring-social-security capability to a Roo generated project using SocialSignin ProviderService modules for component-scanning configuration and to provide a thin API access abstraction layer. Also showcases spring-social-roo-connection-repository, a Roo-persitence backed ConnectionRepository implementation

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published