Permalink
Browse files

Cleanup

  • Loading branch information...
1 parent 7b8e4e5 commit 2db1cc16e9caf0994799d4c5404d97bc73476502 @donbeave committed Jan 27, 2014
View
@@ -1,14 +1,10 @@
*.iws
-*Db.properties
-*Db.script
.settings
-stacktrace.log
-/*.zip
-/plugin.xml
-/*.log
-/*DB.*
-/cobertura.ser
-.DS_Store
-/target/
-/web-app/
-/target-eclipse/
+*.log
+/target
+/web-app
+grails-app/i18n
+*~
+plugin.xml
+*.zip
+*.zip.sha1
@@ -1,28 +1,25 @@
/**
-* @author <a href='mailto:cazacugmihai@gmail.com'>Mihai Cazacu</a>
-* @author <a href='mailto:enrico@comiti.name'>Enrico Comiti</a>
-* @author <a href='mailto:donbeave@gmail.com'>Alexey Zhokhov</a>
-*/
+ * @author <a href='mailto:cazacugmihai@gmail.com'>Mihai Cazacu</a>
+ * @author <a href='mailto:enrico@comiti.name'>Enrico Comiti</a>
+ * @author <a href='mailto:donbeave@gmail.com'>Alexey Zhokhov</a>
+ */
class SpringSecurityOauthGoogleGrailsPlugin {
- def version = "0.2"
- def grailsVersion = "2.0 > *"
- def dependsOn = [springSecurityOauth: '2.0.2 > *']
+ def version = '0.2'
+ def grailsVersion = '2.0 > *'
- def title = "Google for Spring Security OAuth plugin"
- def author = "Mihai Cazacu, Enrico Comiti, Alexey Zhokhov"
- def authorEmail = "donbeave@gmail.com"
+ def title = 'Google for Spring Security OAuth plugin'
def description = '''\
Integrate [Google|http://www.google.com] to [Spring Security OAuth plugin|http://grails.org/plugin/spring-security-oauth].
'''
- def documentation = "https://github.com/donbeave/grails-spring-security-oauth-google"
+ def documentation = 'https://github.com/donbeave/grails-spring-security-oauth-google'
- def license = "APACHE"
+ def license = 'APACHE'
def developers = [
- [name: "Mihai Cazacu", email: "cazacugmihai@gmail.com"],
- [name: "Enrico Comiti", email: "enrico@comiti.name"],
- [name: "Alexey Zhokhov", email: "donbeave@gmail.com"]]
+ [name: 'Mihai Cazacu', email: 'cazacugmihai@gmail.com'],
+ [name: 'Enrico Comiti', email: 'enrico@comiti.name'],
+ [name: 'Alexey Zhokhov', email: 'donbeave@gmail.com']]
def issueManagement = [system: 'GITHUB', url: 'https://github.com/donbeave/grails-spring-security-oauth-google/issues']
View
@@ -1,4 +1,2 @@
-#Grails Metadata file
-#Thu Jan 23 23:21:01 CET 2014
app.grails.version=2.3.5
app.name=spring-security-oauth-google
@@ -1,13 +1,13 @@
-grails.project.class.dir = "target/classes"
-grails.project.test.class.dir = "target/test-classes"
-grails.project.test.reports.dir = "target/test-reports"
+grails.project.class.dir = 'target/classes'
+grails.project.test.class.dir = 'target/test-classes'
+grails.project.test.reports.dir = 'target/test-reports'
-grails.project.dependency.resolver = "maven"
+grails.project.dependency.resolver = 'maven'
grails.project.dependency.resolution = {
- inherits("global") {
+ inherits('global') {
}
- log "warn"
+ log 'warn'
repositories {
grailsCentral()
mavenLocal()
@@ -20,8 +20,8 @@ grails.project.dependency.resolution = {
plugins {
compile ':spring-security-oauth:2.0.2'
- build(":release:3.0.1",
- ":rest-client-builder:1.0.3") {
+ build(':release:3.0.1',
+ ':rest-client-builder:1.0.3') {
export = false
}
}
@@ -1,25 +0,0 @@
-// configuration for plugin testing - will not be included in the plugin zip
-
-log4j = {
-
- error 'org.codehaus.groovy.grails.web.servlet', // controllers
- 'org.codehaus.groovy.grails.web.pages', // GSP
- 'org.codehaus.groovy.grails.web.sitemesh', // layouts
- 'org.codehaus.groovy.grails.web.mapping.filter', // URL mapping
- 'org.codehaus.groovy.grails.web.mapping', // URL mapping
- 'org.codehaus.groovy.grails.commons', // core / classloading
- 'org.codehaus.groovy.grails.plugins', // plugins
- 'org.codehaus.groovy.grails.orm.hibernate', // hibernate integration
- 'org.springframework',
- 'org.hibernate',
- 'net.sf.ehcache.hibernate'
-}
-
-// just for test, to avoid oauthService BeanCreationException "No oauth configuration found"
-environments {
- test {
- oauth {
- providers {}
- }
- }
-}
@@ -18,7 +18,7 @@ package grails.plugin.springsecurity.oauth
import grails.converters.JSON
/**
- * @author Mihai CAZACU(cazacugmihai@gmail.com)
+ * @author <a href='mailto:cazacugmihai@gmail.com'>Mihai Cazacu</a>
*/
class GoogleSpringSecurityOAuthService {
@@ -30,17 +30,17 @@ class GoogleSpringSecurityOAuthService {
* { "email": "username@gmail.com", "verified_email": true }
*/
def createAuthToken(accessToken) {
- def response = oauthService.getGoogleResource(accessToken, "https://www.googleapis.com/oauth2/v1/userinfo")
+ def response = oauthService.getGoogleResource(accessToken, 'https://www.googleapis.com/oauth2/v1/userinfo')
def user
try {
user = JSON.parse(response.body)
} catch (Exception e) {
log.error "Error parsing response from Google. Response:\n${response.body}"
- throw new OAuthLoginException("Error parsing response from Google", e)
+ throw new OAuthLoginException('Error parsing response from Google', e)
}
- if (! user?.email) {
+ if (!user?.email) {
log.error "No user email from Google. Response:\n${response.body}"
- throw new OAuthLoginException("No user email from Google")
+ throw new OAuthLoginException('No user email from Google')
}
return new GoogleOAuthToken(accessToken, user.email)
}
@@ -26,7 +26,7 @@ import org.scribe.model.Token
*/
class GoogleOAuthToken extends OAuthToken {
- public static final String PROVIDER_NAME = "google"
+ public static final String PROVIDER_NAME = 'google'
String email
@@ -39,7 +39,7 @@ class GoogleOAuthToken extends OAuthToken {
String getSocialId() {
return email
}
-
+
String getScreenName() {
return email
}
@@ -1,10 +1,9 @@
package org.grails.plugin.springsecurity.oauth;
+import org.scribe.builder.api.DefaultApi20;
import org.scribe.exceptions.OAuthException;
import org.scribe.extractors.AccessTokenExtractor;
import org.scribe.model.*;
-import org.scribe.builder.*;
-import org.scribe.builder.api.*;
import org.scribe.oauth.OAuth20ServiceImpl;
import org.scribe.oauth.OAuthService;
import org.scribe.utils.OAuthEncoder;
@@ -21,91 +20,91 @@
*/
public class GoogleApi20 extends DefaultApi20 {
- private static final String AUTHORIZE_URL = "https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=%s&redirect_uri=%s";
- private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=%s";
+ private static final String AUTHORIZE_URL = "https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=%s&redirect_uri=%s";
+ private static final String SCOPED_AUTHORIZE_URL = AUTHORIZE_URL + "&scope=%s";
- @Override
- public String getAccessTokenEndpoint() {
- return "https://accounts.google.com/o/oauth2/token";
- }
-
- @Override
- public AccessTokenExtractor getAccessTokenExtractor() {
- return new AccessTokenExtractor() {
+ @Override
+ public String getAccessTokenEndpoint() {
+ return "https://accounts.google.com/o/oauth2/token";
+ }
- @Override
- public Token extract(String response) {
- Preconditions.checkEmptyString(response, "Response body is incorrect. Can't extract a token from an empty string");
+ @Override
+ public AccessTokenExtractor getAccessTokenExtractor() {
+ return new AccessTokenExtractor() {
+
+ @Override
+ public Token extract(String response) {
+ Preconditions.checkEmptyString(response, "Response body is incorrect. Can't extract a token from an empty string");
+
+ Matcher matcher = Pattern.compile("\"access_token\" : \"([^&\"]+)\"").matcher(response);
+ if (matcher.find()) {
+ String token = OAuthEncoder.decode(matcher.group(1));
+ return new Token(token, "", response);
+ } else {
+ throw new OAuthException("Response body is incorrect. Can't extract a token from this: '" + response + "'", null);
+ }
+ }
+ };
+ }
- Matcher matcher = Pattern.compile("\"access_token\" : \"([^&\"]+)\"").matcher(response);
- if (matcher.find()) {
- String token = OAuthEncoder.decode(matcher.group(1));
- return new Token(token, "", response);
+ @Override
+ public String getAuthorizationUrl(OAuthConfig config) {
+ // Append scope if present
+ if (config.hasScope()) {
+ return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(),
+ OAuthEncoder.encode(config.getCallback()),
+ OAuthEncoder.encode(config.getScope()));
} else {
- throw new OAuthException("Response body is incorrect. Can't extract a token from this: '" + response + "'", null);
+ return String.format(AUTHORIZE_URL, config.getApiKey(),
+ OAuthEncoder.encode(config.getCallback()));
}
- }
- };
- }
-
- @Override
- public String getAuthorizationUrl(OAuthConfig config) {
- // Append scope if present
- if (config.hasScope()) {
- return String.format(SCOPED_AUTHORIZE_URL, config.getApiKey(),
- OAuthEncoder.encode(config.getCallback()),
- OAuthEncoder.encode(config.getScope()));
- } else {
- return String.format(AUTHORIZE_URL, config.getApiKey(),
- OAuthEncoder.encode(config.getCallback()));
}
- }
- @Override
- public Verb getAccessTokenVerb() {
- return Verb.POST;
- }
+ @Override
+ public Verb getAccessTokenVerb() {
+ return Verb.POST;
+ }
- @Override
- public OAuthService createService(OAuthConfig config) {
- return new GoogleOAuth2Service(this, config);
- }
+ @Override
+ public OAuthService createService(OAuthConfig config) {
+ return new GoogleOAuth2Service(this, config);
+ }
- private class GoogleOAuth2Service extends OAuth20ServiceImpl {
+ private class GoogleOAuth2Service extends OAuth20ServiceImpl {
- private static final String GRANT_TYPE_AUTHORIZATION_CODE = "authorization_code";
- private static final String GRANT_TYPE = "grant_type";
- private DefaultApi20 api;
- private OAuthConfig config;
+ private static final String GRANT_TYPE_AUTHORIZATION_CODE = "authorization_code";
+ private static final String GRANT_TYPE = "grant_type";
+ private DefaultApi20 api;
+ private OAuthConfig config;
- public GoogleOAuth2Service(DefaultApi20 api, OAuthConfig config) {
- super(api, config);
- this.api = api;
- this.config = config;
- }
+ public GoogleOAuth2Service(DefaultApi20 api, OAuthConfig config) {
+ super(api, config);
+ this.api = api;
+ this.config = config;
+ }
- @Override
- public Token getAccessToken(Token requestToken, Verifier verifier) {
- OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint());
- switch (api.getAccessTokenVerb()) {
- case POST:
- request.addBodyParameter(OAuthConstants.CLIENT_ID, config.getApiKey());
- request.addBodyParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret());
- request.addBodyParameter(OAuthConstants.CODE, verifier.getValue());
- request.addBodyParameter(OAuthConstants.REDIRECT_URI, config.getCallback());
- request.addBodyParameter(GRANT_TYPE, GRANT_TYPE_AUTHORIZATION_CODE);
- break;
- case GET:
- default:
- request.addQuerystringParameter(OAuthConstants.CLIENT_ID, config.getApiKey());
- request.addQuerystringParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret());
- request.addQuerystringParameter(OAuthConstants.CODE, verifier.getValue());
- request.addQuerystringParameter(OAuthConstants.REDIRECT_URI, config.getCallback());
- if (config.hasScope()) request.addQuerystringParameter(OAuthConstants.SCOPE, config.getScope());
- }
- Response response = request.send();
- return api.getAccessTokenExtractor().extract(response.getBody());
+ @Override
+ public Token getAccessToken(Token requestToken, Verifier verifier) {
+ OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint());
+ switch (api.getAccessTokenVerb()) {
+ case POST:
+ request.addBodyParameter(OAuthConstants.CLIENT_ID, config.getApiKey());
+ request.addBodyParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret());
+ request.addBodyParameter(OAuthConstants.CODE, verifier.getValue());
+ request.addBodyParameter(OAuthConstants.REDIRECT_URI, config.getCallback());
+ request.addBodyParameter(GRANT_TYPE, GRANT_TYPE_AUTHORIZATION_CODE);
+ break;
+ case GET:
+ default:
+ request.addQuerystringParameter(OAuthConstants.CLIENT_ID, config.getApiKey());
+ request.addQuerystringParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret());
+ request.addQuerystringParameter(OAuthConstants.CODE, verifier.getValue());
+ request.addQuerystringParameter(OAuthConstants.REDIRECT_URI, config.getCallback());
+ if (config.hasScope()) request.addQuerystringParameter(OAuthConstants.SCOPE, config.getScope());
+ }
+ Response response = request.send();
+ return api.getAccessTokenExtractor().extract(response.getBody());
+ }
}
- }
}
Oops, something went wrong.

0 comments on commit 2db1cc1

Please sign in to comment.