We can't use the type systesm to enforce our requirements, but we can use

obtain containment and a stack of specifically typed outer class references to
accomplish what we need without misleading casts.

This will require changes to Yohoho which I shall make forthwith.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6320 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2010-11-30 18:35:58 +00:00
parent 99795a972c
commit 9c9129a796
8 changed files with 54 additions and 126 deletions
@@ -25,7 +25,9 @@ import javax.annotation.Generated;
import com.threerings.util.Name;
import com.threerings.presents.data.ClientObject;
import com.threerings.presents.data.Permission;
import com.threerings.crowd.chat.data.ChatCodes;
import com.threerings.crowd.chat.data.SpeakObject;
/**
@@ -210,6 +212,26 @@ public class BodyObject extends ClientObject
return OccupantInfo.X_STATUS[status];
}
@Override
protected PermissionPolicy createPermissionPolicy ()
{
return new CrowdPermissionPolicy();
}
protected class CrowdPermissionPolicy extends PermissionPolicy
{
@Override // from PermissionPolicy
public String checkAccess (Permission perm, Object context) {
if (perm == ChatCodes.BROADCAST_ACCESS) {
return getTokens().isAdmin() ? null : ACCESS_DENIED;
} else if (perm == ChatCodes.CHAT_ACCESS) {
return null;
} else {
return super.checkAccess(perm, context);
}
}
}
/** The default (no tokens) access control. */
protected static final TokenRing EMPTY_TOKENS = new TokenRing();
}
@@ -1,49 +0,0 @@
//
// $Id$
//
// Narya library - tools for developing networked games
// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
// http://code.google.com/p/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.data;
import com.threerings.presents.data.ClientObject;
import com.threerings.presents.data.Permission;
import com.threerings.presents.data.PermissionPolicy;
import com.threerings.crowd.chat.data.ChatCodes;
/**
* Implements some Crowd permissions. Note: this is stored <em>inside</em> a {@link BodyObject} and
* will only ever be called by a BodyObject. It is sent over the wire and must be usable on the
* client and server.
*/
public class CrowdPermissionPolicy extends PermissionPolicy
{
@Override // from PermissionPolicy
public String checkAccess (ClientObject clobj, Permission perm, Object context)
{
BodyObject body = (BodyObject)clobj;
if (perm == ChatCodes.BROADCAST_ACCESS) {
return body.getTokens().isAdmin() ? null : ACCESS_DENIED;
} else if (perm == ChatCodes.CHAT_ACCESS) {
return null;
} else {
return super.checkAccess(clobj, perm, context);
}
}
}
@@ -26,7 +26,7 @@ import com.threerings.io.SimpleStreamableObject;
/**
* Defines access control tokens that convey certain privileges to users.
*
* @see CrowdPermissionPolicy
* @see BodyObject#CrowdPermissionPolicy
*/
public class TokenRing extends SimpleStreamableObject
{
@@ -22,12 +22,10 @@
package com.threerings.crowd.server;
import com.threerings.presents.data.ClientObject;
import com.threerings.presents.data.PermissionPolicy;
import com.threerings.presents.server.ClientLocal;
import com.threerings.presents.server.ClientResolver;
import com.threerings.crowd.data.BodyObject;
import com.threerings.crowd.data.CrowdPermissionPolicy;
/**
* Used to configure crowd-specific client object data.
@@ -45,10 +43,4 @@ public class CrowdClientResolver extends ClientResolver
{
return new BodyLocal();
}
@Override // from ClientResolver
public PermissionPolicy createPermissionPolicy ()
{
return new CrowdPermissionPolicy();
}
}