Skip to content

Commit 3796c0d

Browse files
committed
Switched to using DefaultAuthenticationManager
1 parent abae469 commit 3796c0d

File tree

2 files changed

+11
-83
lines changed

2 files changed

+11
-83
lines changed

src/main/java/com/esri/samples/tiledlayers/export_vector_tiles/AuthenticationDialog.java

Lines changed: 0 additions & 65 deletions
This file was deleted.

src/main/java/com/esri/samples/tiledlayers/export_vector_tiles/ExportVectorTilesSample.java

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@
4848
import com.esri.arcgisruntime.mapping.view.MapView;
4949
import com.esri.arcgisruntime.portal.Portal;
5050
import com.esri.arcgisruntime.portal.PortalItem;
51-
import com.esri.arcgisruntime.security.Credential;
51+
import com.esri.arcgisruntime.security.AuthenticationManager;
52+
import com.esri.arcgisruntime.security.DefaultAuthenticationChallengeHandler;
5253
import com.esri.arcgisruntime.symbology.SimpleLineSymbol;
5354
import com.esri.arcgisruntime.tasks.vectortilecache.ExportVectorTilesJob;
5455
import com.esri.arcgisruntime.tasks.vectortilecache.ExportVectorTilesParameters;
@@ -78,31 +79,23 @@ public void start(Stage stage) throws Exception {
7879
mapView = new MapView();
7980

8081
// authenticate with an organization account on arcgis.com
81-
AuthenticationDialog authenticationDialog = new AuthenticationDialog();
82-
authenticationDialog.setOnCloseRequest(r -> {
83-
84-
Credential credential = authenticationDialog.getResult();
85-
// check that configuration was made
86-
if (credential != null) {
87-
88-
Portal portal = new Portal("http://www.arcgis.com", true);
89-
portal.setCredential(credential);
90-
91-
PortalItem portalItem = new PortalItem(portal, "86f556a2d1fd468181855a35e344567f");
82+
AuthenticationManager.setAuthenticationChallengeHandler(new DefaultAuthenticationChallengeHandler());
9283

84+
// get the portal item of the vector tile service
85+
Portal portal = new Portal("http://www.arcgis.com", true);
86+
PortalItem portalItem = new PortalItem(portal, "86f556a2d1fd468181855a35e344567f");
87+
portalItem.addDoneLoadingListener(() -> {
88+
if (portalItem.getLoadStatus() == LoadStatus.LOADED) {
9389
// loading the vector tiled layer will invoke the authentication challenge
9490
ArcGISVectorTiledLayer vectorTiledLayer = new ArcGISVectorTiledLayer(portalItem);
95-
vectorTiledLayer.loadAsync();
96-
97-
// set the layer as the map's basemap
9891
ArcGISMap map = new ArcGISMap(new Basemap(vectorTiledLayer));
9992
mapView.setMap(map);
10093
} else {
101-
Alert alert = new Alert(Alert.AlertType.ERROR, "Item requires authentication.");
94+
Alert alert = new Alert(Alert.AlertType.ERROR, portalItem.getLoadError().getCause().getMessage());
10295
alert.show();
10396
}
10497
});
105-
authenticationDialog.show();
98+
portalItem.loadAsync();
10699

107100
// create a graphics overlay for the map view
108101
GraphicsOverlay graphicsOverlay = new GraphicsOverlay();
@@ -166,7 +159,7 @@ public void start(Stage stage) throws Exception {
166159
ItemResourceCache resourceCache = tilesResult.getItemResourceCache();
167160
Alert preview = new Alert(Alert.AlertType.INFORMATION);
168161
preview.setTitle("Preview");
169-
preview.setHeaderText("Exported tiles to " + tileCache.getPath() + "\n Exported resources to " +
162+
preview.setHeaderText("Exported tiles to " + tileCache.getPath() + "\nExported resources to " +
170163
resourceCache.getPath());
171164
MapView mapPreview = new MapView();
172165
mapPreview.setMinSize(400, 400);

0 commit comments

Comments
 (0)