Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

GREENHOUSE-513 Update to use OAuth 2

  • Loading branch information...
commit 14338c9caf5c2891e6efac219272d7a4267e4218 1 parent 0244fa5
@royclarkson royclarkson authored
Showing with 605 additions and 579 deletions.
  1. +82 −113 AndroidManifest.xml
  2. +2 −2 filters/dev.properties
  3. +6 −5 pom.xml
  4. +4 −4 default.properties → project.properties
  5. +12 −7 res/layout/{signin.xml → authorize.xml}
  6. +89 −0 res/layout/sign_in.xml
  7. +2 −3 res/values/env_settings.xml
  8. +25 −13 res/values/strings.xml
  9. +14 −42 src/com/springsource/greenhouse/MainActivity.java
  10. +41 −42 src/com/springsource/greenhouse/MainApplication.java
  11. +0 −285 src/com/springsource/greenhouse/WebOAuthActivity.java
  12. +17 −9 src/com/springsource/greenhouse/{SignInActivity.java → authorization/AuthorizeActivity.java}
  13. +201 −0 src/com/springsource/greenhouse/authorization/SignInActivity.java
  14. +9 −8 src/org/springframework/social/greenhouse/api/impl/AbstractGreenhouseOperations.java
  15. +2 −2 src/org/springframework/social/greenhouse/api/impl/EventTemplate.java
  16. +6 −10 src/org/springframework/social/greenhouse/api/impl/GreenhouseTemplate.java
  17. +4 −4 src/org/springframework/social/greenhouse/api/impl/SessionTemplate.java
  18. +5 −5 src/org/springframework/social/greenhouse/api/impl/TweetTemplate.java
  19. +6 −7 src/org/springframework/social/greenhouse/api/impl/UserTemplate.java
  20. +24 −6 src/org/springframework/social/greenhouse/connect/GreenhouseConnectionFactory.java
  21. +30 −0 src/org/springframework/social/greenhouse/connect/GreenhouseOAuth2Template.java
  22. +24 −12 src/org/springframework/social/greenhouse/connect/GreenhouseServiceProvider.java
View
195 AndroidManifest.xml
@@ -1,121 +1,90 @@
<?xml version="1.0" encoding="utf-8"?>
-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.springsource.greenhouse"
- android:versionCode="3"
- android:versionName="1.1.1">
-
- <uses-sdk android:minSdkVersion="7"/>
- <uses-permission android:name="android.permission.INTERNET"></uses-permission>
+ package="com.springsource.greenhouse"
+ android:versionCode="3"
+ android:versionName="1.1.1" >
+
+ <uses-sdk android:minSdkVersion="7" />
+
+ <uses-permission android:name="android.permission.INTERNET" >
+ </uses-permission>
<application
- android:name="com.springsource.greenhouse.MainApplication"
- android:icon="@drawable/icon"
- android:label="@string/app_name"
- android:theme="@android:style/Theme.Light">
-
- <activity
- android:name="com.springsource.greenhouse.MainActivity"
- android:theme="@android:style/Theme.Light.NoTitleBar">
-
- <intent-filter>
+ android:name="com.springsource.greenhouse.MainApplication"
+ android:icon="@drawable/icon"
+ android:label="@string/app_name"
+ android:theme="@android:style/Theme.Light" >
+ <activity
+ android:name="com.springsource.greenhouse.MainActivity"
+ android:theme="@android:style/Theme.Light.NoTitleBar" >
+ <intent-filter>
<action android:name="android.intent.action.MAIN" />
+
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
-
- </activity>
-
- <activity
- android:name="com.springsource.greenhouse.SignInActivity"
- android:theme="@android:style/Theme.Light.NoTitleBar" />
-
- <activity
- android:name="com.springsource.greenhouse.WebOAuthActivity"
- android:label="@string/app_name"
- android:noHistory="true"
- android:excludeFromRecents="true" />
-
- <activity
- android:name="com.springsource.greenhouse.MainTabWidget"
- android:label="@string/app_name"
- android:theme="@android:style/Theme.Light.NoTitleBar" />
-
- <activity
- android:name="com.springsource.greenhouse.events.EventsActivityGroup" />
-
- <activity
- android:name="com.springsource.greenhouse.events.EventsActivity" />
-
- <activity
- android:name="com.springsource.greenhouse.events.EventDetailsActivity"
- android:label="@string/title_event_details" />
-
- <activity
- android:name="com.springsource.greenhouse.events.EventDescriptionActivity"
- android:label="@string/title_event_description" />
-
- <activity
- android:name="com.springsource.greenhouse.events.EventTweetsActivity"
- android:label="@string/title_event_tweets" />
-
- <activity
- android:name="com.springsource.greenhouse.events.sessions.EventSessionsFilteredActivity"
- android:label="@string/title_event_sessions_filtered" />
-
- <activity
- android:name="com.springsource.greenhouse.events.sessions.EventSessionsScheduleActivity"
- android:label="@string/title_event_sessions_schedule" />
-
- <activity
- android:name="com.springsource.greenhouse.events.sessions.EventSessionsCurrentActivity"
- android:label="@string/title_event_sessions_current" />
-
- <activity
- android:name="com.springsource.greenhouse.events.sessions.EventSessionsUpcomingActivity"
- android:label="@string/title_event_sessions_upcoming" />
-
- <activity
- android:name="com.springsource.greenhouse.events.sessions.EventSessionsMyFavoritesActivity"
- android:label="@string/title_event_sessions_my_favorites" />
-
- <activity
- android:name="com.springsource.greenhouse.events.sessions.EventSessionsConferenceFavoritesActivity"
- android:label="@string/title_event_sessions_conference_favorites" />
-
- <activity
- android:name="com.springsource.greenhouse.events.sessions.EventSessionsByDayActivity"
- android:label="@string/title_event_sessions_by_day" />
+ </activity>
+ <activity
+ android:name=".authorization.AuthorizeActivity"
+ android:theme="@android:style/Theme.Light.NoTitleBar" />
+ <activity
+ android:name=".authorization.SignInActivity"
+ android:theme="@android:style/Theme.Light.NoTitleBar" />
+ <activity
+ android:name="com.springsource.greenhouse.MainTabWidget"
+ android:label="@string/app_name"
+ android:theme="@android:style/Theme.Light.NoTitleBar" />
+ <activity android:name="com.springsource.greenhouse.events.EventsActivityGroup" />
+ <activity android:name="com.springsource.greenhouse.events.EventsActivity" />
+ <activity
+ android:name="com.springsource.greenhouse.events.EventDetailsActivity"
+ android:label="@string/title_event_details" />
+ <activity
+ android:name="com.springsource.greenhouse.events.EventDescriptionActivity"
+ android:label="@string/title_event_description" />
+ <activity
+ android:name="com.springsource.greenhouse.events.EventTweetsActivity"
+ android:label="@string/title_event_tweets" />
+ <activity
+ android:name="com.springsource.greenhouse.events.sessions.EventSessionsFilteredActivity"
+ android:label="@string/title_event_sessions_filtered" />
+ <activity
+ android:name="com.springsource.greenhouse.events.sessions.EventSessionsScheduleActivity"
+ android:label="@string/title_event_sessions_schedule" />
+ <activity
+ android:name="com.springsource.greenhouse.events.sessions.EventSessionsCurrentActivity"
+ android:label="@string/title_event_sessions_current" />
+ <activity
+ android:name="com.springsource.greenhouse.events.sessions.EventSessionsUpcomingActivity"
+ android:label="@string/title_event_sessions_upcoming" />
+ <activity
+ android:name="com.springsource.greenhouse.events.sessions.EventSessionsMyFavoritesActivity"
+ android:label="@string/title_event_sessions_my_favorites" />
+ <activity
+ android:name="com.springsource.greenhouse.events.sessions.EventSessionsConferenceFavoritesActivity"
+ android:label="@string/title_event_sessions_conference_favorites" />
+ <activity
+ android:name="com.springsource.greenhouse.events.sessions.EventSessionsByDayActivity"
+ android:label="@string/title_event_sessions_by_day" />
+ <activity
+ android:name="com.springsource.greenhouse.events.sessions.EventSessionDetailsActivity"
+ android:label="@string/title_event_session_details" />
+ <activity
+ android:name="com.springsource.greenhouse.events.sessions.EventSessionDescriptionActivity"
+ android:label="@string/title_event_session_description" />
+ <activity
+ android:name="com.springsource.greenhouse.events.sessions.EventSessionRatingActivity"
+ android:label="@string/title_event_session_rating" />
+ <activity
+ android:name="com.springsource.greenhouse.events.sessions.EventSessionTweetsActivity"
+ android:label="@string/title_event_session_tweets" />
+ <activity
+ android:name="com.springsource.greenhouse.twitter.TweetDetailsActivity"
+ android:label="@string/title_tweet_details" />
+ <activity
+ android:name="com.springsource.greenhouse.twitter.PostTweetActivity"
+ android:label="@string/title_post_tweet" />
+ <activity android:name="com.springsource.greenhouse.profile.ProfileActivity" />
+ <activity android:name="com.springsource.greenhouse.InfoActivity" />
+ </application>
- <activity
- android:name="com.springsource.greenhouse.events.sessions.EventSessionDetailsActivity"
- android:label="@string/title_event_session_details" />
-
- <activity
- android:name="com.springsource.greenhouse.events.sessions.EventSessionDescriptionActivity"
- android:label="@string/title_event_session_description" />
-
- <activity
- android:name="com.springsource.greenhouse.events.sessions.EventSessionRatingActivity"
- android:label="@string/title_event_session_rating" />
-
- <activity
- android:name="com.springsource.greenhouse.events.sessions.EventSessionTweetsActivity"
- android:label="@string/title_event_session_tweets" />
-
- <activity
- android:name="com.springsource.greenhouse.twitter.TweetDetailsActivity"
- android:label="@string/title_tweet_details" />
-
- <activity
- android:name="com.springsource.greenhouse.twitter.PostTweetActivity"
- android:label="@string/title_post_tweet" />
-
- <activity
- android:name="com.springsource.greenhouse.profile.ProfileActivity" />
-
- <activity
- android:name="com.springsource.greenhouse.InfoActivity" />
-
- </application>
-
-</manifest>
+</manifest>
View
4 filters/dev.properties
@@ -1,5 +1,5 @@
-consumer.token.key=e9fbccdae98d5696
-consumer.token.secret=9fa283e1eca2d4e8
+client.id=e9fbccdae98d5696
+client.secret=9fa283e1eca2d4e8
connection.repository.encryption.password=password
connection.repository.encryption.salt=5c0744940b5c369b
base.url=http://10.0.2.2:8080/greenhouse/
View
11 pom.xml
@@ -8,14 +8,15 @@
<packaging>apk</packaging>
<name>greenhouse-android</name>
<url>http://www.springsource.org</url>
+ <inceptionYear>2010</inceptionYear>
<organization>
<name>SpringSource</name>
<url>http://www.springsource.org</url>
</organization>
<properties>
- <env>dev</env>
- <android-platform>15</android-platform>
+ <env>prod</env>
+ <android-platform>16</android-platform>
<maven-resources-plugin-version>2.5</maven-resources-plugin-version>
<android-maven-plugin-version>3.3.2</android-maven-plugin-version>
<maven-compiler-plugin-version>2.5.1</maven-compiler-plugin-version>
@@ -29,9 +30,9 @@
<repositories>
<repository>
- <id>spring-milestone</id>
- <name>SpringSource Milestone Repository</name>
- <url>http://repo.springsource.org/libs-milestone</url>
+ <id>spring-snapshot</id>
+ <name>SpringSource Snapshot Repository</name>
+ <url>http://repo.springsource.org/libs-snapshot</url>
</repository>
</repositories>
View
8 default.properties → project.properties
@@ -1,11 +1,11 @@
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
-#
+#
# This file must be checked in Version Control Systems.
-#
+#
# To customize properties used by the Ant build system use,
-# "build.properties", and override values to adapt the script to your
+# "ant.properties", and override values to adapt the script to your
# project structure.
# Project target.
-target=android-7
+target=android-16
View
19 res/layout/signin.xml → res/layout/authorize.xml
@@ -12,8 +12,9 @@
android:background="#6DB33F"
android:layout_alignParentTop="true">
- <ImageView android:id="@+id/logo"
+ <ImageView android:id="@+id/header_logo"
android:src="@drawable/gh_header_logo"
+ android:contentDescription="@string/content_description_greenhouse_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" />
@@ -25,11 +26,14 @@
android:layout_height="wrap_content"
android:layout_centerVertical="true">
- <Button android:id="@+id/signin_button"
- android:layout_width="160dp"
- android:layout_height="wrap_content"
- android:layout_gravity="center_horizontal"
- android:text="@string/login" />
+ <Button
+ android:id="@+id/sign_in_button"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_horizontal"
+ android:layout_marginLeft="30dp"
+ android:layout_marginRight="30dp"
+ android:text="@string/sign_in" />
</FrameLayout>
@@ -38,8 +42,9 @@
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
- <ImageView android:id="@+id/logo"
+ <ImageView android:id="@+id/spring_logo"
android:src="@drawable/spring09_logo"
+ android:contentDescription="@string/content_description_springsource_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" />
View
89 res/layout/sign_in.xml
@@ -0,0 +1,89 @@
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:layout_gravity="fill_vertical"
+ android:background="#ffffff" >
+
+ <FrameLayout
+ android:id="@+id/header_frameLayout"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_alignParentTop="true"
+ android:background="#6DB33F" >
+
+ <ImageView
+ android:id="@+id/greenhouse_header"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_horizontal"
+ android:contentDescription="@string/content_description_greenhouse_header"
+ android:src="@drawable/gh_header_logo" />
+ </FrameLayout>
+
+ <EditText
+ android:id="@+id/username"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_alignParentLeft="true"
+ android:layout_below="@+id/header_frameLayout"
+ android:layout_marginLeft="20dp"
+ android:layout_marginRight="20dp"
+ android:layout_marginTop="20dp"
+ android:ems="10"
+ android:inputType="textEmailAddress" >
+
+ <requestFocus />
+ </EditText>
+
+ <EditText
+ android:id="@+id/password"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_alignLeft="@+id/username"
+ android:layout_alignRight="@+id/username"
+ android:layout_below="@+id/username"
+ android:ems="10"
+ android:inputType="textPassword" />
+
+ <LinearLayout
+ android:id="@+id/buttons_linearlayout"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_alignLeft="@+id/password"
+ android:layout_alignRight="@+id/password"
+ android:layout_below="@+id/password"
+ android:layout_marginTop="20dp"
+ android:weightSum="1.0" >
+
+ <Button
+ android:id="@+id/cancel_button"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_weight=".5"
+ android:text="@string/cancel" />
+
+ <Button
+ android:id="@+id/sign_in_button"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_weight=".5"
+ android:text="@string/sign_in" />
+ </LinearLayout>
+
+ <FrameLayout
+ android:id="@+id/spring_logo_framelayout"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_alignParentBottom="true" >
+
+ <ImageView
+ android:id="@+id/spring_logo"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_horizontal"
+ android:contentDescription="@string/content_description_springsource_logo"
+ android:src="@drawable/spring09_logo" />
+ </FrameLayout>
+
+</RelativeLayout>
View
5 res/values/env_settings.xml
@@ -1,8 +1,7 @@
<resources>
- <string name="consumer_token_key">${consumer.token.key}</string>
- <string name="consumer_token_secret">${consumer.token.secret}</string>
+ <string name="client_id">${client.id}</string>
+ <string name="client_secret">${client.secret}</string>
<string name="connection_repository_encryption_password">${connection.repository.encryption.password}</string>
<string name="connection_repository_encryption_salt">${connection.repository.encryption.salt}</string>
<string name="base_url">${base.url}</string>
- <string name="oauth_callback_url">x-com-springsource-greenhouse://oauth-response</string>
</resources>
View
38 res/values/strings.xml
@@ -1,11 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
+
<string name="app_name">Greenhouse</string>
- <string name="login">Sign In</string>
- <string name="copyright">\u00A9 Copyright 2011 SpringSource</string>
+ <string name="copyright">\u00A9 Copyright 2011&#8211;2012 SpringSource, a division of VMware</string>
+
+ <!-- Button Labels -->
+
+ <string name="sign_in">Sign In</string>
+ <string name="cancel">Cancel</string>
+
+ <!-- Activity Titles -->
+
<string name="title_event_details">Event Details</string>
<string name="title_event_description">Event Description</string>
- <string name="title_event_tweets">Event Tweets</string>
+ <string name="title_event_tweets">Event Tweets</string>
<string name="title_event_sessions_filtered">Filtered Sessions</string>
<string name="title_event_sessions_schedule">Session Schedule</string>
<string name="title_event_sessions_current">Current Sessions</string>
@@ -19,32 +27,36 @@
<string name="title_event_session_tweets">Session Tweets</string>
<string name="title_tweet_details">Tweet Details</string>
<string name="title_post_tweet">Post Tweet</string>
-
+
+ <!-- Image Content Descriptions -->
+
+ <string name="content_description_greenhouse_header">Greenhouse Header</string>
+ <string name="content_description_springsource_logo">SpringSource Logo</string>
+
+ <!-- Arrays used in selection lists -->
+
<string-array name="event_details_options_array">
<item>Filtered Sessions</item>
<item>Session Schedule</item>
<item>Post Tweet</item>
<item>Twitter Feed</item>
</string-array>
-
<string-array name="event_filtered_sessions_options_array">
- <item>Current</item>
- <item>Upcoming</item>
- <item>My Favorites</item>
- <item>Conference Favorites</item>
+ <item>Current</item>
+ <item>Upcoming</item>
+ <item>My Favorites</item>
+ <item>Conference Favorites</item>
</string-array>
-
<string-array name="event_session_details_options_array">
<item>Favorite</item>
<item>Rate</item>
<item>Post Tweet</item>
<item>Twitter Feed</item>
</string-array>
-
<string-array name="tweet_details_options_array">
<item>Reply</item>
<item>Retweet</item>
<item>Quote</item>
</string-array>
-
-</resources>
+
+</resources>
View
56 src/com/springsource/greenhouse/MainActivity.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2011 the original author or authors.
+ * Copyright 2011-2012 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.
@@ -18,6 +18,8 @@
import org.springframework.social.connect.ConnectionRepository;
import org.springframework.social.greenhouse.api.Greenhouse;
+import com.springsource.greenhouse.authorization.AuthorizeActivity;
+
import android.content.Intent;
import android.os.Bundle;
@@ -25,64 +27,34 @@
* @author Roy Clarkson
*/
public class MainActivity extends AbstractGreenhouseActivity {
-
+
@SuppressWarnings("unused")
private static final String TAG = MainActivity.class.getSimpleName();
-
+
private ConnectionRepository connectionRepository;
-
-
+
+ //***************************************
+ // Activity methods
//***************************************
- // Activity methods
- //***************************************
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
-
+
connectionRepository = getApplicationContext().getConnectionRepository();
-
+
Intent intent;
if (isConnected()) {
intent = new Intent(this, MainTabWidget.class);
} else {
- intent = new Intent(this, SignInActivity.class);
+ intent = new Intent(this, AuthorizeActivity.class);
}
-
startActivity(intent);
finish();
}
-
-// @Override
-// protected void onResume()
-// {
-// super.onResume();
-//
-// Uri uri = getIntent().getData();
-// if (!_greenhouseConnectManager.isCallbackUrl(uri))
-// {
-// return;
-// }
-//
-// try
-// {
-// String oauthVerifier = uri.getQueryParameter("oauth_verifier");
-// _greenhouseConnectManager.updateGreenhouseAccessToken(oauthVerifier);
-// }
-// catch (Exception e)
-// {
-// Log.e(TAG, e.getMessage(), e);
-// return;
-// }
-//
-// Intent intent = new Intent(this, MainTabWidget.class);
-// startActivity(intent);
-// finish();
-// }
-
-
+
+ //***************************************
+ // Private methods
//***************************************
- // Private methods
- //***************************************
private boolean isConnected() {
return connectionRepository.findPrimaryConnection(Greenhouse.class) != null;
}
View
83 src/com/springsource/greenhouse/MainApplication.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2011 the original author or authors.
+ * Copyright 2011-2012 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.
@@ -34,75 +34,74 @@
/**
* @author Roy Clarkson
*/
-public class MainApplication extends Application {
-
-// private static final String TAG = MainApplication.class.getSimpleName();
-
+public class MainApplication extends Application {
+
+ @SuppressWarnings("unused")
+ private static final String TAG = MainApplication.class.getSimpleName();
+
private GreenhouseConnectionFactory connectionFactory;
-
+
private ConnectionRepository connectionRepository;
-
+
private Event selectedEvent;
-
+
private EventSession selectedSession;
-
+
private Date selectedDay;
-
+
private Tweet selectedTweet;
-
-
+
+ //***************************************
+ // Application methods
//***************************************
- // Application methods
- //***************************************
@Override
public void onCreate() {
super.onCreate();
- connectionFactory = new GreenhouseConnectionFactory(getConsumerTokenKey(), getConsumerTokenSecret(), getApiUrlBase());
+ connectionFactory = new GreenhouseConnectionFactory(getClientId(), getClientSecret(), getApiUrlBase());
ConnectionFactoryRegistry registry = new ConnectionFactoryRegistry();
registry.addConnectionFactory(connectionFactory);
- connectionRepository = new SQLiteConnectionRepository(new SQLiteConnectionRepositoryHelper(this), registry, AndroidEncryptors.text(getEncryptionPassword(), getEncryptionSalt()));
+ connectionRepository = new SQLiteConnectionRepository(new SQLiteConnectionRepositoryHelper(this), registry,
+ AndroidEncryptors.text(getEncryptionPassword(), getEncryptionSalt()));
}
-
-
+
+ //***************************************
+ // Private methods
//***************************************
- // Private methods
- //***************************************
- private String getConsumerTokenKey() {
- return getString(R.string.consumer_token_key);
- }
-
- private String getConsumerTokenSecret() {
- return getString(R.string.consumer_token_secret);
- }
-
private String getEncryptionPassword() {
return getString(R.string.connection_repository_encryption_password);
}
-
+
private String getEncryptionSalt() {
return getString(R.string.connection_repository_encryption_salt);
}
- private String getApiUrlBase() {
+ public String getClientId() {
+ return getString(R.string.client_id);
+ }
+
+ public String getClientSecret() {
+ return getString(R.string.client_secret);
+ }
+
+ public String getApiUrlBase() {
return getString(R.string.base_url);
}
-
-
+
+ //***************************************
+ // Public methods
//***************************************
- // Public methods
- //***************************************
public ConnectionRepository getConnectionRepository() {
return connectionRepository;
}
-
+
public GreenhouseConnectionFactory getConnectionFactory() {
return connectionFactory;
}
-
+
public Connection<Greenhouse> getPrimaryConnection() {
return getConnectionRepository().findPrimaryConnection(Greenhouse.class);
}
-
+
public Greenhouse getGreenhouseApi() {
Connection<Greenhouse> connection = getPrimaryConnection();
if (connection != null) {
@@ -115,19 +114,19 @@ public Greenhouse getGreenhouseApi() {
public void setSelectedEvent(Event event) {
this.selectedEvent = event;
}
-
+
public Event getSelectedEvent() {
return selectedEvent;
}
-
+
public void setSelectedSession(EventSession session) {
this.selectedSession = session;
}
-
+
public EventSession getSelectedSession() {
return selectedSession;
}
-
+
public void setSelectedDay(Date selectedDay) {
this.selectedDay = selectedDay;
}
@@ -143,5 +142,5 @@ public void setSelectedTweet(Tweet selectedTweet) {
public Tweet getSelectedTweet() {
return selectedTweet;
}
-
+
}
View
285 src/com/springsource/greenhouse/WebOAuthActivity.java
@@ -1,285 +0,0 @@
-/*
- * 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 com.springsource.greenhouse;
-
-import org.springframework.http.HttpStatus;
-import org.springframework.social.connect.Connection;
-import org.springframework.social.connect.ConnectionRepository;
-import org.springframework.social.connect.DuplicateConnectionException;
-import org.springframework.social.greenhouse.api.Greenhouse;
-import org.springframework.social.greenhouse.connect.GreenhouseConnectionFactory;
-import org.springframework.social.oauth1.AuthorizedRequestToken;
-import org.springframework.social.oauth1.OAuth1Parameters;
-import org.springframework.social.oauth1.OAuthToken;
-import org.springframework.web.client.HttpClientErrorException;
-import org.springframework.web.client.HttpServerErrorException;
-
-import android.app.Activity;
-import android.app.AlertDialog;
-import android.content.Context;
-import android.content.DialogInterface;
-import android.content.Intent;
-import android.content.SharedPreferences;
-import android.net.Uri;
-import android.os.AsyncTask;
-import android.os.Bundle;
-import android.util.Log;
-import android.view.Window;
-import android.webkit.WebChromeClient;
-import android.webkit.WebView;
-import android.webkit.WebViewClient;
-
-/**
- * @author Roy Clarkson
- */
-public class WebOAuthActivity extends AbstractGreenhouseActivity {
-
- protected static final String TAG = WebOAuthActivity.class.getSimpleName();
-
- private static final String REQUEST_TOKEN_KEY = "request_token";
-
- private static final String REQUEST_TOKEN_SECRET_KEY = "request_token_secret";
-
- private WebView webView;
-
- private ConnectionRepository connectionRepository;
-
- private GreenhouseConnectionFactory connectionFactory;
-
- private SharedPreferences greenhousePreferences;
-
-
- //***************************************
- // Activity methods
- //***************************************
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- getWindow().requestFeature(Window.FEATURE_PROGRESS);
- getWindow().setFeatureInt(Window.FEATURE_PROGRESS, Window.PROGRESS_VISIBILITY_ON);
-
- webView = new WebView(this);
- setContentView(webView);
-
- webView.setWebViewClient(new OAuthWebViewClient());
- webView.getSettings().setSaveFormData(false);
- webView.getSettings().setSavePassword(false);
-
- final Activity activity = this;
-
- webView.setWebChromeClient(
- new WebChromeClient() {
- public void onProgressChanged(WebView view, int progress) {
- activity.setTitle("Loading...");
- activity.setProgress(progress * 100);
-
- if (progress == 100) {
- activity.setTitle(R.string.app_name);
- }
- }
- }
- );
-
-
- connectionRepository = getApplicationContext().getConnectionRepository();
- connectionFactory = getApplicationContext().getConnectionFactory();
- greenhousePreferences = getSharedPreferences("GreenhouseConnectPreferences", Context.MODE_PRIVATE);
- }
-
- @Override
- public void onStart() {
- super.onStart();
- new GreenhousePreConnectTask().execute();
- }
-
-
- //***************************************
- // Private methods
- //***************************************
- private String getOAuthCallbackUrl() {
- return getString(R.string.oauth_callback_url);
- }
-
- private void displayGreenhouseAuthorization(OAuthToken requestToken) {
-
- if (requestToken == null) {
- return;
- }
-
- // save for later use
- saveRequestToken(requestToken);
-
- // Generate the Greenhouse authorization URL to be used in the browser or web view
- String authUrl = connectionFactory.getOAuthOperations().buildAuthorizeUrl(requestToken.getValue(), OAuth1Parameters.NONE);
-
- // display the Greenhouse authorization screen
- webView.loadUrl(authUrl);
- }
-
- private void displayGreenhouseOptions() {
- Intent intent = new Intent();
- intent.setClass(this, MainActivity.class);
- startActivity(intent);
- finish();
- }
-
- private void saveRequestToken(OAuthToken requestToken) {
- SharedPreferences.Editor editor = greenhousePreferences.edit();
- editor.putString(REQUEST_TOKEN_KEY, requestToken.getValue());
- editor.putString(REQUEST_TOKEN_SECRET_KEY, requestToken.getSecret());
- editor.commit();
- }
-
- private OAuthToken retrieveRequestToken() {
- String token = greenhousePreferences.getString(REQUEST_TOKEN_KEY, null);
- String secret = greenhousePreferences.getString(REQUEST_TOKEN_SECRET_KEY, null);
- return new OAuthToken(token, secret);
- }
-
- private void deleteRequestToken() {
- greenhousePreferences.edit().clear().commit();
- }
-
- private void displayAppAuthorizationError(String message) {
- AlertDialog.Builder builder = new AlertDialog.Builder(this);
- builder.setMessage(message);
- builder.setCancelable(false);
- builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int id) {
- signOut();
- }
- });
- AlertDialog alert = builder.create();
- alert.show();
- }
-
-
- //***************************************
- // Private classes
- //***************************************
- private class GreenhousePreConnectTask extends AsyncTask<Void, Void, OAuthToken> {
-
- private Exception exception;
-
- @Override
- protected void onPreExecute() {
- showProgressDialog("Initializing OAuth Connection...");
- }
-
- @Override
- protected OAuthToken doInBackground(Void... params) {
- try {
- // Fetch a one time use Request Token from Greenhouse
- return connectionFactory.getOAuthOperations().fetchRequestToken(getOAuthCallbackUrl(), null);
- } catch(Exception e) {
- this.exception = e;
- return null;
- }
- }
-
- @Override
- protected void onPostExecute(OAuthToken requestToken) {
- dismissProgressDialog();
-
- if (exception != null && exception instanceof HttpClientErrorException) {
- if (((HttpClientErrorException)exception).getStatusCode() == HttpStatus.UNAUTHORIZED) {
- displayAppAuthorizationError("This application is not authorized to connect to Greenhouse");
- }
- } else {
- displayGreenhouseAuthorization(requestToken);
- }
- }
- }
-
- private class GreenhousePostConnectTask extends AsyncTask<String, Void, Void> {
-
- private Exception exception;
-
- @Override
- protected void onPreExecute() {
- showProgressDialog("Finalizing OAuth Connection...");
- }
-
- @Override
- protected Void doInBackground(String... params) {
- if (params.length <= 0) {
- return null;
- }
-
- final String verifier = params[0];
- OAuthToken requestToken = retrieveRequestToken();
-
- // Authorize the Request Token
- AuthorizedRequestToken authorizedRequestToken = new AuthorizedRequestToken(requestToken, verifier);
-
- OAuthToken accessToken = null;
- try {
- // Exchange the Authorized Request Token for the Access Token
- accessToken = connectionFactory.getOAuthOperations().exchangeForAccessToken(authorizedRequestToken, null);
- } catch(Exception e) {
- exception = e;
- return null;
- }
-
- deleteRequestToken();
-
- // Persist the connection and Access Token to the repository
- Connection<Greenhouse> connection = connectionFactory.createConnection(accessToken);
-
- try {
- connectionRepository.addConnection(connection);
- } catch (DuplicateConnectionException e) {
- Log.i(TAG, "attempting to add duplicate connection", e);
- }
-
- return null;
- }
-
- @Override
- protected void onPostExecute(Void v) {
- dismissProgressDialog();
-
- if (exception != null && exception instanceof HttpServerErrorException) {
- if (((HttpServerErrorException)exception).getStatusCode() == HttpStatus.INTERNAL_SERVER_ERROR) {
- displayAppAuthorizationError("You are already connected with another Android device. Please remove the connection at Greenhouse and try again.");
- }
- } else {
- displayGreenhouseOptions();
- }
- }
- }
-
- private class OAuthWebViewClient extends WebViewClient {
-
- @Override
- public boolean shouldOverrideUrlLoading(WebView view, String url) {
- Uri uri = Uri.parse(url);
-
- if (uri.getScheme().equals("x-com-springsource-greenhouse") && uri.getHost().equals("oauth-response")) {
- String oauthVerifier = uri.getQueryParameter("oauth_verifier");
-
- if (oauthVerifier != null) {
- Log.d(TAG, "oauth_verifier: " + oauthVerifier);
- new GreenhousePostConnectTask().execute(oauthVerifier);
- return true;
- }
- }
-
- return false;
- }
- }
-}
View
26 ...ringsource/greenhouse/SignInActivity.java → ...ouse/authorization/AuthorizeActivity.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2011 the original author or authors.
+ * Copyright 2011-2012 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.
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.springsource.greenhouse;
+package com.springsource.greenhouse.authorization;
import android.app.Activity;
import android.content.Intent;
@@ -26,21 +26,29 @@
/**
* @author Roy Clarkson
*/
-public class SignInActivity extends Activity {
+public class AuthorizeActivity extends Activity {
//***************************************
- // Activity methods
- //***************************************
+ // Activity methods
+ //***************************************
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- setContentView(R.layout.signin);
+ setContentView(R.layout.authorize);
- findViewById(R.id.signin_button).setOnClickListener(new OnClickListener() {
+ findViewById(R.id.sign_in_button).setOnClickListener(new OnClickListener() {
public void onClick(final View view) {
- startActivity(new Intent(SignInActivity.this, WebOAuthActivity.class));
- finish();
+ startActivity(new Intent(AuthorizeActivity.this, SignInActivity.class));
}
});
}
+
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ super.onActivityResult(requestCode, resultCode, data);
+ if (resultCode == RESULT_OK) {
+ finish();
+ }
+ }
+
}
View
201 src/com/springsource/greenhouse/authorization/SignInActivity.java
@@ -0,0 +1,201 @@
+/*
+ * Copyright 2012 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 com.springsource.greenhouse.authorization;
+
+import java.util.Map;
+
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.MediaType;
+import org.springframework.social.connect.Connection;
+import org.springframework.social.connect.ConnectionRepository;
+import org.springframework.social.connect.DuplicateConnectionException;
+import org.springframework.social.greenhouse.api.Greenhouse;
+import org.springframework.social.greenhouse.connect.GreenhouseConnectionFactory;
+import org.springframework.social.oauth2.AccessGrant;
+import org.springframework.util.LinkedMultiValueMap;
+import org.springframework.util.MultiValueMap;
+import org.springframework.web.client.HttpClientErrorException;
+import org.springframework.web.client.RestTemplate;
+
+import android.app.AlertDialog;
+import android.content.Intent;
+import android.os.AsyncTask;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.EditText;
+
+import com.springsource.greenhouse.AbstractGreenhouseActivity;
+import com.springsource.greenhouse.MainActivity;
+import com.springsource.greenhouse.R;
+
+/**
+ * @author Roy Clarkson
+ */
+public class SignInActivity extends AbstractGreenhouseActivity {
+
+ private static final String TAG = SignInActivity.class.getSimpleName();
+
+ //***************************************
+ // Activity methods
+ //***************************************
+ @Override
+ public void onCreate(final Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.sign_in);
+
+ findViewById(R.id.cancel_button).setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(final View view) {
+ finish();
+ }
+ });
+
+ findViewById(R.id.sign_in_button).setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(final View view) {
+ if (validateFormData()) {
+ new SignInTask().execute();
+ } else {
+ displayAppAuthorizationError("Your email or password was entered incorrectly.");
+ }
+ }
+ });
+ }
+
+ // ***************************************
+ // Private methods
+ // ***************************************
+ private boolean validateFormData() {
+ EditText editText = (EditText) findViewById(R.id.username);
+ String username = editText.getText().toString().trim();
+ editText = (EditText) findViewById(R.id.password);
+ String password = editText.getText().toString().trim();
+ if (username.length() > 0 && password.length() > 0) {
+ return true;
+ }
+ return false;
+ }
+
+ private void displayAppAuthorizationError(String message) {
+ new AlertDialog.Builder(this).setMessage(message).setCancelable(false)
+ .setPositiveButton("OK", null).create().show();
+ }
+
+ private void displayGreenhouseOptions() {
+ Intent intent = new Intent();
+ intent.setClass(this, MainActivity.class);
+ startActivity(intent);
+ setResult(RESULT_OK);
+ finish();
+ }
+
+ private AccessGrant extractAccessGrant(Map<String, Object> result) {
+ return new AccessGrant((String) result.get("access_token"), (String) result.get("scope"),
+ (String) result.get("refresh_token"), getIntegerValue(result, "expires_in"));
+ }
+
+ // Retrieves object from map into an Integer, regardless of the object's actual type. Allows for flexibility in object type (eg, "3600" vs 3600).
+ private Integer getIntegerValue(Map<String, Object> map, String key) {
+ try {
+ return Integer.valueOf(String.valueOf(map.get(key))); // normalize to String before creating integer value;
+ } catch (NumberFormatException e) {
+ return null;
+ }
+ }
+
+ //***************************************
+ // Private classes
+ //***************************************
+ private class SignInTask extends AsyncTask<Void, Void, Void> {
+ private MultiValueMap<String, String> formData;
+
+ private Exception exception;
+
+ @Override
+ protected void onPreExecute() {
+ showProgressDialog("Signing in...");
+
+ EditText editText = (EditText) findViewById(R.id.username);
+ String username = editText.getText().toString().trim();
+
+ editText = (EditText) findViewById(R.id.password);
+ String password = editText.getText().toString().trim();
+
+ formData = new LinkedMultiValueMap<String, String>();
+ formData.add("grant_type", "password");
+ formData.add("username", username);
+ formData.add("password", password);
+ formData.add("client_id", getApplicationContext().getClientId());
+ formData.add("client_secret", getApplicationContext().getClientSecret());
+ formData.add("scope", "read,write");
+ Log.d(TAG, formData.toString());
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ protected Void doInBackground(Void... params) {
+ try {
+ final String url = getApplicationContext().getApiUrlBase() + "oauth/token";
+ Log.d(TAG, url);
+ HttpHeaders requestHeaders = new HttpHeaders();
+ requestHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
+ HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<MultiValueMap<String, String>>(formData, requestHeaders);
+ RestTemplate restTemplate = new RestTemplate(true);
+ Map<String, Object> responseBody = restTemplate.exchange(url, HttpMethod.POST, requestEntity, Map.class).getBody();
+ Log.d(TAG, responseBody.toString());
+
+ // Persist the connection and AccessGrant to the repository
+ AccessGrant accessGrant = extractAccessGrant(responseBody);
+ GreenhouseConnectionFactory connectionFactory = getApplicationContext().getConnectionFactory();
+ ConnectionRepository connectionRepository = getApplicationContext().getConnectionRepository();
+ Connection<Greenhouse> connection = connectionFactory.createConnection(accessGrant);
+ connectionRepository.addConnection(connection);
+ } catch (Exception e) {
+ Log.e(TAG, e.getLocalizedMessage(), e);
+ this.exception = e;
+ }
+
+ return null;
+ }
+
+ @Override
+ protected void onPostExecute(Void v) {
+ dismissProgressDialog();
+ if (exception != null) {
+ String message;
+ if (exception instanceof HttpClientErrorException
+ && (((HttpClientErrorException) exception).getStatusCode() == HttpStatus.BAD_REQUEST)
+ || ((HttpClientErrorException) exception).getStatusCode() == HttpStatus.UNAUTHORIZED) {
+ message = "Your email or password was entered incorrectly.";
+ } else if (exception instanceof DuplicateConnectionException) {
+ message = "The connection already exists.";
+ } else {
+ Log.e(TAG, exception.getLocalizedMessage(), exception);
+ message = "A problem occurred with the network connection. Please try again in a few minutes.";
+ }
+ displayAppAuthorizationError(message);
+ } else {
+ displayGreenhouseOptions();
+ }
+ }
+ }
+
+}
View
17 src/org/springframework/social/greenhouse/api/impl/AbstractGreenhouseOperations.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2011 the original author or authors.
+ * Copyright 2011-2012 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.
@@ -17,6 +17,7 @@
import java.net.URI;
+import org.springframework.social.MissingAuthorizationException;
import org.springframework.social.support.URIBuilder;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
@@ -25,19 +26,19 @@
* @author Roy Clarkson
*/
class AbstractGreenhouseOperations {
-
- private final boolean isAuthorizedForUser;
+
+ private final boolean isAuthorized;
private final String apiUrlBase;
- public AbstractGreenhouseOperations(boolean isAuthorizedForUser, String apiUrlBase) {
- this.isAuthorizedForUser = isAuthorizedForUser;
+ public AbstractGreenhouseOperations(boolean isAuthorized, String apiUrlBase) {
+ this.isAuthorized = isAuthorized;
this.apiUrlBase = apiUrlBase;
}
- protected void requireUserAuthorization() {
- if (!isAuthorizedForUser) {
- throw new IllegalStateException("User authorization required: GreenhouseTemplate must be created with OAuth credentials to perform this operation.");
+ protected void requireAuthorization() {
+ if (!isAuthorized) {
+ throw new MissingAuthorizationException();
}
}
View
4 src/org/springframework/social/greenhouse/api/impl/EventTemplate.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2011 the original author or authors.
+ * Copyright 2011-2012 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.
@@ -37,7 +37,7 @@ public EventTemplate(RestTemplate restTemplate, boolean isAuthorizedForUser, Str
}
public List<Event> getUpcomingEvents() {
- requireUserAuthorization();
+ requireAuthorization();
return restTemplate.getForObject(buildUri("events"), EventList.class);
}
View
16 src/org/springframework/social/greenhouse/api/impl/GreenhouseTemplate.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2011 the original author or authors.
+ * Copyright 2011-2012 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.
@@ -25,14 +25,13 @@
import org.springframework.social.greenhouse.api.SessionOperations;
import org.springframework.social.greenhouse.api.TweetOperations;
import org.springframework.social.greenhouse.api.UserOperations;
-import org.springframework.social.oauth1.AbstractOAuth1ApiBinding;
+import org.springframework.social.oauth2.AbstractOAuth2ApiBinding;
/**
* This is the central class for interacting with Greenhouse.
- *
* @author Roy Clarkson
*/
-public class GreenhouseTemplate extends AbstractOAuth1ApiBinding implements Greenhouse {
+public class GreenhouseTemplate extends AbstractOAuth2ApiBinding implements Greenhouse {
private final String apiUrlBase;
@@ -46,13 +45,10 @@
/**
* Create a new instance of GreenhouseTemplate.
- * @param apiKey the application's API key
- * @param apiSecret the application's API secret
- * @param accessToken an access token acquired through OAuth authentication with Greenhouse
- * @param accessTokenSecret an access token secret acquired through OAuth authentication with Greenhouse
+ * @param accessToken an access token acquired through OAuth 2 authentication with Greenhouse
*/
- public GreenhouseTemplate(String consumerKey, String consumerSecret, String accessToken, String accessTokenSecret, String apiUrlBase) {
- super(consumerKey, consumerSecret, accessToken, accessTokenSecret);
+ public GreenhouseTemplate(String accessToken, String apiUrlBase) {
+ super(accessToken);
this.apiUrlBase = apiUrlBase;
registerGreenhouseJsonModule();
getRestTemplate().setErrorHandler(new GreenhouseErrorHandler());
View
8 src/org/springframework/social/greenhouse/api/impl/SessionTemplate.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2011 the original author or authors.
+ * Copyright 2011-2012 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.
@@ -47,7 +47,7 @@ public SessionTemplate(RestTemplate restTemplate, boolean isAuthorizedForUser, S
}
public List<EventSession> getFavoriteSessions(long eventId) {
- requireUserAuthorization();
+ requireAuthorization();
String url = new StringBuilder().append("events/").append(eventId).append("/sessions/favorites").toString();
return restTemplate.getForObject(buildUri(url), EventSessionList.class);
}
@@ -58,13 +58,13 @@ public SessionTemplate(RestTemplate restTemplate, boolean isAuthorizedForUser, S
}
public boolean updateFavoriteSession(long eventId, long sessionId) {
- requireUserAuthorization();
+ requireAuthorization();
String url = new StringBuilder().append("events/").append(eventId).append("/sessions/").append(sessionId).append("/favorite").toString();
return restTemplate.exchange(buildUri(url), HttpMethod.PUT, null, Boolean.class).getBody();
}
public float rateSession(long eventId, long sessionId, int rating, String comment) {
- requireUserAuthorization();
+ requireAuthorization();
String url = new StringBuilder().append("events/").append(eventId).append("/sessions/").append(sessionId).append("/rating").toString();
MultiValueMap<String, String> postData = new LinkedMultiValueMap<String, String>();
postData.add("value", String.valueOf(rating));
View
10 src/org/springframework/social/greenhouse/api/impl/TweetTemplate.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2011 the original author or authors.
+ * Copyright 2011-2012 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.
@@ -62,7 +62,7 @@ public TweetFeed getTweetsForEventSession(long eventId, long sessionId, int page
}
public void postTweetForEvent(long eventId, String status) {
- requireUserAuthorization();
+ requireAuthorization();
String url = new StringBuilder().append("events/").append(eventId).append("/tweets").toString();
MultiValueMap<String, String> postData = new LinkedMultiValueMap<String, String>();
postData.add("status", status);
@@ -70,7 +70,7 @@ public void postTweetForEvent(long eventId, String status) {
}
public void postTweetForEventSession(long eventId, long sessionId, String status) {
- requireUserAuthorization();
+ requireAuthorization();
String url = new StringBuilder().append("events/").append(eventId).append("/sessions/").append(sessionId).append("/tweets").toString();
MultiValueMap<String, String> postData = new LinkedMultiValueMap<String, String>();
postData.add("status", status);
@@ -78,7 +78,7 @@ public void postTweetForEventSession(long eventId, long sessionId, String status
}
public void retweetForEvent(long eventId, long tweetId) {
- requireUserAuthorization();
+ requireAuthorization();
String url = new StringBuilder().append("events/").append(eventId).append("/retweet").toString();
MultiValueMap<String, String> postData = new LinkedMultiValueMap<String, String>();
postData.add("tweetId", String.valueOf(tweetId));
@@ -86,7 +86,7 @@ public void retweetForEvent(long eventId, long tweetId) {
}
public void retweetForEventSession(long eventId, long sessionId, long tweetId) {
- requireUserAuthorization();
+ requireAuthorization();
String url = new StringBuilder().append("events/").append(eventId).append("/sessions/").append(sessionId).append("/retweet").toString();
MultiValueMap<String, String> postData = new LinkedMultiValueMap<String, String>();
postData.add("tweetId", String.valueOf(tweetId));
View
13 src/org/springframework/social/greenhouse/api/impl/UserTemplate.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2011 the original author or authors.
+ * Copyright 2011-2012 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.
@@ -21,30 +21,29 @@
/**
* Implementation of the {@link UserOperations} interface providing binding to Greenhouse's user-oriented REST resources.
- *
* @author Roy Clarkson
*/
class UserTemplate extends AbstractGreenhouseOperations implements UserOperations {
private final RestTemplate restTemplate;
- public UserTemplate(RestTemplate restTemplate, boolean isAuthorizedForUser, String apiUrlBase) {
- super(isAuthorizedForUser, apiUrlBase);
+ public UserTemplate(RestTemplate restTemplate, boolean isAuthorized, String apiUrlBase) {
+ super(isAuthorized, apiUrlBase);
this.restTemplate = restTemplate;
}
public long getAccountId() {
- requireUserAuthorization();
+ requireAuthorization();
return getUserProfile().getAccountId();
}
public String getDisplayName() {
- requireUserAuthorization();
+ requireAuthorization();
return getUserProfile().getDisplayName();
}
public GreenhouseProfile getUserProfile() {
- requireUserAuthorization();
+ requireAuthorization();
GreenhouseProfile profile = restTemplate.getForObject(buildUri("members/@self"), GreenhouseProfile.class);
profile.setApiUrlBase(getApiUrlBase());
return profile;
View
30 src/org/springframework/social/greenhouse/connect/GreenhouseConnectionFactory.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2011 the original author or authors.
+ * Copyright 2011-2012 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.
@@ -15,15 +15,33 @@
*/
package org.springframework.social.greenhouse.connect;
-import org.springframework.social.connect.support.OAuth1ConnectionFactory;
+import org.springframework.social.connect.support.OAuth2ConnectionFactory;
import org.springframework.social.greenhouse.api.Greenhouse;
/**
+ * Greenhouse ConnectionFactory implementation.
* @author Roy Clarkson
*/
-public class GreenhouseConnectionFactory extends OAuth1ConnectionFactory<Greenhouse> {
+public class GreenhouseConnectionFactory extends OAuth2ConnectionFactory<Greenhouse> {
- public GreenhouseConnectionFactory(String consumerKey, String consumerSecret, String apiUrlBase) {
- super("greenhouse", new GreenhouseServiceProvider(consumerKey, consumerSecret, apiUrlBase), new GreenhouseAdapter());
- }
+ /**
+ * Creates a GreenhouseConnectionFactory for the given client ID and secret.
+ * Using this constructor, no application namespace is set
+ * @param clientId The application's Client ID as assigned by Greenhouse
+ * @param clientSecret The application's Client Secret as assigned by Greenhouse
+ */
+ public GreenhouseConnectionFactory(String clientId, String clientSecret) {
+ super("greenhouse", new GreenhouseServiceProvider(clientId, clientSecret), new GreenhouseAdapter());
+ }
+
+ /**
+ * Creates a GreenhouseConnectionFactory for the given application ID, secret, and namespace.
+ * @param clientId The application's Client ID as assigned by Greenhouse
+ * @param clientSecret The application's Client Secret as assigned by Greenhouse
+ * @param apiUrlBase The application's API base URL
+ */
+ public GreenhouseConnectionFactory(String clientId, String clientSecret, String apiUrlBase) {
+ super("greenhouse", new GreenhouseServiceProvider(clientId, clientSecret, apiUrlBase), new GreenhouseAdapter());
+ }
+
}
View
30 src/org/springframework/social/greenhouse/connect/GreenhouseOAuth2Template.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2012 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.greenhouse.connect;
+
+import org.springframework.social.oauth2.OAuth2Template;
+
+/**
+ * Greenhouse-specific extension of OAuth2Template.
+ * @author Roy Clarkson
+ */
+public class GreenhouseOAuth2Template extends OAuth2Template {
+
+ public GreenhouseOAuth2Template(String clientId, String clientSecret) {
+ super(clientId, clientSecret, "https://greenhouse.springsource.org/signin", "https://greenhouse.springsource.org/oauth/token");
+ }
+
+}
View
36 src/org/springframework/social/greenhouse/connect/GreenhouseServiceProvider.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2011 the original author or authors.
+ * Copyright 2011-2012 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.
@@ -17,31 +17,43 @@
import org.springframework.social.greenhouse.api.Greenhouse;
import org.springframework.social.greenhouse.api.impl.GreenhouseTemplate;
-import org.springframework.social.oauth1.AbstractOAuth1ServiceProvider;
-import org.springframework.social.oauth1.OAuth1Template;
+import org.springframework.social.oauth2.AbstractOAuth2ServiceProvider;
/**
* Greenhouse ServiceProvider implementation.
- *
* @author Roy Clarkson
*/
-public class GreenhouseServiceProvider extends AbstractOAuth1ServiceProvider<Greenhouse> {
+public class GreenhouseServiceProvider extends AbstractOAuth2ServiceProvider<Greenhouse> {
private final String apiUrlBase;
- public GreenhouseServiceProvider(String consumerKey, String consumerSecret, String apiUrlBase) {
- super(consumerKey, consumerSecret, new OAuth1Template(consumerKey, consumerSecret,
- apiUrlBase + "oauth/request_token",
- apiUrlBase + "oauth/confirm_access",
- apiUrlBase + "oauth/access_token"));
+ /**
+ * Creates a GreenhouseServiceProvider for the given client ID and secret.
+ * @param clientId The application's Client ID as assigned by Greenhouse
+ * @param clientSecret The application's Client Secret as assigned by Greenhouse
+ */
+ public GreenhouseServiceProvider(String clientId, String clientSecret) {
+ super(new GreenhouseOAuth2Template(clientId, clientSecret));
+ this.apiUrlBase = null;
+ }
+
+ /**
+ * Creates a GreenhouseServiceProvider for the given client ID and secret.
+ * @param clientId The application's Client ID as assigned by Greenhouse
+ * @param clientSecret The application's Client Secret as assigned by Greenhouse
+ * @param apiUrlBase The application's API base URL
+ */
+ public GreenhouseServiceProvider(String clientId, String clientSecret, String apiUrlBase) {
+ super(new GreenhouseOAuth2Template(clientId, clientSecret));
this.apiUrlBase = apiUrlBase;
}
- public Greenhouse getApi(String accessToken, String secret) {
- return new GreenhouseTemplate(getConsumerKey(), getConsumerSecret(), accessToken, secret, getApiUrlBase());
+ public Greenhouse getApi(String accessToken) {
+ return new GreenhouseTemplate(accessToken, getApiUrlBase());
}
private String getApiUrlBase() {
return apiUrlBase;
}
+
}

0 comments on commit 14338c9

Please sign in to comment.
Something went wrong with that request. Please try again.