NTLM authentication failing - java

I'm trying to get NTLM authentication working in some Java code, but getting 401'd.
This page makes me think the following code (source for NTLMEngineImpl is from Apache HTTPClient and modified slightly here):
System.out.println(new NTLMEngineImpl().generateType3Msg("Zaphod", "Beeblebrox", "Ursa-Minor", "LightCity", "TlRMTVNTUAACAAAAAAAAACgAAAABggAAU3J2Tm9uY2UAAAAAAAAAAA=="));
Should output:
TlRMTVNTUAADAAAAGAAYAHIAAAAYABgAigAAABQAFABAAAAADAAMAFQAAAASABIAYAAAAAAAAACiAAAAAYIAAFUAUgBTAEEALQBNAEkATgBPAFIAWgBhAHAAaABvAGQATABJAEcASABUAEMASQBUAFkArYfKbe/jRoW5xDxHeoxC1gBmfWiS5+iX4OAN4xBKG/IFPwfH3agtPEia6YnhsADT
Instead I get:
TlRMTVNTUAADAAAAGAAYAEgAAAAYABgAYAAAABQAFAB4AAAADAAMAIwAAAASABIAmAAAAAAAAACqAAAAAYIAAgUBKAoAAAAPrYfKbe/jRoW5xDxHeoxC1gBmfWiS5+iX4OAN4xBKG/IFPwfH3agtPEia6YnhsADTVQBSAFMAQQAtAE0ASQBOAE8AUgBaAGEAcABoAG8AZABMAGkAZwBoAHQAQwBpAHQAeQA=
Which looks close - I think the expected string is almost, but not quite, a substring of the actual string. So where does the extra data come from and how can I fix it?

Related

Jmeter : Issue with HTTP request returns java.net.URISyntaxException

I am using an RSS feed generated by our test application to verify if there are any broken links on our website.
When I use these URLs in the HTTP sampler after some pre-processing (to split the URL to extract protocol, host, domain), most of the URL's are working just fine but I am facing issues in some random cases as explained below.
for example: below mentioned URLs throw URI exception. The separator between the highlighted text in these URLs mentioned below does not seem to a normal hyphen. It's some special character which I guess needs special handling.
Failed URL from the feed
https://abc.xyz.com/article/worksheet-development-planning—manager-preparation-10200/download/
https://abc.xyz.com/article/worksheet-development-planning—worker-preparation-10201/download/
JMeter Result from Assertion Listener
See link below for JMeter Result from Assertion Listener
URL gets encoded with some unexpected characters
You're right, this — symbol needs to be URL-encoded, to wit your URL path should look like
article%252Fworksheet-development-planning%25E2%2580%2594manager-preparation-10200%252Fdownload%252F
JMeter provides __urlencode() function which can perform URL-encoding of the passed parameter on the fly so you can use it directly in the "Path" field of the HTTP Request sampler like:
${__urlencode(/article/worksheet-development-planning—manager-preparation-10200/download/)}
Check out Apache JMeter Functions - An Introduction article to learn more about JMeter Functions concept.

Open an authenticated image served by django from java using Apache http client

I Am serving an authenticated image using django. The image is behind a view which require login, and in the end I have to check more things than just the authentication.
Because of a reason to complicated to explain here, I cannot use the real url to the image, but I Am serving it with a custom url leading to the authenticated view.
From java the image must be reachable, to save or display. For this part I use Apache httpclient.
In Apacahe I tried a lot of things (every example and combination of examples...) but can't seem to get it working.
For other parts of the webapp I use django-rest-framwork, which I succesfully connected to from java (and c and curl).
I use the login_reuired decorator in django, which makes the attempt to get to the url redirect to a login page first.
Trying the link and the login in a webviewer, I see the 200 code (OK) in the server console.
Trying the link with the httpclient, I get a 302 Found in the console.... (looking up 302, it means a redirect..)
this is what I do in django:
in urls.py:
url(r'^photolink/(?P<filename>.*)$', 'myapp.views.photolink',name='photolink'),
in views.py:
import mimetypes
import os
#login_required
def photolink(request, filename):
# from the filename I get the image object, for this question not interesting
# there is a good reason for this complicated way to reach a photo, but not the point here
filename_photo = some_image_object.url
base_filename=os.path.basename(filename_photo)
# than this is the real path and filename to the photo:
path_filename=os.path.join(settings.MEDIA_ROOT,'photos',mac,base_filename)
mime = mimetypes.guess_type(filename_photot)[0]
logger.debug("mimetype response = %s" % mime)
image_data = open(path_filename, 'rb').read()
return HttpResponse(image_data, mimetype=mime)
by the way, if i get this working i need another decorator to pass some other tests....
but i first need to get this thing working....
for now it's not a secured url.... plain http.
in java i tried a lot of things... using apache's httpclient 4.2.1
proxy, cookies, authentication negociation, with follow redirects... and so on...
Am I overlooking some basic thing here?...
it seems the login of the website client is not suitable for automated login...
so the problem can be in my code in django....or in the java code....
In the end the problem was, using HTTP authorization.
Which is not by default used in the login_required decorator.
adding a custom decorator that checks for HTTP authorization did the trick:
see this example: http://djangosnippets.org/snippets/243/

How to send a unix path as part of a JSON object to a web service via GET

Sorry if this is a duplicate question but google isn't smart enough to understand me or I'm too dumb to express my question simple enough for it to understand.
I don't know if this is my problem but I'm 90% sure this is it.
I'd like to know how to represent a Unix path within a GET request so that my web service doesn't return a 404. I think it's because one of my JSON fields in the query is a Unix path and because of the slashes, the webservice thinks it's part of the URL and not a part of my query.
For example, I'm using a RESTClient that's an add-on to Mozilla to test my web service. For the POST request, I enter as the url
http://mytestserver:8080/mydir/
and in the body, I put in my JSON object
{"filename":"obit.jpg", "Path":"test/2/1"}
This method works fine. I get a status code 200 and a return JSON object with the expected output.
When I use the same string for a GET request, I get a status code 404 and no return JSON object. I put as the url in the RESTClient
http://mytestserver:8080/mydir/{"filename":"obit.jpg", "Path":"test/2/1"}
and I get a status code 404 and the response body just says 404 - Not found
To further test my theory, I entered the following url in a GET request, removing the /2/1 from the path, which works.
http://mytestserver:8080/mydir/{"filename":"obit.jpg", "Path":"test"}
I've tried encapsulating the whole JSON string in quotes but that didn't work either so I've run out of things to try.
Thanks in advance for any help you can give me. If I need to show some code, please let me know, although, I don't think it's a code problem, I think it's a representation problem. Thanks.
Found out that JSON objects are usually sent via POST, not GET. Since I appended it to the URL via GET, it gave me problems. Per How to send a GET request with a "/" in the query

Getting, (#803) Some of the aliases you requested do not exist error

When i am trying to get data from facebook using graph api, i am getting this error,
{"error":
{"message":"(#803) Some of the aliases you requested do not exist: 124186682456_10151302011177457&access_token=REMOVED_ACCESS_TOKEN",
"type":"OAuthException",
"code":803}}
Can anyone help me in how to solve this problem.
Thanks in advance...
If that is an accurate representation of the error you're receiving, you're incorrectly appending the access token after a & character instead of a ?.
You need to use ? for the start of the query string, and & to separate the parameters inside the query string
e.g.
https://graph.facebook.com/124186682456_10151302011177457?access_token=ACCESS_TOKEN
Placement of access_token parameter immediately after ? has nothing to do with issue...
It could be that your URL is littered with %20 or similar stuff.
I got this error when trying a test example from Facebook API documentation, at first I have read highest voted answer, but moving access_token parameter immediately after ? didn't work, I then inspected URL more closely and found some of encoded spaces %20 that were stuck to parameter fields and some others, removing which fixed the issue.
try following URL (just replace access_token parameter with yours)
https://graph.facebook.com/search?type=place&fields=name,checkins,picture&q=cafe&center=40.7304,-73.9921&distance=1000&access_token=[YOUR_ACCESS_TOKEN]
If it works look for problem in Facebook parameter names
Hope this saves you some time.
This was happening for me with the Instagram content publishing API which also rides off the facebook graph api. It seems to happen when something is wrong with the API URL you are trying to send to Facebook via GET request.
In my case, something was happening in my code causing the user_id and access_token to not be passed to the URL before trying to query the graph API.

Facebook returns #access_token

I am using Java Scribe + Spring MVC to access Facebook authentication API.
However, the URL with the access token I am getting back from Facebook is in this format:
/facebookCallback#access_token=[long chunk]&expires_in=5028
As you can see, the access_token is preceded by a #, which disallows me from obtaining the access_code as a normal parameter.
Is there any reason why Facebook is appending the # instead of a ?
var hash = document.location.hash;
I think you mean Javascript , and not Java Scribe ?
you are probably using the callback parameter which is designed for the JS library. Make sure you are not sending an incorrect parameter for "type".
Turns out that it probably was caused by my school network. I tried the exact same code both in school and at home and got different results (school - error, home - correct).
The problem solved by itself the next day in school so I won't be able to find out exactly why. Thanks to those who helped.

Categories