Multiuser Protection and the Mediator Pattern CSE 432

  • Slides: 16
Download presentation
Multiuser Protection and the Mediator Pattern CSE 432 02/22/2006 Matt Brenneke

Multiuser Protection and the Mediator Pattern CSE 432 02/22/2006 Matt Brenneke

Multiuser Protection l Follow Unix design, user and other l Users must have a

Multiuser Protection l Follow Unix design, user and other l Users must have a login name l Basic authentication, user must provide login name and password

User Object Restrictions l Clients can’t create User objects at will l User object

User Object Restrictions l Clients can’t create User objects at will l User object must always have a valid login name l Client can’t instantiate a user w/o name and password

Creation l l l Abstract Factory? No, Families of Objects Builder? No, different representation

Creation l l l Abstract Factory? No, Families of Objects Builder? No, different representation Factory Method? No, similar to Abstract Fact. Prototype? No, What, not How Singleton? Bingo!

Singleton - modified l Authentication – – – l Call Intantiate() log. In(), and

Singleton - modified l Authentication – – – l Call Intantiate() log. In(), and add user and password parameters. Can return 0 if user or password is invalid Client can’t change log. In() by subclassing User Multiple User objects – – Keeps a hash of User objects Only one User object per username

Reading a file l Before – l stream. Out(ostream&); Now – stream. Out(ostream&, User*);

Reading a file l Before – l stream. Out(ostream&); Now – stream. Out(ostream&, User*);

Common case l Give the user parameter a default value – l void stream.

Common case l Give the user parameter a default value – l void stream. Out(ostream&, const User* = 0); Add set. User and get. User functions to the User class – – static const User* User: : get. User(); static void User: : set. User(const User*);

stream. Out() changes l Check for User* == 0 – Call User: : get.

stream. Out() changes l Check for User* == 0 – Call User: : get. User() if true l is. Readable() -> is. Readable. By(user) l is. Readable. By checks User->get. Login. Name against the Node’s owner.

Groups? l Groups have zero or more users. l A user can be a

Groups? l Groups have zero or more users. l A user can be a member of zero or more groups.

Group Object Representation l Composite? No – – – l Groups aren’t recursive A

Group Object Representation l Composite? No – – – l Groups aren’t recursive A user might belong to several groups Don’t want to treat groups and users the same Mediator! – – Relationship between groups and nodes is complex and variable Needs loose coupling

Mediator Overview l Intent – – – Encapsulate how a set of objects interact

Mediator Overview l Intent – – – Encapsulate how a set of objects interact Promote loose coupling Allows you to vary interaction independently

Mediator Participants l Mediator – l Concrete. Mediator (optional) – – l Interface for

Mediator Participants l Mediator – l Concrete. Mediator (optional) – – l Interface for communicating with Colleagues Implements coordination between Colleagues Knows and maintains its Colleague classes – – Knows its mediator class Communicates with Mediator only

Mediator Consequences l l l Limits Subclassing Decouples Colleagues Simplifies object protocols Abstracts how

Mediator Consequences l l l Limits Subclassing Decouples Colleagues Simplifies object protocols Abstracts how objects cooperate Centralizes control – May become monolithic itself

Applied to Groups Mediator Grouping Users Groups

Applied to Groups Mediator Grouping Users Groups

Group Class members l l l static get. Grouping() static set. Grouping(Grouping*, User*); register(User*,

Group Class members l l l static get. Grouping() static set. Grouping(Grouping*, User*); register(User*, Group*, User*); unregister(User*, Group*, User*); get. Group(string, index); get. User(Group, index);

Wrapping Up Chapter 2 l l l Composite provides structure Proxy provides symlinks Visitor

Wrapping Up Chapter 2 l l l Composite provides structure Proxy provides symlinks Visitor allows new, type specific functionality Template Method provided basic protection Singleton and Mediator combine to allow full Multi-user protection