Developer

MAF Logon Task Flow

Implement the logon flow in your app.

Context

To complete this flow, you must obtain the Android Native Client SDK libraries, which are part of the SAP Mobile Platform Client SDK Installer. MAFLogon ships in the form of separate artifacts such as:
  • Library JAR files
  • Android libraries (AAR files)

By default, the installer places these files in <SMP_HOME>\MobileSDK<version>\NativeSDK\ODataFramework\Android\ and <SMP_HOME>\MobileSDK<version>\NativeSDK\MAFReuse\Android\.

Before you can use MAFLogon, you must add associated artifacts. You must also add dependent jars and aars, and configure your build settings. For the rest of the procedure, we assume that you are starting a new project for Android. If you are working with an existing project, the steps may vary.

Procedure

  1. In Android Studio, create a new project or open an existing one.
  2. Ensure that AndroidManifest.xml contains the INTERNET permission:
    <uses-permission android:name="android.permission.INTERNET"/>
    and:
    <uses-permission android:name="com.sap.mobile.clientHub.CLIENTHUB_ACCESS_PERMISSION"/> 
    if ClientHub is used.
  3. Copy jar and aar files into the libs folder of your project:
    • MobilePlace.aar
    • HttpConversation.aar
    • HttpConvAuthFlows.aar
    • Connectivity.aar
    • ClientLog.aar
    • SupportabilityFacade.aar
    • AfariaSLL.aar
    • Common.aar
    • CoreServices.aar
    • DataVaultLib.aar
    • perflib.jar
    • Request.aar
    • sap-e2etrace.jar
    • ClientHubSLL.aar
    • maflogoncore.aar
    • maflogger.aar
    • maflogonui.aar
    • mafuicomponents.aar
    • mafsettingscreen.aar
  4. Update your build.gradle file:
    Add this line into the dependencies section of the build.gradle file:
    compile fileTree(include: ['*.jar'], dir: 'libs')
    After this line within the dependencies section, insert the following lines for each of the AAR files you copied into the libs folder:
    compile(name:'nameOfYourAARFileWithoutExtension', ext:'aar')
    For example:
    compile(name:' mafcalendar-1.210.0', ext:'aar')

    And so on. Insert a line for each AAR file.

  5. Implement the necessary code:
    1. Create a new Activity class (or use an existing one) and add these fields:
      	final static int LOGON_SUCCESS = 101;
      	final static int LOGON_FAIL = 102;
      	final static int LOGON_SUCCESS_DEMO = 103;
      	final static int LOGON_FAIL_DEMO = 104;
      
      	private TextView label;
      	private LinearLayout root_layout;
      	private MAFButton actionButton;
      	private LogonUIFacade logonUIFacade;	
      	private final String APPLICATIONID = "com.sap.maf.test.adr.logonapp";
      
    2. Implement the following code in the onCreate() method (the activity_main.xml must contain a TextView element with the following attribute and attributevalue: android:id="@+id/label" ):
      	protected void onCreate(Bundle savedInstanceState) {
      		super.onCreate(savedInstanceState);
      
      		LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      		root_layout = (LinearLayout) inflater.inflate(R.layout.activity_main, null);
      		LayoutParams lr_lps = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
      		lr_lps.gravity = Gravity.CENTER;
      		label = (TextView) root_layout.findViewById(R.id.label);
      		label.setLayoutParams(lr_lps);
      		actionButton = new MAFButton(this, MAFButton.NORMAL_BUTTON);
      		actionButton.setLayoutParams(lr_lps);
      		root_layout.addView(actionButton);
      
      		// INIT LOGON
      		doLogon();
      
      	}
      
    3. Implement the doLogon() and doLogout() methods:
      private void doLogon() {
      		// present MAF Logon Screen
      		// get an instance of the LogonUIFacade
      		if (logonUIFacade == null) {
      			logonUIFacade = LogonUIFacade.getInstance();
      		}
      		// init LogonUIFacede
      		logonUIFacade.init(this, this, APPLICATIONID);
      		// ask LogonUIFacede to present the logon screen
      		// set the resulting view as the content view for this activity
      		setContentView(logonUIFacade.logon());
      
      	}
      
      	private void doLogout() {
      		//delete registered user
      		logonUIFacade.deleteUser();
      		//restart logon process
      		doLogon();
      	}
      
    4. Implement the LogonListener:
      public class MainActivity extends Activity implements LogonListener{
          ...
      }
      
    5. Implement methods of the LogonListener:
      // START OF LogonListener interface implementation
      	// ===========================================================
      	@Override
      	public void objectFromSecureStoreForKey() {
      
      	}
      
      	@Override
      	public void onApplicationSettingsUpdated() {
      
      	}
      
      	@Override
      	public void onBackendPasswordChanged(boolean arg0) {
      
      	}
      
      	@Override
      	public void onLogonFinished(String errorMessage, boolean isUserLoggedOn, LogonContext logonContext) {
      		// hides MAFLogonUI when logon finished and returns to main activity
      
      		boolean isDemoMode = logonContext.getLogonConnection().isDemoMode();
      
      		if (isDemoMode) {
      				// case LOGON_DEMO:
      				label.setText("LOGON Demo screen");
      				actionButton.setText("Logout");
      				actionButton.setOnClickListener(new OnClickListener() {
      
      					@Override
      					public void onClick(View v) {
      						doLogout();
      					}
      				});
      
      		} else {
      			if (isUserLoggedOn) {
      				// case LOGON_SUCCESS:
      				label.setText("LOGON SUCCESS");
      				actionButton.setText("Logout");
      				actionButton.setOnClickListener(new OnClickListener() {
      
      					@Override
      					public void onClick(View v) {
      						doLogout();
      					}
      				});
      			} else {
      				// case LOGON_FAIL:
      				label.setText("LOGON FAILED");
      				actionButton.setText("Retry to logon");
      				actionButton.setOnClickListener(new OnClickListener() {
      
      					@Override
      					public void onClick(View v) {
      						doLogon();
      					}
      				});
      
      			}
      		}
      		runOnUiThread(new Runnable() {
      			
      			@Override
      			public void run() {
      				setContentView(root_layout);
      			}
      		});
      	}
      
      	@Override
      	public void onSecureStorePasswordChanged(boolean arg0, String arg1) {
      
      	}
      
      	@Override
      	public void onUserDeleted() {
      		setContentView(logonUIFacade.logon());
      
      	}
      
      	@Override
      	public void registrationInfo() {
      
      	}
      	
      
      	@Override
      	public void onRefreshCertificate(boolean arg0, String arg1) {
      		
      	}
      	
      	// END OF LogonListener interface implementation
      	// ===========================================================