forked from organicmaps/organicmaps-tmp
[android] Implemented secure storage on Java side
This commit is contained in:
parent
4512d63893
commit
19c5b06135
5 changed files with 37 additions and 35 deletions
|
@ -62,17 +62,20 @@ public abstract class BaseMwmAuthorizationFragment extends BaseMwmToolbarFragmen
|
|||
public void onActivityResult(int requestCode, int resultCode, Intent data)
|
||||
{
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (resultCode == Activity.RESULT_OK && requestCode == Constants.REQ_CODE_GET_SOCIAL_TOKEN
|
||||
&& data != null)
|
||||
|
||||
if (requestCode != Constants.REQ_CODE_GET_SOCIAL_TOKEN
|
||||
|| resultCode != Activity.RESULT_OK || data == null)
|
||||
{
|
||||
String socialToken = data.getStringExtra(Constants.EXTRA_SOCIAL_TOKEN);
|
||||
if (!TextUtils.isEmpty(socialToken))
|
||||
{
|
||||
onStartAuthorization();
|
||||
@Framework.SocialTokenType
|
||||
int type = data.getIntExtra(Constants.EXTRA_TOKEN_TYPE, -1);
|
||||
Framework.nativeAuthenticateUser(socialToken, type);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
String socialToken = data.getStringExtra(Constants.EXTRA_SOCIAL_TOKEN);
|
||||
if (!TextUtils.isEmpty(socialToken))
|
||||
{
|
||||
onStartAuthorization();
|
||||
@Framework.SocialTokenType
|
||||
int type = data.getIntExtra(Constants.EXTRA_TOKEN_TYPE, -1);
|
||||
Framework.nativeAuthenticateUser(socialToken, type);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -77,17 +77,17 @@ public class SocialAuthDialogFragment extends BaseMwmDialogFragment
|
|||
@Framework.SocialTokenType int type)
|
||||
{
|
||||
Fragment caller = getTargetFragment();
|
||||
if (caller == null)
|
||||
return;
|
||||
|
||||
Intent data = null;
|
||||
if (caller != null)
|
||||
if (resultCode == Activity.RESULT_OK)
|
||||
{
|
||||
if (resultCode == Activity.RESULT_OK)
|
||||
{
|
||||
data = new Intent();
|
||||
data.putExtra(Constants.EXTRA_SOCIAL_TOKEN, socialToken);
|
||||
data.putExtra(Constants.EXTRA_TOKEN_TYPE, type);
|
||||
}
|
||||
caller.onActivityResult(Constants.REQ_CODE_GET_SOCIAL_TOKEN, Activity.RESULT_OK, data);
|
||||
data = new Intent();
|
||||
data.putExtra(Constants.EXTRA_SOCIAL_TOKEN, socialToken);
|
||||
data.putExtra(Constants.EXTRA_TOKEN_TYPE, type);
|
||||
}
|
||||
caller.onActivityResult(Constants.REQ_CODE_GET_SOCIAL_TOKEN, resultCode, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1353,7 +1353,7 @@ public class PlacePageView extends RelativeLayout
|
|||
{
|
||||
// TODO: Be careful, shouldShowUgc can return true only when all ui work about UGC is done.
|
||||
// Now (01.08.2017) UI is not ready for UGC yet.
|
||||
if (true)
|
||||
if (mMapObject.shouldShowUGC())
|
||||
{
|
||||
UGC.setListener(this);
|
||||
UGC.requestUGC(mMapObject.getFeatureId());
|
||||
|
|
|
@ -65,7 +65,7 @@ public final class HttpClient
|
|||
|
||||
HttpURLConnection connection = null;
|
||||
|
||||
logUrlSafely(p.url);
|
||||
LOGGER.d(TAG, "Connecting to " + makeUrlSafe(p.url));
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -147,7 +147,7 @@ public final class HttpClient
|
|||
// GET data from the server or receive response body
|
||||
p.httpResponseCode = connection.getResponseCode();
|
||||
LOGGER.d(TAG, "Received HTTP " + p.httpResponseCode + " from server, content encoding = "
|
||||
+ connection.getContentEncoding() + ", for request = " + p.url);
|
||||
+ connection.getContentEncoding() + ", for request = " + makeUrlSafe(p.url));
|
||||
|
||||
if (p.httpResponseCode >= 300 && p.httpResponseCode < 400)
|
||||
p.receivedUrl = connection.getHeaderField("Location");
|
||||
|
@ -239,10 +239,9 @@ public final class HttpClient
|
|||
return in;
|
||||
}
|
||||
|
||||
private static void logUrlSafely(@NonNull final String url)
|
||||
private static String makeUrlSafe(@NonNull final String url)
|
||||
{
|
||||
String safeUrl = url.replaceAll("(token|password|key)=([^&]+)", "***");
|
||||
LOGGER.d(TAG, "Connecting to " + safeUrl);
|
||||
return url.replaceAll("(token|password|key)=([^&]+)", "***");
|
||||
}
|
||||
|
||||
private static class HttpHeader
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
package com.mapswithme.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import com.mapswithme.maps.BuildConfig;
|
||||
import com.mapswithme.maps.MwmApplication;
|
||||
import com.mapswithme.util.log.Logger;
|
||||
import com.mapswithme.util.log.LoggerFactory;
|
||||
|
||||
|
@ -11,29 +13,27 @@ public final class SecureStorage
|
|||
{
|
||||
private static final Logger LOGGER = LoggerFactory.INSTANCE.getLogger(LoggerFactory.Type.MISC);
|
||||
private static final String TAG = SecureStorage.class.getSimpleName();
|
||||
private static final SharedPreferences mPrefs
|
||||
= MwmApplication.get().getSharedPreferences("secure", Context.MODE_PRIVATE);
|
||||
|
||||
private SecureStorage() {}
|
||||
|
||||
public static void save(@NonNull String key, @NonNull String value)
|
||||
{
|
||||
if (BuildConfig.DEBUG)
|
||||
LOGGER.d(TAG, "save: key = " + key + ", value = " + value);
|
||||
// TODO: implement @alexzatsepin
|
||||
LOGGER.d(TAG, "save: key = " + key);
|
||||
mPrefs.edit().putString(key, value).apply();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String load(@NonNull String key)
|
||||
{
|
||||
if (BuildConfig.DEBUG)
|
||||
LOGGER.d(TAG, "load: key = " + key);
|
||||
// TODO: implement @alexzatsepin
|
||||
return null;
|
||||
LOGGER.d(TAG, "load: key = " + key);
|
||||
return mPrefs.getString(key, null);
|
||||
}
|
||||
|
||||
public static void remove(@NonNull String key)
|
||||
{
|
||||
if (BuildConfig.DEBUG)
|
||||
LOGGER.d(TAG, "remove: key = " + key);
|
||||
// TODO: implement @alexzatsepin
|
||||
LOGGER.d(TAG, "remove: key = " + key);
|
||||
mPrefs.edit().remove(key).apply();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue