Skip to content

Commit

Permalink
Merge pull request #49 from Onegini/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Robert Szuba authored Dec 19, 2016
2 parents bd040f4 + c3120f2 commit 5b503e0
Show file tree
Hide file tree
Showing 13 changed files with 145 additions and 78 deletions.
14 changes: 8 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ android {
applicationId "com.onegini.mobile.exampleapp"
minSdkVersion 16
targetSdkVersion 23
versionCode 5
versionName "2.2.0"
versionCode 6
versionName "2.3.0"
multiDexEnabled true
}
buildTypes {
Expand All @@ -63,11 +63,14 @@ android {
dexOptions {
javaMaxHeapSize "4g"
}
packagingOptions {
exclude 'META-INF/rxjava.properties'
}
}

dependencies {
// Onegini SDK
compile('com.onegini.mobile.sdk.android:onegini-sdk:6.02.00@aar') {
compile('com.onegini.mobile.sdk.android:onegini-sdk:6.03.00@aar') {
transitive = true
exclude module: 'fido-client'
exclude module: 'samsungsds-ccom'
Expand All @@ -86,12 +89,11 @@ dependencies {
// DI for views
compile 'com.jakewharton:butterknife:7.0.1'
// RxJava
compile 'io.reactivex:rxandroid:1.1.0'
compile 'io.reactivex:rxandroid:1.2.1'
compile 'io.reactivex:rxjava:1.2.3'

// Samsung's FIDO client
compile 'com.samsung.sds.fido.uaf.sdk:fido-client:1.4.1@aar'
compile 'org.fidoalliance.uaf.client.common:samsungsds-ccom:1.4.1@aar'
compile 'com.samsung.sds.fido.uaf.message:samsungsds-um:1.4.1'
// Google Guava
compile 'com.google.guava:guava:19.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class OneginiConfigModel implements OneginiClientConfigModel {
private final String appIdentifier = "ExampleApp";
private final String appPlatform = "android";
private final String redirectionUri = "oneginiexample://loginsuccess";
private final String appVersion = "2.2.0";
private final String appVersion = "2.3.0";
private final String baseURL = "https://demo-msp.onegini.com";
private final String resourceBaseURL = "https://demo-msp.onegini.com/resources";
private final String keystoreHash = "910638c3e6c17ec9ab2a74969abab06b34470d29c21d8ad8a65af243a1ccb69f";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import com.onegini.mobile.exampleapp.view.handler.MobileAuthenticationPinRequestHandler;
import com.onegini.mobile.exampleapp.view.handler.MobileAuthenticationRequestHandler;
import com.onegini.mobile.exampleapp.view.handler.PinAuthenticationRequestHandler;
import com.onegini.mobile.exampleapp.view.handler.RegistrationURLHandler;
import com.onegini.mobile.exampleapp.view.handler.RegistrationRequestHandler;
import com.onegini.mobile.sdk.android.client.OneginiClient;
import com.onegini.mobile.sdk.android.client.OneginiClientBuilder;

Expand All @@ -41,19 +41,19 @@ public static OneginiClient getOneginiClient(final Context context) {

private static OneginiClient buildSDK(final Context context) {
final Context applicationContext = context.getApplicationContext();
final RegistrationRequestHandler registrationRequestHandler = new RegistrationRequestHandler(applicationContext);
final CreatePinRequestHandler createPinRequestHandler = new CreatePinRequestHandler(applicationContext);
final PinAuthenticationRequestHandler pinAuthenticationRequestHandler = new PinAuthenticationRequestHandler(applicationContext);
final RegistrationURLHandler registrationURLHandler = new RegistrationURLHandler(context);

// will throw OneginiConfigNotFoundException if OneginiConfigModel class can't be found
return new OneginiClientBuilder(applicationContext, createPinRequestHandler, pinAuthenticationRequestHandler)
return new OneginiClientBuilder(applicationContext, registrationRequestHandler, createPinRequestHandler, pinAuthenticationRequestHandler)
// handlers for optional functionalities
.setFingerprintAuthenticatioRequestHandler(new FingerprintAuthenticationRequestHandler(applicationContext))
.setFidoAuthenticationRequestHandler(new FidoAuthenticationRequestHandler(applicationContext))
.setMobileAuthenticationRequestHandler(new MobileAuthenticationRequestHandler(applicationContext))
.setMobileAuthenticationPinRequestHandler(new MobileAuthenticationPinRequestHandler(applicationContext))
.setFingerprintAuthenticatioRequestHandler(new FingerprintAuthenticationRequestHandler(applicationContext))
.setMobileAuthenticationFingerprintRequestHandler(new MobileAuthenticationFingerprintRequestHandler(applicationContext))
.setOneginiURLHandler(registrationURLHandler)
.setMobileAuthenticationFidoRequestHandler(new MobileAuthenticationFidoRequestHandler(applicationContext))
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ public void onError(final OneginiMobileAuthenticationError oneginiMobileAuthenti
// 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
// 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
// this point.
} else if (errorType == OneginiMobileAuthenticationError.ACTION_CANCELED) {
showToast("The user cancelled the mobile authentication request");
} else if (errorType == OneginiMobileAuthenticationError.DEVICE_DEREGISTERED) {
new DeregistrationUtil(getApplicationContext()).onDeviceDeregistered();
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ protected void onCreate(final Bundle savedInstanceState) {
@SuppressWarnings("unused")
@OnClick(R.id.button_logout)
public void logout() {
final OneginiClient oneginiClient = OneginiSDK.getOneginiClient(this);
final UserProfile userProfile = oneginiClient.getUserClient().getAuthenticatedUserProfile();
OneginiSDK.getOneginiClient(this).getUserClient().logout(
new OneginiLogoutHandler() {
@Override
Expand All @@ -73,20 +75,24 @@ public void onSuccess() {

@Override
public void onError(final OneginiLogoutError oneginiLogoutError) {
handleLogoutError(oneginiLogoutError);
handleLogoutError(oneginiLogoutError, userProfile);
}
}
);
}

private void handleLogoutError(final OneginiLogoutError oneginiLogoutError) {
private void handleLogoutError(final OneginiLogoutError oneginiLogoutError, final UserProfile userProfile) {
@OneginiLogoutError.LogoutErrorType final int errorType = oneginiLogoutError.getErrorType();
if (errorType == OneginiLogoutError.LOCAL_LOGOUT) {
showToast("The user was only logged out on the device. The access token has not been invalidated on the server-side.");
} else if (errorType == OneginiLogoutError.GENERAL_ERROR) {
// General error handling for other, less relevant errors
showToast("Logout error: " + oneginiLogoutError.getErrorDescription());

if (errorType == OneginiLogoutError.DEVICE_DEREGISTERED) {
new DeregistrationUtil(this).onDeviceDeregistered();
} else if (errorType == OneginiLogoutError.USER_DEREGISTERED) {
new DeregistrationUtil(this).onUserDeregistered(userProfile);
}

// other errors don't really require our reaction, but you might consider displaying some message to the user
showToast("Logout error: " + oneginiLogoutError.getErrorDescription());

startLoginActivity();
}

Expand All @@ -100,36 +106,37 @@ public void deregisterUser() {
return;
}

new DeregistrationUtil(this).onUserDeregistered(userProfile);
oneginiClient.getUserClient().deregisterUser(userProfile, new OneginiDeregisterUserProfileHandler() {
@Override
public void onSuccess() {
onUserDeregistered(userProfile);
onUserDeregistered();
}

@Override
public void onError(final OneginiDeregistrationError oneginiDeregistrationError) {
onUserDeregistrationError(oneginiDeregistrationError, userProfile);
onUserDeregistrationError(oneginiDeregistrationError);
}
}
);
}

private void onUserDeregistered(final UserProfile userProfile) {
new DeregistrationUtil(this).onUserDeregistered(userProfile);
private void onUserDeregistered() {
showToast("deregisterUserSuccess");

startLoginActivity();
}

private void onUserDeregistrationError(final OneginiDeregistrationError oneginiDeregistrationError, final UserProfile userProfile) {
new DeregistrationUtil(this).onUserDeregistered(userProfile);
private void onUserDeregistrationError(final OneginiDeregistrationError oneginiDeregistrationError) {
@OneginiDeregistrationError.DeregistrationErrorType final int errorType = oneginiDeregistrationError.getErrorType();
if (errorType == OneginiDeregistrationError.LOCAL_DEREGISTRATION) {
showToast("The user was only logged out on the device. The access token has not been invalidated on the server-side.");
} else if (errorType == OneginiDeregistrationError.GENERAL_ERROR) {
// General error handling for other, less relevant errors
showToast("Logout error: " + oneginiDeregistrationError.getErrorDescription());
if (errorType == OneginiDeregistrationError.DEVICE_DEREGISTERED) {
// Deregistration failed due to missing device credentials. Register app once again.
new DeregistrationUtil(this).onDeviceDeregistered();
}

// other errors don't really require our reaction, but you might consider displaying some message to the user
showToast("Deregistration error: " + oneginiDeregistrationError.getErrorDescription());

startLoginActivity();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import com.onegini.mobile.exampleapp.model.User;
import com.onegini.mobile.exampleapp.storage.UserStorage;
import com.onegini.mobile.exampleapp.util.DeregistrationUtil;
import com.onegini.mobile.exampleapp.view.handler.RegistrationRequestHandler;
import com.onegini.mobile.sdk.android.client.OneginiClient;
import com.onegini.mobile.sdk.android.handlers.OneginiRegistrationHandler;
import com.onegini.mobile.sdk.android.handlers.error.OneginiRegistrationError;
Expand All @@ -52,6 +53,9 @@ public class RegistrationActivity extends Activity {
@Bind(R.id.create_profile_button)
Button createProfileButton;
@SuppressWarnings({ "unused", "WeakerAccess" })
@Bind(R.id.cancel_registration_button)
Button cancelRegistrationButton;
@SuppressWarnings({ "unused", "WeakerAccess" })
@Bind(R.id.progress_bar_register)
ProgressBar progressBar;
@SuppressWarnings({ "unused", "WeakerAccess" })
Expand All @@ -76,6 +80,7 @@ protected void onCreate(final Bundle savedInstanceState) {
private void setupUserInterface() {
createProfileButton.setEnabled(false);
layoutRegisterContent.setVisibility(View.GONE);
cancelRegistrationButton.setVisibility(View.VISIBLE);
progressBar.setVisibility(View.VISIBLE);
userProfileDebugText.setText("");
nameEditText.addTextChangedListener(new ProfileNameChangeListener());
Expand All @@ -88,9 +93,14 @@ public void onNewIntent(final Intent intent) {
}

private void handleRedirection(final Uri uri) {
if (uri == null) {
return;
}

final OneginiClient client = OneginiSDK.getOneginiClient(getApplicationContext());
if (uri != null && client.getConfigModel().getRedirectUri().startsWith(uri.getScheme())) {
client.getUserClient().handleRegistrationCallback(uri);
final String redirectUri = client.getConfigModel().getRedirectUri();
if (redirectUri.startsWith(uri.getScheme())) {
RegistrationRequestHandler.handleRegistrationCallback(uri);
}
}

Expand Down Expand Up @@ -139,6 +149,9 @@ private void handleRegistrationErrors(final OneginiRegistrationError oneginiRegi
handleGeneralError(oneginiRegistrationError);
break;
}
// start login screen again
startActivity(new Intent(this, LoginActivity.class));
finish();
}

private void handleGeneralError(final OneginiRegistrationError oneginiRegistrationError) {
Expand All @@ -156,6 +169,7 @@ private void handleGeneralError(final OneginiRegistrationError oneginiRegistrati

private void askForProfileName() {
progressBar.setVisibility(View.GONE);
cancelRegistrationButton.setVisibility(View.GONE);
layoutRegisterContent.setVisibility(View.VISIBLE);
}

Expand All @@ -166,6 +180,12 @@ public void onCreateProfileClick() {
startDashboardActivity();
}

@SuppressWarnings("unused")
@OnClick(R.id.cancel_registration_button)
public void onCancelRegistrationButton() {
RegistrationRequestHandler.onRegistrationCanceled();
}

private void showToast(final String message) {
Toast.makeText(this, message, Toast.LENGTH_LONG).show();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,15 @@ public void onSuccess() {

@Override
public void onError(final OneginiAuthenticatorDeregistrationError error) {
onErrorOccurred(position, error.getErrorDescription());
@OneginiAuthenticatorDeregistrationError.AuthenticatorDeregistrationErrorType int errorType = error.getErrorType();
if (errorType == OneginiAuthenticatorDeregistrationError.USER_NOT_AUTHENTICATED) {
startLoginActivity();
} else if (errorType == OneginiAuthenticatorDeregistrationError.USER_DEREGISTERED) {
new DeregistrationUtil(SettingsAuthenticatorsActivity.this).onUserDeregistered(authenticatedUserProfile);
} else if (errorType == OneginiAuthenticatorDeregistrationError.DEVICE_DEREGISTERED) {
new DeregistrationUtil(SettingsAuthenticatorsActivity.this).onDeviceDeregistered();
}

onErrorOccurred(position, error.getErrorDescription());
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import static com.onegini.mobile.exampleapp.Constants.COMMAND_START;
import static com.onegini.mobile.exampleapp.Constants.EXTRA_COMMAND;
import static com.onegini.mobile.exampleapp.view.activity.AuthenticationActivity.EXTRA_USER_PROFILE_ID;
import static com.onegini.mobile.exampleapp.view.activity.MobileAuthenticationFidoActivity.*;
import static com.onegini.mobile.exampleapp.view.activity.MobileAuthenticationFidoActivity.EXTRA_MESSAGE;

import android.content.Context;
import android.content.Intent;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright (c) 2016 Onegini B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.onegini.mobile.exampleapp.view.handler;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import com.onegini.mobile.sdk.android.handlers.request.OneginiRegistrationRequestHandler;
import com.onegini.mobile.sdk.android.handlers.request.callback.OneginiRegistrationCallback;

public class RegistrationRequestHandler implements OneginiRegistrationRequestHandler {

private static OneginiRegistrationCallback CALLBACK;

/**
* Finish registration action with result from web browser
*/
public static void handleRegistrationCallback(final Uri uri) {
if (CALLBACK != null) {
CALLBACK.handleRegistrationCallback(uri);
CALLBACK = null;
}
}

/**
* Cancel registration action in case of web browser error
*/
public static void onRegistrationCanceled() {
if (CALLBACK != null) {
CALLBACK.denyRegistration();
CALLBACK = null;
}
}

private final Context context;

public RegistrationRequestHandler(final Context context) {
this.context = context;
}

@Override
public void startRegistration(final Uri uri, final OneginiRegistrationCallback oneginiRegistrationCallback) {
CALLBACK = oneginiRegistrationCallback;

// We're going to launch external browser to allow user to log in. You could also use embedded WebView instead.
final Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);

context.startActivity(intent);
}
}

This file was deleted.

Loading

0 comments on commit 5b503e0

Please sign in to comment.