KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > manentia > kasai > services > Win32AuthService


1 package org.manentia.kasai.services;
2
3 import com.koala.commons.log.Log;
4 import java.net.UnknownHostException JavaDoc;
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 /*
15  *
16  */

17
18
19
20
21 /**
22  *
23  * @author JK Adams
24  */

25 public class Win32AuthService implements AuthService {
26     public int checkPassword(String JavaDoc userName, String JavaDoc 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 JavaDoc 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 JavaDoc userName, String JavaDoc oldPassword, String JavaDoc newPassword) throws ServiceException {
49         // NOT SUPPORTED YET
50
}
51     
52     public void setPassword(String JavaDoc userName, String JavaDoc password)
53         throws ServiceException, InvalidPasswordException{
54     
55         // NOT SUPPORTED YET
56
}
57     
58     public String JavaDoc resetPassword(String JavaDoc userName) throws ServiceException {
59         return null;
60     }
61
62 }
63
Popular Tags