PresenceProxy.java 4.51 KB
Newer Older
Matt Tucker's avatar
Matt Tucker committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
/**
 * $RCSfile$
 * $Revision$
 * $Date$
 *
 * Copyright (C) 2002 CoolServlets, Inc. All rights reserved.
 *
 * This software is the proprietary information of CoolServlets, Inc.
 * Use is subject to license terms.
 */
package org.jivesoftware.messenger.spi;

import org.jivesoftware.messenger.*;
import org.jivesoftware.messenger.auth.AuthToken;
import org.jivesoftware.messenger.auth.Permissions;
import org.jivesoftware.messenger.auth.UnauthorizedException;
import java.util.Date;

/**
 * Protection proxy for the Presence class.
 *
 * @author Iain Shigeoka
 */
public class PresenceProxy extends AbstractPacketProxy implements Presence {

    private Presence presence;

    public PresenceProxy(Presence presence, AuthToken authToken, Permissions permissions) {
        super(presence, authToken, permissions);
        this.presence = presence;
    }

    public boolean isAvailable() {
        return presence.isAvailable();
    }

    public void setAvailable(boolean online) throws UnauthorizedException {
        if ((presence.getUserID() == authToken.getUserID()) ||
                permissions.hasPermission(Permissions.SYSTEM_ADMIN | Permissions.USER_ADMIN)) {
            presence.setAvailable(online);
        }
        else {
            throw new org.jivesoftware.messenger.auth.UnauthorizedException();
        }
    }

    public boolean isVisible() {
        return presence.isVisible();
    }

    public void setVisible(boolean visible) throws UnauthorizedException {
        if ((presence.getUserID() == authToken.getUserID()) ||
                permissions.hasPermission(Permissions.SYSTEM_ADMIN | Permissions.USER_ADMIN)) {
            presence.setVisible(visible);
        }
        else {
            throw new org.jivesoftware.messenger.auth.UnauthorizedException();
        }
    }

    public String getID() {
        return presence.getID();
    }

    public long getUserID() {
        return presence.getUserID();
    }

    public Date getLoginTime() {
        return presence.getLoginTime();
    }

    public Date getLastUpdateTime() {
        return presence.getLastUpdateTime();
    }

    public void setLastUpdateTime(Date time) throws UnauthorizedException {
        if ((presence.getUserID() == authToken.getUserID()) ||
                permissions.hasPermission(Permissions.SYSTEM_ADMIN | Permissions.USER_ADMIN)) {
            presence.setLastUpdateTime(time);
        }
        else {
            throw new UnauthorizedException();
        }
    }

    public int getShow() {
        return presence.getShow();
    }

    public void setShow(int status) throws UnauthorizedException {
        if ((presence.getUserID() == authToken.getUserID()) ||
                permissions.hasPermission(Permissions.SYSTEM_ADMIN | Permissions.USER_ADMIN)) {
            presence.setShow(status);
        }
        else {
            throw new UnauthorizedException();
        }
    }

    public String getStatus() {
        return presence.getStatus();
    }

    public void setStatus(String status) throws UnauthorizedException {
        if ((presence.getUserID() == authToken.getUserID()) ||
                permissions.hasPermission(Permissions.SYSTEM_ADMIN | Permissions.USER_ADMIN)) {
            presence.setStatus(status);
        }
        else {
            throw new UnauthorizedException();
        }
    }

    public int getPriority() {
        return presence.getPriority();
    }

    public void setPriority(int priority) throws UnauthorizedException {
        if ((presence.getUserID() == authToken.getUserID()) ||
                permissions.hasPermission(Permissions.SYSTEM_ADMIN | Permissions.USER_ADMIN)) {
            presence.setPriority(priority);
        }
        else {
            throw new UnauthorizedException();
        }
    }

    public RoutePriority getRoutePriority() {
        return presence.getRoutePriority();
    }

    public void setRoutePriority(RoutePriority priority) {
        presence.setRoutePriority(priority);
    }

    public XMPPError getError() {
        return presence.getError();
    }

    public Type getType() {
        return presence.getType();
    }

    public XMPPAddress getRecipient() {
        return presence.getRecipient();
    }

    public XMPPAddress getSender() {
        return presence.getSender();
    }

    public Session getOriginatingSession() {
        return presence.getOriginatingSession();
    }

    public XMPPPacket.Type typeFromString(String type) {
        return presence.typeFromString(type);
    }

    public XMPPFragment createDeepCopy() {
        return presence.createDeepCopy();
    }
}