1 package org.manentia.kasai.services; 2 3 import com.koala.commons.log.Log; 4 import java.net.UnknownHostException ; 5 import java.util.*; 6 import jcifs.UniAddress; 7 import jcifs.smb.NtlmPasswordAuthentication; 8 import jcifs.smb.SmbException; 9 import jcifs.smb.SmbSession; 10 import org.apache.commons.lang.exception.ExceptionUtils; 11 import org.manentia.kasai.exceptions.InvalidPasswordException; 12 import org.manentia.kasai.exceptions.ServiceException; 13 import org.manentia.kasai.util.Constants; 14 17 18 19 20 21 25 public class Win32AuthService implements AuthService { 26 public int checkPassword(String userName, String password) throws ServiceException { 27 28 int result = AUTH_BAD_USERNAME; 29 30 ResourceBundle res = ResourceBundle.getBundle( 31 Constants.PROPERTY_FILE); 32 try { 33 NtlmPasswordAuthentication npa = new NtlmPasswordAuthentication(res.getString("kasai.win32.domain"), userName, password); 34 SmbSession.logon(UniAddress.getByName(res.getString("kasai.win32.domainController")), npa); 35 result = AUTH_OK; 36 } 37 catch (UnknownHostException uhe){ 38 Log.getInstance(Constants.PROPERTY_FILE).write(Win32AuthService.class.getName(), "checkPassword", "The domain controller could not be reached (" + ExceptionUtils.getStackTrace(uhe) + ")", java.util.logging.Level.SEVERE); 39 40 throw new ServiceException(Win32AuthService.class.getName() + ".unknownhost", uhe); 41 } 42 catch (SmbException se){ 43 Log.getInstance(Constants.PROPERTY_FILE).write(Win32AuthService.class.getName(), "checkPassword", "Invalid username or password in the domain (" + ExceptionUtils.getStackTrace(se) + ")", java.util.logging.Level.INFO); 44 } 45 return result; 46 } 47 48 public void changePassword(String userName, String oldPassword, String newPassword) throws ServiceException { 49 } 51 52 public void setPassword(String userName, String password) 53 throws ServiceException, InvalidPasswordException{ 54 55 } 57 58 public String resetPassword(String userName) throws ServiceException { 59 return null; 60 } 61 62 } 63 | Popular Tags |