Cleaned up the fine-grained permissions system a bit so that Yohoho can make
use of it in good conscience. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5117 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1358,7 +1358,7 @@ public class ChatDirector extends BasicDirector
|
|||||||
|
|
||||||
public boolean checkAccess (BodyObject user)
|
public boolean checkAccess (BodyObject user)
|
||||||
{
|
{
|
||||||
return user.checkAccess(ChatCodes.BROADCAST_ACCESS, null) == null;
|
return user.checkAccess(ChatCodes.BROADCAST_ACCESS) == null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
package com.threerings.crowd.chat.data;
|
package com.threerings.crowd.chat.data;
|
||||||
|
|
||||||
import com.threerings.presents.data.InvocationCodes;
|
import com.threerings.presents.data.InvocationCodes;
|
||||||
|
import com.threerings.presents.data.Permission;
|
||||||
|
|
||||||
import com.threerings.crowd.data.BodyObject;
|
import com.threerings.crowd.data.BodyObject;
|
||||||
|
|
||||||
@@ -40,13 +41,11 @@ 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
|
/** The access control identifier for normal chat privileges. */
|
||||||
* BodyObject#checkAccess}. */
|
public static final Permission CHAT_ACCESS = new Permission();
|
||||||
public static final String CHAT_ACCESS = "crowd.chat.chat";
|
|
||||||
|
|
||||||
/** The access control identifier for broadcast chat privileges. See {@link
|
/** The access control identifier for broadcast chat privileges. */
|
||||||
* BodyObject#checkAccess}. */
|
public static final Permission BROADCAST_ACCESS = new Permission();
|
||||||
public static final String BROADCAST_ACCESS = "crowd.chat.broadcast";
|
|
||||||
|
|
||||||
/** The configuration key for idle time. */
|
/** The configuration key for idle time. */
|
||||||
public static final String IDLE_TIME_KEY = "narya.chat.idle_time";
|
public static final String IDLE_TIME_KEY = "narya.chat.idle_time";
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ import com.threerings.crowd.chat.data.UserMessage;
|
|||||||
* The chat provider handles the server side of the chat-related invocation services.
|
* The chat provider handles the server side of the chat-related invocation services.
|
||||||
*/
|
*/
|
||||||
public class ChatProvider
|
public class ChatProvider
|
||||||
implements ChatCodes, InvocationProvider
|
implements InvocationProvider
|
||||||
{
|
{
|
||||||
/** Interface to allow an auto response to a tell message. */
|
/** Interface to allow an auto response to a tell message. */
|
||||||
public static interface TellAutoResponder
|
public static interface TellAutoResponder
|
||||||
@@ -128,13 +128,10 @@ public class ChatProvider
|
|||||||
throws InvocationException
|
throws InvocationException
|
||||||
{
|
{
|
||||||
// ensure that the caller has normal chat privileges
|
// ensure that the caller has normal chat privileges
|
||||||
BodyObject source = (BodyObject)caller;
|
InvocationException.requireAccess(caller, ChatCodes.CHAT_ACCESS);
|
||||||
String errmsg = source.checkAccess(CHAT_ACCESS, null);
|
|
||||||
if (errmsg != null) {
|
|
||||||
throw new InvocationException(errmsg);
|
|
||||||
}
|
|
||||||
|
|
||||||
// deliver the tell message to the target
|
// deliver the tell message to the target
|
||||||
|
BodyObject source = (BodyObject)caller;
|
||||||
deliverTell(createTellMessage(source, message), target, listener);
|
deliverTell(createTellMessage(source, message), target, listener);
|
||||||
|
|
||||||
// inform the auto-responder if needed
|
// inform the auto-responder if needed
|
||||||
@@ -151,11 +148,8 @@ public class ChatProvider
|
|||||||
throws InvocationException
|
throws InvocationException
|
||||||
{
|
{
|
||||||
// make sure the requesting user has broadcast privileges
|
// make sure the requesting user has broadcast privileges
|
||||||
|
InvocationException.requireAccess(caller, ChatCodes.BROADCAST_ACCESS);
|
||||||
BodyObject body = (BodyObject)caller;
|
BodyObject body = (BodyObject)caller;
|
||||||
String errmsg = body.checkAccess(BROADCAST_ACCESS, null);
|
|
||||||
if (errmsg != null) {
|
|
||||||
throw new InvocationException(errmsg);
|
|
||||||
}
|
|
||||||
broadcast(body.getVisibleName(), null, message, false, true);
|
broadcast(body.getVisibleName(), null, message, false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -215,12 +209,12 @@ public class ChatProvider
|
|||||||
if (_chatForwarder != null && _chatForwarder.forwardTell(message, target, listener)) {
|
if (_chatForwarder != null && _chatForwarder.forwardTell(message, target, listener)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
throw new InvocationException(USER_NOT_ONLINE);
|
throw new InvocationException(ChatCodes.USER_NOT_ONLINE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tobj.status == OccupantInfo.DISCONNECTED) {
|
if (tobj.status == OccupantInfo.DISCONNECTED) {
|
||||||
String errmsg = MessageBundle.compose(
|
String errmsg = MessageBundle.compose(
|
||||||
USER_DISCONNECTED, TimeUtil.getTimeOrderString(
|
ChatCodes.USER_DISCONNECTED, TimeUtil.getTimeOrderString(
|
||||||
System.currentTimeMillis() - tobj.statusTime, TimeUtil.SECOND));
|
System.currentTimeMillis() - tobj.statusTime, TimeUtil.SECOND));
|
||||||
throw new InvocationException(errmsg);
|
throw new InvocationException(errmsg);
|
||||||
}
|
}
|
||||||
@@ -275,7 +269,7 @@ public class ChatProvider
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
SpeakUtil.sendSpeak(object, from, bundle, msg, BROADCAST_MODE);
|
SpeakUtil.sendSpeak(object, from, bundle, msg, ChatCodes.BROADCAST_MODE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ 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.presents.data.InvocationCodes;
|
||||||
|
import com.threerings.presents.data.Permission;
|
||||||
|
|
||||||
import com.threerings.crowd.chat.data.ChatCodes;
|
import com.threerings.crowd.chat.data.ChatCodes;
|
||||||
import com.threerings.crowd.chat.data.SpeakObject;
|
import com.threerings.crowd.chat.data.SpeakObject;
|
||||||
@@ -87,27 +88,6 @@ public class BodyObject extends ClientObject
|
|||||||
return (location == null) ? -1 : location.placeOid;
|
return (location == null) ? -1 : location.placeOid;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks whether or not this user has access to the specified 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 String checkAccess (String feature, Object context)
|
|
||||||
{
|
|
||||||
// our default access control policy; how quaint
|
|
||||||
if (ChatCodes.BROADCAST_ACCESS.equals(feature)) {
|
|
||||||
return getTokens().isAdmin() ? null : ChatCodes.ACCESS_DENIED;
|
|
||||||
} else if (ChatCodes.CHAT_ACCESS.equals(feature)) {
|
|
||||||
return null;
|
|
||||||
} else {
|
|
||||||
return InvocationCodes.ACCESS_DENIED;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns this user's access control tokens.
|
* Returns this user's access control tokens.
|
||||||
*/
|
*/
|
||||||
@@ -157,6 +137,18 @@ public class BodyObject extends ClientObject
|
|||||||
setLocation(null);
|
setLocation(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override // from ClientObject
|
||||||
|
public String checkAccess (Permission perm, Object context)
|
||||||
|
{
|
||||||
|
if (perm == ChatCodes.BROADCAST_ACCESS) {
|
||||||
|
return getTokens().isAdmin() ? null : ChatCodes.ACCESS_DENIED;
|
||||||
|
} else if (perm == ChatCodes.CHAT_ACCESS) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
return super.checkAccess(perm, context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// documentation inherited
|
// documentation inherited
|
||||||
public void applyToListeners (ListenerOp op)
|
public void applyToListeners (ListenerOp op)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -24,8 +24,9 @@ package com.threerings.crowd.data;
|
|||||||
import com.threerings.io.SimpleStreamableObject;
|
import com.threerings.io.SimpleStreamableObject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines access control tokens that convey certain privileges to users (see {@link
|
* Defines access control tokens that convey certain privileges to users.
|
||||||
* BodyObject#checkAccess}).
|
*
|
||||||
|
* @see BodyObject#checkAccess
|
||||||
*/
|
*/
|
||||||
public class TokenRing extends SimpleStreamableObject
|
public class TokenRing extends SimpleStreamableObject
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -27,10 +27,8 @@ import com.threerings.presents.dobj.DObject;
|
|||||||
import com.threerings.presents.dobj.DSet;
|
import com.threerings.presents.dobj.DSet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Every client in the system has an associated client object to which
|
* A distributed object to which only the client subscribes. Used to deliver messages solely to a
|
||||||
* only they subscribe. The client object can be used to deliver messages
|
* particular client as well as to publish client-specific data.
|
||||||
* solely to a particular client as well as to publish client-specific
|
|
||||||
* data.
|
|
||||||
*/
|
*/
|
||||||
public class ClientObject extends DObject
|
public class ClientObject extends DObject
|
||||||
{
|
{
|
||||||
@@ -39,14 +37,12 @@ public class ClientObject extends DObject
|
|||||||
public static final String RECEIVERS = "receivers";
|
public static final String RECEIVERS = "receivers";
|
||||||
// AUTO-GENERATED: FIELDS END
|
// AUTO-GENERATED: FIELDS END
|
||||||
|
|
||||||
/** The name of a message event delivered to the client when they
|
/** The name of a message event delivered to the client when they switch usernames (and
|
||||||
* switch usernames (and therefore user objects). */
|
* therefore user objects). */
|
||||||
public static final String CLOBJ_CHANGED = "!clobj_changed!";
|
public static final String CLOBJ_CHANGED = "!clobj_changed!";
|
||||||
|
|
||||||
/** Used to publish all invocation service receivers registered on
|
/** Used to publish all invocation service receivers registered on this client. */
|
||||||
* this client. */
|
public DSet<InvocationReceiver.Registration> receivers = DSet.newDSet();
|
||||||
public DSet<InvocationReceiver.Registration> receivers =
|
|
||||||
new DSet<InvocationReceiver.Registration>();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a short string identifying this client.
|
* Returns a short string identifying this client.
|
||||||
@@ -56,6 +52,27 @@ public class ClientObject extends DObject
|
|||||||
return "(" + getOid() + ")";
|
return "(" + getOid() + ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether or not this client has access to the specified feature. 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 String checkAccess (Permission feature, Object context)
|
||||||
|
{
|
||||||
|
return InvocationCodes.ACCESS_DENIED;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A version of {@link #checkAccess(Permission,Object} that provides no context.
|
||||||
|
*/
|
||||||
|
public String checkAccess (Permission feature)
|
||||||
|
{
|
||||||
|
return checkAccess(feature, null);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used for reference counting client objects, adds a reference to
|
* Used for reference counting client objects, adds a reference to
|
||||||
* this object.
|
* this object.
|
||||||
@@ -81,9 +98,6 @@ public class ClientObject extends DObject
|
|||||||
return (--_references > 0);
|
return (--_references > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Used to reference count resolved client objects. */
|
|
||||||
protected transient int _references;
|
|
||||||
|
|
||||||
// AUTO-GENERATED: METHODS START
|
// AUTO-GENERATED: METHODS START
|
||||||
/**
|
/**
|
||||||
* Requests that the specified entry be added to the
|
* Requests that the specified entry be added to the
|
||||||
@@ -133,4 +147,7 @@ public class ClientObject extends DObject
|
|||||||
this.receivers = clone;
|
this.receivers = clone;
|
||||||
}
|
}
|
||||||
// AUTO-GENERATED: METHODS END
|
// AUTO-GENERATED: METHODS END
|
||||||
|
|
||||||
|
/** Used to reference count resolved client objects. */
|
||||||
|
protected transient int _references;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
//
|
||||||
|
// $Id$
|
||||||
|
//
|
||||||
|
// Narya library - tools for developing networked games
|
||||||
|
// Copyright (C) 2002-2008 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.presents.data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A value class used by {@link ClientObject#checkAccess} to do fine-grained access control.
|
||||||
|
*/
|
||||||
|
public class Permission
|
||||||
|
{
|
||||||
|
}
|
||||||
@@ -65,6 +65,22 @@ public class DSet<E extends DSet.Entry>
|
|||||||
public Comparable getKey ();
|
public Comparable getKey ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new DSet of the appropriate generic type.
|
||||||
|
*/
|
||||||
|
public static <E extends DSet.Entry> DSet<E> newDSet ()
|
||||||
|
{
|
||||||
|
return new DSet<E>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new DSet of the appropriate generic type.
|
||||||
|
*/
|
||||||
|
public static <E extends DSet.Entry> DSet<E> newDSet (Iterable<E> source)
|
||||||
|
{
|
||||||
|
return new DSet<E>(source);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a distributed set and populates it with values from the supplied iterator. This
|
* Creates a distributed set and populates it with values from the supplied iterator. This
|
||||||
* should be done before the set is unleashed into the wild distributed object world because no
|
* should be done before the set is unleashed into the wild distributed object world because no
|
||||||
|
|||||||
@@ -23,11 +23,37 @@ package com.threerings.presents.server;
|
|||||||
|
|
||||||
import com.threerings.util.MessageBundle;
|
import com.threerings.util.MessageBundle;
|
||||||
|
|
||||||
|
import com.threerings.presents.data.ClientObject;
|
||||||
|
import com.threerings.presents.data.Permission;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to report failures when executing service requests.
|
* Used to report failures when executing service requests.
|
||||||
*/
|
*/
|
||||||
public class InvocationException extends Exception
|
public class InvocationException extends Exception
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Requires that the specified client have the specified permissions.
|
||||||
|
*
|
||||||
|
* @throws InvocationException if they do not.
|
||||||
|
*/
|
||||||
|
public static void requireAccess (ClientObject clobj, Permission perm, Object context)
|
||||||
|
throws InvocationException
|
||||||
|
{
|
||||||
|
String errmsg = clobj.checkAccess(perm, context);
|
||||||
|
if (errmsg != null) {
|
||||||
|
throw new InvocationException(errmsg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A version of {@link #requireAccess} that takes no context.
|
||||||
|
*/
|
||||||
|
public static void requireAccess (ClientObject clobj, Permission perm)
|
||||||
|
throws InvocationException
|
||||||
|
{
|
||||||
|
requireAccess(clobj, perm);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs an invocation exception with the supplied cause code
|
* Constructs an invocation exception with the supplied cause code
|
||||||
* string.
|
* string.
|
||||||
|
|||||||
Reference in New Issue
Block a user