1 4 package com.openedit.archive.authenticate; 5 6 import java.net.InetAddress ; 7 8 import jcifs.UniAddress; 9 import jcifs.smb.NtlmPasswordAuthentication; 10 import jcifs.smb.SmbSession; 11 12 import org.apache.commons.logging.Log; 13 import org.apache.commons.logging.LogFactory; 14 15 import com.openedit.OpenEditException; 16 17 public class WindowsAuthentication 18 { 19 private static final Log log = LogFactory.getLog(WindowsAuthentication.class); 20 21 public boolean login(String inName, String inPassword, String inDomain ) throws OpenEditException 22 { 23 return login( inName, inPassword, inDomain, null); 24 } 25 public boolean login(String inName, String inPassword, String inDomainOrBlank, String inServer) throws OpenEditException 26 { 27 28 if( inDomainOrBlank == null) 30 { 31 inDomainOrBlank = ""; 32 } 33 NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(inDomainOrBlank, inName, inPassword); 34 35 try 36 { 37 InetAddress ip = null; 38 if( inServer == null) 39 { 40 String address = InetAddress.getLocalHost().getHostAddress(); ip = InetAddress.getByName(address); 42 } 43 else 44 { 45 ip = InetAddress.getByName(inServer); } 47 UniAddress controller = new UniAddress(ip); 48 SmbSession.logon(controller, auth); 49 return true; 50 } 51 catch ( Exception ex ) 52 { 53 log.error(ex); 54 return false; 55 } 56 110 } 111 } 112 | Popular Tags |