Skip to content

Commit 24b2f34

Browse files
author
Robert Szuba
authored
Merge pull request #39 from Onegini/develop
Develop
2 parents cf24826 + 6970121 commit 24b2f34

22 files changed

+310
-181
lines changed

app/build.gradle

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,20 @@ apply plugin: 'me.tatarka.retrolambda'
1919

2020
allprojects {
2121
apply plugin: 'maven'
22-
2322
repositories {
2423
mavenLocal()
2524
mavenCentral()
26-
if(project.hasProperty('artifactory_user') && project.hasProperty('artifactory_password')) {
25+
if (project.hasProperty('artifactory_user') && project.hasProperty('artifactory_password')) {
2726
maven {
2827
url "https://repo.onegini.com/artifactory/public"
2928
credentials {
3029
username artifactory_user
3130
password artifactory_password
3231
}
3332
}
33+
} else {
34+
throw new InvalidUserDataException("You must configure the 'artifactory_user' and 'artifactory_password' properties in your project before you can " +
35+
"build it.")
3436
}
3537
}
3638
}
@@ -48,8 +50,8 @@ android {
4850
applicationId "com.onegini.mobile.exampleapp"
4951
minSdkVersion 16
5052
targetSdkVersion 23
51-
versionCode 3
52-
versionName "2.0.0"
53+
versionCode 4
54+
versionName "2.1.0"
5355
multiDexEnabled true
5456
}
5557
buildTypes {
@@ -59,37 +61,24 @@ android {
5961
}
6062
}
6163
dexOptions {
62-
incremental true
6364
javaMaxHeapSize "4g"
6465
}
6566
}
6667

6768
dependencies {
6869
// Onegini SDK
69-
compile 'com.onegini.mobile.sdk.android:onegini-sdk:6.00.01:release@aar'
70-
71-
// Ocra 100.00.00
72-
compile 'com.onegini.misc:og-ocra:100.00.00'
70+
compile('com.onegini.mobile.sdk.android:onegini-sdk:6.01.00@aar') {
71+
transitive = true
72+
}
7373

7474
// Google Support
7575
compile 'com.android.support:appcompat-v7:23.3.0'
7676
compile 'com.android.support:cardview-v7:23.3.0'
7777
compile 'com.android.support:recyclerview-v7:23.3.0'
7878

79-
// Http Client
80-
compile 'com.squareup.okhttp:okhttp:2.4.0'
81-
compile 'com.squareup.okhttp:okhttp-urlconnection:2.4.0'
82-
// Rest Client
83-
compile 'com.squareup.retrofit:retrofit:1.9.0'
8479
// Google cloud messaging (GCM)
85-
compile 'com.google.android.gms:play-services-base:9.6.1'
8680
compile 'com.google.android.gms:play-services-gcm:9.6.1'
87-
// Spongy castle
88-
compile 'com.madgag.spongycastle:core:1.54.0.0'
89-
compile 'com.madgag.spongycastle:prov:1.54.0.0'
90-
compile 'com.madgag.spongycastle:pg:1.54.0.0'
91-
compile 'com.madgag.spongycastle:pkix:1.54.0.0'
92-
compile 'com.nimbusds:nimbus-jose-jwt:3.6'
81+
9382
// Support for multidex
9483
compile 'com.android.support:multidex:1.0.1'
9584
// DI for views

app/src/main/AndroidManifest.xml

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,19 @@
1717
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
1818
package="com.onegini.mobile.exampleapp">
1919

20+
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
2021
<uses-permission android:name="android.permission.WAKE_LOCK"/>
2122

22-
<permission
23-
android:name="com.onegini.mobile.exampleapp.permission.C2D_MESSAGE"
24-
android:protectionLevel="signature"/>
2523
<uses-permission android:name="org.fidoalliance.uaf.permissions.FIDO_CLIENT"/>
26-
<uses-permission android:name="com.onegini.mobile.exampleapp.permission.C2D_MESSAGE"/>
2724

2825
<application
2926
android:name="android.support.multidex.MultiDexApplication"
30-
android:allowBackup="true"
27+
android:allowBackup="false"
3128
android:icon="@mipmap/ic_launcher"
3229
android:label="@string/app_name"
3330
android:supportsRtl="true"
3431
android:theme="@style/AppTheme">
32+
3533
<activity
3634
android:name=".view.activity.SplashScreenActivity"
3735
android:screenOrientation="portrait">
@@ -92,20 +90,31 @@
9290
android:parentActivityName=".view.activity.DashboardActivity"
9391
android:screenOrientation="portrait"/>
9492

93+
<service
94+
android:name=".network.gcm.GCMListenerService"
95+
android:exported="false">
96+
<intent-filter>
97+
<action android:name="com.google.android.c2dm.intent.RECEIVE"/>
98+
</intent-filter>
99+
</service>
100+
<service
101+
android:name=".network.gcm.GCMInstanceIDListenerService"
102+
android:exported="false">
103+
<intent-filter>
104+
<action android:name="com.google.android.gms.iid.InstanceID"/>
105+
</intent-filter>
106+
</service>
107+
95108
<receiver
96-
android:name=".network.gcm.GCMBroadcastReceiver"
109+
android:name="com.google.android.gms.gcm.GcmReceiver"
110+
android:exported="true"
97111
android:permission="com.google.android.c2dm.permission.SEND">
98112
<intent-filter>
99113
<action android:name="com.google.android.c2dm.intent.RECEIVE"/>
100-
101114
<category android:name="com.onegini.mobile.exampleapp"/>
102-
103-
<action android:name="com.google.android.c2dm.intent.REGISTRATION"/>
104115
</intent-filter>
105116
</receiver>
106117

107-
<service android:name=".network.gcm.GCMIntentService"/>
108-
109118
<meta-data
110119
android:name="com.google.android.gms.version"
111120
android:value="@integer/google_play_services_version"/>

app/src/main/java/com/onegini/mobile/exampleapp/Constants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@
1818
public interface Constants {
1919
String[] DEFAULT_SCOPES = { "read" };
2020
String NEW_LINE = "\n";
21-
String SPACE = " ";
2221
String GCM_SENDER_ID = "586427927998";
22+
String GCM_REGISTRATION_COMPLETE = "gmc_registration_complete";
2323
}

app/src/main/java/com/onegini/mobile/exampleapp/OneginiConfigModel.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@
1818
import android.os.Build;
1919
import com.onegini.mobile.sdk.android.model.OneginiClientConfigModel;
2020

21+
@SuppressWarnings("unused")
2122
public class OneginiConfigModel implements OneginiClientConfigModel {
2223

2324
private final String appIdentifier = "ExampleApp";
2425
private final String appPlatform = "android";
2526
private final String redirectionUri = "oneginiexample://loginsuccess";
26-
private final String appVersion = "2.0.0";
27+
private final String appVersion = "2.1.0";
2728
private final String baseURL = "https://demo-msp.onegini.com";
2829
private final String resourceBaseURL = "https://demo-msp.onegini.com/resources";
2930
private final String keystoreHash = "910638c3e6c17ec9ab2a74969abab06b34470d29c21d8ad8a65af243a1ccb69f";
30-
private final int maxPinFailures = 3;
3131

3232
@Override
3333
public String getAppIdentifier() {
@@ -79,11 +79,6 @@ public boolean shouldGetIdToken() {
7979
return false;
8080
}
8181

82-
@Override
83-
public int getMaxPinFailures() {
84-
return maxPinFailures;
85-
}
86-
8782
@Override
8883
public String toString() {
8984
return "ConfigModel{" +
@@ -92,7 +87,6 @@ public String toString() {
9287
", redirectionUri='" + redirectionUri + "'" +
9388
", appVersion='" + appVersion + "'" +
9489
", baseURL='" + baseURL + "'" +
95-
", maxPinFailures='" + maxPinFailures + "'" +
9690
", resourceBaseURL='" + resourceBaseURL + "'" +
9791
"}";
9892
}

app/src/main/java/com/onegini/mobile/exampleapp/network/gcm/GCMBroadcastReceiver.java

Lines changed: 0 additions & 34 deletions
This file was deleted.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright (c) 2016 Onegini B.V.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.onegini.mobile.exampleapp.network.gcm;
17+
18+
import com.google.android.gms.iid.InstanceIDListenerService;
19+
import com.onegini.mobile.exampleapp.OneginiSDK;
20+
import com.onegini.mobile.exampleapp.storage.SettingsStorage;
21+
import com.onegini.mobile.exampleapp.util.DeregistrationUtil;
22+
import com.onegini.mobile.sdk.android.handlers.OneginiMobileAuthenticationEnrollmentHandler;
23+
import com.onegini.mobile.sdk.android.handlers.error.OneginiMobileAuthenticationEnrollmentError;
24+
import com.onegini.mobile.sdk.android.model.entity.UserProfile;
25+
26+
public class GCMInstanceIDListenerService extends InstanceIDListenerService {
27+
28+
/**
29+
* Called if InstanceID token is updated. This may occur if the security of the previous token had been compromised. This call is initiated by the InstanceID
30+
* provider.
31+
*/
32+
@Override
33+
public void onTokenRefresh() {
34+
final OneginiMobileAuthenticationEnrollmentHandler mobileAuthenticationEnrollmentHandler = new OneginiMobileAuthenticationEnrollmentHandler() {
35+
@Override
36+
public void onSuccess() {
37+
setMobileAuthenticationEnabled(true);
38+
}
39+
40+
@Override
41+
public void onError(final OneginiMobileAuthenticationEnrollmentError error) {
42+
@OneginiMobileAuthenticationEnrollmentError.MobileAuthenticationEnrollmentErrorType final int errorType = error.getErrorType();
43+
// This method is called when a mobile authentication enrollment error occurs, for example when the device is deregistered
44+
if (errorType == OneginiMobileAuthenticationEnrollmentError.DEVICE_DEREGISTERED) {
45+
new DeregistrationUtil(GCMInstanceIDListenerService.this).onDeviceDeregistered();
46+
}
47+
setMobileAuthenticationEnabled(false);
48+
}
49+
};
50+
final GCMRegistrationService gcmRegistrationService = new GCMRegistrationService(this);
51+
gcmRegistrationService.registerGCMService(mobileAuthenticationEnrollmentHandler);
52+
}
53+
54+
private void setMobileAuthenticationEnabled(final boolean isEnabled) {
55+
UserProfile authenticatedUserProfile = OneginiSDK.getOneginiClient(this).getUserClient().getAuthenticatedUserProfile();
56+
if (authenticatedUserProfile == null) {
57+
return;
58+
}
59+
60+
final SettingsStorage settingsStorage = new SettingsStorage(GCMInstanceIDListenerService.this);
61+
settingsStorage.setMobileAuthenticationEnabled(authenticatedUserProfile, isEnabled);
62+
}
63+
}

app/src/main/java/com/onegini/mobile/exampleapp/network/gcm/GCMIntentService.java renamed to app/src/main/java/com/onegini/mobile/exampleapp/network/gcm/GCMListenerService.java

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,12 @@
1717

1818
import java.util.Set;
1919

20-
import android.app.IntentService;
21-
import android.content.Intent;
2220
import android.os.Bundle;
2321
import android.util.Log;
2422
import android.widget.Toast;
23+
import com.google.android.gms.gcm.GcmListenerService;
2524
import com.onegini.mobile.exampleapp.OneginiSDK;
26-
import com.onegini.mobile.exampleapp.storage.SettingsStorage;
27-
import com.onegini.mobile.exampleapp.storage.UserStorage;
25+
import com.onegini.mobile.exampleapp.util.DeregistrationUtil;
2826
import com.onegini.mobile.sdk.android.client.OneginiClient;
2927
import com.onegini.mobile.sdk.android.exception.OneginiInitializationException;
3028
import com.onegini.mobile.sdk.android.handlers.OneginiInitializationHandler;
@@ -33,30 +31,24 @@
3331
import com.onegini.mobile.sdk.android.handlers.error.OneginiMobileAuthenticationError;
3432
import com.onegini.mobile.sdk.android.model.entity.UserProfile;
3533

36-
public class GCMIntentService extends IntentService {
34+
public class GCMListenerService extends GcmListenerService {
3735

38-
private static final String TAG = GCMIntentService.class.getSimpleName();
36+
private static final String TAG = GCMListenerService.class.getSimpleName();
3937

40-
public GCMIntentService() {
41-
super(TAG);
42-
}
4338

4439
@Override
45-
protected void onHandleIntent(final Intent intent) {
46-
final Bundle extras = intent.getExtras();
47-
if (!extras.isEmpty()) {
40+
public void onMessageReceived(String from, Bundle data) {
41+
if (!data.isEmpty()) {
4842
Log.i(TAG, "Push message received");
4943

5044
try {
51-
handleMobileAuthenticationRequest(extras);
45+
handleMobileAuthenticationRequest(data);
5246
} catch (OneginiInitializationException exception) {
5347
// Onegini SDK hasn't been started yet so we have to do it
5448
// before handling the mobile authentication request
55-
setupOneginiSDK(extras);
49+
setupOneginiSDK(data);
5650
}
5751
}
58-
// Release the wake lock provided by the WakefulBroadcastReceiver.
59-
GCMBroadcastReceiver.completeWakefulIntent(intent);
6052
}
6153

6254
private void setupOneginiSDK(final Bundle extras) {
@@ -73,7 +65,11 @@ public void onSuccess(final Set<UserProfile> removedUserProfiles) {
7365

7466
@Override
7567
public void onError(final OneginiInitializationError error) {
76-
Toast.makeText(GCMIntentService.this, error.getErrorDescription(), Toast.LENGTH_LONG).show();
68+
@OneginiInitializationError.InitializationErrorType final int errorType = error.getErrorType();
69+
if (errorType == OneginiInitializationError.DEVICE_DEREGISTERED) {
70+
new DeregistrationUtil(getApplicationContext()).onDeviceDeregistered();
71+
}
72+
Toast.makeText(GCMListenerService.this, error.getErrorDescription(), Toast.LENGTH_LONG).show();
7773
}
7874
});
7975
}
@@ -82,25 +78,28 @@ private void handleMobileAuthenticationRequest(final Bundle extras) {
8278
OneginiSDK.getOneginiClient(this).getUserClient().handleMobileAuthenticationRequest(extras, new OneginiMobileAuthenticationHandler() {
8379
@Override
8480
public void onSuccess() {
85-
Toast.makeText(GCMIntentService.this, "Mobile authentication success", Toast.LENGTH_SHORT).show();
81+
Toast.makeText(GCMListenerService.this, "Mobile authentication success", Toast.LENGTH_SHORT).show();
8682
}
8783

8884
@Override
8985
public void onError(final OneginiMobileAuthenticationError oneginiMobileAuthenticationError) {
90-
Toast.makeText(GCMIntentService.this, oneginiMobileAuthenticationError.getErrorDescription(), Toast.LENGTH_SHORT).show();
91-
if (oneginiMobileAuthenticationError.getErrorType() == OneginiMobileAuthenticationError.USER_DEREGISTERED) {
92-
new SettingsStorage(GCMIntentService.this).setMobileAuthenticationEnabled(false);
93-
} else if (oneginiMobileAuthenticationError.getErrorType() == OneginiMobileAuthenticationError.ACTION_CANCELED) {
94-
// the user denied incoming mobile authentication request
86+
Toast.makeText(GCMListenerService.this, oneginiMobileAuthenticationError.getErrorDescription(), Toast.LENGTH_SHORT).show();
87+
@OneginiMobileAuthenticationError.MobileAuthenticationEnrollmentErrorType final int errorType = oneginiMobileAuthenticationError.getErrorType();
88+
if (errorType == OneginiMobileAuthenticationError.USER_DEREGISTERED) {
89+
// the user was deregister, for example he provided a wrong PIN for too many times. You can handle the deregistration here, but since this application
90+
// supports multiple profiles we handle it when the user tries to login the next time because we don't know which user profile was deregistered at
91+
// this point.
92+
} else if (errorType == OneginiMobileAuthenticationError.ACTION_CANCELED) {
93+
Toast.makeText(GCMListenerService.this, "The user cancelled the mobile authentication request", Toast.LENGTH_LONG).show();
9594
}
9695
}
9796
});
9897
}
9998

10099
private void removeUserProfiles(final Set<UserProfile> removedUserProfiles, final Bundle extras) {
101-
final UserStorage userStorage = new UserStorage(this);
100+
final DeregistrationUtil deregistrationUtil = new DeregistrationUtil(this);
102101
for (final UserProfile userProfile : removedUserProfiles) {
103-
userStorage.removeUser(userProfile);
102+
deregistrationUtil.onUserDeregistered(userProfile);
104103
}
105104
handleMobileAuthenticationRequest(extras);
106105
}

0 commit comments

Comments
 (0)