on 10-28-2016 8:29 AM
I am trying to implement certificate based authentication with android native application with SMP3.0 sp11
I configured the appid in SMP3.0 for x509 certificate based authentication and tested with rest client by using the user certificate demouser.p12
Now I installed the certificate demouser.p12 in android device and used maf login components and libs in android project. I am referring the doc below-
http://help.sap.com/saphelp_smp3011sdk/helpdata/en/3c/227ce642834b60a210baacc39cc7d7/content.htm
I am not able to call the getCertificate method. Please suggest what wrong i am doing.
-------------------------------------------------------------------------------------------------------------------
package com.sample.x509test; import android.app.Activity; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.net.Uri; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.text.InputType; import android.util.Log; import android.widget.EditText; import android.widget.LinearLayout; import android.widget.TextView; import android.widget.Toast; import com.google.android.gms.appindexing.Action; import com.google.android.gms.appindexing.AppIndex; import com.google.android.gms.common.api.GoogleApiClient; import com.sap.maf.tools.logon.core.LogonCore; import com.sap.maf.tools.logon.core.LogonCoreException; import com.sap.maf.tools.logon.core.reg.RegistrationManager; import com.sap.maf.tools.logon.logonui.api.CertificateProvider; import com.sap.maf.tools.logon.logonui.api.CertificateProviderException; import com.sap.maf.tools.logon.logonui.api.CertificateProviderListener; import com.sap.maf.tools.logon.logonui.api.LogonListener; import com.sap.maf.tools.logon.logonui.api.LogonUIFacade; import com.sap.maf.tools.logon.manager.LogonContext; import com.sap.maf.tools.logon.manager.LogonManager; import java.util.Map; import javax.net.ssl.X509KeyManager; public class MAFLogonActivity extends AppCompatActivity implements LogonListener, CertificateProvider{ private String _alias = "defaultAlias"; private String _filePath = "defaultFilePath"; private String _certPwd = "defaultPassword"; private String _appId; private Activity _activity; Context mContext; CertificateProviderListener certificateProviderListener; /** * ATTENTION: This was auto-generated to implement the App Indexing API. * See https://g.co/AppIndexing/AndroidStudio for more information. */ private GoogleApiClient client; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //setContentView(R.layout.activity_maflogon); // set context reference mContext = this; // get an instance of the LogonUIFacade LogonUIFacade mLogonUIFacade = LogonUIFacade.getInstance(); //Initialize the Logon UI Facade mLogonUIFacade.init(this, mContext, AppSettings.APP_ID); //customize the maf logon screen mLogonUIFacade.setDefaultValue(LogonCore.SharedPreferenceKeys.PREFERENCE_ID_SUPSERVERURL, XXXXXX); mLogonUIFacade.setDefaultValue(LogonCore.SharedPreferenceKeys.PREFERENCE_ID_SUPSERVERPORT, "8082"); mLogonUIFacade.setDefaultValue(LogonCore.SharedPreferenceKeys.PREFERENCE_ID_HTTPSSTATUS, "True"); mLogonUIFacade.setDefaultValue(LogonCore.SharedPreferenceKeys.PREFERENCE_ID_SECCONFIG, "CertAuth"); mLogonUIFacade.setDefaultValue(LogonCore.SharedPreferenceKeys.PREFERENCE_ID_APPID, "com.x509.test"); mLogonUIFacade.setDefaultValue(LogonCore.SharedPreferenceKeys.PREFERENCE_ID_USERCREATIONPOLICY, "certificate"); /* mLogonUIFacade.isFieldHidden(LogonCore.SharedPreferenceKeys.PREFERENCE_ID_USERNAME, true); mLogonUIFacade.isFieldHidden(LogonCore.SharedPreferenceKeys.PREFERENCE_ID_PASSWORD, true);*/ mLogonUIFacade.isFieldHidden(LogonCore.SharedPreferenceKeys.PREFERENCE_ID_SUPSERVERFARMID, true); mLogonUIFacade.isFieldHidden(LogonCore.SharedPreferenceKeys.PREFERENCE_ID_URLSUFFIX, true); mLogonUIFacade.isFieldHidden(LogonCore.SharedPreferenceKeys.PREFERENCE_ID_MOBILEUSER, true); mLogonUIFacade.isFieldHidden(LogonCore.SharedPreferenceKeys.PREFERENCE_ID_ACTIVATIONCODE, true); mLogonUIFacade.isFieldHidden(LogonCore.SharedPreferenceKeys.PREFERENCE_ID_HTTPSSTATUS, true); mLogonUIFacade.isFieldHidden(LogonCore.SharedPreferenceKeys.PREFERENCE_ID_GATEWAYCLIENT, true); mLogonUIFacade.isFieldHidden(LogonCore.SharedPreferenceKeys.PREFERENCE_ID_SUPSERVERDOMAIN, true); mLogonUIFacade.isFieldHidden(LogonCore.SharedPreferenceKeys.PREFERENCE_ID_PINGPATH, true); mLogonUIFacade.isFieldHidden(LogonCore.SharedPreferenceKeys.PREFERENCE_ID_GWONLY, true); mLogonUIFacade.isFieldHidden(LogonCore.SharedPreferenceKeys.PREFERENCE_ID_MOBILEPLACE, true); mLogonUIFacade.isFieldHidden(LogonCore.SharedPreferenceKeys.PREFERENCE_ID_PASSCODESTATUS, true); mLogonUIFacade.isFieldHidden(LogonCore.SharedPreferenceKeys.PREFERENCE_ID_VAULTPOLICY, true); setContentView(mLogonUIFacade.logon()); // ATTENTION: This was auto-generated to implement the App Indexing API. // See https://g.co/AppIndexing/AndroidStudio for more information. } @Override public void getCertificate(CertificateProviderListener callback) { certificateProviderListener = callback; mContext = (Activity) LogonUIFacade.getInstance().getActivityContext(); mContext.startActivity(new Intent(mContext, ProviderActivity.class)); } @Override public X509KeyManager getStoredCertificate() { // This function is how the certificate is retrieved synchronously. CustomKeyManager keyManager = null; try { keyManager = new CustomKeyManager(_filePath, _certPwd, _alias); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return keyManager; } @Override public void deleteStoredCertificate() throws CertificateProviderException { } @Override public void onLogonFinished(String s, boolean b, LogonContext logonContext) { String TAG = MAFLogonActivity.class.getSimpleName(); Log.d(TAG, "onLogonFinished: " + s); //Check if it finished successfully if (b) { try { //For debugging purposes will log the app connection id and // the end point url. // In a productive app, remember to remove these logs String appConnID = LogonCore.getInstance().getLogonContext().getConnId(); Log.d(TAG, "onLogonFinished: appcid:" + appConnID); Log.d(TAG, "onLogonFinished: endpointurl:" + logonContext.getEndPointUrl()); } catch (LogonManager.LogonManagerException e) { Log.e(TAG, e.getLocalizedMessage(), e); } catch (LogonCoreException e) { Log.e(TAG, e.getLocalizedMessage(), e); } // Navigate to the Main menu screen Intent goToNextActivity = new Intent(this, MainActivity.class); startActivity(goToNextActivity); finish(); } } @Override public void onSecureStorePasswordChanged(boolean b, String s) { } @Override public void onBackendPasswordChanged(boolean b) { } @Override public void onUserDeleted() { } @Override public void onApplicationSettingsUpdated() { } @Override public void registrationInfo() { } @Override public void objectFromSecureStoreForKey() { } @Override public void onRefreshCertificate(boolean b, String s) { } }
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.