RosterItemProxy.java 2.9 KB
Newer Older
Matt Tucker's avatar
Matt Tucker committed
1 2 3 4 5
/**
 * $RCSfile$
 * $Revision$
 * $Date$
 *
Matt Tucker's avatar
Matt Tucker committed
6
 * Copyright (C) 2004 Jive Software. All rights reserved.
Matt Tucker's avatar
Matt Tucker committed
7
 *
Matt Tucker's avatar
Matt Tucker committed
8 9
 * This software is published under the terms of the GNU Public License (GPL),
 * a copy of which is included in this distribution.
Matt Tucker's avatar
Matt Tucker committed
10
 */
Matt Tucker's avatar
Matt Tucker committed
11

Matt Tucker's avatar
Matt Tucker committed
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
package org.jivesoftware.messenger.spi;

import org.jivesoftware.messenger.XMPPAddress;
import org.jivesoftware.messenger.auth.AuthToken;
import org.jivesoftware.messenger.auth.Permissions;
import org.jivesoftware.messenger.auth.UnauthorizedException;
import org.jivesoftware.messenger.user.RosterItem;
import java.util.List;

/**
 * Standard security proxy
 *
 * @author Iain Shigeoka
 */
public class RosterItemProxy implements RosterItem {

    private RosterItem item;
    private AuthToken authToken;
    private Permissions permissions;

    public RosterItemProxy(RosterItem item, AuthToken authToken, Permissions permissions) {
        this.authToken = authToken;
        this.permissions = permissions;
        this.item = item;
    }

    public SubType getSubStatus() {
        return item.getSubStatus();
    }

    public void setSubStatus(SubType subStatus) throws UnauthorizedException {
        if (permissions.hasPermission(Permissions.SYSTEM_ADMIN | Permissions.USER_ADMIN)) {
            item.setSubStatus(subStatus);
        }
        else {
            throw new org.jivesoftware.messenger.auth.UnauthorizedException();
        }
    }

    public AskType getAskStatus() {
        return item.getAskStatus();
    }

    public void setAskStatus(AskType askStatus) throws UnauthorizedException {
        if (permissions.hasPermission(Permissions.SYSTEM_ADMIN | Permissions.USER_ADMIN)) {
            item.setAskStatus(askStatus);
        }
        else {
            throw new UnauthorizedException();
        }
    }

    public RecvType getRecvStatus() {
        return item.getRecvStatus();
    }

    public void setRecvStatus(RecvType recvStatus) throws UnauthorizedException {
        if (permissions.hasPermission(Permissions.SYSTEM_ADMIN | Permissions.USER_ADMIN)) {
            item.setRecvStatus(recvStatus);
        }
        else {
            throw new UnauthorizedException();
        }
    }

    public XMPPAddress getJid() {
        return item.getJid();
    }

    public String getNickname() {
        return item.getNickname();
    }

    public void setNickname(String nickname) throws UnauthorizedException {
        if (permissions.hasPermission(Permissions.SYSTEM_ADMIN | Permissions.USER_ADMIN)) {
            item.setNickname(nickname);
        }
        else {
            throw new UnauthorizedException();
        }
    }

    public List getGroups() {
        return item.getGroups();
    }

    public void setGroups(List groups) throws UnauthorizedException {
        if (permissions.hasPermission(Permissions.SYSTEM_ADMIN | Permissions.USER_ADMIN)) {
            item.setGroups(groups);
        }
        else {
            throw new UnauthorizedException();
        }
    }
}