Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java EE 综合讨论区  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 如何在java中实现nt domain 的user 认证
merlin45





发贴: 137
积分: 20
于 2002-12-25 23:18 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
使用package jcifs.smb.*;
实现

private boolean authenticateUser(Request req, HttpServletResponse resp) {
HttpSession session = req.getSession(false);

//get the server ip and path from property file
String ServerPath = "";
try {
  ResourceBundle rb = ResourceBundle.getBundle("top");
  ServerPath = rb.getString("ServerPath");
} catch (Exception e) {
  return false;      
}

String uid = req.getParameter("username");
String pw = req.getParameter("password");
String dm = req.getParameter("domain");
StringBuffer authString = new StringBuffer("smb://");
authString.append(dm);
authString.append(';');
authString.append(uid);
authString.append(':');
authString.append(pw);
authString.append('@');
authString.append(ServerPath);//server's ip address + "/" + shared directory of server

// the codes below are the smb authenticate.
try {
  SmbFile sf = new SmbFile(authString.toString());
  sf.isDirectory();
} catch (Exception e) {
  String str = e.toString();
  if (str.indexOf("Access denied") != -1) {
    return false;
  }
}

Random rand = (Random)session.getValue("random");
if (rand == null) {
  rand = new Random();
  session.putValue("random", rand);
}
String sid = "" + rand.nextLong();
session.putValue("securityid", sid);
Cookie coo = new Cookie("securityid", sid);
resp.addCookie(coo);

String username = (String)session.getValue("logonid");
String domain = (String)session.getValue("logondomain");
if (username == null || !username.equals(uid)) {
  Cookie coo2 = new Cookie("logonid", uid);
  coo2.setMaxAge(10000000);
  resp.addCookie(coo2);
  session.putValue("logonid", uid);
}
if (domain == null || !domain.equals(dm)) {
  Cookie coo3 = new Cookie("logondomain", dm);
  coo3.setMaxAge(10000000);
  resp.addCookie(coo3);
  session.putValue("logondomain", dm);
}

mm.getUsrProfileBean();
return true;
}

这是我3年前一个程序最初的做法,大家看一下什么地方可以改进




话题树型展开
人气 标题 作者 字数 发贴时间
5697 如何在java中实现nt domain 的user 认证 merlin45 2460 2002-12-25 23:18

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923