Skip to content

Commit 51ada3e

Browse files
committed
Rename to AuthenticationCallback and onRestore
1 parent cf8b4dc commit 51ada3e

File tree

5 files changed

+46
-53
lines changed

5 files changed

+46
-53
lines changed

Parse/src/main/java/com/parse/ParseAuthenticationCallbacks.java renamed to Parse/src/main/java/com/parse/AuthenticationCallback.java

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
/**
1414
* Provides a general interface for delegation of third party authentication callbacks.
1515
*/
16-
public interface ParseAuthenticationCallbacks {
16+
public interface AuthenticationCallback {
1717
/**
1818
* Called when restoring third party authentication credentials that have been serialized,
1919
* such as session keys, etc.
2020
* <p />
21-
* <strong>Note:</strong> This will be executed in a background thread.
21+
* <strong>Note:</strong> This will be executed on a background thread.
2222
*
2323
* @param authData
2424
* The auth data for the provider. This value may be {@code null} when
@@ -27,13 +27,5 @@ public interface ParseAuthenticationCallbacks {
2727
* @return {@code true} iff the {@code authData} was successfully synchronized or {@code false}
2828
* if user should no longer be associated because of bad {@code authData}.
2929
*/
30-
boolean onRestoreAuthentication(Map<String, String> authData);
31-
32-
/**
33-
* Called when deauthenticating (logging out) the user associated with this third party
34-
* authentication source.
35-
* <p />
36-
* <strong>Note:</strong> This will be executed in a background thread.
37-
*/
38-
void onDeauthenticate();
30+
boolean onRestore(Map<String, String> authData);
3931
}

Parse/src/main/java/com/parse/ParseAuthenticationManager.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,32 +18,32 @@
1818
/** package */ class ParseAuthenticationManager {
1919

2020
private final Object lock = new Object();
21-
private final Map<String, ParseAuthenticationCallbacks> callbacks = new HashMap<>();
21+
private final Map<String, AuthenticationCallback> callbacks = new HashMap<>();
2222
private final ParseCurrentUserController controller;
2323

2424
public ParseAuthenticationManager(ParseCurrentUserController controller) {
2525
this.controller = controller;
2626
}
2727

28-
public void register(final String authType, ParseAuthenticationCallbacks callbacks) {
28+
public void register(final String authType, AuthenticationCallback callback) {
2929
if (authType == null) {
3030
throw new IllegalArgumentException("Invalid authType: " + null);
3131
}
3232

3333
synchronized (lock) {
3434
if (this.callbacks.containsKey(authType)) {
35-
throw new IllegalStateException("Callbacks already registered for <" + authType + ">: "
35+
throw new IllegalStateException("Callback already registered for <" + authType + ">: "
3636
+ this.callbacks.get(authType));
3737
}
38-
this.callbacks.put(authType, callbacks);
38+
this.callbacks.put(authType, callback);
3939
}
4040

4141
if (ParseAnonymousUtils.AUTH_TYPE.equals(authType)) {
4242
// There's nothing to synchronize
4343
return;
4444
}
4545

46-
// Synchronize the current user with the auth callbacks.
46+
// Synchronize the current user with the auth callback.
4747
controller.getAsync(false).onSuccessTask(new Continuation<ParseUser, Task<Void>>() {
4848
@Override
4949
public Task<Void> then(Task<ParseUser> task) throws Exception {
@@ -57,31 +57,31 @@ public Task<Void> then(Task<ParseUser> task) throws Exception {
5757
}
5858

5959
public Task<Boolean> restoreAuthenticationAsync(String authType, final Map<String, String> authData) {
60-
final ParseAuthenticationCallbacks callbacks;
60+
final AuthenticationCallback callback;
6161
synchronized (lock) {
62-
callbacks = this.callbacks.get(authType);
62+
callback = this.callbacks.get(authType);
6363
}
64-
if (callbacks == null) {
64+
if (callback == null) {
6565
return Task.forResult(true);
6666
}
6767
return Task.call(new Callable<Boolean>() {
6868
@Override
6969
public Boolean call() throws Exception {
70-
return callbacks.onRestoreAuthentication(authData);
70+
return callback.onRestore(authData);
7171
}
7272
}, ParseExecutors.io());
7373
}
7474

7575
public Task<Void> deauthenticateAsync(String authType) {
76-
final ParseAuthenticationCallbacks callbacks;
76+
final AuthenticationCallback callback;
7777
synchronized (lock) {
78-
callbacks = this.callbacks.get(authType);
78+
callback = this.callbacks.get(authType);
7979
}
80-
if (callbacks != null) {
80+
if (callback != null) {
8181
return Task.call(new Callable<Void>() {
8282
@Override
8383
public Void call() throws Exception {
84-
callbacks.onDeauthenticate();
84+
callback.onRestore(null);
8585
return null;
8686
}
8787
}, ParseExecutors.io());

Parse/src/main/java/com/parse/ParseUser.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,18 +1079,19 @@ public ParseUser fetchIfNeeded() throws ParseException {
10791079
//region Third party authentication
10801080

10811081
/**
1082-
* Registers third party authentication callbacks.
1082+
* Registers a third party authentication callback.
10831083
* <p />
10841084
* <strong>Note:</strong> This shouldn't be called directly unless developing a third party authentication
10851085
* library.
10861086
*
1087-
* @param callbacks The third party authentication callbacks to be registered.
1087+
* @param authType The name of the third party authentication source.
1088+
* @param callback The third party authentication callback to be registered.
10881089
*
1089-
* @see ParseAuthenticationCallbacks
1090+
* @see AuthenticationCallback
10901091
*/
1091-
public static void registerAuthenticationCallbacks(
1092-
String authType, ParseAuthenticationCallbacks callbacks) {
1093-
getAuthenticationManager().register(authType, callbacks);
1092+
public static void registerAuthenticationCallback(
1093+
String authType, AuthenticationCallback callback) {
1094+
getAuthenticationManager().register(authType, callback);
10941095
}
10951096

10961097
/**
@@ -1103,7 +1104,7 @@ public static void registerAuthenticationCallbacks(
11031104
* @param authData The user credentials of the third party authentication source.
11041105
* @return A {@code Task} is resolved when logging in completes.
11051106
*
1106-
* @see ParseAuthenticationCallbacks
1107+
* @see AuthenticationCallback
11071108
*/
11081109
public static Task<ParseUser> logInWithInBackground(
11091110
final String authType, final Map<String, String> authData) {
@@ -1214,7 +1215,7 @@ public Task<ParseUser> then(Task<Void> task) throws Exception {
12141215
* @param authType The name of the third party authentication source.
12151216
* @return {@code true} if linked, otherwise {@code false}.
12161217
*
1217-
* @see ParseAuthenticationCallbacks
1218+
* @see AuthenticationCallback
12181219
*/
12191220
public boolean isLinked(String authType) {
12201221
Map<String, Map<String, String>> authData = getAuthData();
@@ -1314,7 +1315,7 @@ public Task<Void> then(Task<Void> task) throws Exception {
13141315
* @param authData The user credentials of the third party authentication source.
13151316
* @return A {@code Task} is resolved when linking completes.
13161317
*
1317-
* @see ParseAuthenticationCallbacks
1318+
* @see AuthenticationCallback
13181319
*/
13191320
public Task<Void> linkWithInBackground(
13201321
String authType, Map<String, String> authData) {
@@ -1333,7 +1334,7 @@ public Task<Void> linkWithInBackground(
13331334
* @param authType The name of the third party authentication source.
13341335
* @return A {@code Task} is resolved when unlinking completes.
13351336
*
1336-
* @see ParseAuthenticationCallbacks
1337+
* @see AuthenticationCallback
13371338
*/
13381339
public Task<Void> unlinkFromInBackground(final String authType) {
13391340
if (authType == null) {

Parse/src/test/java/com/parse/ParseAuthenticationManagerTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,21 @@ public class ParseAuthenticationManagerTest {
3131

3232
private ParseAuthenticationManager manager;
3333
private ParseCurrentUserController controller;
34-
private ParseAuthenticationCallbacks provider;
34+
private AuthenticationCallback provider;
3535

3636
@Before
3737
public void setUp() {
3838
controller = mock(ParseCurrentUserController.class);
3939
manager = new ParseAuthenticationManager(controller);
40-
provider = mock(ParseAuthenticationCallbacks.class);
40+
provider = mock(AuthenticationCallback.class);
4141
}
4242

4343
//region testRegister
4444

4545
@Test
4646
public void testRegisterMultipleShouldThrow() {
4747
when(controller.getAsync(false)).thenReturn(Task.<ParseUser>forResult(null));
48-
ParseAuthenticationCallbacks provider2 = mock(ParseAuthenticationCallbacks.class);
48+
AuthenticationCallback provider2 = mock(AuthenticationCallback.class);
4949

5050
manager.register("test_provider", provider);
5151

@@ -55,7 +55,7 @@ public void testRegisterMultipleShouldThrow() {
5555

5656
@Test
5757
public void testRegisterAnonymous() {
58-
manager.register("anonymous", mock(ParseAuthenticationCallbacks.class));
58+
manager.register("anonymous", mock(AuthenticationCallback.class));
5959
verifyNoMoreInteractions(controller);
6060
}
6161

@@ -74,14 +74,14 @@ public void testRegister() {
7474
@Test
7575
public void testRestoreAuthentication() throws ParseException {
7676
when(controller.getAsync(false)).thenReturn(Task.<ParseUser>forResult(null));
77-
when(provider.onRestoreAuthentication(Matchers.<Map<String, String>>any()))
77+
when(provider.onRestore(Matchers.<Map<String, String>>any()))
7878
.thenReturn(true);
7979
manager.register("test_provider", provider);
8080

8181
Map<String, String> authData = new HashMap<>();
8282
ParseTaskUtils.wait(manager.restoreAuthenticationAsync("test_provider", authData));
8383

84-
verify(provider).onRestoreAuthentication(authData);
84+
verify(provider).onRestore(authData);
8585
}
8686

8787
@Test
@@ -91,6 +91,6 @@ public void testDeauthenticateAsync() throws ParseException {
9191

9292
ParseTaskUtils.wait(manager.deauthenticateAsync("test_provider"));
9393

94-
verify(provider).onDeauthenticate();
94+
verify(provider).onRestore(null);
9595
}
9696
}

Parse/src/test/java/com/parse/ParseUserTest.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -569,10 +569,10 @@ public void testlinkWithInBackgroundWithSaveAsyncSuccess() throws Exception {
569569
when(currentUserController.getAsync(anyBoolean())).thenReturn(Task.<ParseUser>forResult(null));
570570
ParseCorePlugins.getInstance().registerCurrentUserController(currentUserController);
571571
// Register mock callbacks
572-
ParseAuthenticationCallbacks callbacks = mock(ParseAuthenticationCallbacks.class);
573-
when(callbacks.onRestoreAuthentication(Matchers.<Map<String, String>>any()))
572+
AuthenticationCallback callbacks = mock(AuthenticationCallback.class);
573+
when(callbacks.onRestore(Matchers.<Map<String, String>>any()))
574574
.thenReturn(true);
575-
ParseUser.registerAuthenticationCallbacks("facebook", callbacks);
575+
ParseUser.registerAuthenticationCallback("facebook", callbacks);
576576

577577
ParseUser user = new ParseUser();
578578
// To make synchronizeAuthData work
@@ -600,7 +600,7 @@ public void testlinkWithInBackgroundWithSaveAsyncSuccess() throws Exception {
600600
verify(partialMockUser, times(1))
601601
.saveAsync(eq("sessionTokenAgain"), eq(false), Matchers.<Task<Void>>any());
602602
// Make sure synchronizeAuthData() is called
603-
verify(callbacks, times(1)).onRestoreAuthentication(authData);
603+
verify(callbacks, times(1)).onRestore(authData);
604604
}
605605

606606
@Test
@@ -1289,10 +1289,10 @@ public void testSynchronizeAuthData() throws Exception {
12891289
when(currentUserController.getAsync(anyBoolean())).thenReturn(Task.forResult(currentUser));
12901290
ParseCorePlugins.getInstance().registerCurrentUserController(currentUserController);
12911291
// Register mock callbacks
1292-
ParseAuthenticationCallbacks callbacks = mock(ParseAuthenticationCallbacks.class);
1293-
when(callbacks.onRestoreAuthentication(Matchers.<Map<String, String>>any()))
1292+
AuthenticationCallback callbacks = mock(AuthenticationCallback.class);
1293+
when(callbacks.onRestore(Matchers.<Map<String, String>>any()))
12941294
.thenReturn(true);
1295-
ParseUser.registerAuthenticationCallbacks("facebook", callbacks);
1295+
ParseUser.registerAuthenticationCallback("facebook", callbacks);
12961296

12971297
// Set user initial state
12981298
String authType = "facebook";
@@ -1307,7 +1307,7 @@ public void testSynchronizeAuthData() throws Exception {
13071307
ParseTaskUtils.wait(user.synchronizeAuthDataAsync(authType));
13081308

13091309
// Make sure we restore authentication
1310-
verify(callbacks, times(1)).onRestoreAuthentication(authData);
1310+
verify(callbacks, times(1)).onRestore(authData);
13111311
}
13121312

13131313
@Test
@@ -1318,10 +1318,10 @@ public void testSynchronizeAllAuthData() throws Exception {
13181318
when(currentUserController.getAsync(anyBoolean())).thenReturn(Task.forResult(currentUser));
13191319
ParseCorePlugins.getInstance().registerCurrentUserController(currentUserController);
13201320
// Register mock callbacks
1321-
ParseAuthenticationCallbacks callbacks = mock(ParseAuthenticationCallbacks.class);
1322-
when(callbacks.onRestoreAuthentication(Matchers.<Map<String, String>>any()))
1321+
AuthenticationCallback callbacks = mock(AuthenticationCallback.class);
1322+
when(callbacks.onRestore(Matchers.<Map<String, String>>any()))
13231323
.thenReturn(true);
1324-
ParseUser.registerAuthenticationCallbacks("facebook", callbacks);
1324+
ParseUser.registerAuthenticationCallback("facebook", callbacks);
13251325

13261326
// Set user initial state
13271327
String facebookAuthType = "facebook";
@@ -1336,7 +1336,7 @@ public void testSynchronizeAllAuthData() throws Exception {
13361336
ParseTaskUtils.wait(user.synchronizeAllAuthDataAsync());
13371337

13381338
// Make sure we restore authentication
1339-
verify(callbacks, times(1)).onRestoreAuthentication(facebookAuthData);
1339+
verify(callbacks, times(1)).onRestore(facebookAuthData);
13401340
}
13411341

13421342
//endregion

0 commit comments

Comments
 (0)