Show TOC

MAF Logon Task FlowLocate this document in the navigation structure

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
  • Resources as android library project (apklib 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 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 Eclipse, 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 files into the libs folder of your project:
    • MobilePlace.jar
    • HttpConversation.jar
    • HttpConvAuthFlows.jar
    • Connectivity.jar
    • ClientLog.jar
    • SupportabilityFacade.jar
    • AfariaSLL.jar
    • Common.jar
    • CoreServices.jar
    • DataVaultLib.jar
    • perflib.jar
    • Request.jar
    • sap-e2etrace.jar
    • ClientHubSLL.jar
    • maflogoncore.jar
    • maflogger.jar
    • maflogonui.jar
    • mafuicomponents.jar
    • mafsettingscreen.jar
  4. Extract and import apklib projects into your workspace:
    1. In the resources folders, change the extension from .apklib to .zip.
    2. Unzip the project.
    3. Import and copy the project into your workspace.
    4. Ensure it is marked as Android Library project in the project settings.
    5. The required apklib projects are:
      • maflogonui-res.apklib
      • mafsettingscreen-res.apklib
      • mafuicomponents-res.apklib
  5. Add the Android Library projects as dependencies to your project: right-click your project and select Start of the navigation path Properties Next navigation step Android End of the navigation path and add the dependent library projects to the list of dependencies.
  6. 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
      	// ===========================================================