SessionManagerProxy.java 6.34 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 11 12 13 14 15 16 17 18
 */

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.Iterator;
Matt Tucker's avatar
Matt Tucker committed
19
import java.util.Collection;
Matt Tucker's avatar
Matt Tucker committed
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
import javax.xml.stream.XMLStreamException;

/**
 * Standard security proxy
 *
 * @author Iain Shigeoka
 */
public class SessionManagerProxy implements SessionManager {

    private SessionManager sessionManager;
    private Permissions permissions;

    public SessionManagerProxy(SessionManager sessionManager, AuthToken auth, Permissions permission) {
        this.sessionManager = sessionManager;
        this.permissions = permission;
    }

    public Session createSession(Connection conn) throws UnauthorizedException {
        return sessionManager.createSession(conn);
    }

    public void changePriority(XMPPAddress sender, int priority) throws UnauthorizedException {
        if (permissions.hasPermission(Permissions.SYSTEM_ADMIN | Permissions.USER_ADMIN)) {
            sessionManager.changePriority(sender, priority);
        }
        else {
            throw new UnauthorizedException();
        }
    }

    public Session getBestRoute(XMPPAddress recipient) throws UnauthorizedException {
        if (permissions.hasPermission(Permissions.SYSTEM_ADMIN | Permissions.USER_ADMIN)) {
            return sessionManager.getBestRoute(recipient);
        }
        else {
            throw new UnauthorizedException();
        }
    }

    public boolean isActiveRoute(XMPPAddress route) {
        return sessionManager.isActiveRoute(route);
    }

    public Session getSession(XMPPAddress address)
            throws UnauthorizedException, SessionNotFoundException {
        if (permissions.hasPermission(Permissions.SYSTEM_ADMIN | Permissions.USER_ADMIN)) {
            return sessionManager.getSession(address);
        }
        else {
            throw new UnauthorizedException();
        }
    }

Matt Tucker's avatar
Matt Tucker committed
73 74
    public Collection<Session> getSessions() {
        return sessionManager.getSessions();
Matt Tucker's avatar
Matt Tucker committed
75 76
    }

Matt Tucker's avatar
Matt Tucker committed
77 78
    public Collection<Session> getSessions(SessionResultFilter filter) {
        return sessionManager.getSessions(filter);
Matt Tucker's avatar
Matt Tucker committed
79 80
    }

Matt Tucker's avatar
Matt Tucker committed
81 82
    public Iterator getAnonymousSessions() {
        return sessionManager.getAnonymousSessions();
Matt Tucker's avatar
Matt Tucker committed
83 84
    }

Matt Tucker's avatar
Matt Tucker committed
85
    public Collection<Session> getSessions(String username) throws UnauthorizedException {
Matt Tucker's avatar
Matt Tucker committed
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 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
        if (permissions.hasPermission(Permissions.SYSTEM_ADMIN | Permissions.USER_ADMIN)) {
            return sessionManager.getSessions(username);
        }
        else {
            throw new UnauthorizedException();
        }
    }

    public int getTotalSessionCount() throws UnauthorizedException {
        if (permissions.hasPermission(Permissions.SYSTEM_ADMIN | Permissions.USER_ADMIN)) {
            return sessionManager.getTotalSessionCount();
        }
        else {
            throw new UnauthorizedException();
        }
    }

    public int getSessionCount() throws UnauthorizedException {
        if (permissions.hasPermission(Permissions.SYSTEM_ADMIN | Permissions.USER_ADMIN)) {
            return sessionManager.getSessionCount();
        }
        else {
            throw new UnauthorizedException();
        }
    }

    public int getAnonymousSessionCount() throws UnauthorizedException {
        if (permissions.hasPermission(Permissions.SYSTEM_ADMIN | Permissions.USER_ADMIN)) {
            return sessionManager.getAnonymousSessionCount();
        }
        else {
            throw new UnauthorizedException();
        }
    }

    public int getSessionCount(String username) throws UnauthorizedException {
        if (permissions.hasPermission(Permissions.SYSTEM_ADMIN | Permissions.USER_ADMIN)) {
            return sessionManager.getSessionCount(username);
        }
        else {
            throw new UnauthorizedException();
        }
    }

    public Iterator getSessionUsers() throws UnauthorizedException {
        if (permissions.hasPermission(Permissions.SYSTEM_ADMIN | Permissions.USER_ADMIN)) {
            return sessionManager.getSessionUsers();
        }
        else {
            throw new UnauthorizedException();
        }
    }

    public void sendServerMessage(String subject, String body)
            throws UnauthorizedException {
        if (permissions.hasPermission(Permissions.SYSTEM_ADMIN | Permissions.USER_ADMIN)) {
            sessionManager.sendServerMessage(subject, body);
        }
        else {
            throw new UnauthorizedException();
        }
    }

    public void sendServerMessage(XMPPAddress address, String subject, String body)
            throws UnauthorizedException, SessionNotFoundException {
        if (permissions.hasPermission(Permissions.SYSTEM_ADMIN | Permissions.USER_ADMIN)) {
            sessionManager.sendServerMessage(address, subject, body);
        }
        else {
            throw new UnauthorizedException();
        }
    }

    public void broadcast(XMPPPacket packet) throws
            UnauthorizedException, PacketException, XMLStreamException {
        if (permissions.hasPermission(Permissions.SYSTEM_ADMIN | Permissions.USER_ADMIN)) {
            sessionManager.broadcast(packet);
        }
        else {
            throw new UnauthorizedException();
        }
    }

    public void userBroadcast(String username, XMPPPacket packet) throws
            UnauthorizedException, PacketException, XMLStreamException {
        if (permissions.hasPermission(Permissions.SYSTEM_ADMIN | Permissions.USER_ADMIN)) {
            sessionManager.userBroadcast(username, packet);
        }
        else {
            throw new UnauthorizedException();
        }
    }

    public void addAnonymousSession(Session session) {
        sessionManager.addAnonymousSession(session);
    }

    public int getConflictKickLimit() {
        return sessionManager.getConflictKickLimit();
    }

    public void setConflictKickLimit(int limit) throws UnauthorizedException {
        if (permissions.hasPermission(Permissions.SYSTEM_ADMIN | Permissions.USER_ADMIN)) {
            sessionManager.setConflictKickLimit(limit);
        }
        else {
            throw new UnauthorizedException();
        }
    }
}