Commit f4d85f95 authored by Matija Obreza's avatar Matija Obreza

Updated and cleaned up dependencies

Using spring-social-google instead of google-plus-java-api
parent 1e1045b6
...@@ -57,8 +57,8 @@ ...@@ -57,8 +57,8 @@
<spring.framework.version>3.2.10.RELEASE</spring.framework.version> <spring.framework.version>3.2.10.RELEASE</spring.framework.version>
<spring.security.version>3.2.1.RELEASE</spring.security.version> <spring.security.version>3.2.1.RELEASE</spring.security.version>
<spring.security.oauth2.version>1.0.5.RELEASE</spring.security.oauth2.version> <spring.security.oauth2.version>1.0.5.RELEASE</spring.security.oauth2.version>
<org.springframework.social-version>1.0.3.RELEASE</org.springframework.social-version> <org.springframework.social-version>1.1.0.RELEASE</org.springframework.social-version>
<org.springframework.social-google-version>1.0.0.M3</org.springframework.social-google-version> <org.springframework.social-google-version>1.0.0.RELEASE</org.springframework.social-google-version>
<mysql.version>5.1.31</mysql.version> <mysql.version>5.1.31</mysql.version>
<hazelcast.version>3.4</hazelcast.version> <hazelcast.version>3.4</hazelcast.version>
...@@ -68,7 +68,7 @@ ...@@ -68,7 +68,7 @@
<jaxb-api.version>2.1</jaxb-api.version> <jaxb-api.version>2.1</jaxb-api.version>
<!--Container --> <!--Container -->
<jetty.version>9.1.2.v20140210</jetty.version> <jetty.version>9.2.9.v20150224</jetty.version>
<maven.test.skip>false</maven.test.skip> <maven.test.skip>false</maven.test.skip>
...@@ -77,6 +77,10 @@ ...@@ -77,6 +77,10 @@
<repositories> <repositories>
<repository> <repository>
<id>central</id>
<url>http://repo.maven.apache.org/maven2</url>
</repository>
<!-- <repository>
<id>JBOSS</id> <id>JBOSS</id>
<url>http://repository.jboss.org/nexus/content/groups/public</url> <url>http://repository.jboss.org/nexus/content/groups/public</url>
</repository> </repository>
...@@ -84,13 +88,13 @@ ...@@ -84,13 +88,13 @@
<id>ibiblio.mirrors</id> <id>ibiblio.mirrors</id>
<name>ibiblio.mirrors</name> <name>ibiblio.mirrors</name>
<url>http://mirrors.ibiblio.org/pub/mirrors/maven2</url> <url>http://mirrors.ibiblio.org/pub/mirrors/maven2</url>
</repository> </repository> -->
<repository> <!-- <repository>
<id>spring-social-google</id> <id>spring-social-google</id>
<name>Spring Social Google</name> <name>Spring Social Google</name>
<url>http://gabiaxel.github.io/maven/</url> <url>http://gabiaxel.github.io/maven/</url>
</repository> </repository> -->
<repository> <!-- <repository>
<id>sonatype-oss</id> <id>sonatype-oss</id>
<url>https://oss.sonatype.org/content/groups/public</url> <url>https://oss.sonatype.org/content/groups/public</url>
</repository> </repository>
...@@ -98,19 +102,15 @@ ...@@ -98,19 +102,15 @@
<id>releases</id> <id>releases</id>
<name>Releases</name> <name>Releases</name>
<url>https://oss.sonatype.org/content/repositories/releases</url> <url>https://oss.sonatype.org/content/repositories/releases</url>
</repository> </repository> -->
<repository>
<id>sonatype mirror</id>
<url>http://search.maven.org/remotecontent?filepath=</url>
</repository>
</repositories> </repositories>
<pluginRepositories> <!-- <pluginRepositories>
<pluginRepository> <pluginRepository>
<id>sonatype mirror</id> <id>sonatype mirror</id>
<url>http://search.maven.org/remotecontent?filepath=</url> <url>http://search.maven.org/remotecontent?filepath=</url>
</pluginRepository> </pluginRepository>
</pluginRepositories> </pluginRepositories> -->
<dependencies> <dependencies>
...@@ -326,11 +326,6 @@ ...@@ -326,11 +326,6 @@
<version>0.0.7</version> <version>0.0.7</version>
</dependency> </dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.2.5</version>
</dependency>
<dependency> <dependency>
<groupId>net.sf.opencsv</groupId> <groupId>net.sf.opencsv</groupId>
...@@ -472,46 +467,6 @@ ...@@ -472,46 +467,6 @@
<version>${org.springframework.social-version}</version> <version>${org.springframework.social-version}</version>
</dependency> </dependency>
<dependency>
<groupId>com.google.oauth-client</groupId>
<artifactId>google-oauth-client-servlet</artifactId>
<version>1.17.0-rc</version>
<exclusions>
<exclusion>
<artifactId>servlet-api</artifactId>
<groupId>javax.servlet</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.googlecode.googleplus</groupId>
<artifactId>google-plus-java-api</artifactId>
<exclusions>
<exclusion>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
</exclusion>
<exclusion>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
</exclusion>
</exclusions>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.google.api.client</groupId>
<artifactId>google-api-client</artifactId>
<exclusions>
<exclusion>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
</exclusion>
</exclusions>
<version>1.3.1-alpha</version>
</dependency>
<dependency> <dependency>
<groupId>xml-apis</groupId> <groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId> <artifactId>xml-apis</artifactId>
...@@ -538,6 +493,11 @@ ...@@ -538,6 +493,11 @@
<artifactId>prettytime</artifactId> <artifactId>prettytime</artifactId>
<version>3.2.5.Final</version> <version>3.2.5.Final</version>
</dependency> </dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.3.6</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
......
...@@ -16,8 +16,6 @@ ...@@ -16,8 +16,6 @@
package org.genesys2.server.service; package org.genesys2.server.service;
import java.util.List;
public interface SearchService { public interface SearchService {
// <T> List<T> autocomplete(String searchQuery, Class<T> clazz); // <T> List<T> autocomplete(String searchQuery, Class<T> clazz);
......
...@@ -35,7 +35,7 @@ import org.springframework.security.web.authentication.SavedRequestAwareAuthenti ...@@ -35,7 +35,7 @@ import org.springframework.security.web.authentication.SavedRequestAwareAuthenti
import org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler; import org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler;
import org.springframework.social.google.api.Google; import org.springframework.social.google.api.Google;
import org.springframework.social.google.api.impl.GoogleTemplate; import org.springframework.social.google.api.impl.GoogleTemplate;
import org.springframework.social.google.api.userinfo.GoogleUserInfo; import org.springframework.social.google.api.plus.Person;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
...@@ -74,11 +74,11 @@ public class GoogleSocialController extends BaseController { ...@@ -74,11 +74,11 @@ public class GoogleSocialController extends BaseController {
} }
final Google google = new GoogleTemplate(accessToken); final Google google = new GoogleTemplate(accessToken);
final GoogleUserInfo userInfo = google.userOperations().getUserInfo(); final Person userInfo = google.plusOperations().getGoogleProfile();
if (!userService.exists(userInfo.getEmail())) { if (!userService.exists(userInfo.getAccountEmail())) {
final String pwd = RandomStringUtils.randomAlphanumeric(20); final String pwd = RandomStringUtils.randomAlphanumeric(20);
final User user = userService.createAccount(userInfo.getEmail(), pwd, userInfo.getName()); final User user = userService.createAccount(userInfo.getAccountEmail(), pwd, userInfo.getDisplayName());
userService.userEmailValidated(user.getUuid()); userService.userEmailValidated(user.getUuid());
} }
......
...@@ -29,11 +29,11 @@ import org.apache.commons.logging.Log; ...@@ -29,11 +29,11 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair; import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.URLEncodedUtils; import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.message.BasicNameValuePair; import org.apache.http.message.BasicNameValuePair;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
...@@ -43,7 +43,7 @@ import org.springframework.security.core.context.SecurityContextHolder; ...@@ -43,7 +43,7 @@ import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.social.google.api.userinfo.GoogleUserInfo; import org.springframework.social.google.api.plus.Person;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
...@@ -54,8 +54,8 @@ public class GoogleOAuthUtil { ...@@ -54,8 +54,8 @@ public class GoogleOAuthUtil {
private static final Log LOG = LogFactory.getLog(GoogleOAuthUtil.class); private static final Log LOG = LogFactory.getLog(GoogleOAuthUtil.class);
public static final String LOCAL_GOOGLEAUTH_PATH = "/google/auth"; public static final String LOCAL_GOOGLEAUTH_PATH = "/google/auth";
private ObjectMapper mapper=new ObjectMapper(); private ObjectMapper mapper = new ObjectMapper();
@Value("${base.url}") @Value("${base.url}")
private String baseUrl; private String baseUrl;
...@@ -70,30 +70,35 @@ public class GoogleOAuthUtil { ...@@ -70,30 +70,35 @@ public class GoogleOAuthUtil {
private UserDetailsService userDetailsService; private UserDetailsService userDetailsService;
public String exchangeForAccessToken(HttpServletRequest request) throws IOException { public String exchangeForAccessToken(HttpServletRequest request) throws IOException {
final HttpClient httpclient = new DefaultHttpClient(); final CloseableHttpClient httpclient = HttpClientBuilder.create().build();
final HttpPost httppost = new HttpPost("https://accounts.google.com/o/oauth2/token");
try {
final HttpPost httppost = new HttpPost("https://accounts.google.com/o/oauth2/token");
final List<NameValuePair> params = new ArrayList<>(); final List<NameValuePair> params = new ArrayList<>();
params.add(new BasicNameValuePair("code", request.getParameter("code"))); params.add(new BasicNameValuePair("code", request.getParameter("code")));
params.add(new BasicNameValuePair("client_id", googleApiClientId)); params.add(new BasicNameValuePair("client_id", googleApiClientId));
params.add(new BasicNameValuePair("client_secret", secret)); params.add(new BasicNameValuePair("client_secret", secret));
params.add(new BasicNameValuePair("redirect_uri", baseUrl + LOCAL_GOOGLEAUTH_PATH)); params.add(new BasicNameValuePair("redirect_uri", baseUrl + LOCAL_GOOGLEAUTH_PATH));
params.add(new BasicNameValuePair("grant_type", "authorization_code")); params.add(new BasicNameValuePair("grant_type", "authorization_code"));
params.add(new BasicNameValuePair("scope", "")); params.add(new BasicNameValuePair("scope", ""));
httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8")); httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
final HttpResponse response = httpclient.execute(httppost); final HttpResponse response = httpclient.execute(httppost);
final BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8")); final BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
final StringBuilder builder = new StringBuilder(); final StringBuilder builder = new StringBuilder();
for (String line = null; (line = reader.readLine()) != null;) { for (String line = null; (line = reader.readLine()) != null;) {
builder.append(line).append("\n"); builder.append(line).append("\n");
} }
JsonNode json = mapper.readTree(builder.toString()); JsonNode json = mapper.readTree(builder.toString());
return json.has("access_token") ? json.get("access_token").textValue() : null; return json.has("access_token") ? json.get("access_token").textValue() : null;
} finally {
httpclient.close();
}
} }
public String getAuthenticationUrl() { public String getAuthenticationUrl() {
...@@ -113,12 +118,12 @@ public class GoogleOAuthUtil { ...@@ -113,12 +118,12 @@ public class GoogleOAuthUtil {
return "https://accounts.google.com/o/oauth2/auth?" + query; return "https://accounts.google.com/o/oauth2/auth?" + query;
} }
public Authentication googleAuthentication(GoogleUserInfo userInfo) { public Authentication googleAuthentication(Person userInfo) {
try { try {
final UserDetails userDetails = userDetailsService.loadUserByUsername(userInfo.getEmail()); final UserDetails userDetails = userDetailsService.loadUserByUsername(userInfo.getAccountEmail());
if (!(userDetails.isEnabled() && userDetails.isAccountNonExpired() && userDetails.isAccountNonLocked() && userDetails.isCredentialsNonExpired())) { if (!(userDetails.isEnabled() && userDetails.isAccountNonExpired() && userDetails.isAccountNonLocked() && userDetails.isCredentialsNonExpired())) {
LOG.warn("Google login canceled: Account currently not available: " + userInfo.getEmail()); LOG.warn("Google login canceled: Account currently not available: " + userInfo.getAccountEmail());
return null; return null;
} }
...@@ -127,7 +132,7 @@ public class GoogleOAuthUtil { ...@@ -127,7 +132,7 @@ public class GoogleOAuthUtil {
return authentication; return authentication;
} catch (final UsernameNotFoundException e) { } catch (final UsernameNotFoundException e) {
LOG.warn("Authentication with Google+ failed: No such user " + userInfo.getEmail()); LOG.warn("Authentication with Google+ failed: No such user " + userInfo.getAccountEmail());
return null; return null;
} }
} }
......
...@@ -19,19 +19,16 @@ package org.genesys2.server.oauth; ...@@ -19,19 +19,16 @@ package org.genesys2.server.oauth;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import java.io.IOException; import java.io.IOException;
import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import org.apache.commons.collections.SetUtils;
import org.junit.Test; import org.junit.Test;
import org.springframework.security.oauth2.common.DefaultExpiringOAuth2RefreshToken; import org.springframework.security.oauth2.common.DefaultExpiringOAuth2RefreshToken;
import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken; import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken;
import org.springframework.security.oauth2.common.DefaultOAuth2RefreshToken; import org.springframework.security.oauth2.common.DefaultOAuth2RefreshToken;
import org.springframework.security.oauth2.common.OAuth2AccessToken;
import org.springframework.security.oauth2.common.OAuth2RefreshToken; import org.springframework.security.oauth2.common.OAuth2RefreshToken;
import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.JsonProcessingException;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment