AGOL Java App Login Example (Quartz Beta 2)

1584
4
Jump to solution
08-11-2016 12:40 PM
thomasbales
Occasional Contributor

How do you set an application to login and get secure content from AGOL? There seems to be some documentation and a new Credential class in the beta, but I am not sure how to do this.

Tags (4)
0 Kudos
1 Solution

Accepted Solutions
nita14
by
Occasional Contributor III

Hi Thomas,

here you are:

 Portal portal = new Portal("http://www.arcgis.com");
            UserCredential credentials = new UserCredential("LogiCaseSensitive", "PasswordCaseSensitive");
            portal.setCredential(credentials);
            portal.loadAsync();
            
            portal.addDoneLoadingListener(new Runnable() {
                @Override
                public void run() {
                    if (portal.getLoadStatus() == LoadStatus.LOADED) {
                        
                        ListenableFuture<PortalUserContent> content = portal.getPortalUser().fetchContentAsync();
                        content.addDoneListener(new Runnable() {
                            @Override
                            public void run() {
                                try {
                                    PortalUserContent myContent = content.get();
                                    for (PortalItem item : myContent.getItems()) {
                                        System.out.println("item title " + item.getTitle());


                                    }
                                } catch (InterruptedException | ExecutionException ex) {
                                    Logger.getLogger(QuartzBeta2.class.getName()).log(Level.SEVERE, null, ex);
                                }


                            }


                        });
                        
                    }


                }
            });

More details on: Access portal content—ArcGIS Runtime SDK for Java (Quartz Beta) | ArcGIS for Developers

Regards,

Adam

View solution in original post

0 Kudos
4 Replies
nita14
by
Occasional Contributor III

Hi Thomas,

here you are:

 Portal portal = new Portal("http://www.arcgis.com");
            UserCredential credentials = new UserCredential("LogiCaseSensitive", "PasswordCaseSensitive");
            portal.setCredential(credentials);
            portal.loadAsync();
            
            portal.addDoneLoadingListener(new Runnable() {
                @Override
                public void run() {
                    if (portal.getLoadStatus() == LoadStatus.LOADED) {
                        
                        ListenableFuture<PortalUserContent> content = portal.getPortalUser().fetchContentAsync();
                        content.addDoneListener(new Runnable() {
                            @Override
                            public void run() {
                                try {
                                    PortalUserContent myContent = content.get();
                                    for (PortalItem item : myContent.getItems()) {
                                        System.out.println("item title " + item.getTitle());


                                    }
                                } catch (InterruptedException | ExecutionException ex) {
                                    Logger.getLogger(QuartzBeta2.class.getName()).log(Level.SEVERE, null, ex);
                                }


                            }


                        });
                        
                    }


                }
            });

More details on: Access portal content—ArcGIS Runtime SDK for Java (Quartz Beta) | ArcGIS for Developers

Regards,

Adam

0 Kudos
thomasbales
Occasional Contributor

I am sorry I was not clear. I am interested in getting content that is assigned to a specific group in my organizational account and therefore I have two options. These are  OAuth 2.0 authentication and app login. The only reference I can find is at Use OAuth 2.0 authentication—ArcGIS Runtime SDK for Java | ArcGIS for Developers ​. But, looking at the Quartz java API reference I can only find a class called Credentials for portal. In it, there is a setCredential from json string something like the code below. I am wondering if this is the way to use the client id and client secret for an app to login to AGOL to get secured content. If it is, I need to know how to format the json string so I can automatically get content. If this is not the way to do it I need some guidance. 

I want to create an offline/online app but the content that get delivered to the application has to be secure and from AGOL. Any help is appreciated.

final Portal portal = new Portal("http://www.arcgis.com", true);

portal.setCredential(Credential.fromJson("")); /

Thanks,

Tom

0 Kudos
thomasbales
Occasional Contributor

Sorry, just checked my email.

Thank you so much.

0 Kudos
thomasbales
Occasional Contributor

Thank you

0 Kudos