Skip to content

Token authentication #347

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 35 commits into from
May 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
06205fd
add sample class file and README.md
Apr 26, 2019
7a2a502
README.md: instructions - change 'tap' to 'click'
Apr 26, 2019
9427b73
add scene, basemap, stack pane and elevation
Apr 26, 2019
c51e529
add camera and set camera view
Apr 26, 2019
ad7bd29
capture mouse click and translate to surfacePoint
Apr 26, 2019
bfae92c
clear existing graphics and create new graphcs on LMB click
Apr 26, 2019
430546f
add vbox for label, set font size, add screenshot
Apr 26, 2019
9ea5c97
fix indentation
Apr 29, 2019
5ecb44e
typo
Apr 29, 2019
01927ef
add isStillSincePress condition to event capture
Apr 29, 2019
970f8f5
elevationFuture: display Alert instead of printStackTrace
Apr 29, 2019
019cc9c
Alert to show exception cause and message
Apr 30, 2019
d09ce4d
add text symbol with elevation to clicked screen point
Apr 30, 2019
998c7cf
setSurfacePlacement to Relative, create symbol on surface and text at…
Apr 30, 2019
62d477b
define points for polyline, raise marker text above polyline
JonLavi May 1, 2019
d14b584
Tidy imports and comments
JonLavi May 1, 2019
4dd9e97
Display marker line for elevation measurement
JonLavi May 1, 2019
709cab2
Update Screenshot
JonLavi May 1, 2019
4239528
set TextSymbol alignment to bottom
JonLavi May 2, 2019
e5853d6
fix indentation
JonLavi May 2, 2019
a489a86
bring updating of marker text back into start method
JonLavi May 2, 2019
986f84c
round elevation to nearest metre
JonLavi May 2, 2019
41ef987
code formatting, convert README to HTML
JonLavi May 2, 2019
a800bfc
create graphics for marker/text at start and reuse
JonLavi May 2, 2019
9432212
reorder imports
JonLavi May 2, 2019
4eb5f74
change indentation to 2 spaces
JonLavi May 7, 2019
8f1bf7b
Update README.md - remove html IDs and img alt
JonLavi May 7, 2019
25ab786
tags, 'tapped screen point' -> 'selected screen point'
JonLavi May 9, 2019
8900be5
isStillSincePress guard directly after click
JonLavi May 9, 2019
aa6798b
comments
JonLavi May 9, 2019
8340f9f
add sample class
JonLavi May 9, 2019
6367c14
comments, readme, screenshot
JonLavi May 10, 2019
77f6e97
readme to hmtl format
JonLavi May 10, 2019
f5ab84c
delete files not in this sample
JonLavi May 10, 2019
2b56b45
readme edits and code formatting
JonLavi May 13, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<h1>Token authentication</h1>

<p>Access a map service that is secured with an ArcGIS token-based authentication.</p>

<p><img src="TokenAuthentication.png"/></p>

<h2>Use case</h2>

<p>Applications often require accessing data from private map services on remote servers. A token authentication system can be used to allow app users who hold a valid username and password to access the remote service. </p>

<h2>How to use the sample</h2>

<p>When starting the sample, the user is challenged for an ArcGIS Online login to view the protected map service. Enter a username and password for an ArcGIS Online named user account (such as your ArcGIS for Developers account). Upon successful authentication, the protected map service will display in the map.</p>

<h2>How it works</h2>

<ol>
<li>Create an <code>AuthenticationChallengeHandler</code> using the <code>DefaultAuthenticationChallengeHandler</code> to handle the challenges sent by the protected map service.</li>
<li>Set the <code>AuthenticationChallengeHandler</code> used by the <code>AuthenticationManager</code>.</li>
<li>Create a <code>Portal</code> to ArcGIS Online.</li>
<li>Create a <code>PortalItem</code> for the protected web map using the <code>Portal</code> and Item ID of the protected map service as parameters</li>
<li>Create an <code>ArcGISMap</code> from the portal item, and display it in a <code>MapView</code></li>
<li>Set the map to display in the map view.</li>
</ol>

<h2>Relevant API</h2>

<ul>
<li>AuthenticationChallengeHandler</li>
<li>AuthenticationManager</li>
<li>DefaultAuthenticationChallengeHandler</li>
<li>Map</li>
<li>MapView</li>
<li>Portal</li>
<li>PortalItem</li>
</ul>

<h2>Tags</h2>

<p>authentication, map service, security, token</p>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/*
* Copyright 2019 Esri
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.esri.samples.portal.token_authentication;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

import com.esri.arcgisruntime.mapping.ArcGISMap;
import com.esri.arcgisruntime.mapping.view.MapView;
import com.esri.arcgisruntime.portal.Portal;
import com.esri.arcgisruntime.portal.PortalItem;
import com.esri.arcgisruntime.security.AuthenticationChallengeHandler;
import com.esri.arcgisruntime.security.AuthenticationManager;
import com.esri.arcgisruntime.security.DefaultAuthenticationChallengeHandler;

public class TokenAuthenticationSample extends Application {

private MapView mapView;

@Override
public void start(Stage stage) {

try {
// create stack pane and application scene
StackPane stackPane = new StackPane();
Scene scene = new Scene(stackPane);

// set title, size, and add scene to stage
stage.setTitle("Token Authentication Sample");
stage.setWidth(800);
stage.setHeight(700);
stage.setScene(scene);
stage.show();

// set up an authentication handler to take credentials for access to the protected map service
AuthenticationChallengeHandler authenticationChallengeHandler = new DefaultAuthenticationChallengeHandler();
AuthenticationManager.setAuthenticationChallengeHandler(authenticationChallengeHandler);

// create a portal to ArcGIS Online
Portal portal = new Portal("https://www.arcgis.com/");

// create a portal item using the portal and the item id of a protected map service
PortalItem portalItem = new PortalItem(portal, "e5039444ef3c48b8a8fdc9227f9be7c1");

// create a map with the portal item
ArcGISMap map = new ArcGISMap(portalItem);

// set the map to be displayed in the map view
mapView = new MapView();
mapView.setMap(map);

// add the map view to stack pane
stackPane.getChildren().add(mapView);

} catch (Exception e) {
// on any error, display the stack trace.
e.printStackTrace();
}
}

/**
* Stops and releases all resources used in application.
*/
@Override
public void stop() {

if (mapView != null) {
mapView.dispose();
}
}

/**
* Opens and runs application.
*
* @param args arguments passed to this application
*/
public static void main(String[] args) {

Application.launch(args);
}
}