Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Genesys Backend
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
46
Issues
46
List
Boards
Labels
Service Desk
Milestones
Operations
Operations
Incidents
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Genesys PGR
Genesys Backend
Commits
f4d85f95
Commit
f4d85f95
authored
Feb 25, 2015
by
Matija Obreza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
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
Showing
5 changed files
with
55 additions
and
95 deletions
+55
-95
pom.xml
pom.xml
+19
-59
src/main/java/org/genesys2/server/service/SearchService.java
src/main/java/org/genesys2/server/service/SearchService.java
+0
-2
src/main/java/org/genesys2/server/servlet/controller/GoogleSocialController.java
...ys2/server/servlet/controller/GoogleSocialController.java
+4
-4
src/main/java/org/genesys2/server/servlet/util/GoogleOAuthUtil.java
...ava/org/genesys2/server/servlet/util/GoogleOAuthUtil.java
+32
-27
src/test/java/org/genesys2/server/oauth/OAuthTokenSerializationTest.java
...rg/genesys2/server/oauth/OAuthTokenSerializationTest.java
+0
-3
No files found.
pom.xml
View file @
f4d85f95
...
@@ -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>
...
...
src/main/java/org/genesys2/server/service/SearchService.java
View file @
f4d85f95
...
@@ -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);
...
...
src/main/java/org/genesys2/server/servlet/controller/GoogleSocialController.java
View file @
f4d85f95
...
@@ -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
.
get
Account
Email
()))
{
final
String
pwd
=
RandomStringUtils
.
randomAlphanumeric
(
20
);
final
String
pwd
=
RandomStringUtils
.
randomAlphanumeric
(
20
);
final
User
user
=
userService
.
createAccount
(
userInfo
.
get
Email
(),
pwd
,
userInfo
.
get
Name
());
final
User
user
=
userService
.
createAccount
(
userInfo
.
get
AccountEmail
(),
pwd
,
userInfo
.
getDisplay
Name
());
userService
.
userEmailValidated
(
user
.
getUuid
());
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;
...
@@ -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
.
get
Account
Email
());
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
.
get
Account
Email
());
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
.
get
Account
Email
());
return
null
;
return
null
;
}
}
}
}
...
...
src/test/java/org/genesys2/server/oauth/OAuthTokenSerializationTest.java
View file @
f4d85f95
...
@@ -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
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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