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:
@@ -34,6 +34,10 @@ public interface ChatCodes extends InvocationCodes
|
||||
/** The message identifier for a chat notification message. */
|
||||
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
|
||||
* {@link BodyObject#checkAccess}. */
|
||||
public static final String BROADCAST_ACCESS = "crowd.chat.broadcast";
|
||||
|
||||
@@ -74,16 +74,6 @@ public class ChatProvider
|
||||
_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
|
||||
* than iterating over the place objects and sending to each of them.
|
||||
@@ -117,9 +107,11 @@ public class ChatProvider
|
||||
TellListener listener)
|
||||
throws InvocationException
|
||||
{
|
||||
// make sure the caller is authorized to perform this action
|
||||
if ((_comAuth != null) && (!_comAuth.authorized(caller))) {
|
||||
return;
|
||||
// ensure that the caller has normal chat privileges
|
||||
BodyObject source = (BodyObject)caller;
|
||||
String errmsg = source.checkAccess(CHAT_ACCESS, null);
|
||||
if (errmsg != null) {
|
||||
throw new InvocationException(errmsg);
|
||||
}
|
||||
|
||||
// make sure the target user is online
|
||||
@@ -136,7 +128,6 @@ public class ChatProvider
|
||||
}
|
||||
|
||||
// deliver a tell notification to the target player
|
||||
BodyObject source = (BodyObject)caller;
|
||||
sendTellMessage(tobj, source.username, null, message);
|
||||
|
||||
// let the teller know it went ok
|
||||
@@ -163,11 +154,11 @@ public class ChatProvider
|
||||
InvocationListener listener)
|
||||
throws InvocationException
|
||||
{
|
||||
BodyObject body = (BodyObject)caller;
|
||||
|
||||
// make sure the requesting user has broadcast privileges
|
||||
if (!body.checkAccess(BROADCAST_ACCESS, null)) {
|
||||
throw new InvocationException(ACCESS_DENIED);
|
||||
BodyObject body = (BodyObject)caller;
|
||||
String errmsg = body.checkAccess(BROADCAST_ACCESS, null);
|
||||
if (errmsg != null) {
|
||||
throw new InvocationException(errmsg);
|
||||
}
|
||||
|
||||
broadcast(body.username, null, message, false);
|
||||
@@ -247,8 +238,8 @@ public class ChatProvider
|
||||
public static void sendTellMessage (
|
||||
BodyObject target, Name speaker, String bundle, String message)
|
||||
{
|
||||
UserMessage msg =
|
||||
new UserMessage(message, bundle, speaker, DEFAULT_MODE);
|
||||
UserMessage msg = new UserMessage(
|
||||
message, bundle, speaker, DEFAULT_MODE);
|
||||
SpeakProvider.sendMessage(target, msg);
|
||||
|
||||
// note that the teller "heard" what they said
|
||||
@@ -261,9 +252,6 @@ public class ChatProvider
|
||||
/** Reference to our auto responder object. */
|
||||
protected static TellAutoResponder _autoRespond;
|
||||
|
||||
/** The entity that will authorize our chatters. */
|
||||
protected static CommunicationAuthorizer _comAuth;
|
||||
|
||||
/** An alternative object to which broadcasts should be sent. */
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* 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)
|
||||
{
|
||||
// make sure the caller is authorized to perform this action
|
||||
if ((_comAuth != null) && (!_comAuth.authorized(caller))) {
|
||||
// ensure that the caller has normal chat privileges
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -145,8 +141,7 @@ public class SpeakProvider
|
||||
|
||||
} else {
|
||||
// issue the speak message on our speak object
|
||||
sendSpeak(_speakObj, ((BodyObject)caller).username,
|
||||
null, message, mode);
|
||||
sendSpeak(_speakObj, source.username, null, message, mode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -409,9 +404,6 @@ public class SpeakProvider
|
||||
|
||||
/** The entity that will validate our speakers. */
|
||||
protected SpeakerValidator _validator;
|
||||
|
||||
/** The entity that will authorize our speakers. */
|
||||
protected static CommunicationAuthorizer _comAuth;
|
||||
|
||||
/** Recent chat history for the server. */
|
||||
protected static HashMap _histories = new HashMap();
|
||||
|
||||
@@ -24,6 +24,9 @@ package com.threerings.crowd.data;
|
||||
import com.threerings.util.Name;
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
@@ -80,10 +83,20 @@ public class BodyObject extends ClientObject
|
||||
* feature. Currently used by the chat system to regulate access to
|
||||
* chat broadcasts but also forms the basis of an extensible
|
||||
* 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
|
||||
|
||||
@@ -29,7 +29,7 @@ import com.threerings.presents.dobj.RootDObjectManager;
|
||||
import com.threerings.presents.server.InvocationException;
|
||||
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.server.PlaceRegistry;
|
||||
|
||||
@@ -64,16 +64,6 @@ public class SpotProvider
|
||||
_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.
|
||||
*/
|
||||
@@ -250,12 +240,13 @@ public class SpotProvider
|
||||
public void clusterSpeak (ClientObject caller, String message, byte mode)
|
||||
throws InvocationException
|
||||
{
|
||||
// make sure the caller is authorized to perform this action
|
||||
if ((_comAuth != null) && (!_comAuth.authorized(caller))) {
|
||||
return;
|
||||
// ensure the caller has normal chat access
|
||||
BodyObject source = (BodyObject)caller;
|
||||
String errmsg = source.checkAccess(ChatCodes.CHAT_ACCESS, null);
|
||||
if (errmsg != null) {
|
||||
throw new InvocationException(errmsg);
|
||||
}
|
||||
|
||||
BodyObject source = (BodyObject)caller;
|
||||
sendClusterChatMessage(getCallerSceneId(caller), source.getOid(),
|
||||
source.username, null, message, mode);
|
||||
}
|
||||
@@ -323,7 +314,4 @@ public class SpotProvider
|
||||
|
||||
/** The object manager we use to do dobject stuff. */
|
||||
protected RootDObjectManager _omgr;
|
||||
|
||||
/** The entity that will authorize our speaker. */
|
||||
protected static CommunicationAuthorizer _comAuth;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user