Get Resource Details in Azure Subscription using Java Rest API - java

I have a Java Application running on Tomcat. I want to get the details of all machines installed in Microsoft Azure portal by taking user's subscription details as input. Preferably a REST API. I am expecting response same like what we get in azure resource explorer.
I made a request with this url "https://management.core.windows.net/"+subscriptionId+"/services/disks" following this method. It gives me result like this
<Disks xmlns="http://schemas.microsoft.com/windowsazure" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Disk>
<AttachedTo>
<DeploymentName>TEST1</DeploymentName>
<HostedServiceName>TEST1</HostedServiceName>
<RoleName>TEST1</RoleName>
</AttachedTo><OS>Linux</OS>
<Location>South Central US</Location>
<LogicalDiskSizeInGB>30</LogicalDiskSizeInGB>
<MediaLink>link.vhd</MediaLink>
<Name>TEST1-TEST1-0-20</Name>
<SourceImageName>imageName</SourceImageName>
When I call the same method with
"https://management.azure.com/subscriptions/"+subscriptionid+"/providers/Microsoft.Compute/virtualMachines?api-version=2016-03-30" I am getting 401 error.
I even tried downloading the SDK , ListVirtualMachines.java is listing some 600 images, not the one under my subscription.
How Can I achieve it using JAVA REST API?

Per my experience, this issue is due to the authentication method. I do all the requests that you have made and I get the same results with you.
The 401 error code means "Unauthorized". Your authentication method is right for the old REST API request, but not for new.
The new authentication is handled by Azure Active Directory(AD).
The followings may be useful for you.
You could figure out Virtual Machines Rest API by this URL https://msdn.microsoft.com/en-us/library/mt163647.aspx.
You could understand how to authenticate Azure Resource Manager Request by Azure Active Directory by this URL https://msdn.microsoft.com/en-us/library/dn790557.aspx.
Hope it helps. Any concerns, please feel free to let me know.

Related

Developing UCWA applications for Skype for Business Online

I'm trying to develop a simple java client that needs to access Skype for Business APIs in order to setup an online meeting (i.e. I need to retrieve a simple setup meeting URL by invoking an UCWA API).
I followed this Microsoft tutorial step-by-step:
https://learn.microsoft.com/en-us/skype-sdk/ucwa/developingucwaapplicationsforsfbonline
I have an Office 365 Business Premium license and I configured a custom domain (correctly registered and added at the zone DNS file);
I configured and registered my java client app on Azure (taking care to assign required delegated permission for Skype for Business capabilities);
I performed the Sign-in phase and Azure is able to recognize me;
I performed the Autodiscovery phase in order to retrieve the user's UCWA home pool;
I sent a GET request to the Azure oauth2 endpoint with response 401 error (and this is the expected behaviour by the authentication handshake);
Unfortunately, I failed when I request an access token using implicit grant flow: Azure responds with a Sign-In HTML page rather than the json object containing the oauth2 access token.
What's wrong on this GET request?
GET https://login.microsoftonline.com/oauth2/authorize?
response_type=id_token
&client_id=my_application_client_id
&redirect_uri=configured_redirect_uri
&state=UUID_generated_code
&resource=UCWA_home_pool
HTTP/1.1
This GET URL looks like that one used for the Sign-In phase (step 3); I suspect that it isn't the right request URL.
I tryed to put my domain on the URL:
https://login.microsoftonline.com/my_domain_name/oauth2/authorize
and I tryed to put a common domain name (as reported on the documentation):
https://login.microsoftonline.com/common/oauth2/authorize
But Azure still reponds with a Sign-In page (and response code 200 OK).
Can someone help me please?
Please check the oauth2AllowImplicitFlow property in manifest of your application after downloading the latest manifest file. It should be set to true for this to wrok. If it's still false, only then I would expect the redirect to sign-in page as you're seeing.
More detailed steps here -
Configure your app for OAuth implicit grant flow

Oauth Jira authentication client issue when requesting token using OAuthTutorialClient-1.0.jar

I'm trying to authenticate my java application against the JIRA REST API using OAuth (1.0a as OAuth 2.0 is not supported).
For this purpose, I'm trying to complete first of all the guide provided by atlassian at:
https://developer.atlassian.com/server/jira/platform/oauth/
However, I can´t move on from Step 2. Do the “OAuth dance”.
When executing java -jar OAuthTutorialClient-1.0.jar requestToken I'm getting the following error output:
com.google.api.client.http.HttpResponseException: 400
oauth_parameters_absent=oauth_consumer_key&oauth_problem=parameter_absent
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1070)
at com.google.api.client.auth.oauth.AbstractOAuthGetToken.execute(Abstrac
at com.atlassian.oauth.client.example.JiraOAuthClient.getAndAuthorizeTemp
at com.atlassian.oauth.client.example.OAuthClient.handleGetRequestTokenAc
at com.atlassian.oauth.client.example.OAuthClient.execute(OAuthClient.jav
at com.atlassian.oauth.client.example.ClientMain.main(ClientMain.java:18)
It seems to me there is an issue with my private/public key despite I have followed every previous step showed in the guide. Moreover the error message doesn't provide any more details besides the above.
My config.properties file looks like this:
#Mon Mar 26 19:41:28 CEST 2018
jira_home=https://jira.myserver.com
consumer_key=OauthKey
private_key=MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBANRno34rGDJ48PkMdVKH/48g2Gvjn4ACSmppXXtUZ59Mk6PO2OB/iF5Z3XS5yO9Dsyj1UzVR0TtWCUAHMYlSRNCvEhsG7g31snKh+bn6TbVYpzvDgKV7V64juWZkadC3tQcljwMBVSRTV5TBDLuyvqyl0NKqbyBdhtnJCqpK1rUPAgMBAAECgYBLs/yDdVyUcKKCQTx3g91D6BL6sRAiEa7wKkmVMUoVbreYRJrruMijyCez+JtzG4/5Yyaa9GQ8X7fASFARf27iw3qeHtcZyQjcCHzEg6vNd9jMOcr4aGh5dnNK0qVoEvVuIf38yw2Kdrhch++Xy4T/8qwFiuaaOabqhg73ZUiDYQJBAPR9OkremW4pySs2wMhxwigW0JOKnZUgGRjK1UHKqvqJjrherEo1MP0btZ1cQdvUyCa0Q8TCgZ9eR/DFy+pNQrkCQQDeZ7SulproyM8mqIb9B33sWN+YqIVJZN6jjOaZy+ZHBzQLHmv3TU7C0KB3v/9+WXKa/mT0Zxm1noSBx49PX/IHAkEA8GpYMRlVrPOgI0NzLWhX8U4GCp/LN8JZi3yhWlHt8fHkiz5lk49cvfhKjhQTmxVRQGYRIeHWzx1KBuSqEZup2QJBAKULHKA7DzYUXvV3NsVq292ajkOBO3gdrMJ9+1rCX17yT4K4zrI04m/b1llHV9hxlITEqDJemEuZGQgeCZGDx90CQQDL504bCmx3aXeNLQheVkzmJdyjaRfxrgycVSNgRPMeqR7fK2+taaOp9cDfYPTiu+y4RSFdigCJBd3PaT41DL5H
Anyway, My ultimate goal is to authenticate my java application against the JIRA REST API using OAuth, hence I need to know how to get the access token.
Could you please help on this?
I didn't get the guide example working, no answer from atlassian neither.
However I could get my goal of getting my java application connected to jira via rest client thanks to the following resources:
https://github.com/lisanlai/jira.oauth.client
(in order to generate the access token)
https://community.atlassian.com/t5/Questions/Access-to-JIRA-ressource-using-com-atlassian-jira-jira-rest-java/qaq-p/705465
(in order to set up oauth in the jira rest client)
OAuth authentication in jira by using Java
(same as before, just from other point of view)
Just in case it helps to anyone.

Using java to upload a file to a Sharepoint Online repository authenticated by ADFS SSO?

I need to upload a file to a sharepoint online repository (Office 365). I need to do this in java and the sharepoint online site uses ADFS for single sign-on.
So far, all of the examples, sample-code, etc I've works for most of those requirements, but fails at one critical part (e.g.: java file upload with sso for a local sharepoint 2013 site, or java file upload to sharepoint online, but without the ADFS part). Authentication against ADFS seems to be one of the big sticking points.
Does anyone have an example of this working that meets all of those requirements?
edit-to-add: and, naturally, I've got no budget to do things like buy a commercial library that might do this quick-and-easy. :\
The below are the steps you need to execute.
Since you are trying to upload from JAVA, the only option SharePoint gives is REST API - I guess you are clear on this part.
O365 identifies you(Java call) only if you send the auth token(SAML token) along with the Request body of your REST API call
So you have to get the SAML token first and pass it with your REST Api call
Check out these links which explain the authentication process to O365 with ADFS.
Other thread in Stackoverflow
Claim auth from ADFS
A blog post about getting auth in a windows 8 app. https://blogs.msdn.microsoft.com/omarv/2012/11/15/developing-windows-8-store-apps-for-sharepoint-online-with-sso-single-sign-on/
Only thing you have to do is, replace the C# parts with equivalent Java API calls.

Get details of all resources in my Azure Subscription using JAVA API

I am looking for something similar to this but using JAVA rest API calls.
I want to get the list of all the resources (including virtual machines, storage disks, network devices etc) and their basic properties(like ip address, disk space etc)
I have tried making API calls following this link.
When I make an http request to this url
"https://management.azure.com/subscriptions/"+subscriptionId+"/resourceGroups/"+resourceGroupName+"/providers/Microsoft.Compute/virtualMachines?api-version="+apiVersion
But I am getting a 401 error. Am I calling the right URL ? if not which URL I should be calling ?
But I am getting a 401 error. Am I calling the right URL ? if not
which URL I should be calling ?
You're calling the right URL however you're providing incorrect parameters to the API call. The link you mentioned is for making Azure Service Management API calls however what you need to dod is make Azure Resource Manager (ARM) API calls.
Like Azure Service Management API, ARM API requests need to be authenticated. In case of former, the requests are authenticated by using a management certificate. In case of latter, you would need to use a token that you get by authenticating the user against an Azure AD.
Please see this link for more details on authenticating/authorizing ARM API requests: https://azure.microsoft.com/en-us/documentation/articles/resource-manager-api-authentication/.
In order to list all resources in a resource group, you can definitely make use of ARM REST API. However now SDKs are available for you that you can consume directly. To learn more about these SDKs, please see this link: https://azure.microsoft.com/en-in/blog/azure-resource-manager-preview-sdks/.

Blackboard Java Web Services error, using AXIS2 through SOAP - Security Header

I need to use Blackboard Web Services and I don't know how to establish a connection throught SOAP. I need something like Security Header. I read a lot, but always when I try to connect I get this kind of error.
I have a little big problem with this exception. Nothing is clear for me. I have nothing at the application log. I cannnot guess what should be the problem. I read also about AXIS2, Timestamps...
2016-03-08 20:53:58,739 ERROR edu.ku.it.si.registerproxytool.controller.RegisterToolController.registerProxyToolWithBlackboard:84 - There was an error in registering the tool: WSDoAllReceiver: Incoming message does not contain required Security header
Process finished with exit code 0
I'm looking to connect with a Blackboard web service through SOAP, and I can not send a correct Security Header
I read a lot about it, and finally I found this article. I'm using the project this guy post in the pdf. I have a Blackboard instance working at localhost on port 9876. I can do everything I want with it. It works fully.
I also tried to use SOAPui and I'm reaching a different error:
WSDoAllReceiver: security processing failed (actions mismatch)
I don't want to read more, I read more than 150 articles about it, and nothing.
Thanks :)
I have just started playing around with Blackboard web services, at the moment I am just accessing using SOAPui.
I am able to connect and send various functions, along the way I experienced the same error via SOAPui as you and so I found your question.
I overcame this error by doing the following:
Create a session using ContextWS.initialize, the username should be 'session' and the password 'nosession'. If successful this should return a token string.
Login using ContextWS.login. The username in the header should be 'session' and the password should be the token returned in 1. The userid and password in the body should be those of a user with sufficient web services permissions. If successful this should return 'true'.
Call whichever WS functions you wish. Always send the 'session' and token username and password in the header.
I found this here:
https://community.blackboard.com/docs/DOC-1116
I also found https://community.blackboard.com/thread/2147 and the linked youtube video useful to understand how to send the data correctly using SOAPui - you may need to change the wsdl url to https as SOAPui reverts it to a standard http. You also need to add a timestamp for every call.

Categories

Resources