<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Adding Secured Services to CredentialCache in ArcGIS Runtime SDK for Android Questions</title>
    <link>https://community.esri.com/t5/arcgis-runtime-sdk-for-android-questions/adding-secured-services-to-credentialcache/m-p/116262#M867</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Erick,&lt;/P&gt;&lt;P&gt;Yeah that makes sense.&amp;nbsp; What is happening is that OAuth (OAuthTokenCredential)&amp;nbsp; portal credentials do work and I can see those credentials in the Credential Cache automatically.&amp;nbsp; However secured service credentials (UserCredential) do not seem to get added automatically.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Below is the code we use...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;First we attempt to add the FeatureLayer which is derived from ServiceFeatureTable where the url to the secure service is passed in prior to the ServiceFeatureTable.&amp;nbsp; mAgencyCredential is a Credential variable.&amp;nbsp;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN style="color: #000080; font-weight: bold;"&gt;if &lt;/SPAN&gt;(&lt;SPAN style="color: #660e7a;"&gt;mAgencyCredentials &lt;/SPAN&gt;!= &lt;SPAN style="color: #000080; font-weight: bold;"&gt;null&lt;/SPAN&gt;) {  &lt;SPAN style="color: #808080;"&gt;//Check if credentials already available
&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;      &lt;/SPAN&gt;fsTable.setCredential(&lt;SPAN style="color: #660e7a;"&gt;mAgencyCredentials&lt;/SPAN&gt;);  &lt;SPAN style="color: #808080;"&gt;//on premise shared through AGOL&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;
&lt;/SPAN&gt;}
FeatureLayer fLayer = &lt;SPAN style="color: #000080; font-weight: bold;"&gt;new &lt;/SPAN&gt;FeatureLayer(fsTable);
&lt;SPAN style="color: #660e7a; font-weight: bold;"&gt;mMap&lt;/SPAN&gt;.getOperationalLayers().add(fLayer);&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When we do the ".add" command this will automatically trigger the class we built to check credentials.&amp;nbsp; If null or invalid&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN style="color: #000080; font-weight: bold;"&gt;public class &lt;/SPAN&gt;S1AuthenticationChallengeHandler &lt;SPAN style="color: #000080; font-weight: bold;"&gt;extends &lt;/SPAN&gt;DefaultAuthenticationChallengeHandler {
   &lt;SPAN style="color: #000080; font-weight: bold;"&gt;public &lt;/SPAN&gt;S1AuthenticationChallengeHandler(Activity context) {
      &lt;SPAN style="color: #000080; font-weight: bold;"&gt;super&lt;/SPAN&gt;(context);
   }

   &lt;SPAN style="color: #000080; font-weight: bold;"&gt;private &lt;/SPAN&gt;String &lt;SPAN style="color: #660e7a; font-weight: bold;"&gt;lastFSPassIn &lt;/SPAN&gt;= &lt;SPAN style="color: #008000; font-weight: bold;"&gt;""&lt;/SPAN&gt;;

   &lt;SPAN style="color: #000080; font-weight: bold;"&gt;public static &lt;/SPAN&gt;Boolean &lt;SPAN style="color: #660e7a;"&gt;backPressed &lt;/SPAN&gt;= &lt;SPAN style="color: #000080; font-weight: bold;"&gt;false&lt;/SPAN&gt;;  &lt;SPAN style="color: #808080;"&gt;//used to prevent login screen from showing up when user backs out of web map preview window.
&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;
&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;   &lt;/SPAN&gt;&lt;SPAN style="color: #808000;"&gt;@Override
&lt;/SPAN&gt;&lt;SPAN style="color: #808000;"&gt;   &lt;/SPAN&gt;&lt;SPAN style="color: #000080; font-weight: bold;"&gt;public &lt;/SPAN&gt;AuthenticationChallengeResponse handleChallenge(AuthenticationChallenge challenge) {
      &lt;SPAN style="color: #000080; font-weight: bold;"&gt;if &lt;/SPAN&gt;(challenge.getRemoteResource() &lt;SPAN style="color: #000080; font-weight: bold;"&gt;instanceof &lt;/SPAN&gt;Portal) {  &lt;SPAN style="color: #808080;"&gt;//instance of portal
&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;         // let DefaultAuthenticationChallengeHandler handle this challenge
&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;         &lt;/SPAN&gt;&lt;SPAN style="color: #000080; font-weight: bold;"&gt;return super&lt;/SPAN&gt;.handleChallenge(challenge);
      } &lt;SPAN style="color: #000080; font-weight: bold;"&gt;else &lt;/SPAN&gt;{  &lt;SPAN style="color: #808080;"&gt;//secured service
&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;         &lt;/SPAN&gt;&lt;SPAN style="color: #000080; font-weight: bold;"&gt;if &lt;/SPAN&gt;(!&lt;SPAN style="color: #660e7a;"&gt;backPressed&lt;/SPAN&gt;) {  &lt;SPAN style="color: #808080;"&gt;//back pressed on FeatureServiceLogin triggers one more handler event unfortunately by doing a countdown.  Do not want to trigger another countdownlatch so if backpressed do nothing&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;
&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;               &lt;/SPAN&gt;&lt;SPAN style="color: #000080; font-weight: bold;"&gt;int &lt;/SPAN&gt;maxAttempts = &lt;SPAN style="color: #0000ff;"&gt;5&lt;/SPAN&gt;;
               &lt;SPAN style="color: #000080; font-weight: bold;"&gt;if &lt;/SPAN&gt;(challenge.getFailureCount() &amp;gt; maxAttempts) {
                  &lt;SPAN style="color: #808080;"&gt;// exceeded maximum amount of attempts. Act like it was a cancel
&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;                  &lt;/SPAN&gt;Toast.&lt;SPAN&gt;makeText&lt;/SPAN&gt;(S1ViewerActivity.&lt;SPAN&gt;getS1ViewerActivity&lt;/SPAN&gt;(), &lt;SPAN style="color: #008000; font-weight: bold;"&gt;"Exceeded maximum amount of attempts. Please try again!"&lt;/SPAN&gt;, Toast.&lt;SPAN style="color: #660e7a; font-weight: bold;"&gt;LENGTH_LONG&lt;/SPAN&gt;).show();
                  &lt;SPAN style="color: #000080; font-weight: bold;"&gt;return new &lt;/SPAN&gt;AuthenticationChallengeResponse(AuthenticationChallengeResponse.Action.&lt;SPAN style="color: #660e7a; font-weight: bold;"&gt;CANCEL&lt;/SPAN&gt;, challenge);
               }

               String fsURL = challenge.getRemoteResource().getUri();

               &lt;SPAN style="color: #000080; font-weight: bold;"&gt;if &lt;/SPAN&gt;(!fsURL.endsWith(&lt;SPAN style="color: #008000; font-weight: bold;"&gt;"/FeatureServer"&lt;/SPAN&gt;)) {
                  &lt;SPAN style="color: #000080; font-weight: bold;"&gt;if &lt;/SPAN&gt;(fsURL.contains(&lt;SPAN style="color: #008000; font-weight: bold;"&gt;"/FeatureServer"&lt;/SPAN&gt;)) {
                     fsURL = fsURL.substring(&lt;SPAN style="color: #0000ff;"&gt;0&lt;/SPAN&gt;, fsURL.indexOf(&lt;SPAN style="color: #008000; font-weight: bold;"&gt;"/FeatureServer"&lt;/SPAN&gt;) + &lt;SPAN style="color: #0000ff;"&gt;14&lt;/SPAN&gt;);
                  }
               }

               &lt;SPAN style="color: #000080; font-weight: bold;"&gt;final &lt;/SPAN&gt;String fsURLPassIn = fsURL;
               &lt;SPAN style="color: #808080;"&gt;// create a countdown latch with a count of one to synchronize the dialog
&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;               &lt;/SPAN&gt;DownloadHelper.&lt;SPAN style="color: #660e7a;"&gt;signal &lt;/SPAN&gt;= &lt;SPAN style="color: #000080; font-weight: bold;"&gt;new &lt;/SPAN&gt;CountDownLatch(&lt;SPAN style="color: #0000ff;"&gt;1&lt;/SPAN&gt;);

               S1ViewerActivity.&lt;SPAN&gt;getS1ViewerActivity&lt;/SPAN&gt;().runOnUiThread(&lt;SPAN style="color: #000080; font-weight: bold;"&gt;new &lt;/SPAN&gt;Runnable() {
                  &lt;SPAN style="color: #808000;"&gt;@Override
&lt;/SPAN&gt;&lt;SPAN style="color: #808000;"&gt;                  &lt;/SPAN&gt;&lt;SPAN style="color: #000080; font-weight: bold;"&gt;public void &lt;/SPAN&gt;run() {
                     &lt;SPAN style="color: #000080; font-weight: bold;"&gt;try &lt;/SPAN&gt;{
                        &lt;SPAN style="color: #000080; font-weight: bold;"&gt;if &lt;/SPAN&gt;(DownloadHelper.&lt;SPAN style="color: #660e7a;"&gt;downloadSyncAction &lt;/SPAN&gt;!= &lt;SPAN style="color: #000080; font-weight: bold;"&gt;null&lt;/SPAN&gt;) {
                              &lt;SPAN style="color: #000080; font-weight: bold;"&gt;if &lt;/SPAN&gt;(MapExtentDownloadFS.&lt;SPAN&gt;getMapExtentDownloadFS&lt;/SPAN&gt;() != &lt;SPAN style="color: #000080; font-weight: bold;"&gt;null&lt;/SPAN&gt;) {
&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;showFSLogin(errorLabel, fsURLPassIn);  //this will prompt user to type in username and password&lt;/PRE&gt;}&lt;BR /&gt; }&lt;BR /&gt; } &lt;SPAN style="color: #000080; font-weight: bold;"&gt;catch &lt;/SPAN&gt;(Exception e) {&lt;BR /&gt; e.printStackTrace();&lt;BR /&gt; }&lt;BR /&gt; }&lt;BR /&gt; });&lt;BR /&gt;&lt;BR /&gt; &lt;SPAN style="color: #000080; font-weight: bold;"&gt;try &lt;/SPAN&gt;{&lt;BR /&gt; DownloadHelper.&lt;SPAN style="color: #660e7a;"&gt;signal&lt;/SPAN&gt;.await();&lt;BR /&gt; } &lt;SPAN style="color: #000080; font-weight: bold;"&gt;catch &lt;/SPAN&gt;(InterruptedException e) {&lt;BR /&gt; String error = &lt;SPAN style="color: #008000; font-weight: bold;"&gt;"Interruption handling AuthenticationChallengeResponse: " &lt;/SPAN&gt;+ e.getMessage();&lt;BR /&gt; &lt;SPAN style="color: #808080;"&gt;//Toast.makeText(this, error, Toast.LENGTH_LONG).show();&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt; &lt;/SPAN&gt;}&lt;BR /&gt; &lt;SPAN style="color: #808080;"&gt;// if credentials were set, return a new auth challenge response with them. otherwise, act like it was a cancel.&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #000080; font-weight: bold;"&gt;if &lt;/SPAN&gt;(&lt;SPAN style="color: #660e7a;"&gt;mAgencyCredentials &lt;/SPAN&gt;!= &lt;SPAN style="color: #000080; font-weight: bold;"&gt;null&lt;/SPAN&gt;) {&lt;BR /&gt; &lt;SPAN style="color: #000080; font-weight: bold;"&gt;return new &lt;/SPAN&gt;AuthenticationChallengeResponse(AuthenticationChallengeResponse.Action.&lt;SPAN style="color: #660e7a; font-weight: bold;"&gt;CONTINUE_WITH_CREDENTIAL&lt;/SPAN&gt;, &lt;SPAN style="color: #660e7a;"&gt;mAgencyCredentials&lt;/SPAN&gt;);&lt;BR /&gt; } &lt;SPAN style="color: #000080; font-weight: bold;"&gt;else &lt;/SPAN&gt;{&lt;BR /&gt; &lt;SPAN style="color: #660e7a; font-weight: bold;"&gt;lastFSPassIn &lt;/SPAN&gt;= &lt;SPAN style="color: #008000; font-weight: bold;"&gt;""&lt;/SPAN&gt;; &lt;SPAN style="color: #808080;"&gt;//In case of failure to login this needs to be set back to empty string in case user tries to login to webmap again.&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #000080; font-weight: bold;"&gt;return new &lt;/SPAN&gt;AuthenticationChallengeResponse(AuthenticationChallengeResponse.Action.&lt;SPAN style="color: #660e7a; font-weight: bold;"&gt;CANCEL&lt;/SPAN&gt;, challenge);&lt;BR /&gt; }&lt;BR /&gt; } &lt;SPAN style="color: #000080; font-weight: bold;"&gt;else &lt;/SPAN&gt;{&lt;BR /&gt; &lt;SPAN style="color: #000080; font-weight: bold;"&gt;return new &lt;/SPAN&gt;AuthenticationChallengeResponse(AuthenticationChallengeResponse.Action.&lt;SPAN style="color: #660e7a; font-weight: bold;"&gt;CANCEL&lt;/SPAN&gt;, challenge);&lt;BR /&gt; }&lt;BR /&gt; }&lt;BR /&gt; }&lt;BR /&gt;}&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The core line of code that runs (in showFSLogin) when login credentials required after typed in is as follows...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN style="color: #660e7a;"&gt;mAgencyCredentials &lt;/SPAN&gt;= &lt;SPAN style="color: #000080; font-weight: bold;"&gt;new &lt;/SPAN&gt;UserCredential(u&lt;SPAN style="color: #660e7a; font-weight: bold;"&gt;serName&lt;/SPAN&gt;, password);&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 06:51:07 GMT</pubDate>
    <dc:creator>Anonymous User</dc:creator>
    <dc:date>2021-12-11T06:51:07Z</dc:date>
    <item>
      <title>Adding Secured Services to CredentialCache</title>
      <link>https://community.esri.com/t5/arcgis-runtime-sdk-for-android-questions/adding-secured-services-to-credentialcache/m-p/116260#M865</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am wondering if there is a way to add Secured Services (non-federated but shared via AGOL) to the CredentialCache?&amp;nbsp; As far as I can tell this does not work.&amp;nbsp; It would be nice to be able to do this so that secured service credentials could be stored in the same way that credentials associated with portal/AGOL are.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The documentation seems to indicate that after credentials are used they are automatically added to the CredentialCache.&amp;nbsp; I see this happening with credentials associated with AGOL but am not seeing that happen with credentials use for secured services.&amp;nbsp; Can Secured (non-federated) Services be used with CredentialCache?&amp;nbsp; I am using the "extends DefaultAuthenticationChallengeHandler" to authenticate secured services.&lt;/P&gt;&lt;PRE style="color: #000000; background-color: #ffffff; font-size: 9.8pt;"&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Sep 2020 14:52:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-runtime-sdk-for-android-questions/adding-secured-services-to-credentialcache/m-p/116260#M865</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2020-09-25T14:52:13Z</dc:date>
    </item>
    <item>
      <title>Re: Adding Secured Services to CredentialCache</title>
      <link>https://community.esri.com/t5/arcgis-runtime-sdk-for-android-questions/adding-secured-services-to-credentialcache/m-p/116261#M866</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi &lt;A href="https://community.esri.com/migrated-users/345134"&gt;Aaron Dick&lt;/A&gt;‌,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;We currently don't have an API to directly add credentials into the Credential Cache.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The credentials should be added to the cache automatically once you have successfully signed to that secured service.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you share how some of the code you're using to authenticate with this service?&lt;/P&gt;&lt;P&gt;Are you using OAuth, Certificate Credential or IWA?&lt;/P&gt;&lt;P&gt;It also seems like you are using a Custom Challenge Handler. Is there anyway you could share your implementation?&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 06 Oct 2020 15:34:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-runtime-sdk-for-android-questions/adding-secured-services-to-credentialcache/m-p/116261#M866</guid>
      <dc:creator>Erick_1</dc:creator>
      <dc:date>2020-10-06T15:34:17Z</dc:date>
    </item>
    <item>
      <title>Re: Adding Secured Services to CredentialCache</title>
      <link>https://community.esri.com/t5/arcgis-runtime-sdk-for-android-questions/adding-secured-services-to-credentialcache/m-p/116262#M867</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Erick,&lt;/P&gt;&lt;P&gt;Yeah that makes sense.&amp;nbsp; What is happening is that OAuth (OAuthTokenCredential)&amp;nbsp; portal credentials do work and I can see those credentials in the Credential Cache automatically.&amp;nbsp; However secured service credentials (UserCredential) do not seem to get added automatically.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Below is the code we use...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;First we attempt to add the FeatureLayer which is derived from ServiceFeatureTable where the url to the secure service is passed in prior to the ServiceFeatureTable.&amp;nbsp; mAgencyCredential is a Credential variable.&amp;nbsp;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN style="color: #000080; font-weight: bold;"&gt;if &lt;/SPAN&gt;(&lt;SPAN style="color: #660e7a;"&gt;mAgencyCredentials &lt;/SPAN&gt;!= &lt;SPAN style="color: #000080; font-weight: bold;"&gt;null&lt;/SPAN&gt;) {  &lt;SPAN style="color: #808080;"&gt;//Check if credentials already available
&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;      &lt;/SPAN&gt;fsTable.setCredential(&lt;SPAN style="color: #660e7a;"&gt;mAgencyCredentials&lt;/SPAN&gt;);  &lt;SPAN style="color: #808080;"&gt;//on premise shared through AGOL&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;
&lt;/SPAN&gt;}
FeatureLayer fLayer = &lt;SPAN style="color: #000080; font-weight: bold;"&gt;new &lt;/SPAN&gt;FeatureLayer(fsTable);
&lt;SPAN style="color: #660e7a; font-weight: bold;"&gt;mMap&lt;/SPAN&gt;.getOperationalLayers().add(fLayer);&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When we do the ".add" command this will automatically trigger the class we built to check credentials.&amp;nbsp; If null or invalid&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN style="color: #000080; font-weight: bold;"&gt;public class &lt;/SPAN&gt;S1AuthenticationChallengeHandler &lt;SPAN style="color: #000080; font-weight: bold;"&gt;extends &lt;/SPAN&gt;DefaultAuthenticationChallengeHandler {
   &lt;SPAN style="color: #000080; font-weight: bold;"&gt;public &lt;/SPAN&gt;S1AuthenticationChallengeHandler(Activity context) {
      &lt;SPAN style="color: #000080; font-weight: bold;"&gt;super&lt;/SPAN&gt;(context);
   }

   &lt;SPAN style="color: #000080; font-weight: bold;"&gt;private &lt;/SPAN&gt;String &lt;SPAN style="color: #660e7a; font-weight: bold;"&gt;lastFSPassIn &lt;/SPAN&gt;= &lt;SPAN style="color: #008000; font-weight: bold;"&gt;""&lt;/SPAN&gt;;

   &lt;SPAN style="color: #000080; font-weight: bold;"&gt;public static &lt;/SPAN&gt;Boolean &lt;SPAN style="color: #660e7a;"&gt;backPressed &lt;/SPAN&gt;= &lt;SPAN style="color: #000080; font-weight: bold;"&gt;false&lt;/SPAN&gt;;  &lt;SPAN style="color: #808080;"&gt;//used to prevent login screen from showing up when user backs out of web map preview window.
&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;
&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;   &lt;/SPAN&gt;&lt;SPAN style="color: #808000;"&gt;@Override
&lt;/SPAN&gt;&lt;SPAN style="color: #808000;"&gt;   &lt;/SPAN&gt;&lt;SPAN style="color: #000080; font-weight: bold;"&gt;public &lt;/SPAN&gt;AuthenticationChallengeResponse handleChallenge(AuthenticationChallenge challenge) {
      &lt;SPAN style="color: #000080; font-weight: bold;"&gt;if &lt;/SPAN&gt;(challenge.getRemoteResource() &lt;SPAN style="color: #000080; font-weight: bold;"&gt;instanceof &lt;/SPAN&gt;Portal) {  &lt;SPAN style="color: #808080;"&gt;//instance of portal
&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;         // let DefaultAuthenticationChallengeHandler handle this challenge
&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;         &lt;/SPAN&gt;&lt;SPAN style="color: #000080; font-weight: bold;"&gt;return super&lt;/SPAN&gt;.handleChallenge(challenge);
      } &lt;SPAN style="color: #000080; font-weight: bold;"&gt;else &lt;/SPAN&gt;{  &lt;SPAN style="color: #808080;"&gt;//secured service
&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;         &lt;/SPAN&gt;&lt;SPAN style="color: #000080; font-weight: bold;"&gt;if &lt;/SPAN&gt;(!&lt;SPAN style="color: #660e7a;"&gt;backPressed&lt;/SPAN&gt;) {  &lt;SPAN style="color: #808080;"&gt;//back pressed on FeatureServiceLogin triggers one more handler event unfortunately by doing a countdown.  Do not want to trigger another countdownlatch so if backpressed do nothing&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;
&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;               &lt;/SPAN&gt;&lt;SPAN style="color: #000080; font-weight: bold;"&gt;int &lt;/SPAN&gt;maxAttempts = &lt;SPAN style="color: #0000ff;"&gt;5&lt;/SPAN&gt;;
               &lt;SPAN style="color: #000080; font-weight: bold;"&gt;if &lt;/SPAN&gt;(challenge.getFailureCount() &amp;gt; maxAttempts) {
                  &lt;SPAN style="color: #808080;"&gt;// exceeded maximum amount of attempts. Act like it was a cancel
&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;                  &lt;/SPAN&gt;Toast.&lt;SPAN&gt;makeText&lt;/SPAN&gt;(S1ViewerActivity.&lt;SPAN&gt;getS1ViewerActivity&lt;/SPAN&gt;(), &lt;SPAN style="color: #008000; font-weight: bold;"&gt;"Exceeded maximum amount of attempts. Please try again!"&lt;/SPAN&gt;, Toast.&lt;SPAN style="color: #660e7a; font-weight: bold;"&gt;LENGTH_LONG&lt;/SPAN&gt;).show();
                  &lt;SPAN style="color: #000080; font-weight: bold;"&gt;return new &lt;/SPAN&gt;AuthenticationChallengeResponse(AuthenticationChallengeResponse.Action.&lt;SPAN style="color: #660e7a; font-weight: bold;"&gt;CANCEL&lt;/SPAN&gt;, challenge);
               }

               String fsURL = challenge.getRemoteResource().getUri();

               &lt;SPAN style="color: #000080; font-weight: bold;"&gt;if &lt;/SPAN&gt;(!fsURL.endsWith(&lt;SPAN style="color: #008000; font-weight: bold;"&gt;"/FeatureServer"&lt;/SPAN&gt;)) {
                  &lt;SPAN style="color: #000080; font-weight: bold;"&gt;if &lt;/SPAN&gt;(fsURL.contains(&lt;SPAN style="color: #008000; font-weight: bold;"&gt;"/FeatureServer"&lt;/SPAN&gt;)) {
                     fsURL = fsURL.substring(&lt;SPAN style="color: #0000ff;"&gt;0&lt;/SPAN&gt;, fsURL.indexOf(&lt;SPAN style="color: #008000; font-weight: bold;"&gt;"/FeatureServer"&lt;/SPAN&gt;) + &lt;SPAN style="color: #0000ff;"&gt;14&lt;/SPAN&gt;);
                  }
               }

               &lt;SPAN style="color: #000080; font-weight: bold;"&gt;final &lt;/SPAN&gt;String fsURLPassIn = fsURL;
               &lt;SPAN style="color: #808080;"&gt;// create a countdown latch with a count of one to synchronize the dialog
&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt;               &lt;/SPAN&gt;DownloadHelper.&lt;SPAN style="color: #660e7a;"&gt;signal &lt;/SPAN&gt;= &lt;SPAN style="color: #000080; font-weight: bold;"&gt;new &lt;/SPAN&gt;CountDownLatch(&lt;SPAN style="color: #0000ff;"&gt;1&lt;/SPAN&gt;);

               S1ViewerActivity.&lt;SPAN&gt;getS1ViewerActivity&lt;/SPAN&gt;().runOnUiThread(&lt;SPAN style="color: #000080; font-weight: bold;"&gt;new &lt;/SPAN&gt;Runnable() {
                  &lt;SPAN style="color: #808000;"&gt;@Override
&lt;/SPAN&gt;&lt;SPAN style="color: #808000;"&gt;                  &lt;/SPAN&gt;&lt;SPAN style="color: #000080; font-weight: bold;"&gt;public void &lt;/SPAN&gt;run() {
                     &lt;SPAN style="color: #000080; font-weight: bold;"&gt;try &lt;/SPAN&gt;{
                        &lt;SPAN style="color: #000080; font-weight: bold;"&gt;if &lt;/SPAN&gt;(DownloadHelper.&lt;SPAN style="color: #660e7a;"&gt;downloadSyncAction &lt;/SPAN&gt;!= &lt;SPAN style="color: #000080; font-weight: bold;"&gt;null&lt;/SPAN&gt;) {
                              &lt;SPAN style="color: #000080; font-weight: bold;"&gt;if &lt;/SPAN&gt;(MapExtentDownloadFS.&lt;SPAN&gt;getMapExtentDownloadFS&lt;/SPAN&gt;() != &lt;SPAN style="color: #000080; font-weight: bold;"&gt;null&lt;/SPAN&gt;) {
&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;showFSLogin(errorLabel, fsURLPassIn);  //this will prompt user to type in username and password&lt;/PRE&gt;}&lt;BR /&gt; }&lt;BR /&gt; } &lt;SPAN style="color: #000080; font-weight: bold;"&gt;catch &lt;/SPAN&gt;(Exception e) {&lt;BR /&gt; e.printStackTrace();&lt;BR /&gt; }&lt;BR /&gt; }&lt;BR /&gt; });&lt;BR /&gt;&lt;BR /&gt; &lt;SPAN style="color: #000080; font-weight: bold;"&gt;try &lt;/SPAN&gt;{&lt;BR /&gt; DownloadHelper.&lt;SPAN style="color: #660e7a;"&gt;signal&lt;/SPAN&gt;.await();&lt;BR /&gt; } &lt;SPAN style="color: #000080; font-weight: bold;"&gt;catch &lt;/SPAN&gt;(InterruptedException e) {&lt;BR /&gt; String error = &lt;SPAN style="color: #008000; font-weight: bold;"&gt;"Interruption handling AuthenticationChallengeResponse: " &lt;/SPAN&gt;+ e.getMessage();&lt;BR /&gt; &lt;SPAN style="color: #808080;"&gt;//Toast.makeText(this, error, Toast.LENGTH_LONG).show();&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt; &lt;/SPAN&gt;}&lt;BR /&gt; &lt;SPAN style="color: #808080;"&gt;// if credentials were set, return a new auth challenge response with them. otherwise, act like it was a cancel.&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #000080; font-weight: bold;"&gt;if &lt;/SPAN&gt;(&lt;SPAN style="color: #660e7a;"&gt;mAgencyCredentials &lt;/SPAN&gt;!= &lt;SPAN style="color: #000080; font-weight: bold;"&gt;null&lt;/SPAN&gt;) {&lt;BR /&gt; &lt;SPAN style="color: #000080; font-weight: bold;"&gt;return new &lt;/SPAN&gt;AuthenticationChallengeResponse(AuthenticationChallengeResponse.Action.&lt;SPAN style="color: #660e7a; font-weight: bold;"&gt;CONTINUE_WITH_CREDENTIAL&lt;/SPAN&gt;, &lt;SPAN style="color: #660e7a;"&gt;mAgencyCredentials&lt;/SPAN&gt;);&lt;BR /&gt; } &lt;SPAN style="color: #000080; font-weight: bold;"&gt;else &lt;/SPAN&gt;{&lt;BR /&gt; &lt;SPAN style="color: #660e7a; font-weight: bold;"&gt;lastFSPassIn &lt;/SPAN&gt;= &lt;SPAN style="color: #008000; font-weight: bold;"&gt;""&lt;/SPAN&gt;; &lt;SPAN style="color: #808080;"&gt;//In case of failure to login this needs to be set back to empty string in case user tries to login to webmap again.&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #808080;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #000080; font-weight: bold;"&gt;return new &lt;/SPAN&gt;AuthenticationChallengeResponse(AuthenticationChallengeResponse.Action.&lt;SPAN style="color: #660e7a; font-weight: bold;"&gt;CANCEL&lt;/SPAN&gt;, challenge);&lt;BR /&gt; }&lt;BR /&gt; } &lt;SPAN style="color: #000080; font-weight: bold;"&gt;else &lt;/SPAN&gt;{&lt;BR /&gt; &lt;SPAN style="color: #000080; font-weight: bold;"&gt;return new &lt;/SPAN&gt;AuthenticationChallengeResponse(AuthenticationChallengeResponse.Action.&lt;SPAN style="color: #660e7a; font-weight: bold;"&gt;CANCEL&lt;/SPAN&gt;, challenge);&lt;BR /&gt; }&lt;BR /&gt; }&lt;BR /&gt; }&lt;BR /&gt;}&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The core line of code that runs (in showFSLogin) when login credentials required after typed in is as follows...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN style="color: #660e7a;"&gt;mAgencyCredentials &lt;/SPAN&gt;= &lt;SPAN style="color: #000080; font-weight: bold;"&gt;new &lt;/SPAN&gt;UserCredential(u&lt;SPAN style="color: #660e7a; font-weight: bold;"&gt;serName&lt;/SPAN&gt;, password);&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 06:51:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-runtime-sdk-for-android-questions/adding-secured-services-to-credentialcache/m-p/116262#M867</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-12-11T06:51:07Z</dc:date>
    </item>
    <item>
      <title>Re: Adding Secured Services to CredentialCache</title>
      <link>https://community.esri.com/t5/arcgis-runtime-sdk-for-android-questions/adding-secured-services-to-credentialcache/m-p/116263#M868</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Aaron,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Could you check if the feature layer fLayer was loaded or was displayed in a MapView before checking the credential cache?&amp;nbsp;Though mAgencyCredentials was set on the service feature table fsTable, if it was not used to load the table or layer successfully, it won't be added to the credential cache.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As a side note that&amp;nbsp;the DefaultAuthenticationChallengeHandler also handle secured services including non-federated services. If you are&amp;nbsp;already aware of it or you have special logic which requires a custom challenge handler, please ignore this side note.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Oct 2020 00:27:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-runtime-sdk-for-android-questions/adding-secured-services-to-credentialcache/m-p/116263#M868</guid>
      <dc:creator>XuemingWu</dc:creator>
      <dc:date>2020-10-09T00:27:30Z</dc:date>
    </item>
    <item>
      <title>Re: Adding Secured Services to CredentialCache</title>
      <link>https://community.esri.com/t5/arcgis-runtime-sdk-for-android-questions/adding-secured-services-to-credentialcache/m-p/1000760#M5365</link>
      <description>&lt;P&gt;Xueming,&lt;/P&gt;&lt;P&gt;Indeed that was the problem.&amp;nbsp; As soon as I added in a line to load fsTable all is good. Thanks again.&amp;nbsp; For those wondering what I am talking about it is just as simple as adding in...&lt;/P&gt;&lt;P&gt;fsTable.loadAsync();&lt;/P&gt;&lt;P&gt;and then all is good.&lt;/P&gt;&lt;P&gt;Thanks Xueming!&lt;/P&gt;</description>
      <pubDate>Thu, 12 Nov 2020 16:44:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-runtime-sdk-for-android-questions/adding-secured-services-to-credentialcache/m-p/1000760#M5365</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2020-11-12T16:44:57Z</dc:date>
    </item>
  </channel>
</rss>

