KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jivesoftware > messenger > plugin > ForumsUserProvider


1 package org.jivesoftware.messenger.plugin;
2
3 import com.caucho.hessian.client.HessianProxyFactory;
4 import com.opensymphony.forums.ws.WSUser;
5 import com.opensymphony.forums.ws.WebServices;
6 import org.jivesoftware.messenger.auth.AuthProvider;
7 import org.jivesoftware.messenger.auth.UnauthorizedException;
8 import org.jivesoftware.messenger.user.User;
9 import org.jivesoftware.messenger.user.UserAlreadyExistsException;
10 import org.jivesoftware.messenger.user.UserNotFoundException;
11 import org.jivesoftware.messenger.user.UserProvider;
12
13 import java.net.MalformedURLException JavaDoc;
14 import java.util.Collection JavaDoc;
15 import java.util.Date JavaDoc;
16 import java.util.Set JavaDoc;
17
18 /**
19  * User: patrick
20  * Date: Jul 22, 2005
21  * Time: 3:10:13 PM
22  */

23 public class ForumsUserProvider implements UserProvider, AuthProvider {
24     private ForumsSettings settings = new ForumsSettings();
25
26     private WebServices getWebServices() {
27         HessianProxyFactory factory = new HessianProxyFactory();
28         WebServices ws = null;
29         try {
30             ws = (WebServices) factory.create(WebServices.class, settings.getUrl());
31         }
32         catch (MalformedURLException JavaDoc e) {
33             e.printStackTrace();
34             throw new RuntimeException JavaDoc(e);
35         }
36         return ws;
37     }
38
39     public boolean isPlainSupported() {
40         return true;
41     }
42
43     public boolean isDigestSupported() {
44         return false;
45     }
46
47     public void authenticate(String JavaDoc username, String JavaDoc password) throws UnauthorizedException {
48         try {
49             boolean auth = !getWebServices().authenticate(username, password);
50             System.out.println("Auth result was: " + auth);
51             if (auth) {
52                 throw new UnauthorizedException();
53             }
54         } catch (Exception JavaDoc e) {
55             e.printStackTrace();
56
57             if (e instanceof UnauthorizedException) {
58                 throw (UnauthorizedException) e;
59             }
60         }
61     }
62
63     public void authenticate(String JavaDoc username, String JavaDoc token, String JavaDoc digest) throws UnauthorizedException {
64         throw new UnauthorizedException();
65     }
66
67
68     public User loadUser(String JavaDoc username) throws UserNotFoundException {
69         WSUser wsUser = getWebServices().getUser(settings.getContext(), username);
70
71         return new User(wsUser.getUsername(), wsUser.getName(), wsUser.getName(),
72                 wsUser.getCreated(), wsUser.getLastModified());
73     }
74
75     public User createUser(String JavaDoc username, String JavaDoc password, String JavaDoc name, String JavaDoc email) throws UserAlreadyExistsException {
76         return null;
77     }
78
79     public void deleteUser(String JavaDoc username) {
80     }
81
82     public int getUserCount() {
83         return 0;
84     }
85
86     public Collection JavaDoc<User> getUsers() {
87         return null;
88     }
89
90     public Collection JavaDoc<User> getUsers(int startIndex, int numResults) {
91         return null;
92     }
93
94     public String JavaDoc getPassword(String JavaDoc username) throws UserNotFoundException, UnsupportedOperationException JavaDoc {
95         return null;
96     }
97
98     public void setPassword(String JavaDoc username, String JavaDoc password) throws UserNotFoundException, UnsupportedOperationException JavaDoc {
99     }
100
101     public void setName(String JavaDoc username, String JavaDoc name) throws UserNotFoundException {
102     }
103
104     public void setEmail(String JavaDoc username, String JavaDoc email) throws UserNotFoundException {
105     }
106
107     public void setCreationDate(String JavaDoc username, Date JavaDoc creationDate) throws UserNotFoundException {
108     }
109
110     public void setModificationDate(String JavaDoc username, Date JavaDoc modificationDate) throws UserNotFoundException {
111     }
112
113     public Set JavaDoc<String JavaDoc> getSearchFields() throws UnsupportedOperationException JavaDoc {
114         return null;
115     }
116
117     public Collection JavaDoc<User> findUsers(Set JavaDoc<String JavaDoc> fields, String JavaDoc query) throws UnsupportedOperationException JavaDoc {
118         return null;
119     }
120
121     public Collection JavaDoc<User> findUsers(Set JavaDoc<String JavaDoc> fields, String JavaDoc query, int startIndex, int numResults) throws UnsupportedOperationException JavaDoc {
122         return null;
123     }
124
125     public boolean isReadOnly() {
126         return true;
127     }
128
129 }
130
Popular Tags