|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
Web Service authentication problem |
« View previous topic :: View next topic » |
Author |
Message
|
vsr |
Posted: Thu Dec 14, 2006 8:51 am Post subject: Web Service authentication problem |
|
|
Centurion
Joined: 04 Apr 2006 Posts: 104
|
Hi all,
My Broker ( MB V5 ) is on Linux and I am trying to call a web service running on a different server. But I am getting authentication problem while trying to access the web service (http : 401 error )
I am getting response from the service from my windows system using my userid through xml-spy.
So how can i solve this problem? |
|
Back to top |
|
 |
mvarghese |
Posted: Sun Dec 17, 2006 8:33 pm Post subject: |
|
|
Centurion
Joined: 27 Sep 2006 Posts: 141
|
First thing u need to do is,wheather in normal way u have acces to other machine webservice<i meant system level all necessary permission is given> or its a problem while accesing from MB only. _________________ Jain Varghese |
|
Back to top |
|
 |
vsr |
Posted: Sun Dec 17, 2006 10:09 pm Post subject: |
|
|
Centurion
Joined: 04 Apr 2006 Posts: 104
|
Thanks for the reply varghese !
I could send the soap request to the webservice through xml-spy using my server( where web service is running ) id and password and i am getting the response too. As soon as i send soap request ,one window populates requesting for id and password.
This web service is implementing basic authorization only not SOAP security .. It needs only my id and password to verify the user. I am not sure but the id and password should be somewhere in the http request header in the broker soap message ..
Can we pass id and password some how to the web service in the esql ? Is there really a place holder for the id & password ? I am trying to find out .. if any one can help me in this , that would be great !! |
|
Back to top |
|
 |
jefflowrey |
Posted: Mon Dec 18, 2006 4:47 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
For basic Authentication, you need to add an Authentication: header to the HTTP Request.
It needs to contain the user name and password constructed as defined here: http://www.w3.org/Protocols/HTTP/1.0/draft-ietf-http-spec.html#BasicAA
The base64 encoding part is the tricky bit, but if you search here for base64, you will eventually find a post that mentions a method on the JavaCompute class that will do encoding and decoding. You can call these routines by defining an ESQL external procedure that points to the class.
It's relatively straight forward, if you have called Java procedures from ESQL before. Otherwise you should read about it a bit first before trying. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
vsr |
Posted: Tue Dec 19, 2006 5:37 am Post subject: |
|
|
Centurion
Joined: 04 Apr 2006 Posts: 104
|
Thank you Jeff, I got the base64 encoding java code and I will update the status once I have done. If it doesn't work then I will go for custome node option ... and I will update that too.. Thanks !! |
|
Back to top |
|
 |
rkford11 |
Posted: Wed Dec 20, 2006 12:50 pm Post subject: |
|
|
Partisan
Joined: 06 Jun 2004 Posts: 316
|
vsr wrote: |
Thank you Jeff, I got the base64 encoding java code and I will update the status once I have done. If it doesn't work then I will go for custome node option ... and I will update that too.. Thanks !! |
VSR,
i have a similar requirement where i need to authenticate(basic) to access the web service.
my design
http i/p --- compute --- httprequest --- httpreply
and in compute node i set the authorization property
SET OutputRoot.HTTPRequestHeader."Authorization" = 'Basic skfkfrkjkrtjk';
can you please help me in this issue.
Thanks |
|
Back to top |
|
 |
jefflowrey |
Posted: Wed Dec 20, 2006 1:32 pm Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
Please read this thread again.
It's pretty clear on how to do this. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
vsr |
Posted: Thu Dec 21, 2006 6:07 am Post subject: |
|
|
Centurion
Joined: 04 Apr 2006 Posts: 104
|
Hi RKFORD11,
Please refer this link , i got good information in this link ...
http://www.mqseries.net/phpBB2/viewtopic.php?t=32277
We need to send this authentication in the http request header like this .
Quote: |
SET OutputRoot.HTTPRequestHeader."Authorization" = 'Basic '||base64Encode(user||':'||password); |
base64Encoder is a Procedure which converts the string value to 64bit. I am pasting the code also, but I am still working on it ... so I can't say if it is correct or not . Once I get the result , I will post again ..This java class has both encoding and decoding methods ..
Thanks !!
Code: |
public class Base64Util
{
public Base64Util()
{
}
public static final String decode(String encoded)
{
return decode(encoded.getBytes());
}
public static final String encode(String plainText)
{
return encode(plainText.getBytes());
}
public static final String decode(byte encoded[])
{
byte plain[] = new byte[(int)((double)encoded.length * 0.75D) + 2];
int ppos = 0;
int epos = 0;
boolean cutShort = false;
for(; epos < encoded.length; epos++)
{
byte code = sixBits(encoded[epos]);
byte ptext = (byte)(code << 2);
epos++;
try
{
code = sixBits(encoded[epos]);
}
catch(Exception e)
{
code = 0;
cutShort = true;
}
ptext |= (code & 0xfffffff0) >>> 4;
plain[ppos++] = ptext;
if(cutShort)
break;
ptext = (byte)((code & 0xf) << 4);
epos++;
try
{
code = sixBits(encoded[epos]);
}
catch(Exception e)
{
code = 0;
}
ptext |= (code & -4) >>> 2;
plain[ppos++] = ptext;
if(cutShort)
break;
ptext = (byte)((code & 3) << 6);
epos++;
try
{
code = sixBits(encoded[epos]);
}
catch(Exception e)
{
code = 0;
}
ptext |= code;
plain[ppos++] = ptext;
}
return new String(plain);
}
public static final String encode(byte plain[])
{
StringBuffer encoded = new StringBuffer((int)((double)plain.length * 1.3400000000000001D) + 1);
int ppos = 0;
int epos = 0;
boolean cutShort = false;
for(; ppos < plain.length; ppos++)
{
byte ptext = plain[ppos];
byte sixbits = (byte)((ptext & -4) >>> 2);
encoded.append(base64(sixbits));
sixbits = (byte)((ptext & 3) << 4);
ppos++;
try
{
ptext = plain[ppos];
}
catch(ArrayIndexOutOfBoundsException e)
{
ptext = 0;
cutShort = true;
}
sixbits |= (byte)((ptext & 0xfffffff0) >>> 4);
encoded.append(base64(sixbits));
if(cutShort)
{
encoded.append("==");
return encoded.toString();
}
sixbits = (byte)((ptext & 0xf) << 2);
ppos++;
try
{
ptext = plain[ppos];
}
catch(ArrayIndexOutOfBoundsException e)
{
ptext = 0;
cutShort = true;
}
sixbits |= (byte)((ptext & 0xffffffc0) >>> 6);
encoded.append(base64(sixbits));
if(cutShort)
{
encoded.append("=");
return encoded.toString();
}
sixbits = (byte)(ptext & 0x3f);
encoded.append(base64(sixbits));
}
return encoded.toString();
}
private static byte sixBits(byte base64)
throws NumberFormatException
{
if(base64 >= 65 && base64 <= 90)
return (byte)(base64 - 65);
if(base64 >= 97 && base64 <= 122)
return (byte)((base64 - 97) + 26);
if(base64 >= 48 && base64 <= 57)
return (byte)((base64 - 48) + 52);
if(base64 == 43)
return 62;
if(base64 == 47)
return 63;
if(base64 == 61)
return 0;
else
throw new NumberFormatException("Not a base64 character: " + base64);
}
private static char base64(byte sixBits)
{
if(sixBits <= 25)
return (char)(65 + sixBits);
if(sixBits <= 51)
return (char)((97 + sixBits) - 26);
if(sixBits <= 61)
return (char)((48 + sixBits) - 52);
if(sixBits == 62)
return '+';
if(sixBits == 63)
return '/';
else
throw new NumberFormatException("Not a base64 digit: " + sixBits);
}
private static final byte UPPER_FOUR = -16;
private static final byte LOWER_FOUR = 15;
private static final byte UPPER_SIX = -4;
private static final byte LOWER_TWO = 3;
private static final byte UPPER_TWO = -64;
private static final byte LOWER_SIX = 63;
} |
|
|
Back to top |
|
 |
nvenkatesh |
Posted: Tue Jun 26, 2007 11:07 pm Post subject: ESQL version Base64 Encoding |
|
|
Apprentice
Joined: 29 Jan 2007 Posts: 45
|
All,
Below is the ESQL version of the Base64 Encoding algorithm,
Code: |
CREATE FUNCTION Base64Encode(IN credential CHARACTER) RETURNS CHARACTER
BEGIN
DECLARE Base64 ROW;
SET Base64.BASE64TABLE[] = LIST{'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','0','1','2','3','4','5','6','7','8','9','+','/'};
DECLARE B64credential CHARACTER '';
DECLARE i INTEGER 1;
DECLARE len INTEGER;
DECLARE credentialbit BIT;
DECLARE PAD BIT B'0';
DECLARE credentialbittrunc BIT;
DECLARE bit6int INTEGER;
DECLARE padlen INTEGER;
SET credentialbit = CAST(credential AS BIT CCSID 1208);
SET padlen = 6 - MOD(LENGTH(credentialbit),6);
IF padlen = 6 THEN
SET padlen = 0;
END IF;
DECLARE bit24mod INTEGER MOD(LENGTH(credentialbit),24);
WHILE i<padlen DO
SET PAD = PAD || B'0';
SET i = i + 1;
END WHILE;
SET credentialbit = credentialbit || PAD;
SET len = LENGTH(credentialbit);
SET i = 1;
WHILE(i<len) DO
SET credentialbittrunc = OVERLAY(B'0000000000000000000000000000000000000000000000000000000000000000' PLACING SUBSTRING(credentialbit FROM i FOR 6) FROM 59 FOR 6);
SET bit6int = CAST(credentialbittrunc AS INTEGER);
SET B64credential = B64credential || Base64.BASE64TABLE[bit6int+1];
SET i = i + 6;
END WHILE;
IF bit24mod = 8 THEN
SET B64credential = B64credential || '==';
ELSEIF bit24mod = 16 THEN
SET B64credential = B64credential || '=';
END IF;
RETURN B64credential;
END; |
just need to confirm, by performance wise which is better whether calling a java function or ESQL procedure? |
|
Back to top |
|
 |
marcin.kasinski |
Posted: Tue Jun 26, 2007 11:20 pm Post subject: Re: ESQL version Base64 Encoding |
|
|
Sentinel
Joined: 21 Dec 2004 Posts: 850 Location: Poland / Warsaw
|
Hi,
Broker has Base64 class.
Why you don't you want to use it ?
Code: |
CREATE PROCEDURE b64Encode(IN source BLOB)
RETURNS CHARACTER
LANGUAGE JAVA
EXTERNAL NAME "com.ibm.broker.javacompute.Base64.encode"; |
_________________ Marcin |
|
Back to top |
|
 |
nvenkatesh |
Posted: Wed Jun 27, 2007 12:38 am Post subject: |
|
|
Apprentice
Joined: 29 Jan 2007 Posts: 45
|
Marcin,
Yes, The broker has a seperate class. but the Java function executes in a seperate JVM process of the broker.
My assumption is that the Java function calls from broker are costlier in terms of performance as compared to the ESQL procedures which runs natively inside the broker. |
|
Back to top |
|
 |
jefflowrey |
Posted: Wed Jun 27, 2007 3:15 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
nvenkatesh wrote: |
Marcin,
Yes, The broker has a seperate class. but the Java function executes in a seperate JVM process of the broker.
My assumption is that the Java function calls from broker are costlier in terms of performance as compared to the ESQL procedures which runs natively inside the broker. |
No, it's not a "separate JVM". The DataFlowEngine process contains both the ESQL execution engine and the JVM.
IBM has done as much as possible to make the performance of Java to be equivalent of the performance of ESQL.
And it's more likely that any hand-built ESQL version of base64 encoding/decoding will perform worse than the one that comes with the product - that is presumably a standard java implementation. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
nvenkatesh |
Posted: Wed Jun 27, 2007 4:14 am Post subject: |
|
|
Apprentice
Joined: 29 Jan 2007 Posts: 45
|
Thanks jefflowrey,
That's the clarification I need.
In any case, I thought ESQL would perform better than Java.
So are you telling that we should avoid ESQL as much as possible and use the Java Compute node or external Java procedures
instead of the normal compute node for complex tasks (as the performance of Java is nearly equivalent to the performance of ESQL as you said)?
Last edited by nvenkatesh on Wed Jun 27, 2007 4:18 am; edited 1 time in total |
|
Back to top |
|
 |
jefflowrey |
Posted: Wed Jun 27, 2007 4:18 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
No.
I'm saying that one should use EXISTING code where it's reasonable to do so, rather than writing NEW code. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
marcin.kasinski |
Posted: Wed Jun 27, 2007 4:26 am Post subject: |
|
|
Sentinel
Joined: 21 Dec 2004 Posts: 850 Location: Poland / Warsaw
|
I will put it this way:
If there is funcionality implemented in broker (ESQL or JAVA) just use it and don't try to write it by your own.
Of course there are exceptions. _________________ Marcin |
|
Back to top |
|
 |
|
|
 |
Goto page 1, 2 Next |
Page 1 of 2 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|