Приведенный ниже код получает имя пользователя из системы, используя метод аутентификации Windows NTLM, мне нужно сравнить имя пользователя (current_user_eid).
Применение метода intern () для предустановленного значения, похоже, работает для инициализированных значений.
Сравнение строк между литеральной строкой и строкой объекта дает мне вывод false, но на экране они дают одинаковый вывод.
<%@ page import="sun.misc.BASE64Encoder" %>
<%
String auth = request.getHeader("Authorization");
String current_user_eid= null;
if (auth == null) {
response.setStatus(response.SC_UNAUTHORIZED);
response.setHeader("WWW-Authenticate", "NTLM");
return;
}
if (auth.startsWith("NTLM")) {
byte[] msg = new sun.misc.BASE64Decoder().decodeBuffer(auth.substring(5));
int off = 0, length, offset;
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());
return;
}
else if (msg[8] == 3) {
off = 30;
length = msg[off+17]*256 + msg[off+16];
offset = msg[off+19]*256 + msg[off+18];
current_user_eid = new String(msg, offset, length);
}
else
return;
length = msg[off+1]*256 + msg[off];
offset = msg[off+3]*256 + msg[off+2];
current_user_eid = new String(msg, offset, length);
length = msg[off+9]*256 + msg[off+8];
offset = msg[off+11]*256 + msg[off+10];
current_user_eid = new String(msg, offset, length); //current system user name "yaseer"
// String Comparison starts here....
String hard_str = new String("yaseer"); //
String hard_str_in=hard_str.intern();
String eid_str=new String(current_user_eid.toString()); //passing the fetched username which is yaseer
String eid_str_in = eid_str.intern(); // system username
String comp_str = "yaseer"; // String for comparison
System.out.println(hard_str_in == comp_str); // give true
System.out.println(eid_str_in == comp_str); // gives false
if(eid_str_in .equals(comp_str ))
{
System.out.println("true");
}
else
{
System.out.println("false");
}
}
%>
Может кто-нибудь помочь мне справиться с этим?