merlin45
发贴: 137
积分: 20
|
于 2002-12-25 23:18
使用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年前一个程序最初的做法,大家看一下什么地方可以改进
|