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 ; 14 import java.util.Collection ; 15 import java.util.Date ; 16 import java.util.Set ; 17 18 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 e) { 33 e.printStackTrace(); 34 throw new RuntimeException (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 username, String 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 e) { 55 e.printStackTrace(); 56 57 if (e instanceof UnauthorizedException) { 58 throw (UnauthorizedException) e; 59 } 60 } 61 } 62 63 public void authenticate(String username, String token, String digest) throws UnauthorizedException { 64 throw new UnauthorizedException(); 65 } 66 67 68 public User loadUser(String 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 username, String password, String name, String email) throws UserAlreadyExistsException { 76 return null; 77 } 78 79 public void deleteUser(String username) { 80 } 81 82 public int getUserCount() { 83 return 0; 84 } 85 86 public Collection <User> getUsers() { 87 return null; 88 } 89 90 public Collection <User> getUsers(int startIndex, int numResults) { 91 return null; 92 } 93 94 public String getPassword(String username) throws UserNotFoundException, UnsupportedOperationException { 95 return null; 96 } 97 98 public void setPassword(String username, String password) throws UserNotFoundException, UnsupportedOperationException { 99 } 100 101 public void setName(String username, String name) throws UserNotFoundException { 102 } 103 104 public void setEmail(String username, String email) throws UserNotFoundException { 105 } 106 107 public void setCreationDate(String username, Date creationDate) throws UserNotFoundException { 108 } 109 110 public void setModificationDate(String username, Date modificationDate) throws UserNotFoundException { 111 } 112 113 public Set <String > getSearchFields() throws UnsupportedOperationException { 114 return null; 115 } 116 117 public Collection <User> findUsers(Set <String > fields, String query) throws UnsupportedOperationException { 118 return null; 119 } 120 121 public Collection <User> findUsers(Set <String > fields, String query, int startIndex, int numResults) throws UnsupportedOperationException { 122 return null; 123 } 124 125 public boolean isReadOnly() { 126 return true; 127 } 128 129 } 130 | Popular Tags |