Commit 09e024e4 authored by Derek DeMoro's avatar Derek DeMoro Committed by derek

Refactoring work.


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@582 b35dd754-fafc-0310-a699-88a17e54d16e
parent e62ea2df
......@@ -11,16 +11,34 @@
package org.jivesoftware.messenger;
import org.jivesoftware.messenger.audit.spi.AuditManagerImpl;
import org.jivesoftware.messenger.container.spi.BootstrapContainer;
import org.jivesoftware.messenger.disco.IQDiscoInfoHandler;
import org.jivesoftware.messenger.disco.IQDiscoItemsHandler;
import org.jivesoftware.messenger.handler.IQAuthHandler;
import org.jivesoftware.messenger.handler.IQPrivateHandler;
import org.jivesoftware.messenger.handler.IQRegisterHandler;
import org.jivesoftware.messenger.handler.IQRosterHandler;
import org.jivesoftware.messenger.handler.IQTimeHandler;
import org.jivesoftware.messenger.handler.IQVersionHandler;
import org.jivesoftware.messenger.handler.IQvCardHandler;
import org.jivesoftware.messenger.handler.PresenceSubscribeHandler;
import org.jivesoftware.messenger.handler.PresenceUpdateHandler;
import org.jivesoftware.messenger.muc.spi.MultiUserChatServerImpl;
import org.jivesoftware.messenger.audit.spi.AuditManagerImpl;
import org.jivesoftware.messenger.handler.*;
import org.jivesoftware.messenger.spi.*;
import org.jivesoftware.messenger.spi.BasicServer;
import org.jivesoftware.messenger.spi.ConnectionManagerImpl;
import org.jivesoftware.messenger.spi.IQRouterImpl;
import org.jivesoftware.messenger.spi.MessageRouterImpl;
import org.jivesoftware.messenger.spi.PacketDelivererImpl;
import org.jivesoftware.messenger.spi.PacketFactoryImpl;
import org.jivesoftware.messenger.spi.PacketRouterImpl;
import org.jivesoftware.messenger.spi.PacketTransporterImpl;
import org.jivesoftware.messenger.spi.PresenceManagerImpl;
import org.jivesoftware.messenger.spi.PresenceRouterImpl;
import org.jivesoftware.messenger.spi.RoutingTableImpl;
import org.jivesoftware.messenger.transport.TransportHandler;
import org.jivesoftware.messenger.user.spi.*;
import org.jivesoftware.messenger.user.OfflineMessageStrategy;
import org.jivesoftware.messenger.user.spi.RosterManagerImpl;
import org.jivesoftware.messenger.user.spi.UserManagerImpl;
/**
* A bootstrap container to launch the Messenger XMPP server. This
......
......@@ -15,7 +15,7 @@ import org.jivesoftware.messenger.auth.UnauthorizedException;
import org.jivesoftware.messenger.user.UserInfo;
import org.jivesoftware.messenger.user.UserInfoProvider;
import org.jivesoftware.messenger.user.UserNotFoundException;
import org.jivesoftware.messenger.user.spi.BasicUserInfo;
import org.jivesoftware.messenger.user.UserInfo;
import org.jivesoftware.util.Log;
import java.util.Date;
......@@ -75,7 +75,7 @@ public class LdapUserInfoProvider implements UserInfoProvider {
* @throws UserNotFoundException
*/
private UserInfo getInfoFromLdap(String username) throws UserNotFoundException {
BasicUserInfo userInfo = null;
UserInfo userInfo = null;
DirContext ctx = null;
try {
String userDN = manager.findUserDN(username);
......@@ -96,7 +96,7 @@ public class LdapUserInfoProvider implements UserInfoProvider {
if (emailField != null) {
email = (String)emailField.get();
}
userInfo = new BasicUserInfo(username, name, email, new Date(), new Date());
userInfo = new UserInfo(username, name, email, new Date(), new Date());
}
catch (Exception e) {
throw new UserNotFoundException(e);
......
......@@ -12,91 +12,156 @@
package org.jivesoftware.messenger.user;
import org.jivesoftware.messenger.auth.UnauthorizedException;
import org.jivesoftware.util.CacheSizes;
import org.jivesoftware.util.Cacheable;
import java.util.Date;
import org.jivesoftware.util.StringUtils;
/**
* <p>The UserInfo interface provides information about and services for users of the system.</p>
* <p/>
* <p>The name and email field will normally be required fields when creating user accounts for most
* implementations. However, some users may wish to keep that information private. Therefore, there
* are two flags to set if the name and email fields should be made visible to other users. If
* the flags are set to deny access, getName() and getEmail() will throw UnauthorizedExceptions to
* users that don't have administrator permissions.</p>
* <p/>
* <p>Security for UserInfo objects is provide by UserInfoProxy protection proxy objects.</p>
* <p>The simplest implementation of UserInfo.</p>
* <p>Useful if you are retrieving user info from a database and just need
* to stuff it into a data structure.</p>
*
* @author Iain Shigeoka
* @author Derek DeMoro
* @see User
*/
public interface UserInfo extends Cacheable {
public class UserInfo implements Cacheable {
/**
* Returns the user's name. The user's name does not have to be to be unique in the system. Some
* users may opt to not let others see their name for privacy reasons. In that case, the user
* can set nameVisible to false. In that case, a call to this method will return null.
*
* @return the name of the user.
*/
String getName();
private String username = null;
private String name = " ";
private String email;
private java.util.Date creationDate;
private java.util.Date modificationDate;
/**
* Sets the user's name. The user's name does not have to be to be unique in the system.
* Create a new UserInfo with default fields.
*
* @param name new name for the user.
* @throws UnauthorizedException if does not have administrator permissions.
* @param username the username.
*/
void setName(String name) throws UnauthorizedException;
public UserInfo(String username) {
this.username = username;
creationDate = new java.util.Date();
modificationDate = new java.util.Date();
}
/**
* Returns the user's email address. Email should be considered to be a required field of a user
* account since it is critical to many user operations performing. If the user sets
* emailVisible to false, this method will always return null.
* <p>Create a new UserInfo given field values.</p>
*
* @return the email address of the user.
* @param username The username
* @param name The user's full name
* @param email The user's email address
*/
String getEmail();
public UserInfo(String username, String name, String email,
java.util.Date creationDate, java.util.Date modificationDate)
{
this.username = username;
this.creationDate = creationDate;
this.modificationDate = modificationDate;
if (email == null || "".equals(email)) {
this.email = " ";
}
else {
this.email = email;
}
if (name != null) {
this.name = name;
}
}
/**
* Sets the user's email address. Email should be considered to be a required field of a user
* account since it is critical to many user operations performing.
*
* @param email new email address for the user.
* @throws UnauthorizedException if does not have administrator permissions.
*/
void setEmail(String email) throws UnauthorizedException;
public String getUsername() {
return username;
}
/**
* Returns the date that the user was created.
*
* @return the date the user was created.
*/
Date getCreationDate();
public String getName() {
return name;
}
/**
* Sets the creation date of the user. In most cases, the creation date will default to when the
* user was entered into the system. However, the date needs to be set manually when importing
* data. In other words, skin authors should ignore this method since it only intended for
* system maintenance.
*
* @param creationDate the date the user was created.
* @throws UnauthorizedException if does not have administrator permissions.
*/
void setCreationDate(Date creationDate) throws UnauthorizedException;
public void setName(String name) throws UnauthorizedException {
if (name == null) {
throw new IllegalArgumentException("Name cannot be null");
}
/**
* Returns the date that the user was last modified.
*
* @return the date the user record was last modified.
*/
Date getModificationDate();
this.name = name;
// Update modification date
modificationDate.setTime(System.currentTimeMillis());
}
public String getEmail() {
return StringUtils.escapeHTMLTags(email);
}
public void setEmail(String email) throws UnauthorizedException {
if (email == null || "".equals(email)) {
email = " ";
}
this.email = email;
// Update modification date
modificationDate.setTime(System.currentTimeMillis());
}
public java.util.Date getCreationDate() {
return creationDate;
}
public void setCreationDate(java.util.Date creationDate) throws UnauthorizedException {
if (creationDate == null) {
throw new IllegalArgumentException("Creation date cannot be null");
}
this.creationDate.setTime(creationDate.getTime());
}
public java.util.Date getModificationDate() {
return modificationDate;
}
public void setModificationDate(java.util.Date modificationDate) throws UnauthorizedException {
if (modificationDate == null) {
throw new IllegalArgumentException("Modification date cannot be null");
}
this.modificationDate.setTime(modificationDate.getTime());
}
public int getCachedSize() {
// Approximate the size of the object in bytes by calculating the size
// of each field.
int size = 0;
size += CacheSizes.sizeOfObject(); // overhead of object
size += CacheSizes.sizeOfLong(); // id
size += CacheSizes.sizeOfString(name); // name
size += CacheSizes.sizeOfString(email); // email
size += CacheSizes.sizeOfBoolean(); // nameVisible
size += CacheSizes.sizeOfBoolean(); // emailVisible
size += CacheSizes.sizeOfDate(); // creationDate
size += CacheSizes.sizeOfDate(); // modificationDate
return size;
}
/**
* Sets the date the user was last modified. Skin authors should ignore this method since it
* only intended for system maintenance.
* Returns a String representation of the User object using the username.
*
* @param modificationDate the date the user was modified.
* @throws UnauthorizedException if does not have administrator permissions.
* @return a String representation of the User object.
*/
void setModificationDate(Date modificationDate) throws UnauthorizedException;
public String toString() {
return name;
}
public int hashCode() {
return username.hashCode();
}
public boolean equals(Object object) {
if (this == object) {
return true;
}
if (object != null && object instanceof User) {
return username.equals(((User)object).getUsername());
}
else {
return false;
}
}
}
\ No newline at end of file
/**
* $RCSfile$
* $Revision$
* $Date$
*
* Copyright (C) 2004 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.messenger.user.spi;
import org.jivesoftware.util.CacheSizes;
import org.jivesoftware.util.StringUtils;
import org.jivesoftware.messenger.auth.UnauthorizedException;
import org.jivesoftware.messenger.user.User;
import org.jivesoftware.messenger.user.UserInfo;
/**
* <p>The simplest implementation of UserInfo.</p>
* <p>Useful if you are retrieving user info from a database and just need
* to stuff it into a data structure.</p>
*
* @author Iain Shigeoka
* @see User
*/
public class BasicUserInfo implements UserInfo {
private String username = null;
private String name = " ";
private String email;
private java.util.Date creationDate;
private java.util.Date modificationDate;
/**
* Create a new UserInfo with default fields.
*
* @param username the username.
*/
public BasicUserInfo(String username) {
this.username = username;
creationDate = new java.util.Date();
modificationDate = new java.util.Date();
}
/**
* <p>Create a new UserInfo given field values.</p>
*
* @param username The username
* @param name The user's full name
* @param email The user's email address
*/
public BasicUserInfo(String username, String name, String email,
java.util.Date creationDate, java.util.Date modificationDate)
{
this.username = username;
this.creationDate = creationDate;
this.modificationDate = modificationDate;
if (email == null || "".equals(email)) {
this.email = " ";
}
else {
this.email = email;
}
if (name != null) {
this.name = name;
}
}
public String getUsername() {
return username;
}
public String getName() {
return name;
}
public void setName(String name) throws UnauthorizedException {
if (name == null) {
throw new IllegalArgumentException("Name cannot be null");
}
this.name = name;
// Update modification date
modificationDate.setTime(System.currentTimeMillis());
}
public String getEmail() {
return StringUtils.escapeHTMLTags(email);
}
public void setEmail(String email) throws UnauthorizedException {
if (email == null || "".equals(email)) {
email = " ";
}
this.email = email;
// Update modification date
modificationDate.setTime(System.currentTimeMillis());
}
public java.util.Date getCreationDate() {
return creationDate;
}
public void setCreationDate(java.util.Date creationDate) throws UnauthorizedException {
if (creationDate == null) {
throw new IllegalArgumentException("Creation date cannot be null");
}
this.creationDate.setTime(creationDate.getTime());
}
public java.util.Date getModificationDate() {
return modificationDate;
}
public void setModificationDate(java.util.Date modificationDate) throws UnauthorizedException {
if (modificationDate == null) {
throw new IllegalArgumentException("Modification date cannot be null");
}
this.modificationDate.setTime(modificationDate.getTime());
}
public int getCachedSize() {
// Approximate the size of the object in bytes by calculating the size
// of each field.
int size = 0;
size += CacheSizes.sizeOfObject(); // overhead of object
size += CacheSizes.sizeOfLong(); // id
size += CacheSizes.sizeOfString(name); // name
size += CacheSizes.sizeOfString(email); // email
size += CacheSizes.sizeOfBoolean(); // nameVisible
size += CacheSizes.sizeOfBoolean(); // emailVisible
size += CacheSizes.sizeOfDate(); // creationDate
size += CacheSizes.sizeOfDate(); // modificationDate
return size;
}
/**
* Returns a String representation of the User object using the username.
*
* @return a String representation of the User object.
*/
public String toString() {
return name;
}
public int hashCode() {
return username.hashCode();
}
public boolean equals(Object object) {
if (this == object) {
return true;
}
if (object != null && object instanceof User) {
return username.equals(((User)object).getUsername());
}
else {
return false;
}
}
}
\ No newline at end of file
/**
* $RCSfile$
* $Revision$
* $Date$
*
* Copyright (C) 2004 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.messenger.user.spi;
import org.jivesoftware.messenger.Presence;
import org.jivesoftware.messenger.auth.AuthToken;
import org.jivesoftware.messenger.auth.Permissions;
import org.jivesoftware.messenger.auth.UnauthorizedException;
import org.jivesoftware.messenger.spi.RosterProxy;
import org.jivesoftware.messenger.user.CachedRoster;
import org.jivesoftware.messenger.user.IQRoster;
public class CachedRosterProxy extends RosterProxy implements CachedRoster {
public CachedRosterProxy(CachedRoster roster, AuthToken authToken, Permissions permissions) {
super(roster, authToken, permissions);
}
public String getUsername() {
return ((CachedRoster)roster).getUsername();
}
public IQRoster getReset() throws UnauthorizedException {
return ((CachedRoster)roster).getReset();
}
public void broadcastPresence(Presence packet) {
((CachedRoster)roster).broadcastPresence(packet);
}
public int getCachedSize() {
return ((CachedRoster)roster).getCachedSize();
}
}
......@@ -11,20 +11,19 @@
package org.jivesoftware.messenger.user.spi;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.jivesoftware.database.DbConnectionManager;
import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log;
import org.jivesoftware.util.StringUtils;
import org.jivesoftware.messenger.auth.UnauthorizedException;
import org.jivesoftware.messenger.user.User;
import org.jivesoftware.messenger.user.UserInfo;
import org.jivesoftware.messenger.user.UserInfoProvider;
import org.jivesoftware.messenger.user.UserNotFoundException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.Log;
import org.jivesoftware.util.StringUtils;
/**
* Catabase implementation of the UserInfoProvider interface.
......@@ -41,7 +40,7 @@ public class DbUserInfoProvider implements UserInfoProvider {
"SELECT name, email, creationDate, modificationDate FROM jiveUser WHERE username=?";
public UserInfo getInfo(String username) throws UserNotFoundException {
BasicUserInfo userInfo = null;
UserInfo userInfo = null;
Connection con = null;
PreparedStatement pstmt = null;
try {
......@@ -55,7 +54,7 @@ public class DbUserInfoProvider implements UserInfoProvider {
}
// We trim() the dates before trying to parse them because some
// databases pad with extra characters when returning the data.
userInfo = new BasicUserInfo(username,
userInfo = new UserInfo(username,
rs.getString(1), // name
rs.getString(2), // email
new java.util.Date(Long.parseLong(rs.getString(3).trim())), // creation date
......
/**
* $RCSfile$
* $Revision$
* $Date$
*
* Copyright (C) 2004 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.messenger.user.spi;
import org.jivesoftware.messenger.auth.AuthToken;
import org.jivesoftware.messenger.auth.Permissions;
import org.jivesoftware.messenger.auth.UnauthorizedException;
import org.jivesoftware.messenger.user.User;
import org.jivesoftware.messenger.user.UserInfo;
import java.util.Date;
/**
* Protection proxy for User objects.
*
* @author Iain Shigeoka
* @see User
*/
public class UserInfoProxy implements UserInfo {
private UserInfo info;
private AuthToken authToken;
private Permissions permissions;
/**
* Create a new UserProxy.
*/
public UserInfoProxy(UserInfo info, AuthToken authToken, Permissions permissions) {
this.info = info;
this.authToken = authToken;
this.permissions = permissions;
}
public String getName() {
return info.getName();
}
public void setName(String name) throws UnauthorizedException {
if (permissions.hasPermission(Permissions.SYSTEM_ADMIN | Permissions.USER_ADMIN)) {
info.setName(name);
}
else {
throw new UnauthorizedException();
}
}
public String getEmail() {
return info.getEmail();
}
public void setEmail(String email) throws UnauthorizedException {
if (permissions.hasPermission(Permissions.SYSTEM_ADMIN | Permissions.USER_ADMIN)) {
info.setEmail(email);
}
else {
throw new UnauthorizedException();
}
}
public Date getCreationDate() {
return info.getCreationDate();
}
public void setCreationDate(Date creationDate)
throws UnauthorizedException {
if (permissions.hasPermission(Permissions.SYSTEM_ADMIN | Permissions.USER_ADMIN)) {
info.setCreationDate(creationDate);
}
else
throw new UnauthorizedException();
}
public Date getModificationDate() {
return info.getModificationDate();
}
public void setModificationDate(Date modifiedDate) throws UnauthorizedException {
if (permissions.hasPermission(Permissions.SYSTEM_ADMIN | Permissions.USER_ADMIN)) {
info.setModificationDate(modifiedDate);
}
else
throw new UnauthorizedException();
}
public int getCachedSize() {
return info.getCachedSize();
}
}
/**
* $RCSfile$
* $Revision$
* $Date$
*
* Copyright (C) 2004 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.messenger.user.spi;
import org.jivesoftware.util.ProxyFactory;
import org.jivesoftware.messenger.auth.AuthToken;
import org.jivesoftware.messenger.auth.Permissions;
import org.jivesoftware.messenger.user.User;
import java.util.Iterator;
/**
* Protection proxy for Iterators of users.
*
* @author Iain Shigeoka
*/
public class UserIteratorProxy implements Iterator {
private Iterator iterator;
private Object nextElement = null;
private AuthToken auth;
private Permissions permissions;
private ProxyFactory proxyFactory;
/**
* Creates a new user iterator proxy.
*
* @param iterator the Iterator to create proxies for.
* @param auth the authorization token.
* @param permissions the permissions that the new proxy will inherit.
*/
public UserIteratorProxy(Iterator iterator, AuthToken auth, Permissions permissions) {
this.iterator = iterator;
this.auth = auth;
this.permissions = permissions;
// Create a class that wraps users with proxies.
proxyFactory = new ProxyFactory() {
public Object createProxy(Object obj, AuthToken auth, Permissions perms) {
User user = (User)obj;
Permissions userPerms = user.getPermissions(auth);
Permissions newPerms = new Permissions(userPerms, perms);
return new UserProxy(user, auth, newPerms);
}
};
}
/**
* Returns true if there are more elements in the iteration.
*
* @return true if the iterator has more elements.
*/
public boolean hasNext() {
// If we are at the end of the list, there can't be any more elements to iterate through.
if (!iterator.hasNext() && nextElement == null) {
return false;
}
// Otherwise, see if nextElement is null. If so, try to load the next element to make sure
// it exists.
if (nextElement == null) {
nextElement = getNextElement();
if (nextElement == null) {
return false;
}
}
return true;
}
/**
* Returns the next element.
*
* @return the next element.
* @throws java.util.NoSuchElementException
* if there are no more elements.
*/
public Object next() throws java.util.NoSuchElementException {
Object element = null;
if (nextElement != null) {
element = nextElement;
nextElement = null;
}
else {
element = getNextElement();
if (element == null) {
throw new java.util.NoSuchElementException();
}
}
return element;
}
/**
* Not supported for security reasons.
*/
public void remove() throws UnsupportedOperationException {
throw new UnsupportedOperationException();
}
/**
* Returns the next available element, or null if there are no more elements.
*
* @return the next available element.
*/
public Object getNextElement() {
while (iterator.hasNext()) {
Object element = proxyFactory.createProxy(iterator.next(), auth, permissions);
if (element != null) {
return element;
}
}
return null;
}
}
\ No newline at end of file
/**
* $RCSfile$
* $Revision$
* $Date$
*
* Copyright (C) 2004 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.messenger.user.spi;
import org.jivesoftware.messenger.container.Container;
import org.jivesoftware.util.JiveConstants;
import org.jivesoftware.messenger.auth.AuthToken;
import org.jivesoftware.messenger.auth.Permissions;
import org.jivesoftware.messenger.auth.UnauthorizedException;
import org.jivesoftware.messenger.user.User;
import org.jivesoftware.messenger.user.UserAlreadyExistsException;
import org.jivesoftware.messenger.user.UserManager;
import org.jivesoftware.messenger.user.UserNotFoundException;
import java.util.Iterator;
/**
* Protection proxy for the UserManager class. It restricts access to
* protected methods by throwing UnauthorizedExceptions when necessary.
*
* @author Iain Shigeoka
* @see org.jivesoftware.messenger.user.UserManager
*/
public class UserManagerProxy implements UserManager {
private UserManager userManager;
private AuthToken auth;
private Permissions permissions;
/**
* Creates a new proxy.
*/
public UserManagerProxy(UserManager userManager, AuthToken auth, Permissions permissions) {
this.userManager = userManager;
this.auth = auth;
this.permissions = permissions;
}
public User createUser(String username, String password, String email)
throws UserAlreadyExistsException, UnauthorizedException {
return userManager.createUser(username, password, email);
}
public User getUser(String username) throws UserNotFoundException {
User user = userManager.getUser(username.toLowerCase());
Permissions userPermissions = user.getPermissions(auth);
Permissions newPermissions = new Permissions(permissions, userPermissions);
return new UserProxy(user, auth, newPermissions);
}
public void deleteUser(User user) throws UnauthorizedException {
if (permissions.hasPermission(Permissions.SYSTEM_ADMIN | Permissions.USER_ADMIN)) {
userManager.deleteUser(user);
}
else {
throw new UnauthorizedException();
}
}
public int getUserCount() {
return userManager.getUserCount();
}
public Iterator users() throws UnauthorizedException {
return userManager.users();
}
public Iterator users(int startIndex, int numResults) throws UnauthorizedException {
return userManager.users(startIndex, numResults);
}
public String getName() {
return null;
}
public void initialize(Container container) {
userManager.initialize(container);
}
public void start() {
userManager.start();
}
public void stop() {
userManager.stop();
}
public void destroy() {
userManager.destroy();
}
}
/**
* $RCSfile$
* $Revision$
* $Date$
*
* Copyright (C) 2004 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.messenger.user.spi;
import org.jivesoftware.messenger.auth.AuthToken;
import org.jivesoftware.messenger.auth.Permissions;
import org.jivesoftware.messenger.auth.UnauthorizedException;
import org.jivesoftware.messenger.user.CachedRoster;
import org.jivesoftware.messenger.user.User;
import org.jivesoftware.messenger.user.UserInfo;
import org.jivesoftware.messenger.user.UserNotFoundException;
import java.util.Iterator;
/**
* Protection proxy for User objects.
*
* @author Iain Shigeoka
* @see User
*/
public class UserProxy implements User {
private User user;
private AuthToken authToken;
private Permissions permissions;
/**
* Create a new UserProxy.
*/
public UserProxy(User user, AuthToken authToken, Permissions permissions) {
this.user = user;
this.authToken = authToken;
this.permissions = permissions;
}
public String getUsername() {
return user.getUsername();
}
public void setPassword(String password) throws UnauthorizedException {
if (permissions.hasPermission(Permissions.SYSTEM_ADMIN | Permissions.USER_ADMIN)) {
user.setPassword(password);
}
else {
throw new UnauthorizedException();
}
}
public UserInfo getInfo() throws UserNotFoundException {
return user.getInfo();
}
public void saveInfo() throws UnauthorizedException {
user.saveInfo();
}
public String getProperty(String name) {
return user.getProperty(name);
}
public void setProperty(String name, String value) throws UnauthorizedException {
if (permissions.hasPermission(Permissions.SYSTEM_ADMIN | Permissions.USER_ADMIN)) {
user.setProperty(name, value);
}
else {
throw new UnauthorizedException();
}
}
public void deleteProperty(String name) throws UnauthorizedException {
if (permissions.hasPermission(Permissions.SYSTEM_ADMIN | Permissions.USER_ADMIN)) {
user.deleteProperty(name);
}
else {
throw new UnauthorizedException();
}
}
public Iterator getPropertyNames() {
return user.getPropertyNames();
}
public CachedRoster getRoster() throws UnauthorizedException {
return new CachedRosterProxy(user.getRoster(), authToken, permissions);
}
public Permissions getPermissions(AuthToken authToken) {
return user.getPermissions(authToken);
}
public boolean isAuthorized(long permissionType) {
return permissions.hasPermission(permissionType);
}
public void setVCardProperty(String name, String value) throws UnauthorizedException {
if (permissions.hasPermission(Permissions.SYSTEM_ADMIN | Permissions.USER_ADMIN)) {
user.setVCardProperty(name, value);
}
else {
throw new UnauthorizedException();
}
}
public String getVCardProperty(String name) {
return user.getVCardProperty(name);
}
public void deleteVCardProperty(String name) throws UnauthorizedException {
if (permissions.hasPermission(Permissions.SYSTEM_ADMIN | Permissions.USER_ADMIN)) {
user.deleteVCardProperty(name);
}
else {
throw new UnauthorizedException();
}
}
public Iterator getVCardPropertyNames() {
return user.getVCardPropertyNames();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment