/** {@inheritDoc} */ @Override public Bundle addAccount( AccountAuthenticatorResponse response, String accountType, String authTokenType, String[] requiredFeatures, Bundle options) throws NetworkErrorException { Log_OC.i(TAG, "Adding account with type " + accountType + " and auth token " + authTokenType); final Bundle bundle = new Bundle(); AccountManager accountManager = AccountManager.get(mContext); Account[] accounts = accountManager.getAccountsByType(MainApp.getAccountType()); if (mContext.getResources().getBoolean(R.bool.multiaccount_support) || accounts.length < 1) { try { validateAccountType(accountType); } catch (AuthenticatorException e) { Log_OC.e(TAG, "Failed to validate account type " + accountType + ": " + e.getMessage()); e.printStackTrace(); return e.getFailureBundle(); } final Intent intent = new Intent(mContext, AuthenticatorActivity.class); intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response); intent.putExtra(KEY_AUTH_TOKEN_TYPE, authTokenType); intent.putExtra(KEY_REQUIRED_FEATURES, requiredFeatures); intent.putExtra(KEY_LOGIN_OPTIONS, options); intent.putExtra(AuthenticatorActivity.EXTRA_ACTION, AuthenticatorActivity.ACTION_CREATE); setIntentFlags(intent); bundle.putParcelable(AccountManager.KEY_INTENT, intent); } else { // Return an error bundle.putInt(AccountManager.KEY_ERROR_CODE, AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION); final String message = String.format( mContext.getString(R.string.auth_unsupported_multiaccount), mContext.getString(R.string.app_name)); bundle.putString(AccountManager.KEY_ERROR_MESSAGE, message); mHandler.post( new Runnable() { @Override public void run() { Toast.makeText(mContext, message, Toast.LENGTH_SHORT).show(); } }); } return bundle; }
/* (non-Javadoc) * @see org.wso2.carbon.identity.application.authentication.framework.AbstractApplicationAuthenticator#initiateAuthenticationRequest(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext) */ @Override protected void initiateAuthenticationRequest( HttpServletRequest request, HttpServletResponse response, AuthenticationContext context) throws AuthenticationFailedException { String loginPage = ConfigurationFacade.getInstance().getAuthenticationEndpointURL(); String queryParams = FrameworkUtils.getQueryStringWithFrameworkContextId( context.getQueryParams(), context.getCallerSessionKey(), context.getContextIdentifier()); try { String retryParam = ""; if (context.isRetrying()) { retryParam = "&authFailure=true&authFailureMsg=login.fail.message"; } else { // Insert entry to DB only if this is not a retry DBUtils.insertUserResponse( context.getContextIdentifier(), String.valueOf(MSSAuthenticator.UserResponse.PENDING)); } // MSISDN will be saved in the context in the MSISDNAuthenticator String msisdn = (String) context.getProperty("msisdn"); MSSRequest mssRequest = new MSSRequest(); mssRequest.setMsisdnNo("+" + msisdn); mssRequest.setSendString( DataHolder.getInstance().getMobileConnectConfig().getMSS().getMssText()); String contextIdentifier = context.getContextIdentifier(); MSSRestClient mssRestClient = new MSSRestClient(contextIdentifier, mssRequest); mssRestClient.start(); response.sendRedirect( response.encodeRedirectURL(loginPage + ("?" + queryParams)) + "&authenticators=" + getName() + ":" + "LOCAL" + retryParam); } catch (IOException e) { throw new AuthenticationFailedException(e.getMessage(), e); } catch (AuthenticatorException e) { throw new AuthenticationFailedException(e.getMessage(), e); } }
/* (non-Javadoc) * @see org.wso2.carbon.identity.application.authentication.framework.AbstractApplicationAuthenticator#processAuthenticationResponse(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, org.wso2.carbon.identity.application.authentication.framework.context.AuthenticationContext) */ @Override protected void processAuthenticationResponse( HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationContext context) throws AuthenticationFailedException { // String msisdn = httpServletRequest.getParameter("msisdn"); log.info("MSS PIN Authenticator authentication Start "); String sessionDataKey = httpServletRequest.getParameter("sessionDataKey"); String msisdn = (String) context.getProperty("msisdn"); boolean isAuthenticated = false; try { String responseStatus = DBUtils.getUserResponse(sessionDataKey); if (responseStatus.equalsIgnoreCase(UserResponse.APPROVED.toString())) { isAuthenticated = true; } } catch (AuthenticatorException e) { log.error("SMS Authentication failed while trying to authenticate", e); throw new AuthenticationFailedException(e.getMessage(), e); } if (!isAuthenticated) { log.info("MSS PIN Authenticator authentication failed "); context.setProperty("faileduser", msisdn); if (log.isDebugEnabled()) { log.debug("User authentication failed due to not existing user MSISDN."); } throw new AuthenticationFailedException("Authentication Failed"); } log.info("MSS PIN Authenticator authentication success for MSISDN - " + msisdn); context.setProperty("msisdn", msisdn); // context.setSubject(msisdn); // AuthenticatedUser user=new AuthenticatedUser(); // context.setSubject(user); AuthenticationContextHelper.setSubject(context, msisdn); String rememberMe = httpServletRequest.getParameter("chkRemember"); if (rememberMe != null && "on".equals(rememberMe)) { context.setRememberMe(true); } }
/** {@inheritDoc} */ @Override public Bundle getAuthToken( AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle options) throws NetworkErrorException { /// validate parameters try { validateAccountType(account.type); validateAuthTokenType(authTokenType); } catch (AuthenticatorException e) { Log_OC.e(TAG, "Failed to validate account type " + account.type + ": " + e.getMessage()); e.printStackTrace(); return e.getFailureBundle(); } /// check if required token is stored final AccountManager am = AccountManager.get(mContext); String accessToken; if (authTokenType.equals(AccountTypeUtils.getAuthTokenTypePass(MainApp.getAccountType()))) { accessToken = am.getPassword(account); } else { accessToken = am.peekAuthToken(account, authTokenType); } if (accessToken != null) { final Bundle result = new Bundle(); result.putString(AccountManager.KEY_ACCOUNT_NAME, account.name); result.putString(AccountManager.KEY_ACCOUNT_TYPE, MainApp.getAccountType()); result.putString(AccountManager.KEY_AUTHTOKEN, accessToken); return result; } /// if not stored, return Intent to access the AuthenticatorActivity and UPDATE the token for // the account final Intent intent = new Intent(mContext, AuthenticatorActivity.class); intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response); intent.putExtra(KEY_AUTH_TOKEN_TYPE, authTokenType); intent.putExtra(KEY_LOGIN_OPTIONS, options); intent.putExtra(AuthenticatorActivity.EXTRA_ACCOUNT, account); intent.putExtra(AuthenticatorActivity.EXTRA_ENFORCED_UPDATE, true); intent.putExtra(AuthenticatorActivity.EXTRA_ACTION, AuthenticatorActivity.ACTION_UPDATE_TOKEN); final Bundle bundle = new Bundle(); bundle.putParcelable(AccountManager.KEY_INTENT, intent); return bundle; }
/** {@inheritDoc} */ @Override public Bundle confirmCredentials( AccountAuthenticatorResponse response, Account account, Bundle options) throws NetworkErrorException { try { validateAccountType(account.type); } catch (AuthenticatorException e) { Log_OC.e(TAG, "Failed to validate account type " + account.type + ": " + e.getMessage()); e.printStackTrace(); return e.getFailureBundle(); } Intent intent = new Intent(mContext, AuthenticatorActivity.class); intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response); intent.putExtra(KEY_ACCOUNT, account); intent.putExtra(KEY_LOGIN_OPTIONS, options); setIntentFlags(intent); Bundle resultBundle = new Bundle(); resultBundle.putParcelable(AccountManager.KEY_INTENT, intent); return resultBundle; }