ClearspaceAdminProvider.java 3.08 KB
Newer Older
1 2 3 4
/**
 * $Revision$
 * $Date$
 *
5
 * Copyright (C) 2005-2008 Jive Software. All rights reserved.
6 7
 *
 * This software is published under the terms of the GNU Public License (GPL),
8 9
 * a copy of which is included in this distribution, or a commercial license
 * agreement with Jive.
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
 */
package org.jivesoftware.openfire.clearspace;

import org.jivesoftware.openfire.admin.AdminProvider;
import static org.jivesoftware.openfire.clearspace.ClearspaceManager.HttpType.GET;
import static org.jivesoftware.openfire.clearspace.WSUtils.parseStringArray;
import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.user.UserNotFoundException;
import org.jivesoftware.util.Log;
import org.xmpp.packet.JID;
import org.dom4j.Element;

import java.util.List;
import java.util.ArrayList;

/**
 * Handles retrieving list of admins from Clearspace.
 *
 * @author Daniel Henninger
 */
public class ClearspaceAdminProvider implements AdminProvider {

    // The UserService webservice url prefix
    protected static final String PERMISSION_URL_PREFIX = "permissionService/";

    long SYSTEM_ADMIN_PERM = 0x800000000000000L;

    public ClearspaceAdminProvider() {

    }

    /**
     * The clearspace provider pulls the admin list from the userPermissions web service
     * @see org.jivesoftware.openfire.admin.AdminProvider#getAdmins()
     */
    public List<JID> getAdmins() {
46 47 48 49
        try {
            String path = PERMISSION_URL_PREFIX + "userPermissions/"+SYSTEM_ADMIN_PERM+"/true";
            Log.debug("ClearspaceAdminProvider: permissions query url is: "+path);
            Element element = ClearspaceManager.getInstance().executeRequest(GET, path);
50

51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
            List<JID> admins = new ArrayList<JID>();
            for (String idStr : parseStringArray(element)) {
                Log.debug("Admin provider got ID number "+idStr);
                Long id = Long.valueOf(idStr);
                try {
                    String username = ClearspaceManager.getInstance().getUsernameByID(id);
                    Log.debug("Admin provider mapped to username "+username);
                    admins.add(XMPPServer.getInstance().createJID(username, null));
                }
                catch (UserNotFoundException e) {
                    // Hrm.  Got a response back that turned out not to exist?  This is "broken".
                }
            }
            return admins;
        } catch (Exception e) {
            // It is not supported exception, wrap it into an UnsupportedOperationException
            throw new UnsupportedOperationException("Unexpected error", e);
        }
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
    }

    /**
     * The clearspace provider does not allow setting admin lists from this interface
     * @see org.jivesoftware.openfire.admin.AdminProvider#setAdmins(java.util.List)  
     */
    public void setAdmins(List<JID> admins) {
        // Silently do nothing.  This shouldn't come up, but more inportantly, we don't want to bother Clearspace.
    }

    /**
     * The clearspace provider is read only
     * @see org.jivesoftware.openfire.admin.AdminProvider#isReadOnly()
     */
    public boolean isReadOnly() {
84
        return true;
85 86 87
    }

}