Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions forgerock-authenticator/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ dependencies {
implementation 'com.google.firebase:firebase-messaging:23.1.2'
implementation 'com.google.android.gms:play-services-location:21.0.1'

implementation 'org.forgerock:forgerock-authenticator:4.1.0'
implementation 'org.forgerock:forgerock-core:4.1.0'
implementation 'org.forgerock:forgerock-authenticator:4.8.3'
implementation 'org.forgerock:forgerock-core:4.8.3'

//add lib via aar-depency
// implementation(name: 'forgerock-authenticator-debug', ext: 'aar')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022-2023 ForgeRock. All rights reserved.
* Copyright (c) 2022-2026 ForgeRock. All rights reserved.
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
Expand Down Expand Up @@ -428,6 +428,25 @@ public void performPushAuthenticationWithBiometric(String notificationId,
}
}

protected void updateDeviceToken(String newToken) {
if (fraClient == null) {
Log.w(TAG, "FRAClient is not initialized yet. Device token update will be skipped.");
return;
}

fraClient.updateDeviceToken(newToken, new FRAListener<Void>() {
@Override
public void onSuccess(Void result) {
Log.d(TAG, "Device token updated successfully.");
}

@Override
public void onException(Exception e) {
Log.e(TAG, "Error updating device token.", e);
}
});
}

private void denyMessage(PushNotification pushNotification, Result flutterResult) {
pushNotification.deny(pushAuthenticationListener(pushNotification, flutterResult));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 ForgeRock. All rights reserved.
* Copyright (c) 2022-2026 ForgeRock. All rights reserved.
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
Expand All @@ -23,11 +23,8 @@ public void onMessageReceived(@NonNull RemoteMessage remoteMessage) {
public void onNewToken(@NonNull String s) {
super.onNewToken(s);

// This FCM method is called if InstanceID token is updated. This may occur if the security
// of the previous token had been compromised.
// Currently OpenAM does not provide an API to receives updates for those tokens. So, there
// is no method available to handle it FRAClient. The current workaround is removed the Push
// mechanism and add it again by scanning a new QRCode.
// Update the device token in the FRAClientWrapper
FRAClientWrapper.getInstanceInBackground(getApplicationContext()).updateDeviceToken(s);
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 ForgeRock. All rights reserved.
* Copyright (c) 2022-2026 ForgeRock. All rights reserved.
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
Expand All @@ -10,17 +10,14 @@
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;

import androidx.annotation.NonNull;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;

/**
* Data Access Object which implements StorageClient interface and uses SecureSharedPreferences from
Expand All @@ -35,17 +32,23 @@ class FRAStorageClient implements StorageClient {
private static final String FORGEROCK_SHARED_PREFERENCES_DATA_ACCOUNT = "com.forgerock.authenticator.DATA.ACCOUNT";
private static final String FORGEROCK_SHARED_PREFERENCES_DATA_MECHANISM = "com.forgerock.authenticator.DATA.MECHANISM";
private static final String FORGEROCK_SHARED_PREFERENCES_DATA_NOTIFICATIONS = "com.forgerock.authenticator.DATA.NOTIFICATIONS";
private static final String FORGEROCK_SHARED_PREFERENCES_DATA_DEVICE_TOKEN = "com.forgerock.android.authenticator.DATA.DEVICE_TOKEN";
private static final String FORGEROCK_SHARED_PREFERENCES_DATA_BACKUP = "com.forgerock.authenticator.DATA.BACKUP";

// Device Token key
private static final String DEVICE_TOKEN_ID = "deviceToken";

//The SharedPreferences to store the data
private final SharedPreferences accountData;
private final SharedPreferences mechanismData;
private final SharedPreferences notificationData;
private final SharedPreferences deviceTokenData;
private final SharedPreferences backupData;

private final HashMap<String, Account> accountMap;
private final HashMap<String, Mechanism> mechanismMap;
private final HashMap<String, PushNotification> notificationMap;
private final HashMap<String, PushDeviceToken> deviceTokenMap;

private static final String TAG = DefaultStorageClient.class.getSimpleName();
private static final int NOTIFICATIONS_MAX_SIZE = 20;
Expand All @@ -62,12 +65,15 @@ public FRAStorageClient(Context context) {
FORGEROCK_SHARED_PREFERENCES_DATA_MECHANISM, FORGEROCK_SHARED_PREFERENCES_KEYS);
this.notificationData = new SecuredSharedPreferences(context,
FORGEROCK_SHARED_PREFERENCES_DATA_NOTIFICATIONS, FORGEROCK_SHARED_PREFERENCES_KEYS);
this.deviceTokenData = new SecuredSharedPreferences(context,
FORGEROCK_SHARED_PREFERENCES_DATA_DEVICE_TOKEN, FORGEROCK_SHARED_PREFERENCES_KEYS);
this.backupData = new SecuredSharedPreferences(context,
FORGEROCK_SHARED_PREFERENCES_DATA_BACKUP, FORGEROCK_SHARED_PREFERENCES_KEYS);

this.accountMap = new HashMap<>();
this.mechanismMap = new HashMap<>();
this.notificationMap = new HashMap<>();
this.deviceTokenMap = new HashMap<>();
}

@Override
Expand Down Expand Up @@ -325,7 +331,7 @@ public boolean removeNotification(PushNotification pushNotification) {
public void removeAllNotifications() {
notificationData.edit()
.clear()
.commit();
.apply();
notificationMap.clear();
}

Expand All @@ -343,6 +349,45 @@ public PushNotification getNotification(String notificationId) {
}
}

@Override
public PushNotification getNotificationByMessageId(String s) {
if(this.notificationMap.isEmpty()) {
this.getAllNotifications();
}

for (PushNotification pushNotification : this.notificationMap.values()) {
if (pushNotification.getMessageId().equals(s)) {
return pushNotification;
}
}

return null;
}

@Override
public boolean setPushDeviceToken(PushDeviceToken pushDeviceToken) {
String pushDeviceTokenJson = pushDeviceToken.serialize();
boolean success = deviceTokenData.edit()
.putString(DEVICE_TOKEN_ID, pushDeviceTokenJson)
.commit();

if(success) {
this.deviceTokenMap.put(DEVICE_TOKEN_ID, pushDeviceToken);
}

return success;
}

@Override
public PushDeviceToken getPushDeviceToken() {
if(this.deviceTokenMap.containsKey(DEVICE_TOKEN_ID)) {
return this.deviceTokenMap.get(DEVICE_TOKEN_ID);
} else {
String json = deviceTokenData.getString(DEVICE_TOKEN_ID, null);
return PushDeviceToken.deserialize(json);
}
}

@Override
public boolean setNotification(@NonNull PushNotification pushNotification) {
String notificationJson = pushNotification.serialize();
Expand All @@ -366,7 +411,8 @@ public boolean setNotification(@NonNull PushNotification pushNotification) {
public boolean isEmpty() {
return accountData.getAll().isEmpty() &&
mechanismData.getAll().isEmpty() &&
notificationData.getAll().isEmpty();
notificationData.getAll().isEmpty() &&
deviceTokenData.getAll().isEmpty();
}

/**
Expand Down
Loading
Loading