Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Genesys PGR
Genesys Backend
Commits
f4d85f95
Commit
f4d85f95
authored
Feb 25, 2015
by
Matija Obreza
Browse files
Updated and cleaned up dependencies
Using spring-social-google instead of google-plus-java-api
parent
1e1045b6
Changes
5
Hide whitespace changes
Inline
Side-by-side
pom.xml
View file @
f4d85f95
...
...
@@ -57,8 +57,8 @@
<spring.framework.version>
3.2.10.RELEASE
</spring.framework.version>
<spring.security.version>
3.2.1.RELEASE
</spring.security.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-google-version>
1.0.0.
M3
</org.springframework.social-google-version>
<org.springframework.social-version>
1.
1.0
.RELEASE
</org.springframework.social-version>
<org.springframework.social-google-version>
1.0.0.
RELEASE
</org.springframework.social-google-version>
<mysql.version>
5.1.31
</mysql.version>
<hazelcast.version>
3.4
</hazelcast.version>
...
...
@@ -68,7 +68,7 @@
<jaxb-api.version>
2.1
</jaxb-api.version>
<!--Container -->
<jetty.version>
9.
1.2
.v201
4
02
10
</jetty.version>
<jetty.version>
9.
2.9
.v201
5
02
24
</jetty.version>
<maven.test.skip>
false
</maven.test.skip>
...
...
@@ -77,6 +77,10 @@
<repositories>
<repository>
<id>
central
</id>
<url>
http://repo.maven.apache.org/maven2
</url>
</repository>
<!-- <repository>
<id>JBOSS</id>
<url>http://repository.jboss.org/nexus/content/groups/public</url>
</repository>
...
...
@@ -84,13 +88,13 @@
<id>ibiblio.mirrors</id>
<name>ibiblio.mirrors</name>
<url>http://mirrors.ibiblio.org/pub/mirrors/maven2</url>
</repository>
<repository>
</repository>
-->
<!--
<repository>
<id>spring-social-google</id>
<name>Spring Social Google</name>
<url>http://gabiaxel.github.io/maven/</url>
</repository>
<repository>
</repository>
-->
<!--
<repository>
<id>sonatype-oss</id>
<url>https://oss.sonatype.org/content/groups/public</url>
</repository>
...
...
@@ -98,19 +102,15 @@
<id>releases</id>
<name>Releases</name>
<url>https://oss.sonatype.org/content/repositories/releases</url>
</repository>
<repository>
<id>
sonatype mirror
</id>
<url>
http://search.maven.org/remotecontent?filepath=
</url>
</repository>
</repository> -->
</repositories>
<pluginRepositories>
<!--
<pluginRepositories>
<pluginRepository>
<id>sonatype mirror</id>
<url>http://search.maven.org/remotecontent?filepath=</url>
</pluginRepository>
</pluginRepositories>
</pluginRepositories>
-->
<dependencies>
...
...
@@ -326,11 +326,6 @@
<version>
0.0.7
</version>
</dependency>
<dependency>
<groupId>
org.apache.httpcomponents
</groupId>
<artifactId>
httpclient
</artifactId>
<version>
4.2.5
</version>
</dependency>
<dependency>
<groupId>
net.sf.opencsv
</groupId>
...
...
@@ -472,46 +467,6 @@
<version>
${org.springframework.social-version}
</version>
</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>
<groupId>
xml-apis
</groupId>
<artifactId>
xml-apis
</artifactId>
...
...
@@ -538,6 +493,11 @@
<artifactId>
prettytime
</artifactId>
<version>
3.2.5.Final
</version>
</dependency>
<dependency>
<groupId>
org.apache.httpcomponents
</groupId>
<artifactId>
httpclient
</artifactId>
<version>
4.3.6
</version>
</dependency>
</dependencies>
<build>
...
...
src/main/java/org/genesys2/server/service/SearchService.java
View file @
f4d85f95
...
...
@@ -16,8 +16,6 @@
package
org.genesys2.server.service
;
import
java.util.List
;
public
interface
SearchService
{
// <T> List<T> autocomplete(String searchQuery, Class<T> clazz);
...
...
src/main/java/org/genesys2/server/servlet/controller/GoogleSocialController.java
View file @
f4d85f95
...
...
@@ -35,7 +35,7 @@ import org.springframework.security.web.authentication.SavedRequestAwareAuthenti
import
org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler
;
import
org.springframework.social.google.api.Google
;
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.ui.Model
;
import
org.springframework.web.bind.annotation.RequestMapping
;
...
...
@@ -74,11 +74,11 @@ public class GoogleSocialController extends BaseController {
}
final
Google
google
=
new
GoogleTemplate
(
accessToken
);
final
GoogleUserInfo
userInfo
=
google
.
us
er
Operations
().
get
UserInfo
();
final
Person
userInfo
=
google
.
pl
usOperations
().
get
GoogleProfile
();
if
(!
userService
.
exists
(
userInfo
.
getEmail
()))
{
if
(!
userService
.
exists
(
userInfo
.
get
Account
Email
()))
{
final
String
pwd
=
RandomStringUtils
.
randomAlphanumeric
(
20
);
final
User
user
=
userService
.
createAccount
(
userInfo
.
getEmail
(),
pwd
,
userInfo
.
getName
());
final
User
user
=
userService
.
createAccount
(
userInfo
.
get
Account
Email
(),
pwd
,
userInfo
.
get
Display
Name
());
userService
.
userEmailValidated
(
user
.
getUuid
());
}
...
...
src/main/java/org/genesys2/server/servlet/util/GoogleOAuthUtil.java
View file @
f4d85f95
...
...
@@ -29,11 +29,11 @@ import org.apache.commons.logging.Log;
import
org.apache.commons.logging.LogFactory
;
import
org.apache.http.HttpResponse
;
import
org.apache.http.NameValuePair
;
import
org.apache.http.client.HttpClient
;
import
org.apache.http.client.entity.UrlEncodedFormEntity
;
import
org.apache.http.client.methods.HttpPost
;
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.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
...
...
@@ -43,7 +43,7 @@ import org.springframework.security.core.context.SecurityContextHolder;
import
org.springframework.security.core.userdetails.UserDetails
;
import
org.springframework.security.core.userdetails.UserDetailsService
;
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
com.fasterxml.jackson.databind.JsonNode
;
...
...
@@ -54,8 +54,8 @@ public class GoogleOAuthUtil {
private
static
final
Log
LOG
=
LogFactory
.
getLog
(
GoogleOAuthUtil
.
class
);
public
static
final
String
LOCAL_GOOGLEAUTH_PATH
=
"/google/auth"
;
private
ObjectMapper
mapper
=
new
ObjectMapper
();
private
ObjectMapper
mapper
=
new
ObjectMapper
();
@Value
(
"${base.url}"
)
private
String
baseUrl
;
...
...
@@ -70,30 +70,35 @@ public class GoogleOAuthUtil {
private
UserDetailsService
userDetailsService
;
public
String
exchangeForAccessToken
(
HttpServletRequest
request
)
throws
IOException
{
final
HttpClient
httpclient
=
new
DefaultHttpClient
();
final
HttpPost
httppost
=
new
HttpPost
(
"https://accounts.google.com/o/oauth2/token"
);
final
CloseableHttpClient
httpclient
=
HttpClientBuilder
.
create
().
build
();
try
{
final
HttpPost
httppost
=
new
HttpPost
(
"https://accounts.google.com/o/oauth2/token"
);
final
List
<
NameValuePair
>
params
=
new
ArrayList
<>();
params
.
add
(
new
BasicNameValuePair
(
"code"
,
request
.
getParameter
(
"code"
)));
params
.
add
(
new
BasicNameValuePair
(
"client_id"
,
googleApiClientId
));
params
.
add
(
new
BasicNameValuePair
(
"client_secret"
,
secret
));
params
.
add
(
new
BasicNameValuePair
(
"redirect_uri"
,
baseUrl
+
LOCAL_GOOGLEAUTH_PATH
));
params
.
add
(
new
BasicNameValuePair
(
"grant_type"
,
"authorization_code"
));
params
.
add
(
new
BasicNameValuePair
(
"scope"
,
""
));
final
List
<
NameValuePair
>
params
=
new
ArrayList
<>();
params
.
add
(
new
BasicNameValuePair
(
"code"
,
request
.
getParameter
(
"code"
)));
params
.
add
(
new
BasicNameValuePair
(
"client_id"
,
googleApiClientId
));
params
.
add
(
new
BasicNameValuePair
(
"client_secret"
,
secret
));
params
.
add
(
new
BasicNameValuePair
(
"redirect_uri"
,
baseUrl
+
LOCAL_GOOGLEAUTH_PATH
));
params
.
add
(
new
BasicNameValuePair
(
"grant_type"
,
"authorization_code"
));
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
StringBuilder
builder
=
new
StringBuilder
();
for
(
String
line
=
null
;
(
line
=
reader
.
readLine
())
!=
null
;)
{
builder
.
append
(
line
).
append
(
"\n"
);
}
final
BufferedReader
reader
=
new
BufferedReader
(
new
InputStreamReader
(
response
.
getEntity
().
getContent
(),
"UTF-8"
));
final
StringBuilder
builder
=
new
StringBuilder
();
for
(
String
line
=
null
;
(
line
=
reader
.
readLine
())
!=
null
;)
{
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
()
{
...
...
@@ -113,12 +118,12 @@ public class GoogleOAuthUtil {
return
"https://accounts.google.com/o/oauth2/auth?"
+
query
;
}
public
Authentication
googleAuthentication
(
GoogleUserInfo
userInfo
)
{
public
Authentication
googleAuthentication
(
Person
userInfo
)
{
try
{
final
UserDetails
userDetails
=
userDetailsService
.
loadUserByUsername
(
userInfo
.
getEmail
());
final
UserDetails
userDetails
=
userDetailsService
.
loadUserByUsername
(
userInfo
.
get
Account
Email
());
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
.
get
Account
Email
());
return
null
;
}
...
...
@@ -127,7 +132,7 @@ public class GoogleOAuthUtil {
return
authentication
;
}
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
.
get
Account
Email
());
return
null
;
}
}
...
...
src/test/java/org/genesys2/server/oauth/OAuthTokenSerializationTest.java
View file @
f4d85f95
...
...
@@ -19,19 +19,16 @@ package org.genesys2.server.oauth;
import
static
org
.
junit
.
Assert
.*;
import
java.io.IOException
;
import
java.util.Collections
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.Map
;
import
java.util.Set
;
import
org.apache.commons.collections.SetUtils
;
import
org.junit.Test
;
import
org.springframework.security.oauth2.common.DefaultExpiringOAuth2RefreshToken
;
import
org.springframework.security.oauth2.common.DefaultOAuth2AccessToken
;
import
org.springframework.security.oauth2.common.DefaultOAuth2RefreshToken
;
import
org.springframework.security.oauth2.common.OAuth2AccessToken
;
import
org.springframework.security.oauth2.common.OAuth2RefreshToken
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment