OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 package org.chromium.net.test; | |
6 | |
7 import android.accounts.AbstractAccountAuthenticator; | |
8 | |
9 import android.accounts.Account; | |
10 import android.accounts.AccountAuthenticatorResponse; | |
11 import android.accounts.AccountManager; | |
12 import android.accounts.AuthenticatorException; | |
13 import android.accounts.NetworkErrorException; | |
14 import android.accounts.OperationCanceledException; | |
15 import android.content.Context; | |
16 import android.os.Bundle; | |
17 | |
18 import org.chromium.base.Log; | |
19 | |
20 import java.io.IOException; | |
21 | |
22 /** | |
23 * Dummy Android authenticator, to test SPNEGO/Keberos support on Android. This is | |
24 * deliberately minimal, and is not intended as an example of how to write a | |
25 * real SPNEGO Authenticator. | |
26 */ | |
27 public class DummySpnegoAuthenticator extends AbstractAccountAuthenticator { | |
28 private static final String SPNEGO_FEATURE = "SPNEGO"; | |
29 | |
30 private static int sAccountNumber = 0; | |
31 | |
32 private static final String TAG = "cr.net.test"; | |
33 /** | |
34 * @param context | |
35 */ | |
36 public DummySpnegoAuthenticator(final Context context) { | |
37 super(context); | |
38 Log.i(TAG, "Constructor"); | |
Bernhard Bauer
2015/06/10 17:11:03
Remove these logging statements?
aberent
2015/06/15 15:52:20
Done.
| |
39 final Thread thread = new Thread() { | |
40 @Override | |
41 public void run() { | |
42 AccountManager am = AccountManager.get(context); | |
43 String features[] = {"SPNEGO"}; | |
44 try { | |
45 Bundle accountBundle = | |
46 am.addAccount("org.chromium.test.DummySpnegoAuthenti cator", "SPNEGO", | |
47 features, null, null, null, null).getResu lt(); | |
48 String accountName = accountBundle.getString(AccountManager. KEY_ACCOUNT_NAME); | |
49 Log.i(TAG, "Account name = " + accountName); | |
50 } catch (OperationCanceledException | AuthenticatorException | I OException e) { | |
51 // TODO(aberent): Auto-generated catch block | |
Bernhard Bauer
2015/06/10 17:11:03
:)
aberent
2015/06/15 15:52:20
Done.
| |
52 e.printStackTrace(); | |
53 } | |
54 } | |
55 }; | |
56 thread.start(); | |
57 } | |
58 | |
59 @Override | |
60 public Bundle addAccount(AccountAuthenticatorResponse arg0, String accountTy pe, String arg2, | |
61 String[] arg3, Bundle arg4) throws NetworkErrorException { | |
62 Log.i(TAG, "addAccount"); | |
63 Bundle result = new Bundle(); | |
64 result.putString(AccountManager.KEY_ACCOUNT_NAME, "SPNEGO Account" + sAc countNumber); | |
65 result.putString(AccountManager.KEY_ACCOUNT_TYPE, accountType); | |
66 sAccountNumber++; | |
67 return result; | |
68 } | |
69 | |
70 @Override | |
71 public Bundle confirmCredentials(AccountAuthenticatorResponse arg0, Account arg1, Bundle arg2) | |
72 throws NetworkErrorException { | |
73 Log.i(TAG, "confirmCredentials"); | |
74 Bundle result = new Bundle(); | |
75 result.putBoolean(AccountManager.KEY_BOOLEAN_RESULT, true); | |
76 return result; | |
77 } | |
78 | |
79 @Override | |
80 public Bundle editProperties(AccountAuthenticatorResponse arg0, String arg1) { | |
81 Log.i(TAG, "editProperties"); | |
82 return new Bundle(); | |
83 } | |
84 | |
85 @Override | |
86 public Bundle getAuthToken(AccountAuthenticatorResponse arg0, Account accoun t, String arg2, | |
87 Bundle arg3) throws NetworkErrorException { | |
88 Log.i(TAG, "getAuthToken, Account name = " + account.name); | |
89 // TODO(aberent): This will need modification as the tests are created. | |
90 Bundle result = new Bundle(); | |
91 result.putString(AccountManager.KEY_ACCOUNT_NAME, account.name); | |
92 result.putString(AccountManager.KEY_ACCOUNT_TYPE, account.type); | |
93 result.putString(AccountManager.KEY_AUTHTOKEN, "DummyToken"); | |
94 return result; | |
95 } | |
96 | |
97 @Override | |
98 public String getAuthTokenLabel(String arg0) { | |
99 Log.i(TAG, "getAuthTokenLabel"); | |
100 return "Spnego " + arg0; | |
101 } | |
102 | |
103 @Override | |
104 public Bundle hasFeatures(AccountAuthenticatorResponse arg0, Account arg1, S tring[] features) | |
105 throws NetworkErrorException { | |
106 Log.i(TAG, "hasFeatures"); | |
107 Bundle result = new Bundle(); | |
108 for (String feature : features) { | |
109 if (!feature.equals(SPNEGO_FEATURE)) { | |
110 result.putBoolean(AccountManager.KEY_BOOLEAN_RESULT, false); | |
111 return result; | |
112 } | |
113 } | |
114 result.putBoolean(AccountManager.KEY_BOOLEAN_RESULT, true); | |
115 return result; | |
116 } | |
117 | |
118 @Override | |
119 public Bundle updateCredentials(AccountAuthenticatorResponse arg0, Account a rg1, String arg2, | |
120 Bundle arg3) throws NetworkErrorException { | |
121 Log.i(TAG, "updateCredentials"); | |
122 Bundle result = new Bundle(); | |
123 result.putInt(AccountManager.KEY_ERROR_CODE, AccountManager.ERROR_CODE_B AD_REQUEST); | |
124 result.putString(AccountManager.KEY_ERROR_MESSAGE, "Can't add new SPNEGO accounts"); | |
125 return result; | |
126 } | |
127 } | |
OLD | NEW |