Skip to content
This repository has been archived by the owner on Apr 5, 2022. It is now read-only.

Added Linkedin Connect and fixed few compilation errors #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions spring-social-showcase/README
@@ -1,6 +1,7 @@
This sample app demonstrates many of the capabilities of the Spring Social project, including: This sample app demonstrates many of the capabilities of the Spring Social project, including:
- Connect to Facebook - Connect to Facebook
- Connect to Twitter - Connect to Twitter
- Connect to LinkedIn
- Sign in using Facebook - Sign in using Facebook
- Sign in using Twitter - Sign in using Twitter


Expand Down
6 changes: 6 additions & 0 deletions spring-social-showcase/pom.xml
Expand Up @@ -58,6 +58,11 @@
<groupId>org.springframework.social</groupId> <groupId>org.springframework.social</groupId>
<artifactId>spring-social-twitter</artifactId> <artifactId>spring-social-twitter</artifactId>
<version>${org.springframework.social-version}</version> <version>${org.springframework.social-version}</version>
</dependency>
<dependency>
<groupId>org.springframework.social</groupId>
<artifactId>spring-social-linkedin</artifactId>
<version>${org.springframework.social-version}</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.springframework.social</groupId> <groupId>org.springframework.social</groupId>
Expand Down Expand Up @@ -265,5 +270,6 @@
<version>1.0-beta-1</version> <version>1.0-beta-1</version>
</plugin> </plugin>
</plugins> </plugins>
<finalName>spring-social-showcase</finalName>
</build> </build>
</project> </project>
Expand Up @@ -6,6 +6,7 @@


import org.springframework.social.connect.ServiceProviderConnectionRepository; import org.springframework.social.connect.ServiceProviderConnectionRepository;
import org.springframework.social.facebook.api.FacebookApi; import org.springframework.social.facebook.api.FacebookApi;
import org.springframework.social.linkedin.api.LinkedInApi;
import org.springframework.social.twitter.api.TwitterApi; import org.springframework.social.twitter.api.TwitterApi;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;


Expand All @@ -19,6 +20,7 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons
if (request.getUserPrincipal() != null) { if (request.getUserPrincipal() != null) {
request.setAttribute("connectedToTwitter", connectionRepository.findPrimaryConnectionToServiceApi(TwitterApi.class) != null); request.setAttribute("connectedToTwitter", connectionRepository.findPrimaryConnectionToServiceApi(TwitterApi.class) != null);
request.setAttribute("connectedToFacebook", connectionRepository.findPrimaryConnectionToServiceApi(FacebookApi.class) != null); request.setAttribute("connectedToFacebook", connectionRepository.findPrimaryConnectionToServiceApi(FacebookApi.class) != null);
request.setAttribute("connectedToLinkedIn", connectionRepository.findPrimaryConnectionToServiceApi(LinkedInApi.class) != null);
} }
return true; return true;
} }
Expand Down
Expand Up @@ -9,6 +9,7 @@
import org.springframework.social.connect.ServiceProviderConnection; import org.springframework.social.connect.ServiceProviderConnection;
import org.springframework.social.connect.ServiceProviderConnectionRepository; import org.springframework.social.connect.ServiceProviderConnectionRepository;
import org.springframework.social.facebook.api.FacebookApi; import org.springframework.social.facebook.api.FacebookApi;
import org.springframework.social.linkedin.api.LinkedInApi;
import org.springframework.social.tripit.api.TripItApi; import org.springframework.social.tripit.api.TripItApi;
import org.springframework.social.twitter.api.TwitterApi; import org.springframework.social.twitter.api.TwitterApi;


Expand Down Expand Up @@ -38,5 +39,12 @@ public TwitterApi twitterApi() {
ServiceProviderConnection<TwitterApi> connection = connectionRepository.findPrimaryConnectionToServiceApi(TwitterApi.class); ServiceProviderConnection<TwitterApi> connection = connectionRepository.findPrimaryConnectionToServiceApi(TwitterApi.class);
return connection != null ? connection.getServiceApi() : null; return connection != null ? connection.getServiceApi() : null;
} }

@Bean
@Scope(value="request", proxyMode=ScopedProxyMode.INTERFACES)
public LinkedInApi linkedInApi() {
ServiceProviderConnection<LinkedInApi> connection = connectionRepository.findPrimaryConnectionToServiceApi(LinkedInApi.class);
return connection != null ? connection.getServiceApi() : null;
}


} }
@@ -0,0 +1,27 @@
package org.springframework.social.showcase.linkedin;

import javax.inject.Inject;

import org.springframework.social.linkedin.api.LinkedInApi;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class LinkedInConnectionsController {

private final LinkedInApi linkedInApi;

@Inject
public LinkedInConnectionsController(LinkedInApi linkedInApi) {
this.linkedInApi = linkedInApi;
}

@RequestMapping(value="/linkedin/connections", method=RequestMethod.GET)
public String showFeed(Model model) {
model.addAttribute("connections", linkedInApi.getConnections());
return "linkedin/connections";
}

}
@@ -0,0 +1,51 @@
/*
* 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.showcase.linkedin;

import javax.inject.Inject;

import org.springframework.social.connect.ServiceProviderConnection;
import org.springframework.social.connect.ServiceProviderConnectionRepository;
import org.springframework.social.linkedin.api.LinkedInApi;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class LinkedInProfileController {

private final ServiceProviderConnectionRepository connectionRepository;

private final LinkedInApi linkedInApi;

@Inject
public LinkedInProfileController(ServiceProviderConnectionRepository connectionRepository, LinkedInApi linkedInApi) {
this.connectionRepository = connectionRepository;
this.linkedInApi = linkedInApi;
}

@RequestMapping(value="/linkedin", method=RequestMethod.GET)
public String home(Model model) {
ServiceProviderConnection<LinkedInApi> connection = connectionRepository.findPrimaryConnectionToServiceApi(LinkedInApi.class);
if (connection == null) {
return "redirect:/connect/linkedin";
}
model.addAttribute("profile", linkedInApi.getUserProfile());
return "linkedin/profile";
}

}
Expand Up @@ -18,7 +18,7 @@
import javax.inject.Inject; import javax.inject.Inject;
import javax.validation.Valid; import javax.validation.Valid;


import org.springframework.social.connect.signin.web.ProviderUserSignInUtils; import org.springframework.social.connect.signin.web.ProviderSignInUtils;
import org.springframework.social.showcase.account.Account; import org.springframework.social.showcase.account.Account;
import org.springframework.social.showcase.account.AccountRepository; import org.springframework.social.showcase.account.AccountRepository;
import org.springframework.social.showcase.account.UsernameAlreadyInUseException; import org.springframework.social.showcase.account.UsernameAlreadyInUseException;
Expand Down Expand Up @@ -54,7 +54,7 @@ public String signup(@Valid SignupForm form, BindingResult formBinding, WebReque
} }
boolean accountCreated = createAccount(form, formBinding); boolean accountCreated = createAccount(form, formBinding);
if (accountCreated) { if (accountCreated) {
ProviderUserSignInUtils.handlePostSignUp(request); ProviderSignInUtils.handlePostSignUp(request);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ProviderUserSignInUtils is being replaced by ProviderSignInUtils

return "redirect:/"; return "redirect:/";
} }
return null; return null;
Expand Down
Expand Up @@ -24,3 +24,11 @@
</c:if> </c:if>


<h4><a href="<c:url value="/tripit"/>">TripIt</a></h4> <h4><a href="<c:url value="/tripit"/>">TripIt</a></h4>

<h4><a href="<c:url value="/linkedin"/>">LinkedIn</a></h4>
<c:if test="${connectedToLinkedIn}">
<ul class="menu">
<li><a href="<c:url value="/linkedin"/>">User Profile</a></li>
<li><a href="<c:url value="/linkedin/connections"/>">Connections</a></li>
</ul>
</c:if>
Expand Up @@ -20,7 +20,7 @@
</property> </property>
</bean> </bean>


<bean class="org.springframework.social.connect.signin.web.ProviderUserSignInController"> <bean class="org.springframework.social.connect.signin.web.ProviderSignInController">
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ProviderUserSignInController is being replaced by ProviderSignInController

<constructor-arg value="${application.url}" /> <constructor-arg value="${application.url}" />
</bean> </bean>


Expand Down
Expand Up @@ -26,6 +26,10 @@
<constructor-arg value="${tripit.consumerKey}" /> <constructor-arg value="${tripit.consumerKey}" />
<constructor-arg value="${tripit.consumerSecret}" /> <constructor-arg value="${tripit.consumerSecret}" />
</bean> </bean>
<bean class="org.springframework.social.linkedin.connect.LinkedInServiceProviderConnectionFactory">
<constructor-arg value="${linkedin.consumerKey}" />
<constructor-arg value="${linkedin.consumerSecret}" />
</bean>
</list> </list>
</property> </property>
</bean> </bean>
Expand Down
Expand Up @@ -16,6 +16,8 @@
<prop key="twitter.consumerSecret">Kb8hS0luftwCJX3qVoyiLUMfZDtK1EozFoUkjNLUMx4</prop> <prop key="twitter.consumerSecret">Kb8hS0luftwCJX3qVoyiLUMfZDtK1EozFoUkjNLUMx4</prop>
<prop key="tripit.consumerKey">ee68437fbf8f42315a1b1ebe5a2a3009bd3f5cf9</prop> <prop key="tripit.consumerKey">ee68437fbf8f42315a1b1ebe5a2a3009bd3f5cf9</prop>
<prop key="tripit.consumerSecret">6b3cf4d183cc02076d068eea91080ca0bf666336</prop> <prop key="tripit.consumerSecret">6b3cf4d183cc02076d068eea91080ca0bf666336</prop>
<prop key="linkedin.consumerKey"></prop>
<prop key="linkedin.consumerSecret"></prop>
</util:properties> </util:properties>


</beans> </beans>
@@ -0,0 +1,17 @@
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib uri="http://www.springframework.org/tags" prefix="s" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="sf" %>
<%@ page session="false" %>

<h3>Connect to LinkedIn</h3>

<form action="<c:url value="/connect/linkedin" />" method="POST">
<div class="formInfo">
<p>
You haven't created any connections with LinkedIn yet. Click the button to connect Spring Social Showcase with your LinkedIn account.
(You'll be redirected to LinkedIn where you'll be asked to authorize the connection.)
</p>
</div>
<p><button type="submit"><img src="<c:url value="/resources/social/linkedin/connect_with_linkedin-logo-150x150.jpg" />" width="40px"/></button></p>
</form>
@@ -0,0 +1,19 @@
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://www.springframework.org/tags" prefix="s" %>
<%@ page session="false" %>

<h3>Connected to LinkedIn</h3>

<form id="disconnect" method="post">
<div class="formInfo">
<p>
Spring Social Showcase is connected to your LinkedIn account.
Click the button if you wish to disconnect.
</p>
</div>

<button type="submit">Disconnect</button>
<input type="hidden" name="_method" value="delete" />
</form>

<p><a href="<c:url value="/linkedin" />">View your LinkedIn profile</a></p>
Expand Up @@ -26,5 +26,13 @@
<definition name="connect/tripitConnected" extends="page"> <definition name="connect/tripitConnected" extends="page">
<put-attribute name="content" value="/WEB-INF/views/connect/tripitConnected.jsp" /> <put-attribute name="content" value="/WEB-INF/views/connect/tripitConnected.jsp" />
</definition> </definition>

<definition name="connect/linkedinConnect" extends="page">
<put-attribute name="content" value="/WEB-INF/views/connect/linkedinConnect.jsp" />
</definition>

<definition name="connect/linkedinConnected" extends="page">
<put-attribute name="content" value="/WEB-INF/views/connect/linkedinConnected.jsp" />
</definition>


</tiles-definitions> </tiles-definitions>
@@ -0,0 +1,17 @@
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="sf" %>
<%@ page session="false" %>

<h3>Your LinkedIn Connections</h3>

<ul class="friends">
<c:forEach items="${connections}" var="connection" varStatus="status">
<c:choose>
<c:when test="${status.count%2 == 0}"><c:set var="altrow" value="evenrow"/></c:when>
<c:otherwise><c:set var="altrow" value="oddrow"/></c:otherwise>
</c:choose>
<li class="${altrow}"><a href="${connection.standardProfileUrl}" target="_blank"><c:out value="${connection.firstName}"/>&nbsp;
<c:out value="${connection.lastName}"/></a>&nbsp;<sub><c:out value="${connection.headline}"/></sub>&nbsp;@&nbsp;<c:out value="${connection.industry}"/></li>
</c:forEach>
</ul>
@@ -0,0 +1,40 @@
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib uri="http://www.springframework.org/tags" prefix="s" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="sf" %>
<%@ page session="false" %>
<html>
<head>
<title>Spring Social Showcase: LinkedIn</title>
<style type="text/css">
.evenrow {background-color:white;}
.oddrow {background-color:lightgrey;}
</style>
</head>
<body>
<h1>Spring Social Showcase: LinkedIn</h1>
<p>Hello, <c:out value="${linkedInApi.userProfile.firstName}"/> &nbsp; <c:out value="${linkedInApi.userProfile.lastName}"/>! (<a href="<c:url value="/connect/linkedin"/>">Disconnect from Facebook</a>)</p>
<p>Your LinkedIn profile:</p>
<dl>
<dt>LinkedIn ID:</dt>
<dd><a href="${linkedInApi.profileUrl}" target="_blank"><c:out value="${linkedInApi.userProfile.id}"/></a></dd>
<dt>Industry:</dt>
<dd><c:out value="${linkedInApi.userProfile.industry}"/></dd>
<dt>Headline:</dt>
<dd><c:out value="${linkedInApi.userProfile.headline}"/></dd>
<dt id="friendsIds">Connections:</dt>
<dd><ol>
<c:forEach items="${linkedInApi.connections}" var="connection" varStatus="status">
<c:choose>
<c:when test="${status.count%2 == 0}"><c:set var="altrow" value="evenrow"/></c:when>
<c:otherwise><c:set var="altrow" value="oddrow"/></c:otherwise>
</c:choose>
<li class="${altrow}"><a href="${connection.standardProfileUrl}" target="_blank"><c:out value="${connection.firstName}"/>&nbsp;
<c:out value="${connection.lastName}"/></a>&nbsp;<sub><c:out value="${connection.headline}"/></sub>&nbsp;@&nbsp;<c:out value="${connection.industry}"/></li>
</c:forEach>
</ol></dd>
</dl>

<p><a href="<s:url value="/" />">Return to home page</a></p>
</body>
</html>
@@ -0,0 +1,24 @@
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="sf" %>
<%@ page session="false" %>

<h3>Your LinkedIn Profile</h3>
<p>Hello, <c:out value="${profile.firstName}"/>!</p>
<img src="<c:out value="${profile.profilePictureUrl}"/>" alt="Seems your profile image is not accessible" title=""/>
<dl>
<dt>LinkedIn ID:</dt>
<dd><a href="${profile.standardProfileUrl}" target="_blank"><c:out value="${profile.id}"/></a></dd>
<dt>Name:</dt>
<dd><c:out value="${profile.firstName}"/>&nbsp;<c:out value="${profile.lastName}"/></dd>
<dt>Industry:</dt>
<dd><c:out value="${profile.industry}"/></dd>
<dt>Headline:</dt>
<dd><c:out value="${profile.headline}"/></dd>
</dl>

<c:url value="/connect/linkedin" var="disconnectUrl"/>
<form id="disconnect" action="${disconnectUrl}" method="post">
<button type="submit">Disconnect from LinkedIn</button>
<input type="hidden" name="_method" value="delete" />
</form>
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 2.1//EN" "http://tiles.apache.org/dtds/tiles-config_2_1.dtd">

<tiles-definitions>

<definition name="linkedin/profile" extends="page">
<put-attribute name="content" value="/WEB-INF/views/linkedin/profile.jsp" />
</definition>

<definition name="linkedin/connections" extends="page">
<put-attribute name="content" value="/WEB-INF/views/linkedin/connections.jsp" />
</definition>

</tiles-definitions>
8 changes: 7 additions & 1 deletion spring-social-showcase/src/main/webapp/resources/page.css
Expand Up @@ -99,4 +99,10 @@ ul.choices li {
ul.choices li:first-child { ul.choices li:first-child {
padding-left: 0px; padding-left: 0px;
border-left: none; border-left: none;
} }

.evenrow {background-color:white;}

.oddrow {background-color:lightgrey;}

img {color:red; font-size:small; font-style:italic;}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.