Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial Commit

  • Loading branch information...
commit 4224071b51b279a0c2bbe5d0d89a26b1a8f175f5 0 parents
@sachin-handiekar authored
Showing with 1,579 additions and 0 deletions.
  1. +6 −0 README.md
  2. +11 −0 spring-social-500px-quickstart/.classpath
  3. +42 −0 spring-social-500px-quickstart/.project
  4. +12 −0 spring-social-500px-quickstart/.settings/.jsdtscope
  5. +8 −0 spring-social-500px-quickstart/.settings/org.eclipse.jdt.core.prefs
  6. +4 −0 spring-social-500px-quickstart/.settings/org.eclipse.m2e.core.prefs
  7. +13 −0 spring-social-500px-quickstart/.settings/org.eclipse.wst.common.component
  8. +7 −0 spring-social-500px-quickstart/.settings/org.eclipse.wst.common.project.facet.core.xml
  9. +1 −0  spring-social-500px-quickstart/.settings/org.eclipse.wst.jsdt.ui.superType.container
  10. +1 −0  spring-social-500px-quickstart/.settings/org.eclipse.wst.jsdt.ui.superType.name
  11. +10 −0 spring-social-500px-quickstart/README
  12. +137 −0 spring-social-500px-quickstart/pom.xml
  13. +49 −0 spring-social-500px-quickstart/src/main/java/org/springframework/social/quickstart/HomeController.java
  14. +58 −0 spring-social-500px-quickstart/src/main/java/org/springframework/social/quickstart/config/MainConfig.java
  15. +103 −0 spring-social-500px-quickstart/src/main/java/org/springframework/social/quickstart/config/SocialConfig.java
  16. +59 −0 spring-social-500px-quickstart/src/main/java/org/springframework/social/quickstart/config/WebMvcConfig.java
  17. +2 −0  ...g-social-500px-quickstart/src/main/java/org/springframework/social/quickstart/config/application.properties
  18. +4 −0 spring-social-500px-quickstart/src/main/java/org/springframework/social/quickstart/config/package-info.java
  19. +4 −0 spring-social-500px-quickstart/src/main/java/org/springframework/social/quickstart/package-info.java
  20. +46 −0 spring-social-500px-quickstart/src/main/java/org/springframework/social/quickstart/user/SecurityContext.java
  21. +36 −0 ...ocial-500px-quickstart/src/main/java/org/springframework/social/quickstart/user/SimpleConnectionSignUp.java
  22. +42 −0 ...g-social-500px-quickstart/src/main/java/org/springframework/social/quickstart/user/SimpleSignInAdapter.java
  23. +35 −0 spring-social-500px-quickstart/src/main/java/org/springframework/social/quickstart/user/User.java
  24. +57 −0 ...g-social-500px-quickstart/src/main/java/org/springframework/social/quickstart/user/UserCookieGenerator.java
  25. +92 −0 spring-social-500px-quickstart/src/main/java/org/springframework/social/quickstart/user/UserInterceptor.java
  26. +4 −0 spring-social-500px-quickstart/src/main/java/org/springframework/social/quickstart/user/package-info.java
  27. +3 −0  spring-social-500px-quickstart/src/main/webapp/META-INF/MANIFEST.MF
  28. +25 −0 spring-social-500px-quickstart/src/main/webapp/WEB-INF/views/home.jsp
  29. +12 −0 spring-social-500px-quickstart/src/main/webapp/WEB-INF/views/signin.jsp
  30. +85 −0 spring-social-500px-quickstart/src/main/webapp/WEB-INF/web.xml
  31. +12 −0 spring-social-500px/.classpath
  32. +36 −0 spring-social-500px/.project
  33. +8 −0 spring-social-500px/.settings/org.eclipse.jdt.core.prefs
  34. +4 −0 spring-social-500px/.settings/org.eclipse.m2e.core.prefs
  35. +7 −0 spring-social-500px/.settings/org.eclipse.wst.common.component
  36. +5 −0 spring-social-500px/.settings/org.eclipse.wst.common.project.facet.core.xml
  37. +82 −0 spring-social-500px/pom.xml
  38. +9 −0 spring-social-500px/src/main/java/org/springframework/social/fivepx/api/Fivepx.java
  39. +145 −0 spring-social-500px/src/main/java/org/springframework/social/fivepx/api/FivepxProfile.java
  40. +16 −0 spring-social-500px/src/main/java/org/springframework/social/fivepx/api/UserOperations.java
  41. +42 −0 spring-social-500px/src/main/java/org/springframework/social/fivepx/api/impl/AbstractFivepxOperations.java
  42. +18 −0 spring-social-500px/src/main/java/org/springframework/social/fivepx/api/impl/FivepxModule.java
  43. +69 −0 spring-social-500px/src/main/java/org/springframework/social/fivepx/api/impl/FivepxProfileMixin.java
  44. +35 −0 spring-social-500px/src/main/java/org/springframework/social/fivepx/api/impl/FivepxTemplate.java
  45. +49 −0 spring-social-500px/src/main/java/org/springframework/social/fivepx/api/impl/UserTemplate.java
  46. +44 −0 spring-social-500px/src/main/java/org/springframework/social/fivepx/connect/FivepxAdapter.java
  47. +10 −0 spring-social-500px/src/main/java/org/springframework/social/fivepx/connect/FivepxConnectionFactory.java
  48. +20 −0 spring-social-500px/src/main/java/org/springframework/social/fivepx/connect/FivepxServiceProvider.java
6 README.md
@@ -0,0 +1,6 @@
+#Spring Social 500px
+
+spring-social-500px - Library sources
+spring-social-500px-quickstart - Example application
+
+Live Example: http://500px-demo.cloudfoundry.com/
11 spring-social-500px-quickstart/.classpath
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry including="**/*.java" kind="src" output="target/classes" path="src/main/java"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
+ <attributes>
+ <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="output" path="target/classes"/>
+</classpath>
42 spring-social-500px-quickstart/.project
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>spring-social-quickstart</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.wst.jsdt.core.javascriptValidator</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.wst.common.project.facet.core.builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.wst.validation.validationbuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.m2e.core.maven2Builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
+ <nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.eclipse.m2e.core.maven2Nature</nature>
+ <nature>org.eclipse.wst.common.project.facet.core.nature</nature>
+ <nature>org.eclipse.wst.jsdt.core.jsNature</nature>
+ </natures>
+</projectDescription>
12 spring-social-500px-quickstart/.settings/.jsdtscope
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src/main/webapp"/>
+ <classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.WebProject">
+ <attributes>
+ <attribute name="hide" value="true"/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.baseBrowserLibrary"/>
+ <classpathentry kind="output" path=""/>
+</classpath>
8 spring-social-500px-quickstart/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,8 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
+org.eclipse.jdt.core.compiler.source=1.6
4 spring-social-500px-quickstart/.settings/org.eclipse.m2e.core.prefs
@@ -0,0 +1,4 @@
+activeProfiles=
+eclipse.preferences.version=1
+resolveWorkspaceProjects=true
+version=1
13 spring-social-500px-quickstart/.settings/org.eclipse.wst.common.component
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project-modules id="moduleCoreId" project-version="1.5.0">
+ <wb-module deploy-name="spring-social-quickstart">
+ <wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
+ <wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
+ <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
+ <dependent-module archiveName="spring-social-500px-1.0.0-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/spring-social-500px/spring-social-500px">
+ <dependency-type>uses</dependency-type>
+ </dependent-module>
+ <property name="java-output-path" value="/spring-social-quickstart/target/classes"/>
+ <property name="context-root" value="spring-social-test-500px"/>
+ </wb-module>
+</project-modules>
7 spring-social-500px-quickstart/.settings/org.eclipse.wst.common.project.facet.core.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<faceted-project>
+ <fixed facet="wst.jsdt.web"/>
+ <installed facet="java" version="1.6"/>
+ <installed facet="jst.web" version="2.5"/>
+ <installed facet="wst.jsdt.web" version="1.0"/>
+</faceted-project>
1  spring-social-500px-quickstart/.settings/org.eclipse.wst.jsdt.ui.superType.container
@@ -0,0 +1 @@
+org.eclipse.wst.jsdt.launching.baseBrowserLibrary
1  spring-social-500px-quickstart/.settings/org.eclipse.wst.jsdt.ui.superType.name
@@ -0,0 +1 @@
+Window
10 spring-social-500px-quickstart/README
@@ -0,0 +1,10 @@
+This sample is designed to get you up and running quickly.
+See the walkthrough at: https://github.com/SpringSource/spring-social/wiki/Quick-Start
+
+To run, simply import the project into your IDE and deploy to a Servlet 2.5 or > container such as Tomcat 6 or 7.
+You can also deploy from the command line with:
+$ mvn tomcat:run
+
+Access the project at http://localhost:8080/spring-social-quickstart
+
+Discuss at forum.springsource.org and collaborate with the development team at jira.springframework.org/browse/SOCIAL.
137 spring-social-500px-quickstart/pom.xml
@@ -0,0 +1,137 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.springframework.social</groupId>
+ <artifactId>spring-social-test-500px</artifactId>
+ <name>Spring Social Test 500px</name>
+ <packaging>war</packaging>
+ <version>1.0.0</version>
+ <properties>
+ <java-version>1.6</java-version>
+ <org.springframework.social-version>1.1.0.BUILD-SNAPSHOT</org.springframework.social-version>
+ <org.springframework.social.500px-version>1.0.0-SNAPSHOT</org.springframework.social.500px-version>
+ <org.springframework-version>3.1.1.RELEASE</org.springframework-version>
+ <org.springframework.security.crypto-version>3.1.0.RELEASE</org.springframework.security.crypto-version>
+ </properties>
+ <dependencies>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-webmvc</artifactId>
+ <version>${org.springframework-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-jdbc</artifactId>
+ <version>${org.springframework-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.social</groupId>
+ <artifactId>spring-social-core</artifactId>
+ <version>${org.springframework.social-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.social</groupId>
+ <artifactId>spring-social-web</artifactId>
+ <version>${org.springframework.social-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.social</groupId>
+ <artifactId>spring-social-500px</artifactId>
+ <version>${org.springframework.social.500px-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.security</groupId>
+ <artifactId>spring-security-crypto</artifactId>
+ <version>${org.springframework.security.crypto-version}</version>
+ </dependency>
+ <dependency>
+ <groupId>com.h2database</groupId>
+ <artifactId>h2</artifactId>
+ <version>1.3.159</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.5</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet.jsp</groupId>
+ <artifactId>jsp-api</artifactId>
+ <version>2.1</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>javax.servlet.jsp.jstl</groupId>
+ <artifactId>jstl-api</artifactId>
+ <version>1.2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.web</groupId>
+ <artifactId>jstl-impl</artifactId>
+ <version>1.2</version>
+ </dependency>
+ <!-- CGLIB, only required and used for @Configuration usage: could be removed in future release of Spring -->
+ <dependency>
+ <groupId>cglib</groupId>
+ <artifactId>cglib-nodep</artifactId>
+ <version>2.2</version>
+ </dependency>
+ </dependencies>
+ <repositories>
+ <repository>
+ <id>org.springframework.maven.release</id>
+ <name>Spring Maven Release Repository</name>
+ <url>http://maven.springframework.org/release</url>
+ <releases><enabled>true</enabled></releases>
+ <snapshots><enabled>false</enabled></snapshots>
+ </repository>
+ <!-- For testing against latest Spring snapshots -->
+ <repository>
+ <id>org.springframework.maven.snapshot</id>
+ <name>Spring Maven Snapshot Repository</name>
+ <url>http://maven.springframework.org/snapshot</url>
+ <releases><enabled>false</enabled></releases>
+ <snapshots><enabled>true</enabled></snapshots>
+ </repository>
+ <!-- For developing against latest Spring milestones -->
+ <repository>
+ <id>org.springframework.maven.milestone</id>
+ <name>Spring Maven Milestone Repository</name>
+ <url>http://maven.springframework.org/milestone</url>
+ <snapshots><enabled>false</enabled></snapshots>
+ </repository>
+ </repositories>
+ <build>
+ <resources>
+ <resource>
+ <directory>src/main/java</directory>
+ </resource>
+ </resources>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.3.2</version>
+ <configuration>
+ <source>${java-version}</source>
+ <target>${java-version}</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-war-plugin</artifactId>
+ <version>2.1.1</version>
+ <configuration>
+ <warName>spring-social-quickstart</warName>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>tomcat-maven-plugin</artifactId>
+ <version>1.1</version>
+ </plugin>
+ </plugins>
+ </build>
+</project>
49 spring-social-500px-quickstart/src/main/java/org/springframework/social/quickstart/HomeController.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2011 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.social.quickstart;
+
+import javax.inject.Inject;
+
+import org.springframework.social.fivepx.api.Fivepx;
+import org.springframework.social.fivepx.api.FivepxProfile;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+
+/**
+ * Simple little @Controller that invokes Fivepx and renders the result. The injected {@link Fivepx} reference is
+ * configured with the required authorization credentials for the current user behind the scenes.
+ * @author Keith Donald
+ */
+@Controller
+public class HomeController {
+
+ private final Fivepx fivepx;
+
+ @Inject
+ public HomeController(Fivepx fivepx) {
+ this.fivepx = fivepx;
+ }
+
+ @RequestMapping(value = "/", method = RequestMethod.GET)
+ public String home(Model model) {
+ FivepxProfile profile = fivepx.userOperations().getUserProfile();
+ model.addAttribute("profile", profile);
+ return "home";
+ }
+
+}
58 spring-social-500px-quickstart/src/main/java/org/springframework/social/quickstart/config/MainConfig.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2011 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.social.quickstart.config;
+
+import javax.sql.DataSource;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.ComponentScan.Filter;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.PropertySource;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseFactory;
+import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
+import org.springframework.jdbc.datasource.init.DatabasePopulator;
+import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
+import org.springframework.social.connect.jdbc.JdbcUsersConnectionRepository;
+
+/**
+ * Main configuration class for the application.
+ * Turns on @Component scanning, loads externalized application.properties, and sets up the database.
+ * @author Keith Donald
+ */
+@Configuration
+@ComponentScan(basePackages = "org.springframework.social.quickstart", excludeFilters = { @Filter(Configuration.class) })
+@PropertySource("classpath:org/springframework/social/quickstart/config/application.properties")
+public class MainConfig {
+
+ @Bean(destroyMethod = "shutdown")
+ public DataSource dataSource() {
+ EmbeddedDatabaseFactory factory = new EmbeddedDatabaseFactory();
+ factory.setDatabaseName("spring-social-quickstart");
+ factory.setDatabaseType(EmbeddedDatabaseType.H2);
+ factory.setDatabasePopulator(databasePopulator());
+ return factory.getDatabase();
+ }
+
+ // internal helpers
+
+ private DatabasePopulator databasePopulator() {
+ ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
+ populator.addScript(new ClassPathResource("JdbcUsersConnectionRepository.sql", JdbcUsersConnectionRepository.class));
+ return populator;
+ }
+}
103 spring-social-500px-quickstart/src/main/java/org/springframework/social/quickstart/config/SocialConfig.java
@@ -0,0 +1,103 @@
+/*
+ * Copyright 2011 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.social.quickstart.config;
+
+import javax.inject.Inject;
+import javax.sql.DataSource;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Scope;
+import org.springframework.context.annotation.ScopedProxyMode;
+import org.springframework.core.env.Environment;
+import org.springframework.security.crypto.encrypt.Encryptors;
+import org.springframework.social.connect.ConnectionFactory;
+import org.springframework.social.connect.ConnectionFactoryLocator;
+import org.springframework.social.connect.ConnectionRepository;
+import org.springframework.social.connect.NotConnectedException;
+import org.springframework.social.connect.UsersConnectionRepository;
+import org.springframework.social.connect.jdbc.JdbcUsersConnectionRepository;
+import org.springframework.social.connect.support.ConnectionFactoryRegistry;
+import org.springframework.social.connect.web.ProviderSignInController;
+import org.springframework.social.fivepx.api.Fivepx;
+import org.springframework.social.fivepx.connect.FivepxConnectionFactory;
+import org.springframework.social.quickstart.user.SecurityContext;
+import org.springframework.social.quickstart.user.SimpleConnectionSignUp;
+import org.springframework.social.quickstart.user.SimpleSignInAdapter;
+import org.springframework.social.quickstart.user.User;
+
+@Configuration
+public class SocialConfig {
+
+ @Inject
+ private Environment environment;
+
+ @Inject
+ private DataSource dataSource;
+
+ /**
+ * When a new provider is added to the app, register its {@link ConnectionFactory} here.
+ * @see FivepxConnectionFactory
+ */
+ @Bean
+ public ConnectionFactoryLocator connectionFactoryLocator() {
+ ConnectionFactoryRegistry registry = new ConnectionFactoryRegistry();
+ registry.addConnectionFactory(new FivepxConnectionFactory(environment.getProperty("fivepx.clientId"),
+ environment.getProperty("fivepx.clientSecret")));
+ return registry;
+ }
+
+ /**
+ * Singleton data access object providing access to connections across all users.
+ */
+ @Bean
+ public UsersConnectionRepository usersConnectionRepository() {
+ JdbcUsersConnectionRepository repository = new JdbcUsersConnectionRepository(dataSource,
+ connectionFactoryLocator(), Encryptors.noOpText());
+ repository.setConnectionSignUp(new SimpleConnectionSignUp());
+ return repository;
+ }
+
+ /**
+ * Request-scoped data access object providing access to the current user's connections.
+ */
+ @Bean
+ @Scope(value = "request", proxyMode = ScopedProxyMode.INTERFACES)
+ public ConnectionRepository connectionRepository() {
+ User user = SecurityContext.getCurrentUser();
+ return usersConnectionRepository().createConnectionRepository(user.getId());
+ }
+
+ /**
+ * A proxy to a request-scoped object representing the current user's primary 500px account.
+ * @throws NotConnectedException if the user is not connected to 500px.
+ */
+ @Bean
+ @Scope(value = "request", proxyMode = ScopedProxyMode.INTERFACES)
+ public Fivepx fivepx() {
+ return connectionRepository().getPrimaryConnection(Fivepx.class).getApi();
+ }
+
+ /**
+ * The Spring MVC Controller that allows users to sign-in with their provider accounts.
+ */
+ @Bean
+ public ProviderSignInController providerSignInController() {
+ return new ProviderSignInController(connectionFactoryLocator(), usersConnectionRepository(),
+ new SimpleSignInAdapter());
+ }
+
+}
59 spring-social-500px-quickstart/src/main/java/org/springframework/social/quickstart/config/WebMvcConfig.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2011 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.social.quickstart.config;
+
+import javax.inject.Inject;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.social.connect.UsersConnectionRepository;
+import org.springframework.social.quickstart.user.UserInterceptor;
+import org.springframework.web.servlet.ViewResolver;
+import org.springframework.web.servlet.config.annotation.EnableWebMvc;
+import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
+import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
+import org.springframework.web.servlet.view.InternalResourceViewResolver;
+
+/**
+ * Spring MVC Configuration.
+ * @author Keith Donald
+ */
+@Configuration
+@EnableWebMvc
+public class WebMvcConfig extends WebMvcConfigurerAdapter {
+
+ public void addInterceptors(InterceptorRegistry registry) {
+ registry.addInterceptor(new UserInterceptor(usersConnectionRepository));
+ }
+
+ public void addViewControllers(ViewControllerRegistry registry) {
+ registry.addViewController("/signin");
+ registry.addViewController("/signout");
+ }
+
+ @Bean
+ public ViewResolver viewResolver() {
+ InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
+ viewResolver.setPrefix("/WEB-INF/views/");
+ viewResolver.setSuffix(".jsp");
+ return viewResolver;
+ }
+
+ private @Inject
+ UsersConnectionRepository usersConnectionRepository;
+
+}
2  ...ocial-500px-quickstart/src/main/java/org/springframework/social/quickstart/config/application.properties
@@ -0,0 +1,2 @@
+fivepx.clientId=JtqfOQVwzPaj9UY4ujQSBgkLX34sKDkNqTfRLOvh
+fivepx.clientSecret=gv3PjAg4FnEqLNVSRx7ouaETd5yVhFp3W92OGEXT
4 spring-social-500px-quickstart/src/main/java/org/springframework/social/quickstart/config/package-info.java
@@ -0,0 +1,4 @@
+/**
+ * Configures the quickstart application.
+ */
+package org.springframework.social.quickstart.config;
4 spring-social-500px-quickstart/src/main/java/org/springframework/social/quickstart/package-info.java
@@ -0,0 +1,4 @@
+/**
+ * Contains @Controllers that demonstrate quick-start application functionality.
+ */
+package org.springframework.social.quickstart;
46 ...ng-social-500px-quickstart/src/main/java/org/springframework/social/quickstart/user/SecurityContext.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2011 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.social.quickstart.user;
+
+/**
+ * Simple SecurityContext that stores the currently signed-in connection in a thread local.
+ * @author Keith Donald
+ */
+public final class SecurityContext {
+
+ private static final ThreadLocal<User> currentUser = new ThreadLocal<User>();
+
+ public static User getCurrentUser() {
+ User user = currentUser.get();
+ if (user == null) {
+ throw new IllegalStateException("No user is currently signed in");
+ }
+ return user;
+ }
+
+ public static void setCurrentUser(User user) {
+ currentUser.set(user);
+ }
+
+ public static boolean userSignedIn() {
+ return currentUser.get() != null;
+ }
+
+ public static void remove() {
+ currentUser.remove();
+ }
+
+}
36 ...al-500px-quickstart/src/main/java/org/springframework/social/quickstart/user/SimpleConnectionSignUp.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2011 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.social.quickstart.user;
+
+import java.util.concurrent.atomic.AtomicLong;
+
+import org.springframework.social.connect.Connection;
+import org.springframework.social.connect.ConnectionSignUp;
+
+/**
+ * Simple little {@link ConnectionSignUp} command that allocates new userIds in memory.
+ * Doesn't bother storing a user record in any local database, since this quickstart just stores the user id in a cookie.
+ * @author Keith Donald
+ */
+public final class SimpleConnectionSignUp implements ConnectionSignUp {
+
+ private final AtomicLong userIdSequence = new AtomicLong();
+
+ public String execute(Connection<?> connection) {
+ return Long.toString(userIdSequence.incrementAndGet());
+ }
+
+}
42 ...ocial-500px-quickstart/src/main/java/org/springframework/social/quickstart/user/SimpleSignInAdapter.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2011 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.social.quickstart.user;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.springframework.social.connect.Connection;
+import org.springframework.social.connect.web.SignInAdapter;
+import org.springframework.web.context.request.NativeWebRequest;
+
+/**
+ * Signs the user in by setting the currentUser property on the {@link SecurityContext}.
+ * Remembers the sign-in after the current request completes by storing the user's id in a cookie.
+ * This is cookie is read in {@link UserInterceptor#preHandle(HttpServletRequest, HttpServletResponse, Object)} on subsequent requests.
+ * @author Keith Donald
+ * @see UserInterceptor
+ */
+public final class SimpleSignInAdapter implements SignInAdapter {
+
+ private final UserCookieGenerator userCookieGenerator = new UserCookieGenerator();
+
+ public String signIn(String userId, Connection<?> connection, NativeWebRequest request) {
+ SecurityContext.setCurrentUser(new User(userId));
+ userCookieGenerator.addCookie(userId, request.getNativeResponse(HttpServletResponse.class));
+ return null;
+ }
+
+}
35 spring-social-500px-quickstart/src/main/java/org/springframework/social/quickstart/user/User.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2011 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.social.quickstart.user;
+
+/**
+ * Simple little User model.
+ * Just stores the user's id for simplicity.
+ * @author Keith Donald
+ */
+public final class User {
+
+ private final String id;
+
+ public User(String id) {
+ this.id = id;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+}
57 ...ocial-500px-quickstart/src/main/java/org/springframework/social/quickstart/user/UserCookieGenerator.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2011 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.social.quickstart.user;
+
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.springframework.web.util.CookieGenerator;
+
+/**
+ * Utility class for managing the quick_start user cookie that remembers the signed-in user.
+ * @author Keith Donald
+ */
+final class UserCookieGenerator {
+
+ private final CookieGenerator userCookieGenerator = new CookieGenerator();
+
+ public UserCookieGenerator() {
+ userCookieGenerator.setCookieName("quickstart_user");
+ }
+
+ public void addCookie(String userId, HttpServletResponse response) {
+ userCookieGenerator.addCookie(response, userId);
+ }
+
+ public void removeCookie(HttpServletResponse response) {
+ userCookieGenerator.addCookie(response, "");
+ }
+
+ public String readCookieValue(HttpServletRequest request) {
+ Cookie[] cookies = request.getCookies();
+ if (cookies == null) {
+ return null;
+ }
+ for (Cookie cookie : cookies) {
+ if (cookie.getName().equals(userCookieGenerator.getCookieName())) {
+ return cookie.getValue();
+ }
+ }
+ return null;
+ }
+
+}
92 ...ng-social-500px-quickstart/src/main/java/org/springframework/social/quickstart/user/UserInterceptor.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright 2011 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.springframework.social.quickstart.user;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.springframework.social.connect.UsersConnectionRepository;
+import org.springframework.social.fivepx.api.Fivepx;
+import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
+import org.springframework.web.servlet.view.RedirectView;
+
+/**
+ * Before a request is handled:
+ * 1. sets the current User in the {@link SecurityContext} from a cookie, if present and the user is still connected to Facebook.
+ * 2. requires that the user sign-in if he or she hasn't already.
+ * @author Keith Donald
+ */
+public final class UserInterceptor extends HandlerInterceptorAdapter {
+
+ private final UsersConnectionRepository connectionRepository;
+
+ private final UserCookieGenerator userCookieGenerator = new UserCookieGenerator();
+
+ public UserInterceptor(UsersConnectionRepository connectionRepository) {
+ this.connectionRepository = connectionRepository;
+ }
+
+ public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
+ rememberUser(request, response);
+ handleSignOut(request, response);
+ if (SecurityContext.userSignedIn() || requestForSignIn(request)) {
+ return true;
+ } else {
+ return requireSignIn(request, response);
+ }
+ }
+
+ public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
+ SecurityContext.remove();
+ }
+
+ // internal helpers
+
+ private void rememberUser(HttpServletRequest request, HttpServletResponse response) {
+ String userId = userCookieGenerator.readCookieValue(request);
+ if (userId == null) {
+ return;
+ }
+ if (!userNotFound(userId)) {
+ userCookieGenerator.removeCookie(response);
+ return;
+ }
+ SecurityContext.setCurrentUser(new User(userId));
+ }
+
+ private void handleSignOut(HttpServletRequest request, HttpServletResponse response) {
+ if (SecurityContext.userSignedIn() && request.getServletPath().startsWith("/signout")) {
+ connectionRepository.createConnectionRepository(SecurityContext.getCurrentUser().getId()).removeConnections("fivepx");
+ userCookieGenerator.removeCookie(response);
+ SecurityContext.remove();
+ }
+ }
+
+ private boolean requestForSignIn(HttpServletRequest request) {
+ return request.getServletPath().startsWith("/signin");
+ }
+
+ private boolean requireSignIn(HttpServletRequest request, HttpServletResponse response) throws Exception {
+ new RedirectView("/signin", true).render(null, request, response);
+ return false;
+ }
+
+ private boolean userNotFound(String userId) {
+ // doesn't bother checking a local user database: simply checks if the userId is connected to Facebook
+ return connectionRepository.createConnectionRepository(userId).findPrimaryConnection(Fivepx.class) != null;
+ }
+
+}
4 spring-social-500px-quickstart/src/main/java/org/springframework/social/quickstart/user/package-info.java
@@ -0,0 +1,4 @@
+/**
+ * A simple user authentication model supporting the quickstart application.
+ */
+package org.springframework.social.quickstart.user;
3  spring-social-500px-quickstart/src/main/webapp/META-INF/MANIFEST.MF
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Class-Path:
+
25 spring-social-500px-quickstart/src/main/webapp/WEB-INF/views/home.jsp
@@ -0,0 +1,25 @@
+<%@ page session="false"%>
+<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
+<html>
+<head>
+<title>Home</title>
+</head>
+<body>
+ <ul>
+ <li><a href="<c:url value="/signout" />">Sign Out</a></li>
+ </ul>
+ <h3>User Profile</h3>
+ <form>
+ <fieldset>
+ <img src="${profile.userpicUrl}" width="60" height="60" />
+ <br/>
+ <label>Id</label><input type="text" name="name" value="${profile.id}" />
+ <br />
+ <label>UserName:</label><input type="text" name="name" value="${profile.userName}" />
+ <br />
+ <label>Name:</label><input type="text" name="name" value="${profile.name}" />
+
+ </fieldset>
+ </form>
+</body>
+</html>
12 spring-social-500px-quickstart/src/main/webapp/WEB-INF/views/signin.jsp
@@ -0,0 +1,12 @@
+<%@ page session="false" %>
+<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
+<html>
+ <head>
+ <title>Sign In</title>
+ </head>
+ <body>
+ <form action="<c:url value="/signin/500px" />" method="POST">
+ <button type="submit">Sign in with 500px</button>
+ </form>
+ </body>
+</html>
85 spring-social-500px-quickstart/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,85 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
+
+ <!-- Java-based Spring container definition -->
+ <context-param>
+ <param-name>contextClass</param-name>
+ <param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
+ </context-param>
+
+ <!-- Location of Java @Configuration classes that configure the components that makeup this application -->
+ <context-param>
+ <param-name>contextConfigLocation</param-name>
+ <param-value>org.springframework.social.quickstart.config</param-value>
+ </context-param>
+
+ <!-- Creates the Spring Container shared by all Servlets and Filters -->
+ <listener>
+ <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
+ </listener>
+
+ <!-- Ensure UTF-8 character encoding is used -->
+ <filter>
+ <filter-name>encodingFilter</filter-name>
+ <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
+ <init-param>
+ <param-name>encoding</param-name>
+ <param-value>UTF-8</param-value>
+ </init-param>
+ <init-param>
+ <param-name>forceEncoding</param-name>
+ <param-value>true</param-value>
+ </init-param>
+ </filter>
+
+ <filter-mapping>
+ <filter-name>encodingFilter</filter-name>
+ <url-pattern>/*</url-pattern>
+ </filter-mapping>
+
+ <!-- Enables support for DELETE and PUT request methods with web browser clients -->
+ <filter>
+ <filter-name>hiddenHttpMethodFilter</filter-name>
+ <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
+ </filter>
+
+ <filter-mapping>
+ <filter-name>hiddenHttpMethodFilter</filter-name>
+ <url-pattern>/*</url-pattern>
+ </filter-mapping>
+
+ <!-- H2 Database Console for managing the app's database -->
+ <servlet>
+ <servlet-name>H2Console</servlet-name>
+ <servlet-class>org.h2.server.web.WebServlet</servlet-class>
+ <init-param>
+ <param-name>-webAllowOthers</param-name>
+ <param-value>true</param-value>
+ </init-param>
+ <load-on-startup>2</load-on-startup>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>H2Console</servlet-name>
+ <url-pattern>/admin/h2/*</url-pattern>
+ </servlet-mapping>
+
+ <!-- Handles requests into the application -->
+ <servlet>
+ <servlet-name>appServlet</servlet-name>
+ <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
+ <init-param>
+ <param-name>contextConfigLocation</param-name>
+ <param-value></param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>appServlet</servlet-name>
+ <url-pattern>/</url-pattern>
+ </servlet-mapping>
+
+</web-app>
12 spring-social-500px/.classpath
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" output="target/classes" path="src/main/java"/>
+ <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
+ <attributes>
+ <attribute name="org.eclipse.jst.component.nondependency" value=""/>
+ </attributes>
+ </classpathentry>
+ <classpathentry kind="output" path="target/classes"/>
+</classpath>
36 spring-social-500px/.project
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>spring-social-500px</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.wst.common.project.facet.core.builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.m2e.core.maven2Builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.wst.validation.validationbuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
+ <nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.eclipse.m2e.core.maven2Nature</nature>
+ <nature>org.eclipse.wst.common.project.facet.core.nature</nature>
+ </natures>
+</projectDescription>
8 spring-social-500px/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,8 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
+org.eclipse.jdt.core.compiler.source=1.6
4 spring-social-500px/.settings/org.eclipse.m2e.core.prefs
@@ -0,0 +1,4 @@
+activeProfiles=
+eclipse.preferences.version=1
+resolveWorkspaceProjects=true
+version=1
7 spring-social-500px/.settings/org.eclipse.wst.common.component
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project-modules id="moduleCoreId" project-version="1.5.0">
+ <wb-module deploy-name="spring-social-500px">
+ <wb-resource deploy-path="/" source-path="/src/main/java"/>
+ <wb-resource deploy-path="/" source-path="/src/main/resources"/>
+ </wb-module>
+</project-modules>
5 spring-social-500px/.settings/org.eclipse.wst.common.project.facet.core.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<faceted-project>
+ <installed facet="java" version="1.6"/>
+ <installed facet="jst.utility" version="1.0"/>
+</faceted-project>
82 spring-social-500px/pom.xml
@@ -0,0 +1,82 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.springframework.social</groupId>
+ <artifactId>spring-social-500px</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <name>Spring Social 500px</name>
+ <description>Spring Social extension with connection support and an API binding for 500px</description>
+
+ <properties>
+ <spring.social.version>1.0.2.RELEASE</spring.social.version>
+ <spring.framework.version>3.1.1.RELEASE</spring.framework.version>
+ </properties>
+
+ <url></url>
+ <developers>
+ <developer>
+ <name>Sachin Handiekar</name>
+ <email>sach21@gmail.com</email>
+ <url>http://sachinhandiekar.com</url>
+ </developer>
+ </developers>
+
+ <repositories>
+ <repository>
+ <id>org.springframework.maven.release</id>
+ <name>Spring Maven Release Repository</name>
+ <url>http://maven.springframework.org/release</url>
+ <releases>
+ <enabled>true</enabled>
+ </releases>
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ </repository>
+ <repository>
+ <id>org.springframework.maven.milestone</id>
+ <name>Spring Maven Milestone Repository</name>
+ <url>http://maven.springframework.org/milestone</url>
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ </repository>
+ </repositories>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.springframework.social</groupId>
+ <artifactId>spring-social-core</artifactId>
+ <version>${spring.social.version}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-web</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-web</artifactId>
+ <version>${spring.framework.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.jackson</groupId>
+ <artifactId>jackson-mapper-asl</artifactId>
+ <version>1.9.5</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.0.2</version>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
9 spring-social-500px/src/main/java/org/springframework/social/fivepx/api/Fivepx.java
@@ -0,0 +1,9 @@
+package org.springframework.social.fivepx.api;
+
+import org.springframework.social.ApiBinding;
+
+public interface Fivepx extends ApiBinding {
+
+ UserOperations userOperations();
+
+}
145 spring-social-500px/src/main/java/org/springframework/social/fivepx/api/FivepxProfile.java
@@ -0,0 +1,145 @@
+package org.springframework.social.fivepx.api;
+
+import java.io.Serializable;
+import java.util.Date;
+
+public class FivepxProfile implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ private final long id;
+
+ private final String userName;
+
+ private final String name;
+
+ private final String userpicUrl;
+
+ private String about;
+
+ private String domain;
+
+ private String city;
+
+ private String country;
+
+ private String sex;
+
+ private int followersCount;
+
+ private int inFavouritesCount;
+
+ private int friendsCount;
+
+
+ private int affection;
+
+ private Date registrationDate;
+
+ public FivepxProfile(long id, String userName, String name, String userpicUrl) {
+ super();
+ this.id = id;
+ this.userName = userName;
+ this.name = name;
+ this.userpicUrl = userpicUrl;
+ }
+
+ public String getAbout() {
+ return about;
+ }
+
+ public void setAbout(String about) {
+ this.about = about;
+ }
+
+ public String getDomain() {
+ return domain;
+ }
+
+ public void setDomain(String domain) {
+ this.domain = domain;
+ }
+
+ public String getCity() {
+ return city;
+ }
+
+ public void setCity(String city) {
+ this.city = city;
+ }
+
+ public String getCountry() {
+ return country;
+ }
+
+ public void setCountry(String country) {
+ this.country = country;
+ }
+
+
+
+ public int getFollowersCount() {
+ return followersCount;
+ }
+
+ public void setFollowersCount(int followersCount) {
+ this.followersCount = followersCount;
+ }
+
+ public int getInFavouritesCount() {
+ return inFavouritesCount;
+ }
+
+ public void setInFavouritesCount(int inFavouritesCount) {
+ this.inFavouritesCount = inFavouritesCount;
+ }
+
+ public int getAffection() {
+ return affection;
+ }
+
+ public void setAffection(int affection) {
+ this.affection = affection;
+ }
+
+ public Date getRegistrationDate() {
+ return registrationDate;
+ }
+
+ public void setRegistrationDate(Date registrationDate) {
+ this.registrationDate = registrationDate;
+ }
+
+ public long getId() {
+ return id;
+ }
+
+ public String getUserName() {
+ return userName;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getUserpicUrl() {
+ return userpicUrl;
+ }
+
+ public String getSex() {
+ return sex;
+ }
+
+ public void setSex(String sex) {
+ this.sex = sex;
+ }
+
+ public int getFriendsCount() {
+ return friendsCount;
+ }
+
+ public void setFriendsCount(int friendsCount) {
+ this.friendsCount = friendsCount;
+ }
+
+}
16 spring-social-500px/src/main/java/org/springframework/social/fivepx/api/UserOperations.java
@@ -0,0 +1,16 @@
+package org.springframework.social.fivepx.api;
+
+public interface UserOperations {
+
+ long getProfileId();
+
+ String getScreenName();
+
+ FivepxProfile getUserProfile();
+
+ FivepxProfile getUserProfileWithEmail(String email);
+
+ FivepxProfile getUserProfileWithUsername(String userName);
+
+ FivepxProfile getUserProfileWithId(long userId);
+}
42 spring-social-500px/src/main/java/org/springframework/social/fivepx/api/impl/AbstractFivepxOperations.java
@@ -0,0 +1,42 @@
+package org.springframework.social.fivepx.api.impl;
+
+import java.net.URI;
+
+import org.springframework.social.MissingAuthorizationException;
+import org.springframework.social.support.URIBuilder;
+import org.springframework.util.LinkedMultiValueMap;
+import org.springframework.util.MultiValueMap;
+
+public class AbstractFivepxOperations {
+
+ private final boolean isAuthorized;
+
+ public AbstractFivepxOperations(boolean isAuthorized) {
+ this.isAuthorized = isAuthorized;
+ }
+
+ protected void requireAuthorization() {
+ if (!isAuthorized) {
+ throw new MissingAuthorizationException();
+ }
+ }
+
+ protected URI buildUri(String path) {
+ return buildUri(path, EMPTY_PARAMETERS);
+ }
+
+ protected URI buildUri(String path, String parameterName, String parameterValue) {
+ MultiValueMap<String, String> parameters = new LinkedMultiValueMap<String, String>();
+ parameters.set(parameterName, parameterValue);
+ return buildUri(path, parameters);
+ }
+
+ protected URI buildUri(String path, MultiValueMap<String, String> parameters) {
+ return URIBuilder.fromUri(API_URL_BASE + path).queryParams(parameters).build();
+ }
+
+ private static final String API_URL_BASE = "https://api.500px.com/v1/";
+
+ private static final LinkedMultiValueMap<String, String> EMPTY_PARAMETERS = new LinkedMultiValueMap<String, String>();
+
+}
18 spring-social-500px/src/main/java/org/springframework/social/fivepx/api/impl/FivepxModule.java
@@ -0,0 +1,18 @@
+package org.springframework.social.fivepx.api.impl;
+
+import org.codehaus.jackson.Version;
+import org.codehaus.jackson.map.module.SimpleModule;
+import org.springframework.social.fivepx.api.FivepxProfile;
+
+public class FivepxModule extends SimpleModule {
+
+ public FivepxModule() {
+ super("FivepxModule", new Version(1, 0, 0, null));
+ }
+
+ @Override
+ public void setupModule(SetupContext context) {
+ context.setMixInAnnotations(FivepxProfile.class, FivepxProfileMixin.class);
+
+ }
+}
69 spring-social-500px/src/main/java/org/springframework/social/fivepx/api/impl/FivepxProfileMixin.java
@@ -0,0 +1,69 @@
+package org.springframework.social.fivepx.api.impl;
+
+import java.io.IOException;
+
+import org.codehaus.jackson.JsonNode;
+import org.codehaus.jackson.JsonParser;
+import org.codehaus.jackson.JsonProcessingException;
+import org.codehaus.jackson.annotate.JsonIgnoreProperties;
+import org.codehaus.jackson.map.DeserializationContext;
+import org.codehaus.jackson.map.JsonDeserializer;
+import org.codehaus.jackson.map.annotate.JsonDeserialize;
+import org.springframework.social.fivepx.api.FivepxProfile;
+import org.springframework.social.fivepx.api.impl.FivepxProfileMixin.FivepxProfileDeserializer;
+
+@JsonIgnoreProperties(ignoreUnknown = true)
+@JsonDeserialize(using = FivepxProfileDeserializer.class)
+class FivepxProfileMixin {
+
+ static class FivepxProfileDeserializer extends JsonDeserializer<FivepxProfile> {
+
+ @Override
+ public FivepxProfile deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException,
+ JsonProcessingException {
+ FivepxProfile profile = null;
+ String sex = null;
+ JsonNode tree = jp.readValueAsTree();
+
+ JsonNode profileNode = tree.get("user");
+ long id = profileNode.get("id").asLong();
+ String fullName = profileNode.get("fullname").asText();
+ String userName = profileNode.get("username").asText();
+ String city = profileNode.get("city").asText();
+ String country = profileNode.get("country").asText();
+ String userPicUrl = getUserProfilePicValue(profileNode, "userpic_url");
+ String domain = profileNode.get("domain").asText();
+ String about = profileNode.get("about").asText();
+ int followersCount = profileNode.get("followers_count").getIntValue();
+ int friendsCount = profileNode.get("friends_count").getIntValue();
+ int sexVal = profileNode.get("sex").getIntValue();
+
+ if (sexVal == 0) {
+ sex = "Undefined";
+ }
+ else if (sexVal == 1) {
+ sex = "Male";
+ }
+ else if (sexVal == 2) {
+ sex = "Female";
+ }
+
+
+ profile = new FivepxProfile(id, userName, fullName, userPicUrl);
+ profile.setSex(sex);
+ profile.setAbout(about);
+ profile.setDomain(domain);
+ profile.setFollowersCount(followersCount);
+ profile.setFriendsCount(friendsCount);
+ profile.setCity(city);
+ profile.setCountry(country);
+
+ return profile;
+ }
+
+ private String getUserProfilePicValue(JsonNode node, String nodeName) {
+ return "http://500px.com" + node.get(nodeName).asText();
+ }
+ }
+
+}
35 spring-social-500px/src/main/java/org/springframework/social/fivepx/api/impl/FivepxTemplate.java
@@ -0,0 +1,35 @@
+package org.springframework.social.fivepx.api.impl;
+
+import org.codehaus.jackson.map.ObjectMapper;
+import org.springframework.http.converter.json.MappingJacksonHttpMessageConverter;
+import org.springframework.social.fivepx.api.Fivepx;
+import org.springframework.social.fivepx.api.UserOperations;
+import org.springframework.social.oauth1.AbstractOAuth1ApiBinding;
+
+public class FivepxTemplate extends AbstractOAuth1ApiBinding implements Fivepx {
+
+ private UserOperations userOperations;
+
+ public FivepxTemplate(String consumerKey, String consumerSecret, String accessToken, String accessTokenSecret) {
+ super(consumerKey, consumerSecret, accessToken, accessTokenSecret);
+ initSubApis();
+ }
+
+ public UserOperations userOperations() {
+ return userOperations;
+ }
+
+ @Override
+ protected MappingJacksonHttpMessageConverter getJsonMessageConverter() {
+ MappingJacksonHttpMessageConverter converter = super.getJsonMessageConverter();
+ ObjectMapper objectMapper = new ObjectMapper();
+ objectMapper.registerModule(new FivepxModule());
+ converter.setObjectMapper(objectMapper);
+ return converter;
+ }
+
+ private void initSubApis() {
+ this.userOperations = new UserTemplate(getRestTemplate(), isAuthorized());
+ }
+
+}
49 spring-social-500px/src/main/java/org/springframework/social/fivepx/api/impl/UserTemplate.java
@@ -0,0 +1,49 @@
+package org.springframework.social.fivepx.api.impl;
+
+import org.springframework.social.fivepx.api.FivepxProfile;
+import org.springframework.social.fivepx.api.UserOperations;
+import org.springframework.web.client.RestTemplate;
+
+public class UserTemplate extends AbstractFivepxOperations implements UserOperations {
+ private final RestTemplate restTemplate;
+
+ public UserTemplate(RestTemplate restTemplate, boolean isAuthorizedForUser) {
+ super(isAuthorizedForUser);
+ this.restTemplate = restTemplate;
+ }
+
+ @Override
+ public long getProfileId() {
+ requireAuthorization();
+ return getUserProfile().getId();
+ }
+
+ @Override
+ public String getScreenName() {
+ requireAuthorization();
+ return getUserProfile().getName();
+ }
+
+ @Override
+ public FivepxProfile getUserProfile() {
+ requireAuthorization();
+ return restTemplate.getForObject(buildUri("users"), FivepxProfile.class);
+ }
+
+ @Override
+ public FivepxProfile getUserProfileWithEmail(String email) {
+ return restTemplate.getForObject(buildUri("users/show", "email", email), FivepxProfile.class);
+
+ }
+
+ @Override
+ public FivepxProfile getUserProfileWithUsername(String userName) {
+ return restTemplate.getForObject(buildUri("users/show", "username", userName), FivepxProfile.class);
+
+ }
+
+ @Override
+ public FivepxProfile getUserProfileWithId(long userId) {
+ return restTemplate.getForObject(buildUri("users/show", "id", String.valueOf(userId)), FivepxProfile.class);
+ }
+}
44 spring-social-500px/src/main/java/org/springframework/social/fivepx/connect/FivepxAdapter.java
@@ -0,0 +1,44 @@
+package org.springframework.social.fivepx.connect;
+
+import org.springframework.social.ApiException;
+import org.springframework.social.connect.ApiAdapter;
+import org.springframework.social.connect.ConnectionValues;
+import org.springframework.social.connect.UserProfile;
+import org.springframework.social.connect.UserProfileBuilder;
+import org.springframework.social.fivepx.api.Fivepx;
+import org.springframework.social.fivepx.api.FivepxProfile;
+
+public class FivepxAdapter implements ApiAdapter<Fivepx> {
+
+ @Override
+ public UserProfile fetchUserProfile(Fivepx fivepx) {
+ FivepxProfile profile = fivepx.userOperations().getUserProfile();
+ return new UserProfileBuilder().setName(profile.getName()).setUsername(profile.getName()).build();
+ }
+
+ @Override
+ public void setConnectionValues(Fivepx fivepx, ConnectionValues values) {
+ FivepxProfile profile = fivepx.userOperations().getUserProfile();
+ values.setProviderUserId(Long.toString(profile.getId()));
+ values.setDisplayName(profile.getName());
+ values.setProfileUrl(profile.getDomain());
+ values.setImageUrl(profile.getUserpicUrl());
+ }
+
+ @Override
+ public boolean test(Fivepx fivepx) {
+ try {
+ fivepx.userOperations().getUserProfile();
+ return true;
+ }
+ catch (ApiException e) {
+ return false;
+ }
+ }
+
+ @Override
+ public void updateStatus(Fivepx fivepx, String status) {
+ throw new UnsupportedOperationException("updateStatus() method is not supported!!!");
+ }
+
+}
10 spring-social-500px/src/main/java/org/springframework/social/fivepx/connect/FivepxConnectionFactory.java
@@ -0,0 +1,10 @@
+package org.springframework.social.fivepx.connect;
+
+import org.springframework.social.connect.support.OAuth1ConnectionFactory;
+import org.springframework.social.fivepx.api.Fivepx;
+
+public class FivepxConnectionFactory extends OAuth1ConnectionFactory<Fivepx> {
+ public FivepxConnectionFactory(String consumerKey, String consumerSecret) {
+ super("500px", new FivepxServiceProvider(consumerKey, consumerSecret), new FivepxAdapter());
+ }
+}
20 spring-social-500px/src/main/java/org/springframework/social/fivepx/connect/FivepxServiceProvider.java
@@ -0,0 +1,20 @@
+package org.springframework.social.fivepx.connect;
+
+import org.springframework.social.fivepx.api.Fivepx;
+import org.springframework.social.fivepx.api.impl.FivepxTemplate;
+import org.springframework.social.oauth1.AbstractOAuth1ServiceProvider;
+import org.springframework.social.oauth1.OAuth1Template;
+
+public class FivepxServiceProvider extends AbstractOAuth1ServiceProvider<Fivepx> {
+ public FivepxServiceProvider(String consumerKey, String consumerSecret) {
+ super(consumerKey, consumerSecret, new OAuth1Template(consumerKey, consumerSecret,
+ "https://api.500px.com/v1/oauth/request_token",
+ "https://api.500px.com/v1/oauth/authorize",
+ "https://api.500px.com/v1/oauth/authorize",
+ "https://api.500px.com/v1/oauth/access_token"));
+ }
+
+ public Fivepx getApi(String accessToken, String secret) {
+ return new FivepxTemplate(getConsumerKey(), getConsumerSecret(), accessToken, secret);
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.