|
Problem with NTLM ,data not posting to the server
Hi all,
we are making use of NTLM authentication techninuqe.
we are making use fo JSF with ADF custom components technology.
IT is throws an Exception when we click on any action button
its throws Exception : java.io.EOFException.....
public CheckAuthorisation()
{
try
{
String auth = request.getHeader("Authorization");
if (auth == null)
{
response.setStatus(response.SC_UNAUTHORIZED);
response.setHeader("WWW-Authenticate", "NTLM");
return;
}
if (auth.startsWith("NTLM "))
{
// System.out.println("Auth"+auth);
byte[] msg = new sun.misc.BASE64Decoder().decodeBuffer(auth.substri ng(5));
int off = 0, length, offset;
String s;
if (msg[8] == 1)
{
off = 18;
byte z = 0;
byte[] msg1 = {(byte)'N', (byte)'T', (byte)'L', (byte)'M', (byte)'S',
(byte)'S', (byte)'P', z,
(byte)2, z, z, z, z, z, z, z,
(byte)40, z, z, z, (byte)1, (byte)130, z, z,
z, (byte)2, (byte)2, (byte)2, z, z, z, z, //
z, z, z, z, z, z, z, z};
//
response.setStatus(response.SC_UNAUTHORIZED);
response.setHeader("WWW-Authenticate", "NTLM "
+ new sun.misc.BASE64Encoder().encodeBuffer(msg1).trim() );
response.setStatus(response.SC_UNAUTHORIZED);
return;
}
else if (msg[8] == 3)
{
off = 30;
length = msg[off+17]*256 + msg[off+16];
// System.out.println("length::" + length);
offset = msg[off+19]*256 + msg[off+18];
// System.out.println("offset::" + offset);
s = new String(msg, offset, length);
//out.println(s + " ");
// System.out.println("s::"+s);
}
else
return;
length = msg[off+1]*256 + msg[off];
// System.out.println("Second length::" + length);
offset = msg[off+3]*256 + msg[off+2];
// System.out.println("Second offset::" + offset);
s = new String(msg, offset, length);
//out.println(s + " ");
// System.out.println("Second S::" + s);
Pattern pat = Pattern.compile("[a-z,A-Z,0-9,@,.]+");
Matcher mat = pat.matcher(s);
String s1 = "";
while(mat.find())
s1 = s1+mat.group();
// System.out.println("Got Domain: "+s1);
// out.println(s1);
length = msg[off+9]*256 + msg[off+8];
offset = msg[off+11]*256 + msg[off+10];
s = new String(msg, offset, length);
// System.out.println("Third S::" + s);
pat = Pattern.compile("[a-z,A-Z,0-9,@,.]+");
mat = pat.matcher(s);
s1 = "";
while(mat.find())
s1 = s1+mat.group();
// System.out.println("Got name: "+s1);
if(s.indexOf('.')!=-1)
{
// System.out.println("dots!!!");
}
s.replaceAll("[.]","");
StringBuffer userName=new StringBuffer();
for(char c:s.toCharArray())
{
if((int)c!=0)userName.append(c);
}
out.println("Logged User Name is "+userName);
com.tristar.servicedesk.view.handler.ADSHandler adsHandler=new com.tristar.servicedesk.view.handler.ADSHandler();
out.println("Role is "+adsHandler.IdentifyRolesFromADS(userName.toStrin g()));
String userRole=adsHandler.IdentifyRolesFromADS(userName. toString());
// System.out.println("userRole::"+userRole);
// System.out.println("userName::"+userName);
session.setAttribute("loggedUserName",userName);
session.setAttribute("loggedUserRole",userRole);
// System.out.println("user name from session::"+session.getAttribute("loggedUserName")) ;
//response.setStatus(HttpServletResponse.SC_UNAUTHOR IZED);
System.out.println("Request info "+request.getHeaderNames());
if(session.getAttribute("status")==null)
{
session.setAttribute("status","value");
if(userRole!=null)
response.sendRedirect("faces/app/searchRequest.jsp");
else
// response.sendRedirect("faces/app/searchRequest.jsp");
response.sendRedirect("faces/unauthorisation.jsp");
}
}
}
catch (Exception e)
{
session.setAttribute("loggedUserName",null);
session.setAttribute("loggedUserRole",null);
System.out.println("Exception due to "+e);
e.printStackTrace();
}
}
This is my above code.
its working for everything.
problem only when file uploading comes into discussion.
thanks in advance,
ravi.
|