Further refinement of the permissions system. Eliminated the

CommunicationAuthorizer and rolled that into the BodyObject-based
permissions system. A victory for consolidation and elegance.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3380 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2005-03-03 04:47:57 +00:00
parent bc837ca289
commit c2e2661e66
6 changed files with 45 additions and 93 deletions
@@ -34,6 +34,10 @@ public interface ChatCodes extends InvocationCodes
/** The message identifier for a chat notification message. */ /** The message identifier for a chat notification message. */
public static final String CHAT_NOTIFICATION = "chat"; public static final String CHAT_NOTIFICATION = "chat";
/** The access control identifier for normal chat privileges. See
* {@link BodyObject#checkAccess}. */
public static final String CHAT_ACCESS = "crowd.chat.chat";
/** The access control identifier for broadcast chat privileges. See /** The access control identifier for broadcast chat privileges. See
* {@link BodyObject#checkAccess}. */ * {@link BodyObject#checkAccess}. */
public static final String BROADCAST_ACCESS = "crowd.chat.broadcast"; public static final String BROADCAST_ACCESS = "crowd.chat.broadcast";
@@ -74,16 +74,6 @@ public class ChatProvider
_autoRespond = autoRespond; _autoRespond = autoRespond;
} }
/**
* Set the authorizer we will use to see if the user is allowed to
* perform various chatting actions.
*/
public static void setCommunicationAuthorizer (
CommunicationAuthorizer comAuth)
{
_comAuth = comAuth;
}
/** /**
* Set an object to which all broadcasts should be sent, rather * Set an object to which all broadcasts should be sent, rather
* than iterating over the place objects and sending to each of them. * than iterating over the place objects and sending to each of them.
@@ -117,9 +107,11 @@ public class ChatProvider
TellListener listener) TellListener listener)
throws InvocationException throws InvocationException
{ {
// make sure the caller is authorized to perform this action // ensure that the caller has normal chat privileges
if ((_comAuth != null) && (!_comAuth.authorized(caller))) { BodyObject source = (BodyObject)caller;
return; String errmsg = source.checkAccess(CHAT_ACCESS, null);
if (errmsg != null) {
throw new InvocationException(errmsg);
} }
// make sure the target user is online // make sure the target user is online
@@ -136,7 +128,6 @@ public class ChatProvider
} }
// deliver a tell notification to the target player // deliver a tell notification to the target player
BodyObject source = (BodyObject)caller;
sendTellMessage(tobj, source.username, null, message); sendTellMessage(tobj, source.username, null, message);
// let the teller know it went ok // let the teller know it went ok
@@ -163,11 +154,11 @@ public class ChatProvider
InvocationListener listener) InvocationListener listener)
throws InvocationException throws InvocationException
{ {
BodyObject body = (BodyObject)caller;
// make sure the requesting user has broadcast privileges // make sure the requesting user has broadcast privileges
if (!body.checkAccess(BROADCAST_ACCESS, null)) { BodyObject body = (BodyObject)caller;
throw new InvocationException(ACCESS_DENIED); String errmsg = body.checkAccess(BROADCAST_ACCESS, null);
if (errmsg != null) {
throw new InvocationException(errmsg);
} }
broadcast(body.username, null, message, false); broadcast(body.username, null, message, false);
@@ -247,8 +238,8 @@ public class ChatProvider
public static void sendTellMessage ( public static void sendTellMessage (
BodyObject target, Name speaker, String bundle, String message) BodyObject target, Name speaker, String bundle, String message)
{ {
UserMessage msg = UserMessage msg = new UserMessage(
new UserMessage(message, bundle, speaker, DEFAULT_MODE); message, bundle, speaker, DEFAULT_MODE);
SpeakProvider.sendMessage(target, msg); SpeakProvider.sendMessage(target, msg);
// note that the teller "heard" what they said // note that the teller "heard" what they said
@@ -261,9 +252,6 @@ public class ChatProvider
/** Reference to our auto responder object. */ /** Reference to our auto responder object. */
protected static TellAutoResponder _autoRespond; protected static TellAutoResponder _autoRespond;
/** The entity that will authorize our chatters. */
protected static CommunicationAuthorizer _comAuth;
/** An alternative object to which broadcasts should be sent. */ /** An alternative object to which broadcasts should be sent. */
protected static DObject _broadcastObject; protected static DObject _broadcastObject;
} }
@@ -1,33 +0,0 @@
//
// $Id: CommunicationAuthorizer.java,v 1.2 2004/08/27 02:12:32 mdb Exp $
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved
// http://www.threerings.net/code/narya/
//
// This library is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2.1 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.threerings.crowd.chat.server;
import com.threerings.presents.data.ClientObject;
/**
* An interface used to check and see if the specified client is allowed
* to make said communication.
*/
public interface CommunicationAuthorizer
{
public boolean authorized (ClientObject caller);
}
@@ -93,16 +93,6 @@ public class SpeakProvider
_validator = validator; _validator = validator;
} }
/**
* Set the authorizer we will use to see if the user is allowed to
* perform various speaking actions.
*/
public static void setCommunicationAuthorizer (
CommunicationAuthorizer comAuth)
{
_comAuth = comAuth;
}
/** /**
* Registers a {@link MessageObserver} to be notified whenever a * Registers a {@link MessageObserver} to be notified whenever a
* user-originated chat message is heard by another user. * user-originated chat message is heard by another user.
@@ -126,8 +116,14 @@ public class SpeakProvider
*/ */
public void speak (ClientObject caller, String message, byte mode) public void speak (ClientObject caller, String message, byte mode)
{ {
// make sure the caller is authorized to perform this action // ensure that the caller has normal chat privileges
if ((_comAuth != null) && (!_comAuth.authorized(caller))) { BodyObject source = (BodyObject)caller;
String errmsg = source.checkAccess(CHAT_ACCESS, null);
if (errmsg != null) {
// we normally don't listen for responses to speak messages so
// we can't just throw an InvocationException we have to
// specifically communicate the error to the user
sendFeedback(source, null, errmsg);
return; return;
} }
@@ -145,8 +141,7 @@ public class SpeakProvider
} else { } else {
// issue the speak message on our speak object // issue the speak message on our speak object
sendSpeak(_speakObj, ((BodyObject)caller).username, sendSpeak(_speakObj, source.username, null, message, mode);
null, message, mode);
} }
} }
@@ -409,9 +404,6 @@ public class SpeakProvider
/** The entity that will validate our speakers. */ /** The entity that will validate our speakers. */
protected SpeakerValidator _validator; protected SpeakerValidator _validator;
/** The entity that will authorize our speakers. */
protected static CommunicationAuthorizer _comAuth;
/** Recent chat history for the server. */ /** Recent chat history for the server. */
protected static HashMap _histories = new HashMap(); protected static HashMap _histories = new HashMap();
@@ -24,6 +24,9 @@ package com.threerings.crowd.data;
import com.threerings.util.Name; import com.threerings.util.Name;
import com.threerings.presents.data.ClientObject; import com.threerings.presents.data.ClientObject;
import com.threerings.presents.data.InvocationCodes;
import com.threerings.crowd.chat.data.ChatCodes;
import com.threerings.crowd.chat.data.SpeakObject; import com.threerings.crowd.chat.data.SpeakObject;
/** /**
@@ -80,10 +83,20 @@ public class BodyObject extends ClientObject
* feature. Currently used by the chat system to regulate access to * feature. Currently used by the chat system to regulate access to
* chat broadcasts but also forms the basis of an extensible * chat broadcasts but also forms the basis of an extensible
* fine-grained permissions system. * fine-grained permissions system.
*
* @return null if the user has access, a fully-qualified translatable
* message string indicating the reason for denial of access (or just
* {@link InvocationCodes#ACCESS_DENIED} if you don't want to be
* specific).
*/ */
public boolean checkAccess (String feature, Object context) public String checkAccess (String feature, Object context)
{ {
return false; // our default access control policy; how quaint
if (ChatCodes.CHAT_ACCESS.equals(feature)) {
return null;
} else {
return InvocationCodes.ACCESS_DENIED;
}
} }
// documentation inherited // documentation inherited
@@ -29,7 +29,7 @@ import com.threerings.presents.dobj.RootDObjectManager;
import com.threerings.presents.server.InvocationException; import com.threerings.presents.server.InvocationException;
import com.threerings.presents.server.InvocationProvider; import com.threerings.presents.server.InvocationProvider;
import com.threerings.crowd.chat.server.CommunicationAuthorizer; import com.threerings.crowd.chat.data.ChatCodes;
import com.threerings.crowd.data.BodyObject; import com.threerings.crowd.data.BodyObject;
import com.threerings.crowd.server.PlaceRegistry; import com.threerings.crowd.server.PlaceRegistry;
@@ -64,16 +64,6 @@ public class SpotProvider
_omgr = omgr; _omgr = omgr;
} }
/**
* Set the authorizer we will use to see if the user is allowed to
* perform various chatting actions.
*/
public static void setCommunicationAuthorizer (
CommunicationAuthorizer comAuth)
{
_comAuth = comAuth;
}
/** /**
* Processes a {@link SpotService#traversePortal} request. * Processes a {@link SpotService#traversePortal} request.
*/ */
@@ -250,12 +240,13 @@ public class SpotProvider
public void clusterSpeak (ClientObject caller, String message, byte mode) public void clusterSpeak (ClientObject caller, String message, byte mode)
throws InvocationException throws InvocationException
{ {
// make sure the caller is authorized to perform this action // ensure the caller has normal chat access
if ((_comAuth != null) && (!_comAuth.authorized(caller))) { BodyObject source = (BodyObject)caller;
return; String errmsg = source.checkAccess(ChatCodes.CHAT_ACCESS, null);
if (errmsg != null) {
throw new InvocationException(errmsg);
} }
BodyObject source = (BodyObject)caller;
sendClusterChatMessage(getCallerSceneId(caller), source.getOid(), sendClusterChatMessage(getCallerSceneId(caller), source.getOid(),
source.username, null, message, mode); source.username, null, message, mode);
} }
@@ -323,7 +314,4 @@ public class SpotProvider
/** The object manager we use to do dobject stuff. */ /** The object manager we use to do dobject stuff. */
protected RootDObjectManager _omgr; protected RootDObjectManager _omgr;
/** The entity that will authorize our speaker. */
protected static CommunicationAuthorizer _comAuth;
} }